Skip to content

Commit

Permalink
feat(build): add approve build method to build service
Browse files Browse the repository at this point in the history
  • Loading branch information
ecrupper committed Dec 11, 2023
1 parent 51b27c4 commit 5338377
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 6 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ require (
github.com/buildkite/yaml v0.0.0-20230306222819-0e4e032d4835
github.com/coreos/go-semver v0.3.1
github.com/gin-gonic/gin v1.9.1
github.com/go-vela/server v0.22.0
github.com/go-vela/types v0.22.0
github.com/go-vela/server v0.22.3-0.20231211205434-140d2b1492b7
github.com/go-vela/types v0.22.1-0.20231211143329-1eae2f5e371b
github.com/golang-jwt/jwt/v5 v5.1.0
github.com/google/go-cmp v0.6.0
github.com/google/go-querystring v1.1.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg/+t63MyGU2n5js=
github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
github.com/go-vela/server v0.22.0 h1:zzr7g7sm2Z2mn8hAGlD3wqFHzj8rnQCb4KiCIjTyX1I=
github.com/go-vela/server v0.22.0/go.mod h1:DidWsP+FCWot5ePim0jjvQqhaheOKjSMoVtAfXeNTyU=
github.com/go-vela/types v0.22.0 h1:JmAQ9Hy4HnOgbgNsNz5x1wu3Myv47KoC0rxR9x36OQ4=
github.com/go-vela/types v0.22.0/go.mod h1:ljNY36D6YkpObBbNF7Xslv3oxN4mGuQAwWhnnK/V06I=
github.com/go-vela/server v0.22.3-0.20231211205434-140d2b1492b7 h1:Ou1URiqOj+L56/3dzQgP5ov8dWRyOmW/N8aihZRxlX4=
github.com/go-vela/server v0.22.3-0.20231211205434-140d2b1492b7/go.mod h1:f8bWM2UGX+lKbCyaj11BQWQUSrc5pW7So0G+5BU7vkc=
github.com/go-vela/types v0.22.1-0.20231211143329-1eae2f5e371b h1:8rC4vEVWUFisc11LvGFOsVx76K1HmxxE+jub4s4sb0A=
github.com/go-vela/types v0.22.1-0.20231211143329-1eae2f5e371b/go.mod h1:ljNY36D6YkpObBbNF7Xslv3oxN4mGuQAwWhnnK/V06I=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/golang-jwt/jwt/v5 v5.1.0 h1:UGKbA/IPjtS6zLcdB7i5TyACMgSbOTiR8qzXgw8HWQU=
Expand Down
8 changes: 8 additions & 0 deletions vela/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ func (svc *BuildService) Cancel(org, repo string, build int) (*library.Build, *R
return v, resp, err
}

// Approve takes the build provided and approves it as an admin.
func (svc *BuildService) Approve(org, repo string, build int) (*Response, error) {
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d/approve", org, repo, build)

return svc.client.Call("POST", u, nil, nil)
}

// GetBuildToken returns an auth token for updating build resources.
func (svc *BuildService) GetBuildToken(org, repo string, build int) (*library.Token, *Response, error) {
// set the API endpoint path we send the request to
Expand Down
38 changes: 38 additions & 0 deletions vela/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,44 @@ func TestBuild_Cancel_404(t *testing.T) {
}
}

func TestBuild_Approve_200(t *testing.T) {
// setup context
gin.SetMode(gin.TestMode)

s := httptest.NewServer(server.FakeHandler())
c, _ := NewClient(s.URL, "", nil)

// run test
got, err := c.Build.Approve("github", "octocat", 1)

if err != nil {
t.Errorf("New returned err: %v", err)
}

if got.StatusCode != http.StatusOK {
t.Errorf("Build returned %v, want %v", got.StatusCode, http.StatusOK)
}
}

func TestBuild_Approve_403(t *testing.T) {
// setup context
gin.SetMode(gin.TestMode)

s := httptest.NewServer(server.FakeHandler())
c, _ := NewClient(s.URL, "", nil)

// run test
resp, err := c.Build.Approve("github", "octocat", 0)

if err == nil {
t.Errorf("New returned err: %v", err)
}

if resp.StatusCode != http.StatusForbidden {
t.Errorf("Build returned %v, want %v", resp.StatusCode, http.StatusOK)
}
}

func TestBuild_GetBuildToken_200(t *testing.T) {
// setup context
gin.SetMode(gin.TestMode)
Expand Down

0 comments on commit 5338377

Please sign in to comment.