Move issue milestone assign to issue service and move webhook to notification (#8780)
This commit is contained in:
parent
f518fe6662
commit
8f26397928
9 changed files with 70 additions and 68 deletions
|
@ -20,7 +20,7 @@ type Notifier interface {
|
||||||
|
|
||||||
NotifyNewIssue(*models.Issue)
|
NotifyNewIssue(*models.Issue)
|
||||||
NotifyIssueChangeStatus(*models.User, *models.Issue, bool)
|
NotifyIssueChangeStatus(*models.User, *models.Issue, bool)
|
||||||
NotifyIssueChangeMilestone(doer *models.User, issue *models.Issue)
|
NotifyIssueChangeMilestone(doer *models.User, issue *models.Issue, oldMilestoneID int64)
|
||||||
NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, assignee *models.User, removed bool, comment *models.Comment)
|
NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, assignee *models.User, removed bool, comment *models.Comment)
|
||||||
NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string)
|
NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string)
|
||||||
NotifyIssueClearLabels(doer *models.User, issue *models.Issue)
|
NotifyIssueClearLabels(doer *models.User, issue *models.Issue)
|
||||||
|
|
|
@ -75,7 +75,7 @@ func (*NullNotifier) NotifyDeleteRelease(doer *models.User, rel *models.Release)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotifyIssueChangeMilestone places a place holder function
|
// NotifyIssueChangeMilestone places a place holder function
|
||||||
func (*NullNotifier) NotifyIssueChangeMilestone(doer *models.User, issue *models.Issue) {
|
func (*NullNotifier) NotifyIssueChangeMilestone(doer *models.User, issue *models.Issue, oldMilestoneID int64) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotifyIssueChangeContent places a place holder function
|
// NotifyIssueChangeContent places a place holder function
|
||||||
|
|
|
@ -128,9 +128,9 @@ func NotifyDeleteRelease(doer *models.User, rel *models.Release) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotifyIssueChangeMilestone notifies change milestone to notifiers
|
// NotifyIssueChangeMilestone notifies change milestone to notifiers
|
||||||
func NotifyIssueChangeMilestone(doer *models.User, issue *models.Issue) {
|
func NotifyIssueChangeMilestone(doer *models.User, issue *models.Issue, oldMilestoneID int64) {
|
||||||
for _, notifier := range notifiers {
|
for _, notifier := range notifiers {
|
||||||
notifier.NotifyIssueChangeMilestone(doer, issue)
|
notifier.NotifyIssueChangeMilestone(doer, issue, oldMilestoneID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -419,3 +419,45 @@ func (m *webhookNotifier) NotifyIssueChangeLabels(doer *models.User, issue *mode
|
||||||
log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)
|
log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *webhookNotifier) NotifyIssueChangeMilestone(doer *models.User, issue *models.Issue, oldMilestoneID int64) {
|
||||||
|
var hookAction api.HookIssueAction
|
||||||
|
var err error
|
||||||
|
if issue.MilestoneID > 0 {
|
||||||
|
hookAction = api.HookIssueMilestoned
|
||||||
|
} else {
|
||||||
|
hookAction = api.HookIssueDemilestoned
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = issue.LoadAttributes(); err != nil {
|
||||||
|
log.Error("issue.LoadAttributes failed: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
mode, _ := models.AccessLevel(doer, issue.Repo)
|
||||||
|
if issue.IsPull {
|
||||||
|
err = issue.PullRequest.LoadIssue()
|
||||||
|
if err != nil {
|
||||||
|
log.Error("LoadIssue: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = webhook_module.PrepareWebhooks(issue.Repo, models.HookEventPullRequest, &api.PullRequestPayload{
|
||||||
|
Action: hookAction,
|
||||||
|
Index: issue.Index,
|
||||||
|
PullRequest: issue.PullRequest.APIFormat(),
|
||||||
|
Repository: issue.Repo.APIFormat(mode),
|
||||||
|
Sender: doer.APIFormat(),
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
err = webhook_module.PrepareWebhooks(issue.Repo, models.HookEventIssues, &api.IssuePayload{
|
||||||
|
Action: hookAction,
|
||||||
|
Index: issue.Index,
|
||||||
|
Issue: issue.APIFormat(),
|
||||||
|
Repository: issue.Repo.APIFormat(mode),
|
||||||
|
Sender: doer.APIFormat(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -20,7 +20,6 @@ import (
|
||||||
"code.gitea.io/gitea/modules/timeutil"
|
"code.gitea.io/gitea/modules/timeutil"
|
||||||
"code.gitea.io/gitea/modules/util"
|
"code.gitea.io/gitea/modules/util"
|
||||||
issue_service "code.gitea.io/gitea/services/issue"
|
issue_service "code.gitea.io/gitea/services/issue"
|
||||||
milestone_service "code.gitea.io/gitea/services/milestone"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// SearchIssues searches for issues across the repositories that the user has access to
|
// SearchIssues searches for issues across the repositories that the user has access to
|
||||||
|
@ -494,7 +493,7 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) {
|
||||||
issue.MilestoneID != *form.Milestone {
|
issue.MilestoneID != *form.Milestone {
|
||||||
oldMilestoneID := issue.MilestoneID
|
oldMilestoneID := issue.MilestoneID
|
||||||
issue.MilestoneID = *form.Milestone
|
issue.MilestoneID = *form.Milestone
|
||||||
if err = milestone_service.ChangeMilestoneAssign(issue, ctx.User, oldMilestoneID); err != nil {
|
if err = issue_service.ChangeMilestoneAssign(issue, ctx.User, oldMilestoneID); err != nil {
|
||||||
ctx.Error(500, "ChangeMilestoneAssign", err)
|
ctx.Error(500, "ChangeMilestoneAssign", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@ import (
|
||||||
api "code.gitea.io/gitea/modules/structs"
|
api "code.gitea.io/gitea/modules/structs"
|
||||||
"code.gitea.io/gitea/modules/timeutil"
|
"code.gitea.io/gitea/modules/timeutil"
|
||||||
issue_service "code.gitea.io/gitea/services/issue"
|
issue_service "code.gitea.io/gitea/services/issue"
|
||||||
milestone_service "code.gitea.io/gitea/services/milestone"
|
|
||||||
pull_service "code.gitea.io/gitea/services/pull"
|
pull_service "code.gitea.io/gitea/services/pull"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -420,7 +419,7 @@ func EditPullRequest(ctx *context.APIContext, form api.EditPullRequestOption) {
|
||||||
issue.MilestoneID != form.Milestone {
|
issue.MilestoneID != form.Milestone {
|
||||||
oldMilestoneID := issue.MilestoneID
|
oldMilestoneID := issue.MilestoneID
|
||||||
issue.MilestoneID = form.Milestone
|
issue.MilestoneID = form.Milestone
|
||||||
if err = milestone_service.ChangeMilestoneAssign(issue, ctx.User, oldMilestoneID); err != nil {
|
if err = issue_service.ChangeMilestoneAssign(issue, ctx.User, oldMilestoneID); err != nil {
|
||||||
ctx.Error(500, "ChangeMilestoneAssign", err)
|
ctx.Error(500, "ChangeMilestoneAssign", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,6 @@ import (
|
||||||
"code.gitea.io/gitea/modules/util"
|
"code.gitea.io/gitea/modules/util"
|
||||||
comment_service "code.gitea.io/gitea/services/comments"
|
comment_service "code.gitea.io/gitea/services/comments"
|
||||||
issue_service "code.gitea.io/gitea/services/issue"
|
issue_service "code.gitea.io/gitea/services/issue"
|
||||||
milestone_service "code.gitea.io/gitea/services/milestone"
|
|
||||||
|
|
||||||
"github.com/unknwon/com"
|
"github.com/unknwon/com"
|
||||||
)
|
)
|
||||||
|
@ -1099,7 +1098,7 @@ func UpdateIssueMilestone(ctx *context.Context) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
issue.MilestoneID = milestoneID
|
issue.MilestoneID = milestoneID
|
||||||
if err := milestone_service.ChangeMilestoneAssign(issue, ctx.User, oldMilestoneID); err != nil {
|
if err := issue_service.ChangeMilestoneAssign(issue, ctx.User, oldMilestoneID); err != nil {
|
||||||
ctx.ServerError("ChangeMilestoneAssign", err)
|
ctx.ServerError("ChangeMilestoneAssign", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
21
services/issue/milestone.go
Normal file
21
services/issue/milestone.go
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package issue
|
||||||
|
|
||||||
|
import (
|
||||||
|
"code.gitea.io/gitea/models"
|
||||||
|
"code.gitea.io/gitea/modules/notification"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ChangeMilestoneAssign changes assignment of milestone for issue.
|
||||||
|
func ChangeMilestoneAssign(issue *models.Issue, doer *models.User, oldMilestoneID int64) (err error) {
|
||||||
|
if err = models.ChangeMilestoneAssign(issue, doer, oldMilestoneID); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
notification.NotifyIssueChangeMilestone(doer, issue, oldMilestoneID)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -1,58 +0,0 @@
|
||||||
// Copyright 2019 The Gitea Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a MIT-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package models
|
|
||||||
|
|
||||||
import (
|
|
||||||
"code.gitea.io/gitea/models"
|
|
||||||
"code.gitea.io/gitea/modules/log"
|
|
||||||
api "code.gitea.io/gitea/modules/structs"
|
|
||||||
"code.gitea.io/gitea/modules/webhook"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ChangeMilestoneAssign changes assignment of milestone for issue.
|
|
||||||
func ChangeMilestoneAssign(issue *models.Issue, doer *models.User, oldMilestoneID int64) (err error) {
|
|
||||||
if err = models.ChangeMilestoneAssign(issue, doer, oldMilestoneID); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var hookAction api.HookIssueAction
|
|
||||||
if issue.MilestoneID > 0 {
|
|
||||||
hookAction = api.HookIssueMilestoned
|
|
||||||
} else {
|
|
||||||
hookAction = api.HookIssueDemilestoned
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = issue.LoadAttributes(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
mode, _ := models.AccessLevel(doer, issue.Repo)
|
|
||||||
if issue.IsPull {
|
|
||||||
err = issue.PullRequest.LoadIssue()
|
|
||||||
if err != nil {
|
|
||||||
log.Error("LoadIssue: %v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err = webhook.PrepareWebhooks(issue.Repo, models.HookEventPullRequest, &api.PullRequestPayload{
|
|
||||||
Action: hookAction,
|
|
||||||
Index: issue.Index,
|
|
||||||
PullRequest: issue.PullRequest.APIFormat(),
|
|
||||||
Repository: issue.Repo.APIFormat(mode),
|
|
||||||
Sender: doer.APIFormat(),
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
err = webhook.PrepareWebhooks(issue.Repo, models.HookEventIssues, &api.IssuePayload{
|
|
||||||
Action: hookAction,
|
|
||||||
Index: issue.Index,
|
|
||||||
Issue: issue.APIFormat(),
|
|
||||||
Repository: issue.Repo.APIFormat(mode),
|
|
||||||
Sender: doer.APIFormat(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
Loading…
Reference in a new issue