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

Handle protection status errors for unprotected branches #2092

Merged
merged 2 commits into from
Dec 3, 2021

Conversation

hemachandarv
Copy link
Contributor

Resolves #625

@google-cla google-cla bot added the cla: yes Indication that the PR author has signed a Google Contributor License Agreement. label Sep 13, 2021
@hemachandarv
Copy link
Contributor Author

@gmlewis I've addressed #625 by returning an explicit error in the GET APIs. Do you think this is a good idea?

Also, do you think we should cover the same for the POST APIs too?

@codecov
Copy link

codecov bot commented Sep 13, 2021

Codecov Report

Merging #2092 (0035635) into master (88b13f9) will increase coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2092      +/-   ##
==========================================
+ Coverage   97.75%   97.78%   +0.03%     
==========================================
  Files         107      109       +2     
  Lines        9601     9733     +132     
==========================================
+ Hits         9385     9517     +132     
  Misses        150      150              
  Partials       66       66              
Impacted Files Coverage Δ
github/repos.go 98.66% <100.00%> (+0.01%) ⬆️
github/event.go 100.00% <0.00%> (ø)
github/messages.go 100.00% <0.00%> (ø)
github/actions_runner_groups.go 100.00% <0.00%> (ø)
github/actions_workflow_runs.go 100.00% <0.00%> (ø)
github/orgs_hooks_deliveries.go 100.00% <0.00%> (ø)
github/repos_community_health.go 100.00% <0.00%> (ø)
github/repos_autolinks.go 100.00% <0.00%> (ø)
github/scim.go 100.00% <0.00%> (ø)
github/github.go 97.58% <0.00%> (+<0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 88b13f9...0035635. Read the comment docs.

Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @hemachandarv !
Just a few minor tweaks, please.


w.WriteHeader(http.StatusBadRequest)
fmt.Fprintf(w, `{
"message": "Branch not protected",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"message": "Branch not protected",
"message": githubBranchNotProtected,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gmlewis I'm not sure if we'll be able to use a variable inside a raw string. Am I missing something..?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whups, you are correct. Please use %v and the variable name in that case.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, %q makes more sense here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @gmlewis. I've updated the PR with the suggested changes.


w.WriteHeader(http.StatusBadRequest)
fmt.Fprintf(w, `{
"message": "Branch not protected",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"message": "Branch not protected",
"message": githubBranchNotProtected,


w.WriteHeader(http.StatusBadRequest)
fmt.Fprintf(w, `{
"message": "Branch not protected",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"message": "Branch not protected",
"message": githubBranchNotProtected,

github/repos.go Outdated
Comment on lines 1560 to 1563
if errorResponse, ok := err.(*ErrorResponse); ok {
return errorResponse.Message == githubBranchNotProtected
}
return false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if errorResponse, ok := err.(*ErrorResponse); ok {
return errorResponse.Message == githubBranchNotProtected
}
return false
errorResponse, ok := err.(*ErrorResponse)
return ok && errorResponse.Message == githubBranchNotProtected

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gmlewis Thank you for suggesting this change. I certainly missed this simplification.

Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @hemachandarv !
LGTM.

Awaiting second LGTM before merging.

Copy link
Contributor

@cpanato cpanato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
thanks!

@gmlewis
Copy link
Collaborator

gmlewis commented Dec 3, 2021

Thank you, @cpanato !
Merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Indication that the PR author has signed a Google Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Branch protection status checks returns error for unprotected branches
3 participants