Skip to content

Create closing comment after issue is closed by commit #11310

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

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions modules/repofiles/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,38 +111,44 @@ func UpdateIssuesCommit(doer *models.User, repo *models.Repository, commits []*r
continue
}

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

// Only issues can be closed/reopened this way, and user needs the correct permissions
// However, only issues can be closed/reopened this way, and user needs the correct permissions
if refIssue.IsPull || !canclose {
continue
}

// Only process closing/reopening keywords
if ref.Action != references.XRefActionCloses && ref.Action != references.XRefActionReopens {
continue
shouldChangeStatus = false
}

if !repo.CloseIssuesViaCommitInAnyBranch {
// If the issue was specified to be in a particular branch, don't allow commits in other branches to close it
if refIssue.Ref != "" {
if branchName != refIssue.Ref {
continue
shouldChangeStatus = false
}
// Otherwise, only process commits to the default branch
} else if branchName != repo.DefaultBranch {
continue
shouldChangeStatus = false
}
}
close := (ref.Action == references.XRefActionCloses)
if close != refIssue.IsClosed {

if shouldChangeStatus {
close := (ref.Action == references.XRefActionCloses)
if err := changeIssueStatus(refRepo, refIssue, doer, close); err != nil {
return err
}
}

// Finally send the comment
message := fmt.Sprintf(`<a href="%s/commit/%s">%s</a>`, repo.Link(), c.Sha1, html.EscapeString(c.Message))
if err = models.CreateRefComment(doer, refRepo, refIssue, message, c.Sha1); err != nil {
return err
}
}
}
return nil
Expand Down