summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorBrecht Van Lommel <brecht@blender.org>2023-01-25 05:47:53 +0100
committerGitHub <noreply@github.com>2023-01-24 23:47:53 -0500
commitc8139c0f642a308b544d2f17e7b728ee6762a0eb (patch)
tree0b29563e5a3fe8511e18a1eb6f2cfdf2453fc88a /services
parenta31fedd2c2def13e29a962c751c449491d5a1588 (diff)
downloadgitea-c8139c0f642a308b544d2f17e7b728ee6762a0eb.tar.gz
gitea-c8139c0f642a308b544d2f17e7b728ee6762a0eb.zip
Webhooks: for issue close/reopen action, add commit ID that caused it (#22583)
The `commit_id` property name is the same as equivalent functionality in GitHub. If the action was not caused by a commit, an empty string is used. This can for example be used to automatically add a Resolved label to an issue fixed by a commit, or clear it when the issue is reopened.
Diffstat (limited to 'services')
-rw-r--r--services/issue/commit.go2
-rw-r--r--services/issue/status.go8
-rw-r--r--services/pull/merge.go2
-rw-r--r--services/pull/pull.go4
-rw-r--r--services/webhook/notifier.go4
5 files changed, 11 insertions, 9 deletions
diff --git a/services/issue/commit.go b/services/issue/commit.go
index c3d2e853bb..7a8c71e609 100644
--- a/services/issue/commit.go
+++ b/services/issue/commit.go
@@ -193,7 +193,7 @@ func UpdateIssuesCommit(doer *user_model.User, repo *repo_model.Repository, comm
}
if close != refIssue.IsClosed {
refIssue.Repo = refRepo
- if err := ChangeStatus(refIssue, doer, close); err != nil {
+ if err := ChangeStatus(refIssue, doer, c.Sha1, close); err != nil {
return err
}
}
diff --git a/services/issue/status.go b/services/issue/status.go
index 782ce0bd96..d4a0fce3e5 100644
--- a/services/issue/status.go
+++ b/services/issue/status.go
@@ -14,13 +14,13 @@ import (
)
// ChangeStatus changes issue status to open or closed.
-func ChangeStatus(issue *issues_model.Issue, doer *user_model.User, closed bool) error {
- return changeStatusCtx(db.DefaultContext, issue, doer, closed)
+func ChangeStatus(issue *issues_model.Issue, doer *user_model.User, commitID string, closed bool) error {
+ return changeStatusCtx(db.DefaultContext, issue, doer, commitID, closed)
}
// changeStatusCtx changes issue status to open or closed.
// TODO: if context is not db.DefaultContext we get a deadlock!!!
-func changeStatusCtx(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, closed bool) error {
+func changeStatusCtx(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, commitID string, closed bool) error {
comment, err := issues_model.ChangeIssueStatus(ctx, issue, doer, closed)
if err != nil {
if issues_model.IsErrDependenciesLeft(err) && closed {
@@ -37,7 +37,7 @@ func changeStatusCtx(ctx context.Context, issue *issues_model.Issue, doer *user_
}
}
- notification.NotifyIssueChangeStatus(ctx, doer, issue, comment, closed)
+ notification.NotifyIssueChangeStatus(ctx, doer, commitID, issue, comment, closed)
return nil
}
diff --git a/services/pull/merge.go b/services/pull/merge.go
index bdd2cb0e86..7ffbdb78b0 100644
--- a/services/pull/merge.go
+++ b/services/pull/merge.go
@@ -225,7 +225,7 @@ func Merge(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.U
}
close := ref.RefAction == references.XRefActionCloses
if close != ref.Issue.IsClosed {
- if err = issue_service.ChangeStatus(ref.Issue, doer, close); err != nil {
+ if err = issue_service.ChangeStatus(ref.Issue, doer, pr.MergedCommitID, close); err != nil {
// Allow ErrDependenciesLeft
if !issues_model.IsErrDependenciesLeft(err) {
return err
diff --git a/services/pull/pull.go b/services/pull/pull.go
index 08f70a5e4e..7f81def6d6 100644
--- a/services/pull/pull.go
+++ b/services/pull/pull.go
@@ -532,7 +532,7 @@ func CloseBranchPulls(doer *user_model.User, repoID int64, branch string) error
var errs errlist
for _, pr := range prs {
- if err = issue_service.ChangeStatus(pr.Issue, doer, true); err != nil && !issues_model.IsErrPullWasClosed(err) && !issues_model.IsErrDependenciesLeft(err) {
+ if err = issue_service.ChangeStatus(pr.Issue, doer, "", true); err != nil && !issues_model.IsErrPullWasClosed(err) && !issues_model.IsErrDependenciesLeft(err) {
errs = append(errs, err)
}
}
@@ -566,7 +566,7 @@ func CloseRepoBranchesPulls(ctx context.Context, doer *user_model.User, repo *re
if pr.BaseRepoID == repo.ID {
continue
}
- if err = issue_service.ChangeStatus(pr.Issue, doer, true); err != nil && !issues_model.IsErrPullWasClosed(err) {
+ if err = issue_service.ChangeStatus(pr.Issue, doer, "", true); err != nil && !issues_model.IsErrPullWasClosed(err) {
errs = append(errs, err)
}
}
diff --git a/services/webhook/notifier.go b/services/webhook/notifier.go
index ee80766032..16d2b95812 100644
--- a/services/webhook/notifier.go
+++ b/services/webhook/notifier.go
@@ -229,7 +229,7 @@ func (m *webhookNotifier) NotifyIssueChangeTitle(ctx context.Context, doer *user
}
}
-func (m *webhookNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, actionComment *issues_model.Comment, isClosed bool) {
+func (m *webhookNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *user_model.User, commitID string, issue *issues_model.Issue, actionComment *issues_model.Comment, isClosed bool) {
mode, _ := access_model.AccessLevel(ctx, issue.Poster, issue.Repo)
var err error
if issue.IsPull {
@@ -243,6 +243,7 @@ func (m *webhookNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *use
PullRequest: convert.ToAPIPullRequest(ctx, issue.PullRequest, nil),
Repository: convert.ToRepo(ctx, issue.Repo, mode),
Sender: convert.ToUser(doer, nil),
+ CommitID: commitID,
}
if isClosed {
apiPullRequest.Action = api.HookIssueClosed
@@ -256,6 +257,7 @@ func (m *webhookNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *use
Issue: convert.ToAPIIssue(ctx, issue),
Repository: convert.ToRepo(ctx, issue.Repo, mode),
Sender: convert.ToUser(doer, nil),
+ CommitID: commitID,
}
if isClosed {
apiIssue.Action = api.HookIssueClosed