Skip to content

Commit 1167580

Browse files
committed
When closing issues through commits move comment til after closed
When closing issues through commits create the comment after the issue is closed rather than before. This ensures that the repo issue num is correctly updated. Fix go-gitea#11308 Fix go-gitea#10536 Signed-off-by: Andrew Thornton <[email protected]>
1 parent a1f11a0 commit 1167580

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

modules/repofiles/action.go

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -111,38 +111,44 @@ func UpdateIssuesCommit(doer *models.User, repo *models.Repository, commits []*r
111111
continue
112112
}
113113

114-
message := fmt.Sprintf(`<a href="%s/commit/%s">%s</a>`, repo.Link(), c.Sha1, html.EscapeString(c.Message))
115-
if err = models.CreateRefComment(doer, refRepo, refIssue, message, c.Sha1); err != nil {
116-
return err
114+
shouldChangeStatus := false
115+
// Process closing/reopening keywords
116+
switch ref.Action {
117+
case references.XRefActionCloses:
118+
shouldChangeStatus = !refIssue.IsClosed
119+
case references.XRefActionReopens:
120+
shouldChangeStatus = refIssue.IsClosed
117121
}
118122

119-
// Only issues can be closed/reopened this way, and user needs the correct permissions
123+
// However, only issues can be closed/reopened this way, and user needs the correct permissions
120124
if refIssue.IsPull || !canclose {
121-
continue
122-
}
123-
124-
// Only process closing/reopening keywords
125-
if ref.Action != references.XRefActionCloses && ref.Action != references.XRefActionReopens {
126-
continue
125+
shouldChangeStatus = false
127126
}
128127

129128
if !repo.CloseIssuesViaCommitInAnyBranch {
130129
// If the issue was specified to be in a particular branch, don't allow commits in other branches to close it
131130
if refIssue.Ref != "" {
132131
if branchName != refIssue.Ref {
133-
continue
132+
shouldChangeStatus = false
134133
}
135134
// Otherwise, only process commits to the default branch
136135
} else if branchName != repo.DefaultBranch {
137-
continue
136+
shouldChangeStatus = false
138137
}
139138
}
140-
close := (ref.Action == references.XRefActionCloses)
141-
if close != refIssue.IsClosed {
139+
140+
if shouldChangeStatus {
141+
close := (ref.Action == references.XRefActionCloses)
142142
if err := changeIssueStatus(refRepo, refIssue, doer, close); err != nil {
143143
return err
144144
}
145145
}
146+
147+
// Finally send the comment
148+
message := fmt.Sprintf(`<a href="%s/commit/%s">%s</a>`, repo.Link(), c.Sha1, html.EscapeString(c.Message))
149+
if err = models.CreateRefComment(doer, refRepo, refIssue, message, c.Sha1); err != nil {
150+
return err
151+
}
146152
}
147153
}
148154
return nil

0 commit comments

Comments
 (0)