-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: [CI-8780]: Added new API for decline build to avoid race condition #3499
Conversation
|
handler/api/api.go
Outdated
@@ -242,6 +242,10 @@ func (s Server) Handler() http.Handler { | |||
acl.CheckAdminAccess(), | |||
).Post("/{number}/decline/{stage}", stages.HandleDecline(s.Repos, s.Builds, s.Stages)) | |||
|
|||
r.With( | |||
acl.CheckAdminAccess(), | |||
).Post("/{number}/decline", stages.HandleDeclineV2(s.Repos, s.Builds, s.Stages)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename HandleDeclineV2
to HandleDeclineBuild
"github.com/go-chi/chi" | ||
) | ||
|
||
func HandleDeclineV2( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename file and the func to HandleDeclineBuild.go
and decline_build.go
return | ||
} | ||
|
||
stageList, err := stages.List(r.Context(), build.ID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: variable names in golang can be less verbose. prefer stages
over stageList
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since "stages" is already being used in method itself that's why went with "stageList"
|
||
for _, stage := range stageList { | ||
if stage.Status != core.StatusBlocked { | ||
err := fmt.Errorf("cannot decline build with status %q", stage.Status) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: errors should begin with uppercase
// this test verifies that a 400 bad request status is returned | ||
// from the http.Handler with a human-readable error message if | ||
// the build number url parameter fails to parse. | ||
func TestDecline_InvalidBuildNumberV2(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename the file from declineV2
to decline_build
@@ -0,0 +1,192 @@ | |||
// Copyright 2019 Drone.IO Inc. All rights reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good job on adding tests!
@@ -0,0 +1,192 @@ | |||
// Copyright 2019 Drone.IO Inc. All rights reserved. | |||
// Use of this source code is governed by the Drone Non-Commercial License |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: change the copyright year
No description provided.