-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Add structured close reason for issues (GitHub-compatible state_reason) #37041
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
Draft
a1012112796
wants to merge
15
commits into
go-gitea:main
Choose a base branch
from
a1012112796:zzc/dev/issue_close_reason
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
8f27e66
Add structured close reason for issues (GitHub-compatible state_reason)
a1012112796 38d0781
Merge remote-tracking branch 'origin/main' into zzc/dev/issue_close_r…
a1012112796 b8a1e8e
Revert close-reason colour styling, keep icon-type changes
a1012112796 4420f5c
Refine issue close reason menu UX.
a1012112796 bb5d750
fix lint
a1012112796 2a089bb
Refine issue close reason display copy.
a1012112796 de63336
Refine close reason action layout.
a1012112796 df7630d
fix migration
a1012112796 1b8d370
fix test
a1012112796 5907148
Merge remote-tracking branch 'origin/main' into zzc/dev/issue_close_r…
a1012112796 7ade2f3
fix lint
a1012112796 acf7503
api test update
a1012112796 51c336f
Merge remote-tracking branch 'origin/main' into zzc/dev/issue_close_r…
a1012112796 66eee37
Simplify issue close reason actions.
a1012112796 bdbf3f9
apply review suggestions
a1012112796 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| // Copyright 2026 The Gitea Authors. All rights reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package issues | ||
|
|
||
| import ( | ||
| "fmt" | ||
| ) | ||
|
|
||
| type IssueCloseReason int64 | ||
|
|
||
| const ( | ||
| IssueCloseReasonNone IssueCloseReason = iota | ||
| IssueCloseReasonCompleted | ||
| IssueCloseReasonCompletedByCommit | ||
| IssueCloseReasonCompletedByPull | ||
| IssueCloseReasonAnswered | ||
| IssueCloseReasonDuplicate | ||
| IssueCloseReasonNotPlanned | ||
| ) | ||
|
|
||
| func (r IssueCloseReason) String() string { | ||
| switch r { | ||
| case IssueCloseReasonCompleted: | ||
| return "completed" | ||
| case IssueCloseReasonCompletedByCommit: | ||
| return "completed_by_commit" | ||
| case IssueCloseReasonCompletedByPull: | ||
| return "completed_by_pull" | ||
| case IssueCloseReasonAnswered: | ||
| return "answered" | ||
| case IssueCloseReasonDuplicate: | ||
| return "duplicate" | ||
| case IssueCloseReasonNotPlanned: | ||
| return "not_planned" | ||
| default: | ||
| return "" | ||
| } | ||
| } | ||
|
|
||
| func (r IssueCloseReason) IsValid() bool { | ||
| return r >= IssueCloseReasonNone && r <= IssueCloseReasonNotPlanned | ||
| } | ||
|
|
||
| func ParseIssueCloseReason(reason string) (IssueCloseReason, error) { | ||
| switch reason { | ||
| case "": | ||
| return IssueCloseReasonNone, nil | ||
| case "completed": | ||
| return IssueCloseReasonCompleted, nil | ||
| case "completed_by_commit": | ||
| return IssueCloseReasonCompletedByCommit, nil | ||
| case "completed_by_pull": | ||
| return IssueCloseReasonCompletedByPull, nil | ||
| case "answered": | ||
| return IssueCloseReasonAnswered, nil | ||
| case "duplicate": | ||
| return IssueCloseReasonDuplicate, nil | ||
| case "not_planned": | ||
| return IssueCloseReasonNotPlanned, nil | ||
| default: | ||
| return IssueCloseReasonNone, fmt.Errorf("unknown close reason %q", reason) | ||
| } | ||
| } |
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,84 @@ | ||
| // Copyright 2026 The Gitea Authors. All rights reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package issues | ||
|
|
||
| import "code.gitea.io/gitea/modules/json" | ||
|
|
||
| type closeReasonParam struct { | ||
| IssueIndex int64 `json:"issue_index"` | ||
| CommentID int64 `json:"comment_id"` | ||
| CommitHash string `json:"commit_hash"` | ||
| PullIndex int64 `json:"pull_index"` | ||
| } | ||
|
|
||
| func parseCloseReasonParam(param string) closeReasonParam { | ||
| if param == "" { | ||
| return closeReasonParam{} | ||
| } | ||
| var p closeReasonParam | ||
| _ = json.Unmarshal([]byte(param), &p) | ||
| return p | ||
| } | ||
|
|
||
| func normalizeCloseReason(isClosed bool, reason IssueCloseReason) string { | ||
| if isClosed && reason == IssueCloseReasonNone { | ||
| return IssueCloseReasonCompleted.String() | ||
| } | ||
| return reason.String() | ||
| } | ||
|
|
||
| func (issue *Issue) CloseReasonForDisplay() string { | ||
| return normalizeCloseReason(issue.IsClosed, issue.CloseReason) | ||
| } | ||
|
|
||
| func (issue *Issue) CloseReasonDuplicateIssueIndex() int64 { | ||
| return parseCloseReasonParam(issue.CloseReasonParam).IssueIndex | ||
| } | ||
|
|
||
| func (issue *Issue) CloseReasonAnsweredCommentID() int64 { | ||
| return parseCloseReasonParam(issue.CloseReasonParam).CommentID | ||
| } | ||
|
|
||
| func (issue *Issue) CloseReasonCommitHash() string { | ||
| return parseCloseReasonParam(issue.CloseReasonParam).CommitHash | ||
| } | ||
|
|
||
| func (issue *Issue) CloseReasonPullIndex() int64 { | ||
| return parseCloseReasonParam(issue.CloseReasonParam).PullIndex | ||
| } | ||
|
|
||
| func (c *Comment) CloseReasonForDisplay() string { | ||
| if c.CommentMetaData == nil { | ||
| return "" | ||
| } | ||
| return normalizeCloseReason(true, c.CommentMetaData.CloseReason) | ||
| } | ||
|
|
||
| func (c *Comment) CloseReasonDuplicateIssueIndex() int64 { | ||
| if c.CommentMetaData == nil { | ||
| return 0 | ||
| } | ||
| return parseCloseReasonParam(c.CommentMetaData.CloseReasonParam).IssueIndex | ||
| } | ||
|
|
||
| func (c *Comment) CloseReasonAnsweredCommentID() int64 { | ||
| if c.CommentMetaData == nil { | ||
| return 0 | ||
| } | ||
| return parseCloseReasonParam(c.CommentMetaData.CloseReasonParam).CommentID | ||
| } | ||
|
|
||
| func (c *Comment) CloseReasonCommitHash() string { | ||
| if c.CommentMetaData == nil { | ||
| return "" | ||
| } | ||
| return parseCloseReasonParam(c.CommentMetaData.CloseReasonParam).CommitHash | ||
| } | ||
|
|
||
| func (c *Comment) CloseReasonPullIndex() int64 { | ||
| if c.CommentMetaData == nil { | ||
| return 0 | ||
| } | ||
| return parseCloseReasonParam(c.CommentMetaData.CloseReasonParam).PullIndex | ||
| } |
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
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,16 @@ | ||
| // Copyright 2026 The Gitea Authors. All rights reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package v1_26 | ||
|
|
||
| import "xorm.io/xorm" | ||
|
|
||
| func AddCloseReasonColumnsToIssue(x *xorm.Engine) error { | ||
| type Issue struct { | ||
| CloseReason int64 `xorm:"INDEX DEFAULT 0"` | ||
| CloseReasonParam string `xorm:"TEXT"` | ||
| } | ||
|
|
||
| _, err := x.SyncWithOptions(xorm.SyncOptions{IgnoreDropIndices: true}, new(Issue)) | ||
| return err | ||
| } |
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.