Skip to content

Commit 6f30598

Browse files
committed
Move issue change content from models to service
1 parent af8957b commit 6f30598

File tree

4 files changed

+62
-38
lines changed

4 files changed

+62
-38
lines changed

models/issue.go

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,6 @@ func (issue *Issue) UpdateAttachments(uuids []string) (err error) {
750750

751751
// ChangeContent changes issue content, as the given user.
752752
func (issue *Issue) ChangeContent(doer *User, content string) (err error) {
753-
oldContent := issue.Content
754753
issue.Content = content
755754

756755
sess := x.NewSession()
@@ -772,42 +771,6 @@ func (issue *Issue) ChangeContent(doer *User, content string) (err error) {
772771
if err = sess.Commit(); err != nil {
773772
return err
774773
}
775-
sess.Close()
776-
777-
mode, _ := AccessLevel(issue.Poster, issue.Repo)
778-
if issue.IsPull {
779-
issue.PullRequest.Issue = issue
780-
err = PrepareWebhooks(issue.Repo, HookEventPullRequest, &api.PullRequestPayload{
781-
Action: api.HookIssueEdited,
782-
Index: issue.Index,
783-
Changes: &api.ChangesPayload{
784-
Body: &api.ChangesFromPayload{
785-
From: oldContent,
786-
},
787-
},
788-
PullRequest: issue.PullRequest.APIFormat(),
789-
Repository: issue.Repo.APIFormat(mode),
790-
Sender: doer.APIFormat(),
791-
})
792-
} else {
793-
err = PrepareWebhooks(issue.Repo, HookEventIssues, &api.IssuePayload{
794-
Action: api.HookIssueEdited,
795-
Index: issue.Index,
796-
Changes: &api.ChangesPayload{
797-
Body: &api.ChangesFromPayload{
798-
From: oldContent,
799-
},
800-
},
801-
Issue: issue.APIFormat(),
802-
Repository: issue.Repo.APIFormat(mode),
803-
Sender: doer.APIFormat(),
804-
})
805-
}
806-
if err != nil {
807-
log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)
808-
} else {
809-
go HookQueue.Add(issue.RepoID)
810-
}
811774

812775
return nil
813776
}

modules/notification/webhook/webhook.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,3 +277,41 @@ func (m *webhookNotifier) NotifyNewIssue(issue *models.Issue) {
277277
go models.HookQueue.Add(issue.RepoID)
278278
}
279279
}
280+
281+
func (m *webhookNotifier) NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string) {
282+
mode, _ := models.AccessLevel(issue.Poster, issue.Repo)
283+
var err error
284+
if issue.IsPull {
285+
issue.PullRequest.Issue = issue
286+
err = models.PrepareWebhooks(issue.Repo, models.HookEventPullRequest, &api.PullRequestPayload{
287+
Action: api.HookIssueEdited,
288+
Index: issue.Index,
289+
Changes: &api.ChangesPayload{
290+
Body: &api.ChangesFromPayload{
291+
From: oldContent,
292+
},
293+
},
294+
PullRequest: issue.PullRequest.APIFormat(),
295+
Repository: issue.Repo.APIFormat(mode),
296+
Sender: doer.APIFormat(),
297+
})
298+
} else {
299+
err = models.PrepareWebhooks(issue.Repo, models.HookEventIssues, &api.IssuePayload{
300+
Action: api.HookIssueEdited,
301+
Index: issue.Index,
302+
Changes: &api.ChangesPayload{
303+
Body: &api.ChangesFromPayload{
304+
From: oldContent,
305+
},
306+
},
307+
Issue: issue.APIFormat(),
308+
Repository: issue.Repo.APIFormat(mode),
309+
Sender: doer.APIFormat(),
310+
})
311+
}
312+
if err != nil {
313+
log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)
314+
} else {
315+
go models.HookQueue.Add(issue.RepoID)
316+
}
317+
}

routers/repo/issue.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,7 @@ func UpdateIssueContent(ctx *context.Context) {
10661066
}
10671067

10681068
content := ctx.Query("content")
1069-
if err := issue.ChangeContent(ctx.User, content); err != nil {
1069+
if err := issue_service.ChangeContent(issue, ctx.User, content); err != nil {
10701070
ctx.ServerError("ChangeContent", err)
10711071
return
10721072
}

services/issue/content.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2019 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package issue
6+
7+
import (
8+
"code.gitea.io/gitea/models"
9+
"code.gitea.io/gitea/modules/notification"
10+
)
11+
12+
// ChangeContent changes issue content, as the given user.
13+
func ChangeContent(issue *models.Issue, doer *models.User, content string) (err error) {
14+
oldContent := issue.Content
15+
16+
if err := issue.ChangeContent(doer, content); err != nil {
17+
return err
18+
}
19+
20+
notification.NotifyIssueChangeContent(doer, issue, oldContent)
21+
22+
return nil
23+
}

0 commit comments

Comments
 (0)