diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2019-09-30 21:50:44 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-30 21:50:44 +0800 |
commit | e6113000c5cbbdbf10af7bda472fc8b254ec7605 (patch) | |
tree | e7b9fd86a4e7451083c298d29f09ecaaedf9970c /services | |
parent | a5992d172551f7821e023cd3cbca1a7cc0b919ee (diff) | |
download | gitea-e6113000c5cbbdbf10af7bda472fc8b254ec7605.tar.gz gitea-e6113000c5cbbdbf10af7bda472fc8b254ec7605.zip |
Extract actions on new issue from models to services (#8217)
* extract actions on new issue from models to services
* improve code
* rename services/issues to services/issue
Diffstat (limited to 'services')
-rw-r--r-- | services/issue/issue.go | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/services/issue/issue.go b/services/issue/issue.go new file mode 100644 index 0000000000..5afdfc9901 --- /dev/null +++ b/services/issue/issue.go @@ -0,0 +1,47 @@ +// 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 ( + "fmt" + + "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/log" + api "code.gitea.io/gitea/modules/structs" +) + +// NewIssue creates new issue with labels for repository. +func NewIssue(repo *models.Repository, issue *models.Issue, labelIDs []int64, assigneeIDs []int64, uuids []string) error { + if err := models.NewIssue(repo, issue, labelIDs, assigneeIDs, uuids); err != nil { + return err + } + + if err := models.NotifyWatchers(&models.Action{ + ActUserID: issue.Poster.ID, + ActUser: issue.Poster, + OpType: models.ActionCreateIssue, + Content: fmt.Sprintf("%d|%s", issue.Index, issue.Title), + RepoID: repo.ID, + Repo: repo, + IsPrivate: repo.IsPrivate, + }); err != nil { + log.Error("NotifyWatchers: %v", err) + } + + mode, _ := models.AccessLevel(issue.Poster, issue.Repo) + if err := models.PrepareWebhooks(repo, models.HookEventIssues, &api.IssuePayload{ + Action: api.HookIssueOpened, + Index: issue.Index, + Issue: issue.APIFormat(), + Repository: repo.APIFormat(mode), + Sender: issue.Poster.APIFormat(), + }); err != nil { + log.Error("PrepareWebhooks: %v", err) + } else { + go models.HookQueue.Add(issue.RepoID) + } + + return nil +} |