Add issue updating from commit messages in new pull request

This commit is contained in:
Keith Rutkowski 2018-03-23 10:07:48 -04:00
parent abd1f1f6e1
commit 8a9bd7a9b7
2 changed files with 63 additions and 14 deletions

View File

@ -763,6 +763,33 @@ func MergePullRequestAction(actUser *User, repo *Repository, pull *Issue, commit
return mergePullRequestAction(x, actUser, repo, pull, commits)
}
func newPullRequestAction(e Engine, doer *User, repo *Repository, pull *Issue, commits *PushCommits) (err error) {
if err = NotifyWatchers(&Action{
ActUserID: doer.ID,
ActUser: doer,
OpType: ActionCreatePullRequest,
Content: fmt.Sprintf("%d|%s", pull.Index, pull.Title),
RepoID: repo.ID,
Repo: repo,
IsPrivate: repo.IsPrivate,
}); err != nil {
log.Error(4, "NotifyWatchers: %v", err)
} else if err = pull.MailParticipants(); err != nil {
log.Error(4, "MailParticipants: %v", err)
}
return nil
}
// NewPullRequestAction adds new action for merging pull request.
func NewPullRequestAction(actUser *User, repo *Repository, pull *Issue, commits *PushCommits) error {
if err := UpdateIssuesCommit(actUser, repo, commits.Commits, false); err != nil {
log.Error(4, "updateIssuesCommit: %v", err)
}
return newPullRequestAction(x, actUser, repo, pull, commits)
}
// GetFeedsOptions options for retrieving feeds
type GetFeedsOptions struct {
RequestedUser *User

View File

@ -772,23 +772,45 @@ func NewPullRequest(repo *Repository, pull *Issue, labelIDs []int64, uuids []str
UpdateIssueIndexer(pull.ID)
if err = NotifyWatchers(&Action{
ActUserID: pull.Poster.ID,
ActUser: pull.Poster,
OpType: ActionCreatePullRequest,
Content: fmt.Sprintf("%d|%s", pull.Index, pull.Title),
RepoID: repo.ID,
Repo: repo,
IsPrivate: repo.IsPrivate,
}); err != nil {
log.Error(4, "NotifyWatchers: %v", err)
} else if err = pull.MailParticipants(); err != nil {
log.Error(4, "MailParticipants: %v", err)
}
pr.Issue = pull
pull.PullRequest = pr
mode, _ := AccessLevel(pull.Poster.ID, repo)
var (
baseBranch *Branch
headBranch *Branch
baseCommit *git.Commit
headCommit *git.Commit
baseGitRepo *git.Repository
)
if baseBranch, err = pr.BaseRepo.GetBranch(pr.BaseBranch); err != nil {
return nil
}
if baseCommit, err = baseBranch.GetCommit(); err != nil {
return nil
}
if headBranch, err = pr.HeadRepo.GetBranch(pr.HeadBranch); err != nil {
return nil
}
if headCommit, err = headBranch.GetCommit(); err != nil {
return nil
}
if baseGitRepo, err = git.OpenRepository(pr.BaseRepo.RepoPath()); err != nil {
log.Error(4, "OpenRepository", err)
return nil
}
l, err := baseGitRepo.CommitsBetweenIDs(headCommit.ID.String(), baseCommit.ID.String())
if err != nil {
log.Error(4, "CommitsBetweenIDs: %v", err)
return nil
}
commits := ListToPushCommits(l)
if err = NewPullRequestAction(pull.Poster, repo, pull, commits); err != nil {
log.Error(4, "NewPullRequestAction [%d]: %v", pr.ID, err)
}
if err = PrepareWebhooks(repo, HookEventPullRequest, &api.PullRequestPayload{
Action: api.HookIssueOpened,
Index: pull.Index,