-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Add API branch protection endpoint #9311
Add API branch protection endpoint #9311
Conversation
@davidsvantesson exist there a github a APIv3 reverence? |
@6543 It is not compatible with the Github API. IMHO Github has made a mistake and made API endpoint for branch and branch protection the same. Therefore they don't support wildcard protected branches via API, you can only set branch protection of actual branches. If we intend to implement wildcard protection (#2529), I think we should take the possibility to consider the API while it is not created yet. The original PR is more similar to Github API. I could take up and fix the issues in that one instead, but I think this matter should be discussed first. |
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.
some smal nits
I saw some comment in other issue (from @lafriks I believe) that we should change API endpoints to use teamnames rather than team ids. Then it would make sense to use it for this API also I think. We could also use branch name (or branch protection name in case of wildcard protection) as the API endpoint, but it might require the requester to encode the name in case of wildcards?
Then it would be similar to GitHub but with a different endpoint name, so that branch protection does not have to be under a specific real branch. |
I would take https://github.com/go-gitea/gitea/blob/master/CONTRIBUTING.md#api-v1 into account and use Patch for the edit action ... |
# Conflicts: # modules/convert/convert.go # routers/api/v1/repo/branch.go # routers/api/v1/swagger/options.go # templates/swagger/v1_json.tmpl
1c5a217
to
a46dbc2
Compare
Codecov Report
@@ Coverage Diff @@
## master #9311 +/- ##
==========================================
- Coverage 43.7% 43.61% -0.09%
==========================================
Files 576 583 +7
Lines 80251 80801 +550
==========================================
+ Hits 35070 35239 +169
- Misses 40851 41191 +340
- Partials 4330 4371 +41
Continue to review full report at Codecov.
|
I wonder how github api deals with wildcards as github does support them |
Maybe we should support wildcards branch protection at first. |
@lafriks Github doesn't support wildcard branches through their API, you can only set them via UI. We should avoid that. |
routers/api/v1/repo/branch.go
Outdated
// schema: | ||
// "$ref": "#/definitions/CreateBranchProtectionOption" | ||
// responses: | ||
// "200": |
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.
// "200": | |
// "201": |
routers/api/v1/repo/branch.go
Outdated
return | ||
} | ||
|
||
ctx.JSON(http.StatusOK, convert.ToBranchProtection(bp)) |
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.
ctx.JSON(http.StatusOK, convert.ToBranchProtection(bp)) | |
ctx.JSON(http.StatusCreated, convert.ToBranchProtection(bp)) |
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.
correct http status responce
ping |
Make lg-tm work |
Fix #2922.
Replaces #7093.
I have tried to make this work if we get wildcard protected branches as well. @lafriks maybe you want to have a look.
The new API endpoints:
Also added name of effective branch protection of a branch for repo admins to get more information: