From f694bb45d79dcc093bc6332eabb3af063bc6b088 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 30 Oct 2019 16:36:25 +0800 Subject: Move issue change content from models to service (#8711) * Move issue change content from models to service * fix lint --- modules/notification/webhook/webhook.go | 38 +++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'modules/notification') diff --git a/modules/notification/webhook/webhook.go b/modules/notification/webhook/webhook.go index bd7c8b29d3..a2af152edd 100644 --- a/modules/notification/webhook/webhook.go +++ b/modules/notification/webhook/webhook.go @@ -277,3 +277,41 @@ func (m *webhookNotifier) NotifyNewIssue(issue *models.Issue) { go models.HookQueue.Add(issue.RepoID) } } + +func (m *webhookNotifier) NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string) { + mode, _ := models.AccessLevel(issue.Poster, issue.Repo) + var err error + if issue.IsPull { + issue.PullRequest.Issue = issue + err = models.PrepareWebhooks(issue.Repo, models.HookEventPullRequest, &api.PullRequestPayload{ + Action: api.HookIssueEdited, + Index: issue.Index, + Changes: &api.ChangesPayload{ + Body: &api.ChangesFromPayload{ + From: oldContent, + }, + }, + PullRequest: issue.PullRequest.APIFormat(), + Repository: issue.Repo.APIFormat(mode), + Sender: doer.APIFormat(), + }) + } else { + err = models.PrepareWebhooks(issue.Repo, models.HookEventIssues, &api.IssuePayload{ + Action: api.HookIssueEdited, + Index: issue.Index, + Changes: &api.ChangesPayload{ + Body: &api.ChangesFromPayload{ + From: oldContent, + }, + }, + Issue: issue.APIFormat(), + Repository: issue.Repo.APIFormat(mode), + Sender: doer.APIFormat(), + }) + } + if err != nil { + log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err) + } else { + go models.HookQueue.Add(issue.RepoID) + } +} -- cgit v1.2.3