-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Add API routes to lock and unlock issues #34165
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
098e422
Add an API endpoint to lock issues
YaFou 0cc4523
Change lock issue API endpoint to fit GitHub specifications
YaFou 0b134aa
Add admin permission to lock issues via API
YaFou ee862f4
Change method to normalize lock reason in the API endpoint
YaFou baf6217
Fix code style
YaFou 40e533c
Remove all lock reason checks
YaFou f878b14
Merge branch 'main' into api-lock-issue
wxiaoguang f7959bc
improve comments and tests
wxiaoguang ac53e8b
remove unused translation
wxiaoguang b8fd7f3
Merge branch 'main' into api-lock-issue
wxiaoguang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
// Copyright 2025 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package repo | ||
|
||
import ( | ||
"errors" | ||
"net/http" | ||
|
||
issues_model "code.gitea.io/gitea/models/issues" | ||
api "code.gitea.io/gitea/modules/structs" | ||
"code.gitea.io/gitea/modules/web" | ||
"code.gitea.io/gitea/services/context" | ||
) | ||
|
||
// LockIssue lock an issue | ||
func LockIssue(ctx *context.APIContext) { | ||
// swagger:operation PUT /repos/{owner}/{repo}/issues/{index}/lock issue issueLockIssue | ||
// --- | ||
// summary: Lock an issue | ||
// consumes: | ||
// - application/json | ||
// produces: | ||
// - application/json | ||
// parameters: | ||
// - name: owner | ||
// in: path | ||
// description: owner of the repo | ||
// type: string | ||
// required: true | ||
// - name: repo | ||
// in: path | ||
// description: name of the repo | ||
// type: string | ||
// required: true | ||
// - name: index | ||
// in: path | ||
// description: index of the issue | ||
// type: integer | ||
// format: int64 | ||
// required: true | ||
// - name: body | ||
// in: body | ||
// schema: | ||
// "$ref": "#/definitions/LockIssueOption" | ||
// responses: | ||
// "204": | ||
// "$ref": "#/responses/empty" | ||
// "403": | ||
// "$ref": "#/responses/forbidden" | ||
// "404": | ||
// "$ref": "#/responses/notFound" | ||
|
||
reason := web.GetForm(ctx).(*api.LockIssueOption).Reason | ||
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index")) | ||
if err != nil { | ||
if issues_model.IsErrIssueNotExist(err) { | ||
ctx.APIErrorNotFound(err) | ||
} else { | ||
ctx.APIErrorInternal(err) | ||
} | ||
return | ||
} | ||
|
||
if !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) { | ||
ctx.APIError(http.StatusForbidden, errors.New("no permission to lock this issue")) | ||
return | ||
} | ||
|
||
if !issue.IsLocked { | ||
opt := &issues_model.IssueLockOptions{ | ||
Doer: ctx.ContextUser, | ||
Issue: issue, | ||
Reason: reason, | ||
} | ||
|
||
issue.Repo = ctx.Repo.Repository | ||
err = issues_model.LockIssue(ctx, opt) | ||
if err != nil { | ||
ctx.APIErrorInternal(err) | ||
return | ||
} | ||
} | ||
|
||
ctx.Status(http.StatusNoContent) | ||
} | ||
|
||
// UnlockIssue unlock an issue | ||
func UnlockIssue(ctx *context.APIContext) { | ||
// swagger:operation DELETE /repos/{owner}/{repo}/issues/{index}/lock issue issueUnlockIssue | ||
// --- | ||
// summary: Unlock an issue | ||
// consumes: | ||
// - application/json | ||
// produces: | ||
// - application/json | ||
// parameters: | ||
// - name: owner | ||
// in: path | ||
// description: owner of the repo | ||
// type: string | ||
// required: true | ||
// - name: repo | ||
// in: path | ||
// description: name of the repo | ||
// type: string | ||
// required: true | ||
// - name: index | ||
// in: path | ||
// description: index of the issue | ||
// type: integer | ||
// format: int64 | ||
// required: true | ||
// responses: | ||
// "204": | ||
// "$ref": "#/responses/empty" | ||
// "403": | ||
// "$ref": "#/responses/forbidden" | ||
// "404": | ||
// "$ref": "#/responses/notFound" | ||
|
||
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index")) | ||
if err != nil { | ||
if issues_model.IsErrIssueNotExist(err) { | ||
ctx.APIErrorNotFound(err) | ||
} else { | ||
ctx.APIErrorInternal(err) | ||
} | ||
return | ||
} | ||
|
||
if !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) { | ||
ctx.APIError(http.StatusForbidden, errors.New("no permission to unlock this issue")) | ||
return | ||
} | ||
|
||
if issue.IsLocked { | ||
opt := &issues_model.IssueLockOptions{ | ||
Doer: ctx.ContextUser, | ||
Issue: issue, | ||
} | ||
|
||
issue.Repo = ctx.Repo.Repository | ||
err = issues_model.UnlockIssue(ctx, opt) | ||
if err != nil { | ||
ctx.APIErrorInternal(err) | ||
return | ||
} | ||
} | ||
|
||
ctx.Status(http.StatusNoContent) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.