summaryrefslogtreecommitdiffstats
path: root/services/issue
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2019-10-11 14:44:43 +0800
committerGitHub <noreply@github.com>2019-10-11 14:44:43 +0800
commit46a12f196b1742a2462259ed3dd9c33c4c2f150b (patch)
treeb8203c7d6d91841ce53a7b875135714b372fa1a5 /services/issue
parent9ff9f5ad1d8d2680c9c146831458afdbd4e641df (diff)
downloadgitea-46a12f196b1742a2462259ed3dd9c33c4c2f150b.tar.gz
gitea-46a12f196b1742a2462259ed3dd9c33c4c2f150b.zip
Move change issue title from models to issue service package (#8456)
* move change issue title from models to issue service package * make the change less * fix typo
Diffstat (limited to 'services/issue')
-rw-r--r--services/issue/issue.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/services/issue/issue.go b/services/issue/issue.go
index 5afdfc9901..a28916a7f9 100644
--- a/services/issue/issue.go
+++ b/services/issue/issue.go
@@ -45,3 +45,54 @@ func NewIssue(repo *models.Repository, issue *models.Issue, labelIDs []int64, as
return nil
}
+
+// ChangeTitle changes the title of this issue, as the given user.
+func ChangeTitle(issue *models.Issue, doer *models.User, title string) (err error) {
+ oldTitle := issue.Title
+ issue.Title = title
+
+ if err = issue.ChangeTitle(doer, oldTitle); err != nil {
+ return
+ }
+
+ mode, _ := models.AccessLevel(issue.Poster, issue.Repo)
+ if issue.IsPull {
+ if err = issue.LoadPullRequest(); err != nil {
+ return fmt.Errorf("loadPullRequest: %v", err)
+ }
+ issue.PullRequest.Issue = issue
+ err = models.PrepareWebhooks(issue.Repo, models.HookEventPullRequest, &api.PullRequestPayload{
+ Action: api.HookIssueEdited,
+ Index: issue.Index,
+ Changes: &api.ChangesPayload{
+ Title: &api.ChangesFromPayload{
+ From: oldTitle,
+ },
+ },
+ 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{
+ Title: &api.ChangesFromPayload{
+ From: oldTitle,
+ },
+ },
+ Issue: issue.APIFormat(),
+ Repository: issue.Repo.APIFormat(mode),
+ Sender: issue.Poster.APIFormat(),
+ })
+ }
+
+ if err != nil {
+ log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)
+ } else {
+ go models.HookQueue.Add(issue.RepoID)
+ }
+
+ return nil
+}