Skip to content

Commit 2b32c5d

Browse files
committed
Webhooks: for issue close/reopen action, add commit ID that caused it if any
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.
1 parent 29b78bc commit 2b32c5d

File tree

15 files changed

+25
-21
lines changed

15 files changed

+25
-21
lines changed

modules/notification/action/action.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (a *actionNotifier) NotifyNewIssue(ctx context.Context, issue *issues_model
5656
}
5757

5858
// NotifyIssueChangeStatus notifies close or reopen issue to notifiers
59-
func (a *actionNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, actionComment *issues_model.Comment, closeOrReopen bool) {
59+
func (a *actionNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *user_model.User, commitID string, issue *issues_model.Issue, actionComment *issues_model.Comment, closeOrReopen bool) {
6060
// Compose comment action, could be plain comment, close or reopen issue/pull request.
6161
// This object will be used to notify watchers in the end of function.
6262
act := &activities_model.Action{

modules/notification/base/notifier.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type Notifier interface {
2323
NotifyRenameRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldRepoName string)
2424
NotifyTransferRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldOwnerName string)
2525
NotifyNewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User)
26-
NotifyIssueChangeStatus(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, actionComment *issues_model.Comment, closeOrReopen bool)
26+
NotifyIssueChangeStatus(ctx context.Context, doer *user_model.User, commitID string, issue *issues_model.Issue, actionComment *issues_model.Comment, closeOrReopen bool)
2727
NotifyDeleteIssue(ctx context.Context, doer *user_model.User, issue *issues_model.Issue)
2828
NotifyIssueChangeMilestone(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldMilestoneID int64)
2929
NotifyIssueChangeAssignee(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, assignee *user_model.User, removed bool, comment *issues_model.Comment)

modules/notification/base/null.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (*NullNotifier) NotifyNewIssue(ctx context.Context, issue *issues_model.Iss
3232
}
3333

3434
// NotifyIssueChangeStatus places a place holder function
35-
func (*NullNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, actionComment *issues_model.Comment, isClosed bool) {
35+
func (*NullNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *user_model.User, commitID string, issue *issues_model.Issue, actionComment *issues_model.Comment, isClosed bool) {
3636
}
3737

3838
// NotifyDeleteIssue notify when some issue deleted

modules/notification/mail/mail.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func (m *mailNotifier) NotifyNewIssue(ctx context.Context, issue *issues_model.I
5454
}
5555
}
5656

57-
func (m *mailNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, actionComment *issues_model.Comment, isClosed bool) {
57+
func (m *mailNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *user_model.User, commitID string, issue *issues_model.Issue, actionComment *issues_model.Comment, isClosed bool) {
5858
var actionType activities_model.ActionType
5959
if issue.IsPull {
6060
if isClosed {

modules/notification/notification.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ func NotifyNewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*
7777
}
7878

7979
// NotifyIssueChangeStatus notifies close or reopen issue to notifiers
80-
func NotifyIssueChangeStatus(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, actionComment *issues_model.Comment, closeOrReopen bool) {
80+
func NotifyIssueChangeStatus(ctx context.Context, doer *user_model.User, commitID string, issue *issues_model.Issue, actionComment *issues_model.Comment, closeOrReopen bool) {
8181
for _, notifier := range notifiers {
82-
notifier.NotifyIssueChangeStatus(ctx, doer, issue, actionComment, closeOrReopen)
82+
notifier.NotifyIssueChangeStatus(ctx, doer, commitID, issue, actionComment, closeOrReopen)
8383
}
8484
}
8585

modules/notification/ui/ui.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (ns *notificationService) NotifyNewIssue(ctx context.Context, issue *issues
9393
}
9494
}
9595

96-
func (ns *notificationService) NotifyIssueChangeStatus(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, actionComment *issues_model.Comment, isClosed bool) {
96+
func (ns *notificationService) NotifyIssueChangeStatus(ctx context.Context, doer *user_model.User, commitID string, issue *issues_model.Issue, actionComment *issues_model.Comment, isClosed bool) {
9797
_ = ns.issueQueue.Push(issueNotificationOpts{
9898
IssueID: issue.ID,
9999
NotificationAuthorID: doer.ID,

modules/structs/hook.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ type IssuePayload struct {
352352
Issue *Issue `json:"issue"`
353353
Repository *Repository `json:"repository"`
354354
Sender *User `json:"sender"`
355+
CommitID string `json:"commit_id"`
355356
}
356357

357358
// JSONPayload encodes the IssuePayload to JSON, with an indentation of two spaces.
@@ -386,6 +387,7 @@ type PullRequestPayload struct {
386387
PullRequest *PullRequest `json:"pull_request"`
387388
Repository *Repository `json:"repository"`
388389
Sender *User `json:"sender"`
390+
CommitID string `json:"commit_id"`
389391
Review *ReviewPayload `json:"review"`
390392
}
391393

routers/api/v1/repo/issue.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ func CreateIssue(ctx *context.APIContext) {
654654
}
655655

656656
if form.Closed {
657-
if err := issue_service.ChangeStatus(issue, ctx.Doer, true); err != nil {
657+
if err := issue_service.ChangeStatus(issue, ctx.Doer, "", true); err != nil {
658658
if issues_model.IsErrDependenciesLeft(err) {
659659
ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this issue because it still has open dependencies")
660660
return
@@ -826,7 +826,7 @@ func EditIssue(ctx *context.APIContext) {
826826
}
827827

828828
if statusChangeComment != nil {
829-
notification.NotifyIssueChangeStatus(ctx, ctx.Doer, issue, statusChangeComment, issue.IsClosed)
829+
notification.NotifyIssueChangeStatus(ctx, ctx.Doer, "", issue, statusChangeComment, issue.IsClosed)
830830
}
831831

832832
// Refetch from database to assign some automatic values

routers/api/v1/repo/pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ func EditPullRequest(ctx *context.APIContext) {
600600
}
601601

602602
if statusChangeComment != nil {
603-
notification.NotifyIssueChangeStatus(ctx, ctx.Doer, issue, statusChangeComment, issue.IsClosed)
603+
notification.NotifyIssueChangeStatus(ctx, ctx.Doer, "", issue, statusChangeComment, issue.IsClosed)
604604
}
605605

606606
// change pull target branch

routers/web/repo/issue.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2599,7 +2599,7 @@ func UpdateIssueStatus(ctx *context.Context) {
25992599
}
26002600
for _, issue := range issues {
26012601
if issue.IsClosed != isClosed {
2602-
if err := issue_service.ChangeStatus(issue, ctx.Doer, isClosed); err != nil {
2602+
if err := issue_service.ChangeStatus(issue, ctx.Doer, "", isClosed); err != nil {
26032603
if issues_model.IsErrDependenciesLeft(err) {
26042604
ctx.JSON(http.StatusPreconditionFailed, map[string]interface{}{
26052605
"error": "cannot close this issue because it still has open dependencies",
@@ -2696,7 +2696,7 @@ func NewComment(ctx *context.Context) {
26962696
ctx.Flash.Info(ctx.Tr("repo.pulls.open_unmerged_pull_exists", pr.Index))
26972697
} else {
26982698
isClosed := form.Status == "close"
2699-
if err := issue_service.ChangeStatus(issue, ctx.Doer, isClosed); err != nil {
2699+
if err := issue_service.ChangeStatus(issue, ctx.Doer, "", isClosed); err != nil {
27002700
log.Error("ChangeStatus: %v", err)
27012701

27022702
if issues_model.IsErrDependenciesLeft(err) {

0 commit comments

Comments
 (0)