Only change issue status when commits have been merged

This commit is contained in:
Keith Rutkowski 2018-03-23 09:48:23 -04:00
parent 8536f834e5
commit abd1f1f6e1
2 changed files with 21 additions and 19 deletions

View File

@ -481,7 +481,7 @@ func findIssueReferencesInString(message string, repo *Repository) (map[int64]Ke
} }
// UpdateIssuesCommit checks if issues are manipulated by commit message. // UpdateIssuesCommit checks if issues are manipulated by commit message.
func UpdateIssuesCommit(doer *User, repo *Repository, commits []*PushCommit) error { func UpdateIssuesCommit(doer *User, repo *Repository, commits []*PushCommit, commitsAreMerged bool) error {
// Commits are appended in the reverse order. // Commits are appended in the reverse order.
for i := len(commits) - 1; i >= 0; i-- { for i := len(commits) - 1; i >= 0; i-- {
c := commits[i] c := commits[i]
@ -507,17 +507,19 @@ func UpdateIssuesCommit(doer *User, repo *Repository, commits []*PushCommit) err
} }
} }
// take no action if both KeywordsFoundClose and KeywordsFoundOpen are set if commitsAreMerged {
if (mask & (KeywordsFoundReopen|KeywordsFoundClose)) == KeywordsFoundClose { // take no action if both KeywordsFoundClose and KeywordsFoundOpen are set
if issue.RepoID == repo.ID && !issue.IsClosed { if (mask & (KeywordsFoundReopen|KeywordsFoundClose)) == KeywordsFoundClose {
if err = issue.ChangeStatus(doer, repo, true); err != nil { if issue.RepoID == repo.ID && !issue.IsClosed {
return err if err = issue.ChangeStatus(doer, repo, true); err != nil {
return err
}
} }
} } else if (mask & (KeywordsFoundReopen|KeywordsFoundClose)) == KeywordsFoundReopen {
} else if (mask & (KeywordsFoundReopen|KeywordsFoundClose)) == KeywordsFoundReopen { if issue.RepoID == repo.ID && issue.IsClosed {
if issue.RepoID == repo.ID && issue.IsClosed { if err = issue.ChangeStatus(doer, repo, false); err != nil {
if err = issue.ChangeStatus(doer, repo, false); err != nil { return err
return err }
} }
} }
} }
@ -581,7 +583,7 @@ func CommitRepoAction(opts CommitRepoActionOptions) error {
opts.Commits.CompareURL = repo.ComposeCompareURL(opts.OldCommitID, opts.NewCommitID) opts.Commits.CompareURL = repo.ComposeCompareURL(opts.OldCommitID, opts.NewCommitID)
} }
if err = UpdateIssuesCommit(pusher, repo, opts.Commits.Commits); err != nil { if err = UpdateIssuesCommit(pusher, repo, opts.Commits.Commits, true); err != nil {
log.Error(4, "updateIssuesCommit: %v", err) log.Error(4, "updateIssuesCommit: %v", err)
} }
} }
@ -736,16 +738,12 @@ func TransferRepoAction(doer, oldOwner *User, repo *Repository) error {
return transferRepoAction(x, doer, oldOwner, repo) return transferRepoAction(x, doer, oldOwner, repo)
} }
func mergePullRequestAction(e Engine, doer *User, repo *Repository, issue *Issue, commits *PushCommits) (err error) { func mergePullRequestAction(e Engine, doer *User, repo *Repository, pull *Issue, commits *PushCommits) (err error) {
if err = UpdateIssuesCommit(doer, repo, commits.Commits); err != nil {
log.Error(4, "updateIssuesCommit: %v", err)
}
if err = notifyWatchers(e, &Action{ if err = notifyWatchers(e, &Action{
ActUserID: doer.ID, ActUserID: doer.ID,
ActUser: doer, ActUser: doer,
OpType: ActionMergePullRequest, OpType: ActionMergePullRequest,
Content: fmt.Sprintf("%d|%s", issue.Index, issue.Title), Content: fmt.Sprintf("%d|%s", pull.Index, pull.Title),
RepoID: repo.ID, RepoID: repo.ID,
Repo: repo, Repo: repo,
IsPrivate: repo.IsPrivate, IsPrivate: repo.IsPrivate,
@ -758,6 +756,10 @@ func mergePullRequestAction(e Engine, doer *User, repo *Repository, issue *Issue
// MergePullRequestAction adds new action for merging pull request. // MergePullRequestAction adds new action for merging pull request.
func MergePullRequestAction(actUser *User, repo *Repository, pull *Issue, commits *PushCommits) error { func MergePullRequestAction(actUser *User, repo *Repository, pull *Issue, commits *PushCommits) error {
if err := UpdateIssuesCommit(actUser, repo, commits.Commits, true); err != nil {
log.Error(4, "updateIssuesCommit: %v", err)
}
return mergePullRequestAction(x, actUser, repo, pull, commits) return mergePullRequestAction(x, actUser, repo, pull, commits)
} }

View File

@ -227,7 +227,7 @@ func TestUpdateIssuesCommit(t *testing.T) {
AssertNotExistsBean(t, commentBean) AssertNotExistsBean(t, commentBean)
AssertNotExistsBean(t, &Issue{RepoID: repo.ID, Index: 2}, "is_closed=1") AssertNotExistsBean(t, &Issue{RepoID: repo.ID, Index: 2}, "is_closed=1")
assert.NoError(t, UpdateIssuesCommit(user, repo, pushCommits)) assert.NoError(t, UpdateIssuesCommit(user, repo, pushCommits, true))
AssertExistsAndLoadBean(t, commentBean) AssertExistsAndLoadBean(t, commentBean)
AssertExistsAndLoadBean(t, issueBean, "is_closed=1") AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
CheckConsistencyFor(t, &Action{}) CheckConsistencyFor(t, &Action{})