Skip to content
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

Merged
merged 3 commits into from
Apr 16, 2024

Conversation

ShobhitSingh11
Copy link

No description provided.

@CLAassistant
Copy link

CLAassistant commented Apr 11, 2024

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@@ -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))
Copy link
Collaborator

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(
Copy link
Collaborator

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)
Copy link
Collaborator

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

Copy link
Author

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)
Copy link
Collaborator

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) {
Copy link
Collaborator

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.
Copy link
Collaborator

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
Copy link
Collaborator

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

@vistaarjuneja vistaarjuneja merged commit e1fc66e into drone Apr 16, 2024
@vistaarjuneja vistaarjuneja deleted the CI-8780 branch April 16, 2024 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants