Update issues when a pull request is merged

This commit is contained in:
Keith Rutkowski 2018-03-19 12:25:42 -04:00
parent 1675fc4301
commit 3d99ee30c1
3 changed files with 21 additions and 11 deletions

View File

@ -715,8 +715,12 @@ func TransferRepoAction(doer, oldOwner *User, repo *Repository) error {
return transferRepoAction(x, doer, oldOwner, repo)
}
func mergePullRequestAction(e Engine, doer *User, repo *Repository, issue *Issue) error {
return notifyWatchers(e, &Action{
func mergePullRequestAction(e Engine, doer *User, repo *Repository, issue *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{
ActUserID: doer.ID,
ActUser: doer,
OpType: ActionMergePullRequest,
@ -724,12 +728,16 @@ func mergePullRequestAction(e Engine, doer *User, repo *Repository, issue *Issue
RepoID: repo.ID,
Repo: repo,
IsPrivate: repo.IsPrivate,
})
}); err != nil {
return fmt.Errorf("notifyWatchers: %v", err)
}
return nil
}
// MergePullRequestAction adds new action for merging pull request.
func MergePullRequestAction(actUser *User, repo *Repository, pull *Issue) error {
return mergePullRequestAction(x, actUser, repo, pull)
func MergePullRequestAction(actUser *User, repo *Repository, pull *Issue, commits *PushCommits) error {
return mergePullRequestAction(x, actUser, repo, pull, commits)
}
// GetFeedsOptions options for retrieving feeds

View File

@ -379,6 +379,7 @@ func TestMergePullRequestAction(t *testing.T) {
repo := AssertExistsAndLoadBean(t, &Repository{ID: 1, OwnerID: user.ID}).(*Repository)
repo.Owner = user
issue := AssertExistsAndLoadBean(t, &Issue{ID: 3, RepoID: repo.ID}).(*Issue)
commits := &PushCommits{0, make([]*PushCommit, 0), "", nil}
actionBean := &Action{
OpType: ActionMergePullRequest,
@ -389,7 +390,7 @@ func TestMergePullRequestAction(t *testing.T) {
IsPrivate: repo.IsPrivate,
}
AssertNotExistsBean(t, actionBean)
assert.NoError(t, MergePullRequestAction(user, repo, issue))
assert.NoError(t, MergePullRequestAction(user, repo, issue, commits))
AssertExistsAndLoadBean(t, actionBean)
CheckConsistencyFor(t, &Action{})
}

View File

@ -445,10 +445,6 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository, mergeStyle
log.Error(4, "setMerged [%d]: %v", pr.ID, err)
}
if err = MergePullRequestAction(doer, pr.Issue.Repo, pr.Issue); err != nil {
log.Error(4, "MergePullRequestAction [%d]: %v", pr.ID, err)
}
// Reset cached commit count
cache.Remove(pr.Issue.Repo.GetCommitsCountCacheKey(pr.BaseBranch, true))
@ -488,13 +484,18 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository, mergeStyle
if mergeStyle == MergeStyleMerge {
l.PushFront(mergeCommit)
}
commits := ListToPushCommits(l)
if err = MergePullRequestAction(doer, pr.Issue.Repo, pr.Issue, commits); err != nil {
log.Error(4, "MergePullRequestAction [%d]: %v", pr.ID, err)
}
p := &api.PushPayload{
Ref: git.BranchPrefix + pr.BaseBranch,
Before: pr.MergeBase,
After: mergeCommit.ID.String(),
CompareURL: setting.AppURL + pr.BaseRepo.ComposeCompareURL(pr.MergeBase, pr.MergedCommitID),
Commits: ListToPushCommits(l).ToAPIPayloadCommits(pr.BaseRepo.HTMLURL()),
Commits: commits.ToAPIPayloadCommits(pr.BaseRepo.HTMLURL()),
Repo: pr.BaseRepo.APIFormat(mode),
Pusher: pr.HeadRepo.MustOwner().APIFormat(),
Sender: doer.APIFormat(),