Merge 159abc04df into fe78154895
This commit is contained in:
commit
1f8db73abc
|
|
@ -719,8 +719,9 @@ func TransferRepoAction(doer, oldOwner *User, repo *Repository) error {
|
||||||
return transferRepoAction(x, doer, oldOwner, repo)
|
return transferRepoAction(x, doer, oldOwner, repo)
|
||||||
}
|
}
|
||||||
|
|
||||||
func mergePullRequestAction(e Engine, doer *User, repo *Repository, issue *Issue) error {
|
// MergePullRequestAction adds new action for merging pull request.
|
||||||
return notifyWatchers(e, &Action{
|
func MergePullRequestAction(doer *User, repo *Repository, issue *Issue) error {
|
||||||
|
return notifyWatchers(x, &Action{
|
||||||
ActUserID: doer.ID,
|
ActUserID: doer.ID,
|
||||||
ActUser: doer,
|
ActUser: doer,
|
||||||
OpType: ActionMergePullRequest,
|
OpType: ActionMergePullRequest,
|
||||||
|
|
@ -731,11 +732,6 @@ func mergePullRequestAction(e Engine, doer *User, repo *Repository, issue *Issue
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// MergePullRequestAction adds new action for merging pull request.
|
|
||||||
func MergePullRequestAction(actUser *User, repo *Repository, pull *Issue) error {
|
|
||||||
return mergePullRequestAction(x, actUser, repo, pull)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetFeedsOptions options for retrieving feeds
|
// GetFeedsOptions options for retrieving feeds
|
||||||
type GetFeedsOptions struct {
|
type GetFeedsOptions struct {
|
||||||
RequestedUser *User
|
RequestedUser *User
|
||||||
|
|
|
||||||
200
models/issue.go
200
models/issue.go
|
|
@ -86,6 +86,11 @@ func (issue *Issue) IsOverdue() bool {
|
||||||
return util.TimeStampNow() >= issue.DeadlineUnix
|
return util.TimeStampNow() >= issue.DeadlineUnix
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LoadRepo loads repository
|
||||||
|
func (issue *Issue) LoadRepo() error {
|
||||||
|
return issue.loadRepo(x)
|
||||||
|
}
|
||||||
|
|
||||||
func (issue *Issue) loadRepo(e Engine) (err error) {
|
func (issue *Issue) loadRepo(e Engine) (err error) {
|
||||||
if issue.Repo == nil {
|
if issue.Repo == nil {
|
||||||
issue.Repo, err = getRepositoryByID(e, issue.RepoID)
|
issue.Repo, err = getRepositoryByID(e, issue.RepoID)
|
||||||
|
|
@ -105,14 +110,9 @@ func (issue *Issue) IsTimetrackerEnabled() bool {
|
||||||
return issue.Repo.IsTimetrackerEnabled()
|
return issue.Repo.IsTimetrackerEnabled()
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPullRequest returns the issue pull request
|
// LoadPullRequest loads the issue pull request
|
||||||
func (issue *Issue) GetPullRequest() (pr *PullRequest, err error) {
|
func (issue *Issue) LoadPullRequest() error {
|
||||||
if !issue.IsPull {
|
return issue.loadPullRequest(x)
|
||||||
return nil, fmt.Errorf("Issue is not a pull request")
|
|
||||||
}
|
|
||||||
|
|
||||||
pr, err = getPullRequestByIssueID(x, issue.ID)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (issue *Issue) loadLabels(e Engine) (err error) {
|
func (issue *Issue) loadLabels(e Engine) (err error) {
|
||||||
|
|
@ -368,52 +368,6 @@ func (issue *Issue) HasLabel(labelID int64) bool {
|
||||||
return issue.hasLabel(x, labelID)
|
return issue.hasLabel(x, labelID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (issue *Issue) sendLabelUpdatedWebhook(doer *User) {
|
|
||||||
var err error
|
|
||||||
|
|
||||||
if err = issue.loadRepo(x); err != nil {
|
|
||||||
log.Error(4, "loadRepo: %v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = issue.loadPoster(x); err != nil {
|
|
||||||
log.Error(4, "loadPoster: %v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
mode, _ := AccessLevel(issue.Poster.ID, issue.Repo)
|
|
||||||
if issue.IsPull {
|
|
||||||
if err = issue.loadPullRequest(x); err != nil {
|
|
||||||
log.Error(4, "loadPullRequest: %v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if err = issue.PullRequest.LoadIssue(); err != nil {
|
|
||||||
log.Error(4, "LoadIssue: %v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err = PrepareWebhooks(issue.Repo, HookEventPullRequest, &api.PullRequestPayload{
|
|
||||||
Action: api.HookIssueLabelUpdated,
|
|
||||||
Index: issue.Index,
|
|
||||||
PullRequest: issue.PullRequest.APIFormat(),
|
|
||||||
Repository: issue.Repo.APIFormat(AccessModeNone),
|
|
||||||
Sender: doer.APIFormat(),
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
err = PrepareWebhooks(issue.Repo, HookEventIssues, &api.IssuePayload{
|
|
||||||
Action: api.HookIssueLabelUpdated,
|
|
||||||
Index: issue.Index,
|
|
||||||
Issue: issue.APIFormat(),
|
|
||||||
Repository: issue.Repo.APIFormat(mode),
|
|
||||||
Sender: doer.APIFormat(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
log.Error(4, "PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)
|
|
||||||
} else {
|
|
||||||
go HookQueue.Add(issue.RepoID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (issue *Issue) addLabel(e *xorm.Session, label *Label, doer *User) error {
|
func (issue *Issue) addLabel(e *xorm.Session, label *Label, doer *User) error {
|
||||||
return newIssueLabel(e, issue, label, doer)
|
return newIssueLabel(e, issue, label, doer)
|
||||||
}
|
}
|
||||||
|
|
@ -424,7 +378,6 @@ func (issue *Issue) AddLabel(doer *User, label *Label) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
issue.sendLabelUpdatedWebhook(doer)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -438,7 +391,6 @@ func (issue *Issue) AddLabels(doer *User, labels []*Label) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
issue.sendLabelUpdatedWebhook(doer)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -474,7 +426,6 @@ func (issue *Issue) RemoveLabel(doer *User, label *Label) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
issue.sendLabelUpdatedWebhook(doer)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -521,39 +472,6 @@ func (issue *Issue) ClearLabels(doer *User) (err error) {
|
||||||
return fmt.Errorf("Commit: %v", err)
|
return fmt.Errorf("Commit: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = issue.loadPoster(x); err != nil {
|
|
||||||
return fmt.Errorf("loadPoster: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
mode, _ := AccessLevel(issue.Poster.ID, issue.Repo)
|
|
||||||
if issue.IsPull {
|
|
||||||
err = issue.PullRequest.LoadIssue()
|
|
||||||
if err != nil {
|
|
||||||
log.Error(4, "LoadIssue: %v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err = PrepareWebhooks(issue.Repo, HookEventPullRequest, &api.PullRequestPayload{
|
|
||||||
Action: api.HookIssueLabelCleared,
|
|
||||||
Index: issue.Index,
|
|
||||||
PullRequest: issue.PullRequest.APIFormat(),
|
|
||||||
Repository: issue.Repo.APIFormat(mode),
|
|
||||||
Sender: doer.APIFormat(),
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
err = PrepareWebhooks(issue.Repo, HookEventIssues, &api.IssuePayload{
|
|
||||||
Action: api.HookIssueLabelCleared,
|
|
||||||
Index: issue.Index,
|
|
||||||
Issue: issue.APIFormat(),
|
|
||||||
Repository: issue.Repo.APIFormat(mode),
|
|
||||||
Sender: doer.APIFormat(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
log.Error(4, "PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)
|
|
||||||
} else {
|
|
||||||
go HookQueue.Add(issue.RepoID)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -780,42 +698,6 @@ func (issue *Issue) ChangeTitle(doer *User, title string) (err error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
mode, _ := AccessLevel(issue.Poster.ID, issue.Repo)
|
|
||||||
if issue.IsPull {
|
|
||||||
issue.PullRequest.Issue = issue
|
|
||||||
err = PrepareWebhooks(issue.Repo, 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 = PrepareWebhooks(issue.Repo, 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(4, "PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)
|
|
||||||
} else {
|
|
||||||
go HookQueue.Add(issue.RepoID)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -839,48 +721,12 @@ func AddDeletePRBranchComment(doer *User, repo *Repository, issueID int64, branc
|
||||||
|
|
||||||
// ChangeContent changes issue content, as the given user.
|
// ChangeContent changes issue content, as the given user.
|
||||||
func (issue *Issue) ChangeContent(doer *User, content string) (err error) {
|
func (issue *Issue) ChangeContent(doer *User, content string) (err error) {
|
||||||
oldContent := issue.Content
|
|
||||||
issue.Content = content
|
issue.Content = content
|
||||||
|
|
||||||
if err = UpdateIssueCols(issue, "content"); err != nil {
|
if err = UpdateIssueCols(issue, "content"); err != nil {
|
||||||
return fmt.Errorf("UpdateIssueCols: %v", err)
|
return fmt.Errorf("UpdateIssueCols: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
mode, _ := AccessLevel(issue.Poster.ID, issue.Repo)
|
|
||||||
if issue.IsPull {
|
|
||||||
issue.PullRequest.Issue = issue
|
|
||||||
err = PrepareWebhooks(issue.Repo, 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 = PrepareWebhooks(issue.Repo, 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(4, "PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)
|
|
||||||
} else {
|
|
||||||
go HookQueue.Add(issue.RepoID)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1049,36 +895,6 @@ func NewIssue(repo *Repository, issue *Issue, labelIDs []int64, assigneeIDs []in
|
||||||
return fmt.Errorf("Commit: %v", err)
|
return fmt.Errorf("Commit: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateIssueIndexer(issue.ID)
|
|
||||||
|
|
||||||
if err = NotifyWatchers(&Action{
|
|
||||||
ActUserID: issue.Poster.ID,
|
|
||||||
ActUser: issue.Poster,
|
|
||||||
OpType: ActionCreateIssue,
|
|
||||||
Content: fmt.Sprintf("%d|%s", issue.Index, issue.Title),
|
|
||||||
RepoID: repo.ID,
|
|
||||||
Repo: repo,
|
|
||||||
IsPrivate: repo.IsPrivate,
|
|
||||||
}); err != nil {
|
|
||||||
log.Error(4, "NotifyWatchers: %v", err)
|
|
||||||
}
|
|
||||||
if err = issue.MailParticipants(); err != nil {
|
|
||||||
log.Error(4, "MailParticipants: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
mode, _ := AccessLevel(issue.Poster.ID, issue.Repo)
|
|
||||||
if err = PrepareWebhooks(repo, HookEventIssues, &api.IssuePayload{
|
|
||||||
Action: api.HookIssueOpened,
|
|
||||||
Index: issue.Index,
|
|
||||||
Issue: issue.APIFormat(),
|
|
||||||
Repository: repo.APIFormat(mode),
|
|
||||||
Sender: issue.Poster.APIFormat(),
|
|
||||||
}); err != nil {
|
|
||||||
log.Error(4, "PrepareWebhooks: %v", err)
|
|
||||||
} else {
|
|
||||||
go HookQueue.Add(issue.RepoID)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -658,18 +658,6 @@ func CreateIssueComment(doer *User, repo *Repository, issue *Issue, content stri
|
||||||
return nil, fmt.Errorf("CreateComment: %v", err)
|
return nil, fmt.Errorf("CreateComment: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
mode, _ := AccessLevel(doer.ID, repo)
|
|
||||||
if err = PrepareWebhooks(repo, HookEventIssueComment, &api.IssueCommentPayload{
|
|
||||||
Action: api.HookIssueCommentCreated,
|
|
||||||
Issue: issue.APIFormat(),
|
|
||||||
Comment: comment.APIFormat(),
|
|
||||||
Repository: repo.APIFormat(mode),
|
|
||||||
Sender: doer.APIFormat(),
|
|
||||||
}); err != nil {
|
|
||||||
log.Error(2, "PrepareWebhooks [comment_id: %d]: %v", comment.ID, err)
|
|
||||||
} else {
|
|
||||||
go HookQueue.Add(repo.ID)
|
|
||||||
}
|
|
||||||
return comment, nil
|
return comment, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -783,38 +771,20 @@ func GetCommentsByRepoIDSince(repoID, since int64) ([]*Comment, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateComment updates information of comment.
|
// UpdateComment updates information of comment.
|
||||||
func UpdateComment(doer *User, c *Comment, oldContent string) error {
|
func UpdateComment(doer *User, c *Comment) error {
|
||||||
if _, err := x.ID(c.ID).AllCols().Update(c); err != nil {
|
if _, err := x.ID(c.ID).AllCols().Update(c); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if c.Type == CommentTypeComment {
|
|
||||||
UpdateIssueIndexer(c.IssueID)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.LoadIssue(); err != nil {
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateCommentAction updates action when comment is deleted
|
||||||
|
func UpdateCommentAction(comment *Comment) error {
|
||||||
|
if _, err := x.Where("comment_id = ?", comment.ID).
|
||||||
|
Cols("is_deleted").Update(&Action{IsDeleted: true}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := c.Issue.LoadAttributes(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
mode, _ := AccessLevel(doer.ID, c.Issue.Repo)
|
|
||||||
if err := PrepareWebhooks(c.Issue.Repo, HookEventIssueComment, &api.IssueCommentPayload{
|
|
||||||
Action: api.HookIssueCommentEdited,
|
|
||||||
Issue: c.Issue.APIFormat(),
|
|
||||||
Comment: c.APIFormat(),
|
|
||||||
Changes: &api.ChangesPayload{
|
|
||||||
Body: &api.ChangesFromPayload{
|
|
||||||
From: oldContent,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Repository: c.Issue.Repo.APIFormat(mode),
|
|
||||||
Sender: doer.APIFormat(),
|
|
||||||
}); err != nil {
|
|
||||||
log.Error(2, "PrepareWebhooks [comment_id: %d]: %v", c.ID, err)
|
|
||||||
} else {
|
|
||||||
go HookQueue.Add(c.Issue.Repo.ID)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -837,35 +807,9 @@ func DeleteComment(doer *User, comment *Comment) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if _, err := sess.Where("comment_id = ?", comment.ID).Cols("is_deleted").Update(&Action{IsDeleted: true}); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := sess.Commit(); err != nil {
|
if err := sess.Commit(); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if comment.Type == CommentTypeComment {
|
|
||||||
UpdateIssueIndexer(comment.IssueID)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := comment.LoadIssue(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := comment.Issue.LoadAttributes(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
mode, _ := AccessLevel(doer.ID, comment.Issue.Repo)
|
|
||||||
|
|
||||||
if err := PrepareWebhooks(comment.Issue.Repo, HookEventIssueComment, &api.IssueCommentPayload{
|
|
||||||
Action: api.HookIssueCommentDeleted,
|
|
||||||
Issue: comment.Issue.APIFormat(),
|
|
||||||
Comment: comment.APIFormat(),
|
|
||||||
Repository: comment.Issue.Repo.APIFormat(mode),
|
|
||||||
Sender: doer.APIFormat(),
|
|
||||||
}); err != nil {
|
|
||||||
log.Error(2, "PrepareWebhooks [comment_id: %d]: %v", comment.ID, err)
|
|
||||||
} else {
|
|
||||||
go HookQueue.Add(comment.Issue.Repo.ID)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ package models
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"code.gitea.io/gitea/modules/log"
|
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
"code.gitea.io/gitea/modules/util"
|
"code.gitea.io/gitea/modules/util"
|
||||||
api "code.gitea.io/sdk/gitea"
|
api "code.gitea.io/sdk/gitea"
|
||||||
|
|
@ -366,45 +365,6 @@ func ChangeMilestoneAssign(issue *Issue, doer *User, oldMilestoneID int64) (err
|
||||||
return fmt.Errorf("Commit: %v", err)
|
return fmt.Errorf("Commit: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var hookAction api.HookIssueAction
|
|
||||||
if issue.MilestoneID > 0 {
|
|
||||||
hookAction = api.HookIssueMilestoned
|
|
||||||
} else {
|
|
||||||
hookAction = api.HookIssueDemilestoned
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = issue.LoadAttributes(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
mode, _ := AccessLevel(doer.ID, issue.Repo)
|
|
||||||
if issue.IsPull {
|
|
||||||
err = issue.PullRequest.LoadIssue()
|
|
||||||
if err != nil {
|
|
||||||
log.Error(2, "LoadIssue: %v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err = PrepareWebhooks(issue.Repo, HookEventPullRequest, &api.PullRequestPayload{
|
|
||||||
Action: hookAction,
|
|
||||||
Index: issue.Index,
|
|
||||||
PullRequest: issue.PullRequest.APIFormat(),
|
|
||||||
Repository: issue.Repo.APIFormat(mode),
|
|
||||||
Sender: doer.APIFormat(),
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
err = PrepareWebhooks(issue.Repo, HookEventIssues, &api.IssuePayload{
|
|
||||||
Action: hookAction,
|
|
||||||
Index: issue.Index,
|
|
||||||
Issue: issue.APIFormat(),
|
|
||||||
Repository: issue.Repo.APIFormat(mode),
|
|
||||||
Sender: doer.APIFormat(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
log.Error(2, "PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)
|
|
||||||
} else {
|
|
||||||
go HookQueue.Add(issue.RepoID)
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -445,10 +445,6 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository, mergeStyle
|
||||||
log.Error(4, "setMerged [%d]: %v", pr.ID, err)
|
log.Error(4, "setMerged [%d]: %v", pr.ID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = MergePullRequestAction(doer, pr.Issue.Repo, pr.Issue); err != nil {
|
|
||||||
log.Error(4, "MergePullRequestAction [%d]: %v", pr.ID, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reset cached commit count
|
// Reset cached commit count
|
||||||
cache.Remove(pr.Issue.Repo.GetCommitsCountCacheKey(pr.BaseBranch, true))
|
cache.Remove(pr.Issue.Repo.GetCommitsCountCacheKey(pr.BaseBranch, true))
|
||||||
|
|
||||||
|
|
@ -458,19 +454,6 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository, mergeStyle
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
mode, _ := AccessLevel(doer.ID, pr.Issue.Repo)
|
|
||||||
if err = PrepareWebhooks(pr.Issue.Repo, HookEventPullRequest, &api.PullRequestPayload{
|
|
||||||
Action: api.HookIssueClosed,
|
|
||||||
Index: pr.Index,
|
|
||||||
PullRequest: pr.APIFormat(),
|
|
||||||
Repository: pr.Issue.Repo.APIFormat(mode),
|
|
||||||
Sender: doer.APIFormat(),
|
|
||||||
}); err != nil {
|
|
||||||
log.Error(4, "PrepareWebhooks: %v", err)
|
|
||||||
} else {
|
|
||||||
go HookQueue.Add(pr.Issue.Repo.ID)
|
|
||||||
}
|
|
||||||
|
|
||||||
l, err := baseGitRepo.CommitsBetweenIDs(pr.MergedCommitID, pr.MergeBase)
|
l, err := baseGitRepo.CommitsBetweenIDs(pr.MergedCommitID, pr.MergeBase)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(4, "CommitsBetweenIDs: %v", err)
|
log.Error(4, "CommitsBetweenIDs: %v", err)
|
||||||
|
|
@ -489,21 +472,6 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository, mergeStyle
|
||||||
l.PushFront(mergeCommit)
|
l.PushFront(mergeCommit)
|
||||||
}
|
}
|
||||||
|
|
||||||
p := &api.PushPayload{
|
|
||||||
Ref: git.BranchPrefix + pr.BaseBranch,
|
|
||||||
Before: pr.MergeBase,
|
|
||||||
After: mergeCommit.ID.String(),
|
|
||||||
CompareURL: setting.AppURL + pr.BaseRepo.ComposeCompareURL(pr.MergeBase, pr.MergedCommitID),
|
|
||||||
Commits: ListToPushCommits(l).ToAPIPayloadCommits(pr.BaseRepo.HTMLURL()),
|
|
||||||
Repo: pr.BaseRepo.APIFormat(mode),
|
|
||||||
Pusher: pr.HeadRepo.MustOwner().APIFormat(),
|
|
||||||
Sender: doer.APIFormat(),
|
|
||||||
}
|
|
||||||
if err = PrepareWebhooks(pr.BaseRepo, HookEventPush, p); err != nil {
|
|
||||||
log.Error(4, "PrepareWebhooks: %v", err)
|
|
||||||
} else {
|
|
||||||
go HookQueue.Add(pr.BaseRepo.ID)
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -769,36 +737,8 @@ func NewPullRequest(repo *Repository, pull *Issue, labelIDs []int64, uuids []str
|
||||||
return fmt.Errorf("Commit: %v", err)
|
return fmt.Errorf("Commit: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateIssueIndexer(pull.ID)
|
|
||||||
|
|
||||||
if err = NotifyWatchers(&Action{
|
|
||||||
ActUserID: pull.Poster.ID,
|
|
||||||
ActUser: pull.Poster,
|
|
||||||
OpType: ActionCreatePullRequest,
|
|
||||||
Content: fmt.Sprintf("%d|%s", pull.Index, pull.Title),
|
|
||||||
RepoID: repo.ID,
|
|
||||||
Repo: repo,
|
|
||||||
IsPrivate: repo.IsPrivate,
|
|
||||||
}); err != nil {
|
|
||||||
log.Error(4, "NotifyWatchers: %v", err)
|
|
||||||
} else if err = pull.MailParticipants(); err != nil {
|
|
||||||
log.Error(4, "MailParticipants: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
pr.Issue = pull
|
pr.Issue = pull
|
||||||
pull.PullRequest = pr
|
pull.PullRequest = pr
|
||||||
mode, _ := AccessLevel(pull.Poster.ID, repo)
|
|
||||||
if err = PrepareWebhooks(repo, HookEventPullRequest, &api.PullRequestPayload{
|
|
||||||
Action: api.HookIssueOpened,
|
|
||||||
Index: pull.Index,
|
|
||||||
PullRequest: pr.APIFormat(),
|
|
||||||
Repository: repo.APIFormat(mode),
|
|
||||||
Sender: pull.Poster.APIFormat(),
|
|
||||||
}); err != nil {
|
|
||||||
log.Error(4, "PrepareWebhooks: %v", err)
|
|
||||||
} else {
|
|
||||||
go HookQueue.Add(repo.ID)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"code.gitea.io/git"
|
"code.gitea.io/git"
|
||||||
"code.gitea.io/gitea/modules/log"
|
|
||||||
"code.gitea.io/gitea/modules/process"
|
"code.gitea.io/gitea/modules/process"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
"code.gitea.io/gitea/modules/util"
|
"code.gitea.io/gitea/modules/util"
|
||||||
|
|
@ -195,24 +194,6 @@ func CreateRelease(gitRepo *git.Repository, rel *Release, attachmentUUIDs []stri
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !rel.IsDraft {
|
|
||||||
if err := rel.LoadAttributes(); err != nil {
|
|
||||||
log.Error(2, "LoadAttributes: %v", err)
|
|
||||||
} else {
|
|
||||||
mode, _ := AccessLevel(rel.PublisherID, rel.Repo)
|
|
||||||
if err := PrepareWebhooks(rel.Repo, HookEventRelease, &api.ReleasePayload{
|
|
||||||
Action: api.HookReleasePublished,
|
|
||||||
Release: rel.APIFormat(),
|
|
||||||
Repository: rel.Repo.APIFormat(mode),
|
|
||||||
Sender: rel.Publisher.APIFormat(),
|
|
||||||
}); err != nil {
|
|
||||||
log.Error(2, "PrepareWebhooks: %v", err)
|
|
||||||
} else {
|
|
||||||
go HookQueue.Add(rel.Repo.ID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -391,38 +372,26 @@ func UpdateRelease(doer *User, gitRepo *git.Repository, rel *Release, attachment
|
||||||
|
|
||||||
err = addReleaseAttachments(rel.ID, attachmentUUIDs)
|
err = addReleaseAttachments(rel.ID, attachmentUUIDs)
|
||||||
|
|
||||||
mode, _ := accessLevel(x, doer.ID, rel.Repo)
|
|
||||||
if err1 := PrepareWebhooks(rel.Repo, HookEventRelease, &api.ReleasePayload{
|
|
||||||
Action: api.HookReleaseUpdated,
|
|
||||||
Release: rel.APIFormat(),
|
|
||||||
Repository: rel.Repo.APIFormat(mode),
|
|
||||||
Sender: rel.Publisher.APIFormat(),
|
|
||||||
}); err1 != nil {
|
|
||||||
log.Error(2, "PrepareWebhooks: %v", err)
|
|
||||||
} else {
|
|
||||||
go HookQueue.Add(rel.Repo.ID)
|
|
||||||
}
|
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteReleaseByID deletes a release and corresponding Git tag by given ID.
|
// DeleteReleaseByID deletes a release and corresponding Git tag by given ID.
|
||||||
func DeleteReleaseByID(id int64, u *User, delTag bool) error {
|
func DeleteReleaseByID(id int64, u *User, delTag bool) (*Release, error) {
|
||||||
rel, err := GetReleaseByID(id)
|
rel, err := GetReleaseByID(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("GetReleaseByID: %v", err)
|
return nil, fmt.Errorf("GetReleaseByID: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
repo, err := GetRepositoryByID(rel.RepoID)
|
repo, err := GetRepositoryByID(rel.RepoID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("GetRepositoryByID: %v", err)
|
return nil, fmt.Errorf("GetRepositoryByID: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
has, err := HasAccess(u.ID, repo, AccessModeWrite)
|
has, err := HasAccess(u.ID, repo, AccessModeWrite)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("HasAccess: %v", err)
|
return nil, fmt.Errorf("HasAccess: %v", err)
|
||||||
} else if !has {
|
} else if !has {
|
||||||
return fmt.Errorf("DeleteReleaseByID: permission denied")
|
return nil, fmt.Errorf("DeleteReleaseByID: permission denied")
|
||||||
}
|
}
|
||||||
|
|
||||||
if delTag {
|
if delTag {
|
||||||
|
|
@ -430,11 +399,11 @@ func DeleteReleaseByID(id int64, u *User, delTag bool) error {
|
||||||
fmt.Sprintf("DeleteReleaseByID (git tag -d): %d", rel.ID),
|
fmt.Sprintf("DeleteReleaseByID (git tag -d): %d", rel.ID),
|
||||||
"git", "tag", "-d", rel.TagName)
|
"git", "tag", "-d", rel.TagName)
|
||||||
if err != nil && !strings.Contains(stderr, "not found") {
|
if err != nil && !strings.Contains(stderr, "not found") {
|
||||||
return fmt.Errorf("git tag -d: %v - %s", err, stderr)
|
return nil, fmt.Errorf("git tag -d: %v - %s", err, stderr)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err = x.ID(rel.ID).Delete(new(Release)); err != nil {
|
if _, err = x.ID(rel.ID).Delete(new(Release)); err != nil {
|
||||||
return fmt.Errorf("Delete: %v", err)
|
return nil, fmt.Errorf("Delete: %v", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
rel.IsTag = true
|
rel.IsTag = true
|
||||||
|
|
@ -444,28 +413,12 @@ func DeleteReleaseByID(id int64, u *User, delTag bool) error {
|
||||||
rel.Note = ""
|
rel.Note = ""
|
||||||
|
|
||||||
if _, err = x.ID(rel.ID).AllCols().Update(rel); err != nil {
|
if _, err = x.ID(rel.ID).AllCols().Update(rel); err != nil {
|
||||||
return fmt.Errorf("Update: %v", err)
|
return nil, fmt.Errorf("Update: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rel.Repo = repo
|
rel.Repo = repo
|
||||||
if err = rel.LoadAttributes(); err != nil {
|
return rel, nil
|
||||||
return fmt.Errorf("LoadAttributes: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
mode, _ := accessLevel(x, u.ID, rel.Repo)
|
|
||||||
if err := PrepareWebhooks(rel.Repo, HookEventRelease, &api.ReleasePayload{
|
|
||||||
Action: api.HookReleaseDeleted,
|
|
||||||
Release: rel.APIFormat(),
|
|
||||||
Repository: rel.Repo.APIFormat(mode),
|
|
||||||
Sender: rel.Publisher.APIFormat(),
|
|
||||||
}); err != nil {
|
|
||||||
log.Error(2, "PrepareWebhooks: %v", err)
|
|
||||||
} else {
|
|
||||||
go HookQueue.Add(rel.Repo.ID)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SyncReleasesWithTags synchronizes release table with repository tags
|
// SyncReleasesWithTags synchronizes release table with repository tags
|
||||||
|
|
|
||||||
|
|
@ -1384,15 +1384,7 @@ func createRepository(e *xorm.Session, doer, u *User, repo *Repository) (err err
|
||||||
return fmt.Errorf("getOwnerTeam: %v", err)
|
return fmt.Errorf("getOwnerTeam: %v", err)
|
||||||
} else if err = t.addRepository(e, repo); err != nil {
|
} else if err = t.addRepository(e, repo); err != nil {
|
||||||
return fmt.Errorf("addRepository: %v", err)
|
return fmt.Errorf("addRepository: %v", err)
|
||||||
} else if err = prepareWebhooks(e, repo, HookEventRepository, &api.RepositoryPayload{
|
|
||||||
Action: api.HookRepoCreated,
|
|
||||||
Repository: repo.APIFormat(AccessModeOwner),
|
|
||||||
Organization: u.APIFormat(),
|
|
||||||
Sender: doer.APIFormat(),
|
|
||||||
}); err != nil {
|
|
||||||
return fmt.Errorf("prepareWebhooks: %v", err)
|
|
||||||
}
|
}
|
||||||
go HookQueue.Add(repo.ID)
|
|
||||||
} else {
|
} else {
|
||||||
// Organization automatically called this in addRepository method.
|
// Organization automatically called this in addRepository method.
|
||||||
if err = repo.recalculateAccesses(e); err != nil {
|
if err = repo.recalculateAccesses(e); err != nil {
|
||||||
|
|
@ -1402,8 +1394,6 @@ func createRepository(e *xorm.Session, doer, u *User, repo *Repository) (err err
|
||||||
|
|
||||||
if err = watchRepo(e, doer.ID, repo.ID, true); err != nil {
|
if err = watchRepo(e, doer.ID, repo.ID, true); err != nil {
|
||||||
return fmt.Errorf("watchRepo: %v", err)
|
return fmt.Errorf("watchRepo: %v", err)
|
||||||
} else if err = newRepoAction(e, u, repo); err != nil {
|
|
||||||
return fmt.Errorf("newRepoAction: %v", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -1938,19 +1928,6 @@ func DeleteRepository(doer *User, uid, repoID int64) error {
|
||||||
return fmt.Errorf("Commit: %v", err)
|
return fmt.Errorf("Commit: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if org.IsOrganization() {
|
|
||||||
if err = PrepareWebhooks(repo, HookEventRepository, &api.RepositoryPayload{
|
|
||||||
Action: api.HookRepoDeleted,
|
|
||||||
Repository: repo.APIFormat(AccessModeOwner),
|
|
||||||
Organization: org.APIFormat(),
|
|
||||||
Sender: doer.APIFormat(),
|
|
||||||
}); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
go HookQueue.Add(repo.ID)
|
|
||||||
}
|
|
||||||
|
|
||||||
DeleteRepoFromIndexer(repo)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2149,7 +2126,7 @@ func gatherMissingRepoRecords() ([]*Repository, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteMissingRepositories deletes all repository records that lost Git files.
|
// DeleteMissingRepositories deletes all repository records that lost Git files.
|
||||||
func DeleteMissingRepositories(doer *User) error {
|
func DeleteMissingRepositories(doer *User, onDeleted func(doer *User, repo *Repository)) error {
|
||||||
repos, err := gatherMissingRepoRecords()
|
repos, err := gatherMissingRepoRecords()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("gatherMissingRepoRecords: %v", err)
|
return fmt.Errorf("gatherMissingRepoRecords: %v", err)
|
||||||
|
|
@ -2165,6 +2142,8 @@ func DeleteMissingRepositories(doer *User) error {
|
||||||
if err2 := CreateRepositoryNotice(fmt.Sprintf("DeleteRepository [%d]: %v", repo.ID, err)); err2 != nil {
|
if err2 := CreateRepositoryNotice(fmt.Sprintf("DeleteRepository [%d]: %v", repo.ID, err)); err2 != nil {
|
||||||
return fmt.Errorf("CreateRepositoryNotice: %v", err)
|
return fmt.Errorf("CreateRepositoryNotice: %v", err)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
onDeleted(doer, repo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -2466,19 +2445,6 @@ func ForkRepository(doer, u *User, oldRepo *Repository, name, desc string) (_ *R
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
oldMode, _ := AccessLevel(doer.ID, oldRepo)
|
|
||||||
mode, _ := AccessLevel(doer.ID, repo)
|
|
||||||
|
|
||||||
if err = PrepareWebhooks(oldRepo, HookEventFork, &api.ForkPayload{
|
|
||||||
Forkee: oldRepo.APIFormat(oldMode),
|
|
||||||
Repo: repo.APIFormat(mode),
|
|
||||||
Sender: doer.APIFormat(),
|
|
||||||
}); err != nil {
|
|
||||||
log.Error(2, "PrepareWebhooks [repo_id: %d]: %v", oldRepo.ID, err)
|
|
||||||
} else {
|
|
||||||
go HookQueue.Add(oldRepo.ID)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = repo.UpdateSize(); err != nil {
|
if err = repo.UpdateSize(); err != nil {
|
||||||
log.Error(4, "Failed to update size for repository: %v", err)
|
log.Error(4, "Failed to update size for repository: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
124
modules/notification/action/action.go
Normal file
124
modules/notification/action/action.go
Normal file
|
|
@ -0,0 +1,124 @@
|
||||||
|
// Copyright 2018 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 action
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"code.gitea.io/git"
|
||||||
|
"code.gitea.io/gitea/models"
|
||||||
|
"code.gitea.io/gitea/modules/log"
|
||||||
|
"code.gitea.io/gitea/modules/notification/base"
|
||||||
|
)
|
||||||
|
|
||||||
|
type actionNotifier struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
_ base.Notifier = &actionNotifier{}
|
||||||
|
)
|
||||||
|
|
||||||
|
// NewNotifier returns a new actionNotifier
|
||||||
|
func NewNotifier() base.Notifier {
|
||||||
|
return &actionNotifier{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *actionNotifier) Run() {}
|
||||||
|
|
||||||
|
func (r *actionNotifier) NotifyCreateIssueComment(doer *models.User, repo *models.Repository,
|
||||||
|
issue *models.Issue, comment *models.Comment) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *actionNotifier) NotifyNewIssue(issue *models.Issue) {
|
||||||
|
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: issue.Repo.ID,
|
||||||
|
Repo: issue.Repo,
|
||||||
|
IsPrivate: issue.Repo.IsPrivate,
|
||||||
|
}); err != nil {
|
||||||
|
log.Error(4, "NotifyWatchers: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *actionNotifier) NotifyCloseIssue(issue *models.Issue, doer *models.User) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *actionNotifier) NotifyNewPullRequest(pr *models.PullRequest) {
|
||||||
|
issue := pr.Issue
|
||||||
|
if err := models.NotifyWatchers(&models.Action{
|
||||||
|
ActUserID: issue.Poster.ID,
|
||||||
|
ActUser: issue.Poster,
|
||||||
|
OpType: models.ActionCreatePullRequest,
|
||||||
|
Content: fmt.Sprintf("%d|%s", issue.Index, issue.Title),
|
||||||
|
RepoID: issue.Repo.ID,
|
||||||
|
Repo: issue.Repo,
|
||||||
|
IsPrivate: issue.Repo.IsPrivate,
|
||||||
|
}); err != nil {
|
||||||
|
log.Error(4, "NotifyWatchers: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *actionNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *models.User, baseRepo *git.Repository) {
|
||||||
|
if err := models.MergePullRequestAction(doer, pr.Issue.Repo, pr.Issue); err != nil {
|
||||||
|
log.Error(4, "MergePullRequestAction [%d]: %v", pr.ID, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *actionNotifier) NotifyUpdateComment(doer *models.User, c *models.Comment, oldContent string) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *actionNotifier) NotifyDeleteComment(doer *models.User, c *models.Comment) {
|
||||||
|
if err := models.UpdateCommentAction(c); err != nil {
|
||||||
|
log.Error(4, "UpdateCommentAction [%d]: %v", c.ID, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *actionNotifier) NotifyDeleteRepository(doer *models.User, repo *models.Repository) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *actionNotifier) NotifyForkRepository(doer *models.User, oldRepo, repo *models.Repository) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *actionNotifier) NotifyNewRelease(rel *models.Release) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *actionNotifier) NotifyUpdateRelease(doer *models.User, rel *models.Release) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *actionNotifier) NotifyDeleteRelease(doer *models.User, rel *models.Release) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *actionNotifier) NotifyChangeMilestone(doer *models.User, issue *models.Issue) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *actionNotifier) NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *actionNotifier) NotifyIssueClearLabels(doer *models.User, issue *models.Issue) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *actionNotifier) NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *actionNotifier) NotifyIssueChangeLabels(doer *models.User, issue *models.Issue,
|
||||||
|
addedLabels []*models.Label, removedLabels []*models.Label) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *actionNotifier) NotifyCreateRepository(doer *models.User, u *models.User, repo *models.Repository) {
|
||||||
|
if err := models.NewRepoAction(doer, repo); err != nil {
|
||||||
|
log.Error(4, "NewRepoAction [%d]: %v", repo.ID, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *actionNotifier) NotifyMigrateRepository(doer *models.User, u *models.User, repo *models.Repository) {
|
||||||
|
if err := models.NewRepoAction(doer, repo); err != nil {
|
||||||
|
log.Error(4, "NewRepoAction [%d]: %v", repo.ID, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
36
modules/notification/base/base.go
Normal file
36
modules/notification/base/base.go
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
// Copyright 2018 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 base
|
||||||
|
|
||||||
|
import (
|
||||||
|
"code.gitea.io/git"
|
||||||
|
"code.gitea.io/gitea/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Notifier defines an interface to notify receiver
|
||||||
|
type Notifier interface {
|
||||||
|
Run()
|
||||||
|
NotifyCreateIssueComment(*models.User, *models.Repository,
|
||||||
|
*models.Issue, *models.Comment)
|
||||||
|
NotifyNewIssue(*models.Issue)
|
||||||
|
NotifyCloseIssue(*models.Issue, *models.User)
|
||||||
|
NotifyMergePullRequest(*models.PullRequest, *models.User, *git.Repository)
|
||||||
|
NotifyNewPullRequest(*models.PullRequest)
|
||||||
|
NotifyUpdateComment(*models.User, *models.Comment, string)
|
||||||
|
NotifyDeleteComment(*models.User, *models.Comment)
|
||||||
|
NotifyDeleteRepository(doer *models.User, repo *models.Repository)
|
||||||
|
NotifyForkRepository(doer *models.User, oldRepo, repo *models.Repository)
|
||||||
|
NotifyNewRelease(rel *models.Release)
|
||||||
|
NotifyUpdateRelease(doer *models.User, rel *models.Release)
|
||||||
|
NotifyDeleteRelease(doer *models.User, rel *models.Release)
|
||||||
|
NotifyChangeMilestone(doer *models.User, issue *models.Issue)
|
||||||
|
NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string)
|
||||||
|
NotifyIssueClearLabels(doer *models.User, issue *models.Issue)
|
||||||
|
NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string)
|
||||||
|
NotifyIssueChangeLabels(doer *models.User, issue *models.Issue,
|
||||||
|
addedLabels []*models.Label, removedLabels []*models.Label)
|
||||||
|
NotifyCreateRepository(doer *models.User, u *models.User, repo *models.Repository)
|
||||||
|
NotifyMigrateRepository(doer *models.User, u *models.User, repo *models.Repository)
|
||||||
|
}
|
||||||
96
modules/notification/indexer/indexer.go
Normal file
96
modules/notification/indexer/indexer.go
Normal file
|
|
@ -0,0 +1,96 @@
|
||||||
|
// Copyright 2018 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 indexer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"code.gitea.io/git"
|
||||||
|
"code.gitea.io/gitea/models"
|
||||||
|
"code.gitea.io/gitea/modules/notification/base"
|
||||||
|
)
|
||||||
|
|
||||||
|
type indexerNotifier struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
_ base.Notifier = &indexerNotifier{}
|
||||||
|
)
|
||||||
|
|
||||||
|
// NewNotifier create a new indexerNotifier notifier
|
||||||
|
func NewNotifier() base.Notifier {
|
||||||
|
return &indexerNotifier{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *indexerNotifier) Run() {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *indexerNotifier) NotifyCreateIssueComment(doer *models.User, repo *models.Repository,
|
||||||
|
issue *models.Issue, comment *models.Comment) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *indexerNotifier) NotifyNewIssue(issue *models.Issue) {
|
||||||
|
models.UpdateIssueIndexer(issue.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *indexerNotifier) NotifyCloseIssue(issue *models.Issue, doer *models.User) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *indexerNotifier) NotifyNewPullRequest(pr *models.PullRequest) {
|
||||||
|
models.UpdateIssueIndexer(pr.Issue.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *indexerNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *models.User, baseRepo *git.Repository) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *indexerNotifier) NotifyUpdateComment(doer *models.User, c *models.Comment, oldContent string) {
|
||||||
|
if c.Type == models.CommentTypeComment {
|
||||||
|
models.UpdateIssueIndexer(c.IssueID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *indexerNotifier) NotifyDeleteComment(doer *models.User, comment *models.Comment) {
|
||||||
|
if comment.Type == models.CommentTypeComment {
|
||||||
|
models.UpdateIssueIndexer(comment.IssueID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *indexerNotifier) NotifyDeleteRepository(doer *models.User, repo *models.Repository) {
|
||||||
|
models.DeleteRepoFromIndexer(repo)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *indexerNotifier) NotifyForkRepository(doer *models.User, oldRepo, repo *models.Repository) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *indexerNotifier) NotifyNewRelease(rel *models.Release) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *indexerNotifier) NotifyUpdateRelease(doer *models.User, rel *models.Release) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *indexerNotifier) NotifyDeleteRelease(doer *models.User, rel *models.Release) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *indexerNotifier) NotifyChangeMilestone(doer *models.User, issue *models.Issue) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *indexerNotifier) NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *indexerNotifier) NotifyIssueClearLabels(doer *models.User, issue *models.Issue) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *indexerNotifier) NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *indexerNotifier) NotifyIssueChangeLabels(doer *models.User, issue *models.Issue,
|
||||||
|
addedLabels []*models.Label, removedLabels []*models.Label) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *indexerNotifier) NotifyCreateRepository(doer *models.User, u *models.User, repo *models.Repository) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *indexerNotifier) NotifyMigrateRepository(doer *models.User, u *models.User, repo *models.Repository) {
|
||||||
|
}
|
||||||
95
modules/notification/mail/mail.go
Normal file
95
modules/notification/mail/mail.go
Normal file
|
|
@ -0,0 +1,95 @@
|
||||||
|
// Copyright 2018 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 mail
|
||||||
|
|
||||||
|
import (
|
||||||
|
"code.gitea.io/git"
|
||||||
|
"code.gitea.io/gitea/models"
|
||||||
|
"code.gitea.io/gitea/modules/log"
|
||||||
|
"code.gitea.io/gitea/modules/notification/base"
|
||||||
|
)
|
||||||
|
|
||||||
|
type mailNotifier struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
_ base.Notifier = &mailNotifier{}
|
||||||
|
)
|
||||||
|
|
||||||
|
// NewNotifier create a new mailNotifier notifier
|
||||||
|
func NewNotifier() base.Notifier {
|
||||||
|
return &mailNotifier{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mailNotifier) Run() {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mailNotifier) NotifyCreateIssueComment(doer *models.User, repo *models.Repository,
|
||||||
|
issue *models.Issue, comment *models.Comment) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mailNotifier) NotifyNewIssue(issue *models.Issue) {
|
||||||
|
if err := issue.MailParticipants(); err != nil {
|
||||||
|
log.Error(4, "MailParticipants: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mailNotifier) NotifyCloseIssue(issue *models.Issue, doer *models.User) {
|
||||||
|
if err := issue.MailParticipants(); err != nil {
|
||||||
|
log.Error(4, "MailParticipants: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mailNotifier) NotifyNewPullRequest(pr *models.PullRequest) {
|
||||||
|
if err := pr.Issue.MailParticipants(); err != nil {
|
||||||
|
log.Error(4, "MailParticipants: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mailNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *models.User, baseRepo *git.Repository) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mailNotifier) NotifyUpdateComment(doer *models.User, c *models.Comment, oldContent string) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mailNotifier) NotifyDeleteComment(doer *models.User, c *models.Comment) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mailNotifier) NotifyDeleteRepository(doer *models.User, repo *models.Repository) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mailNotifier) NotifyForkRepository(doer *models.User, oldRepo, repo *models.Repository) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mailNotifier) NotifyNewRelease(rel *models.Release) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mailNotifier) NotifyUpdateRelease(doer *models.User, rel *models.Release) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mailNotifier) NotifyDeleteRelease(doer *models.User, rel *models.Release) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mailNotifier) NotifyChangeMilestone(doer *models.User, issue *models.Issue) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mailNotifier) NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mailNotifier) NotifyIssueClearLabels(doer *models.User, issue *models.Issue) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mailNotifier) NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mailNotifier) NotifyIssueChangeLabels(doer *models.User, issue *models.Issue,
|
||||||
|
addedLabels []*models.Label, removedLabels []*models.Label) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mailNotifier) NotifyCreateRepository(doer *models.User, u *models.User, repo *models.Repository) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mailNotifier) NotifyMigrateRepository(doer *models.User, u *models.User, repo *models.Repository) {
|
||||||
|
}
|
||||||
|
|
@ -1,50 +1,169 @@
|
||||||
// Copyright 2016 The Gitea Authors. All rights reserved.
|
// Copyright 2018 The Gitea Authors. All rights reserved.
|
||||||
// Use of this source code is governed by a MIT-style
|
// Use of this source code is governed by a MIT-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package notification
|
package notification
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"code.gitea.io/git"
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/notification/action"
|
||||||
)
|
"code.gitea.io/gitea/modules/notification/base"
|
||||||
|
"code.gitea.io/gitea/modules/notification/indexer"
|
||||||
type (
|
"code.gitea.io/gitea/modules/notification/mail"
|
||||||
notificationService struct {
|
"code.gitea.io/gitea/modules/notification/ui"
|
||||||
issueQueue chan issueNotificationOpts
|
"code.gitea.io/gitea/modules/notification/webhook"
|
||||||
}
|
|
||||||
|
|
||||||
issueNotificationOpts struct {
|
|
||||||
issue *models.Issue
|
|
||||||
notificationAuthorID int64
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// Service is the notification service
|
notifiers []base.Notifier
|
||||||
Service = ¬ificationService{
|
|
||||||
issueQueue: make(chan issueNotificationOpts, 100),
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// RegisterNotifier providers method to receive notify messages
|
||||||
|
func RegisterNotifier(notifier base.Notifier) {
|
||||||
|
go notifier.Run()
|
||||||
|
notifiers = append(notifiers, notifier)
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
go Service.Run()
|
RegisterNotifier(webhook.NewNotifier())
|
||||||
|
RegisterNotifier(ui.NewNotifier())
|
||||||
|
RegisterNotifier(mail.NewNotifier())
|
||||||
|
RegisterNotifier(indexer.NewNotifier())
|
||||||
|
RegisterNotifier(action.NewNotifier())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ns *notificationService) Run() {
|
// NotifyCreateIssueComment notifies issue comment related message to notifiers
|
||||||
for {
|
func NotifyCreateIssueComment(doer *models.User, repo *models.Repository,
|
||||||
select {
|
issue *models.Issue, comment *models.Comment) {
|
||||||
case opts := <-ns.issueQueue:
|
for _, notifier := range notifiers {
|
||||||
if err := models.CreateOrUpdateIssueNotifications(opts.issue, opts.notificationAuthorID); err != nil {
|
notifier.NotifyCreateIssueComment(doer, repo, issue, comment)
|
||||||
log.Error(4, "Was unable to create issue notification: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ns *notificationService) NotifyIssue(issue *models.Issue, notificationAuthorID int64) {
|
// NotifyNewIssue notifies new issue to notifiers
|
||||||
ns.issueQueue <- issueNotificationOpts{
|
func NotifyNewIssue(issue *models.Issue) {
|
||||||
issue,
|
for _, notifier := range notifiers {
|
||||||
notificationAuthorID,
|
notifier.NotifyNewIssue(issue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotifyCloseIssue notifies close issue to notifiers
|
||||||
|
func NotifyCloseIssue(issue *models.Issue, doer *models.User) {
|
||||||
|
for _, notifier := range notifiers {
|
||||||
|
notifier.NotifyCloseIssue(issue, doer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotifyMergePullRequest notifies merge pull request to notifiers
|
||||||
|
func NotifyMergePullRequest(pr *models.PullRequest, doer *models.User, baseGitRepo *git.Repository) {
|
||||||
|
for _, notifier := range notifiers {
|
||||||
|
notifier.NotifyMergePullRequest(pr, doer, baseGitRepo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotifyNewPullRequest notifies new pull request to notifiers
|
||||||
|
func NotifyNewPullRequest(pr *models.PullRequest) {
|
||||||
|
for _, notifier := range notifiers {
|
||||||
|
notifier.NotifyNewPullRequest(pr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotifyUpdateComment notifies update comment to notifiers
|
||||||
|
func NotifyUpdateComment(doer *models.User, c *models.Comment, oldContent string) {
|
||||||
|
for _, notifier := range notifiers {
|
||||||
|
notifier.NotifyUpdateComment(doer, c, oldContent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotifyDeleteComment notifies delete comment to notifiers
|
||||||
|
func NotifyDeleteComment(doer *models.User, c *models.Comment) {
|
||||||
|
for _, notifier := range notifiers {
|
||||||
|
notifier.NotifyDeleteComment(doer, c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotifyDeleteRepository notifies delete repository to notifiers
|
||||||
|
func NotifyDeleteRepository(doer *models.User, repo *models.Repository) {
|
||||||
|
for _, notifier := range notifiers {
|
||||||
|
notifier.NotifyDeleteRepository(doer, repo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotifyForkRepository notifies fork repository to notifiers
|
||||||
|
func NotifyForkRepository(doer *models.User, oldRepo, repo *models.Repository) {
|
||||||
|
for _, notifier := range notifiers {
|
||||||
|
notifier.NotifyForkRepository(doer, oldRepo, repo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotifyNewRelease notifies new release to notifiers
|
||||||
|
func NotifyNewRelease(rel *models.Release) {
|
||||||
|
for _, notifier := range notifiers {
|
||||||
|
notifier.NotifyNewRelease(rel)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotifyUpdateRelease notifies update release to notifiers
|
||||||
|
func NotifyUpdateRelease(doer *models.User, rel *models.Release) {
|
||||||
|
for _, notifier := range notifiers {
|
||||||
|
notifier.NotifyUpdateRelease(doer, rel)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotifyDeleteRelease notifies delete release to notifiers
|
||||||
|
func NotifyDeleteRelease(doer *models.User, rel *models.Release) {
|
||||||
|
for _, notifier := range notifiers {
|
||||||
|
notifier.NotifyDeleteRelease(doer, rel)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotifyChangeMilestone notifies change milestone to notifiers
|
||||||
|
func NotifyChangeMilestone(doer *models.User, issue *models.Issue) {
|
||||||
|
for _, notifier := range notifiers {
|
||||||
|
notifier.NotifyChangeMilestone(doer, issue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotifyIssueChangeContent notifies change content to notifiers
|
||||||
|
func NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string) {
|
||||||
|
for _, notifier := range notifiers {
|
||||||
|
notifier.NotifyIssueChangeContent(doer, issue, oldContent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotifyIssueClearLabels notifies clear labels to notifiers
|
||||||
|
func NotifyIssueClearLabels(doer *models.User, issue *models.Issue) {
|
||||||
|
for _, notifier := range notifiers {
|
||||||
|
notifier.NotifyIssueClearLabels(doer, issue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotifyIssueChangeTitle notifies change title to notifiers
|
||||||
|
func NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) {
|
||||||
|
for _, notifier := range notifiers {
|
||||||
|
notifier.NotifyIssueChangeTitle(doer, issue, oldTitle)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotifyIssueChangeLabels notifies change labels to notifiers
|
||||||
|
func NotifyIssueChangeLabels(doer *models.User, issue *models.Issue,
|
||||||
|
addedLabels []*models.Label, removedLabels []*models.Label) {
|
||||||
|
for _, notifier := range notifiers {
|
||||||
|
notifier.NotifyIssueChangeLabels(doer, issue, addedLabels, removedLabels)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotifyCreateRepository notifies create repository to notifiers
|
||||||
|
func NotifyCreateRepository(doer *models.User, u *models.User, repo *models.Repository) {
|
||||||
|
for _, notifier := range notifiers {
|
||||||
|
notifier.NotifyCreateRepository(doer, u, repo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotifyMigrateRepository notifies create repository to notifiers
|
||||||
|
func NotifyMigrateRepository(doer *models.User, u *models.User, repo *models.Repository) {
|
||||||
|
for _, notifier := range notifiers {
|
||||||
|
notifier.NotifyMigrateRepository(doer, u, repo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
120
modules/notification/ui/ui.go
Normal file
120
modules/notification/ui/ui.go
Normal file
|
|
@ -0,0 +1,120 @@
|
||||||
|
// Copyright 2018 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 ui
|
||||||
|
|
||||||
|
import (
|
||||||
|
"code.gitea.io/git"
|
||||||
|
"code.gitea.io/gitea/models"
|
||||||
|
"code.gitea.io/gitea/modules/log"
|
||||||
|
"code.gitea.io/gitea/modules/notification/base"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
notificationService struct {
|
||||||
|
issueQueue chan issueNotificationOpts
|
||||||
|
}
|
||||||
|
|
||||||
|
issueNotificationOpts struct {
|
||||||
|
issue *models.Issue
|
||||||
|
notificationAuthorID int64
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
_ base.Notifier = ¬ificationService{}
|
||||||
|
)
|
||||||
|
|
||||||
|
// NewNotifier create a new notificationService notifier
|
||||||
|
func NewNotifier() base.Notifier {
|
||||||
|
return ¬ificationService{
|
||||||
|
issueQueue: make(chan issueNotificationOpts, 100),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ns *notificationService) Run() {
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case opts := <-ns.issueQueue:
|
||||||
|
if err := models.CreateOrUpdateIssueNotifications(opts.issue, opts.notificationAuthorID); err != nil {
|
||||||
|
log.Error(4, "Was unable to create issue notification: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ns *notificationService) NotifyCreateIssueComment(doer *models.User, repo *models.Repository,
|
||||||
|
issue *models.Issue, comment *models.Comment) {
|
||||||
|
ns.issueQueue <- issueNotificationOpts{
|
||||||
|
issue,
|
||||||
|
doer.ID,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ns *notificationService) NotifyNewIssue(issue *models.Issue) {
|
||||||
|
ns.issueQueue <- issueNotificationOpts{
|
||||||
|
issue,
|
||||||
|
issue.Poster.ID,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ns *notificationService) NotifyCloseIssue(issue *models.Issue, doer *models.User) {
|
||||||
|
ns.issueQueue <- issueNotificationOpts{
|
||||||
|
issue,
|
||||||
|
doer.ID,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ns *notificationService) NotifyMergePullRequest(*models.PullRequest, *models.User, *git.Repository) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ns *notificationService) NotifyNewPullRequest(pr *models.PullRequest) {
|
||||||
|
ns.issueQueue <- issueNotificationOpts{
|
||||||
|
pr.Issue,
|
||||||
|
pr.Issue.PosterID,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ns *notificationService) NotifyUpdateComment(doer *models.User, c *models.Comment, oldContent string) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ns *notificationService) NotifyDeleteComment(doer *models.User, c *models.Comment) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ns *notificationService) NotifyDeleteRepository(doer *models.User, repo *models.Repository) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ns *notificationService) NotifyForkRepository(doer *models.User, oldRepo, repo *models.Repository) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ns *notificationService) NotifyNewRelease(rel *models.Release) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ns *notificationService) NotifyUpdateRelease(doer *models.User, rel *models.Release) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ns *notificationService) NotifyDeleteRelease(doer *models.User, rel *models.Release) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ns *notificationService) NotifyChangeMilestone(doer *models.User, issue *models.Issue) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ns *notificationService) NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ns *notificationService) NotifyIssueClearLabels(doer *models.User, issue *models.Issue) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ns *notificationService) NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ns *notificationService) NotifyIssueChangeLabels(doer *models.User, issue *models.Issue,
|
||||||
|
addedLabels []*models.Label, removedLabels []*models.Label) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ns *notificationService) NotifyCreateRepository(doer *models.User, u *models.User, repo *models.Repository) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ns *notificationService) NotifyMigrateRepository(doer *models.User, u *models.User, repo *models.Repository) {
|
||||||
|
}
|
||||||
528
modules/notification/webhook/webhook.go
Normal file
528
modules/notification/webhook/webhook.go
Normal file
|
|
@ -0,0 +1,528 @@
|
||||||
|
// Copyright 2018 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 webhook
|
||||||
|
|
||||||
|
import (
|
||||||
|
"code.gitea.io/gitea/models"
|
||||||
|
"code.gitea.io/gitea/modules/log"
|
||||||
|
"code.gitea.io/gitea/modules/notification/base"
|
||||||
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
|
||||||
|
"code.gitea.io/git"
|
||||||
|
api "code.gitea.io/sdk/gitea"
|
||||||
|
)
|
||||||
|
|
||||||
|
type webhookNotifier struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
_ base.Notifier = &webhookNotifier{}
|
||||||
|
)
|
||||||
|
|
||||||
|
// NewNotifier returns a new webhookNotifier
|
||||||
|
func NewNotifier() base.Notifier {
|
||||||
|
return &webhookNotifier{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *webhookNotifier) Run() {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *webhookNotifier) NotifyCreateIssueComment(doer *models.User, repo *models.Repository,
|
||||||
|
issue *models.Issue, comment *models.Comment) {
|
||||||
|
mode, _ := models.AccessLevel(doer.ID, repo)
|
||||||
|
if err := models.PrepareWebhooks(repo, models.HookEventIssueComment, &api.IssueCommentPayload{
|
||||||
|
Action: api.HookIssueCommentCreated,
|
||||||
|
Issue: issue.APIFormat(),
|
||||||
|
Comment: comment.APIFormat(),
|
||||||
|
Repository: repo.APIFormat(mode),
|
||||||
|
Sender: doer.APIFormat(),
|
||||||
|
}); err != nil {
|
||||||
|
log.Error(2, "PrepareWebhooks [comment_id: %d]: %v", comment.ID, err)
|
||||||
|
} else {
|
||||||
|
go models.HookQueue.Add(repo.ID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotifyNewIssue implements notification.Receiver
|
||||||
|
func (w *webhookNotifier) NotifyNewIssue(issue *models.Issue) {
|
||||||
|
mode, _ := models.AccessLevel(issue.Poster.ID, issue.Repo)
|
||||||
|
if err := models.PrepareWebhooks(issue.Repo, models.HookEventIssues, &api.IssuePayload{
|
||||||
|
Action: api.HookIssueOpened,
|
||||||
|
Index: issue.Index,
|
||||||
|
Issue: issue.APIFormat(),
|
||||||
|
Repository: issue.Repo.APIFormat(mode),
|
||||||
|
Sender: issue.Poster.APIFormat(),
|
||||||
|
}); err != nil {
|
||||||
|
log.Error(4, "PrepareWebhooks: %v", err)
|
||||||
|
} else {
|
||||||
|
go models.HookQueue.Add(issue.RepoID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotifyCloseIssue implements notification.Receiver
|
||||||
|
func (w *webhookNotifier) NotifyCloseIssue(issue *models.Issue, doer *models.User) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *webhookNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *models.User, baseGitRepo *git.Repository) {
|
||||||
|
mode, _ := models.AccessLevel(doer.ID, pr.Issue.Repo)
|
||||||
|
if err := models.PrepareWebhooks(pr.Issue.Repo, models.HookEventPullRequest, &api.PullRequestPayload{
|
||||||
|
Action: api.HookIssueClosed,
|
||||||
|
Index: pr.Index,
|
||||||
|
PullRequest: pr.APIFormat(),
|
||||||
|
Repository: pr.Issue.Repo.APIFormat(mode),
|
||||||
|
Sender: doer.APIFormat(),
|
||||||
|
}); err != nil {
|
||||||
|
log.Error(4, "PrepareWebhooks: %v", err)
|
||||||
|
} else {
|
||||||
|
go models.HookQueue.Add(pr.Issue.Repo.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
l, err := baseGitRepo.CommitsBetweenIDs(pr.MergedCommitID, pr.MergeBase)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(4, "CommitsBetweenIDs: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// It is possible that head branch is not fully sync with base branch for merge commits,
|
||||||
|
// so we need to get latest head commit and append merge commit manually
|
||||||
|
// to avoid strange diff commits produced.
|
||||||
|
mergeCommit, err := baseGitRepo.GetBranchCommit(pr.BaseBranch)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(4, "GetBranchCommit: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
p := &api.PushPayload{
|
||||||
|
Ref: git.BranchPrefix + pr.BaseBranch,
|
||||||
|
Before: pr.MergeBase,
|
||||||
|
After: mergeCommit.ID.String(),
|
||||||
|
CompareURL: setting.AppURL + pr.BaseRepo.ComposeCompareURL(pr.MergeBase, pr.MergedCommitID),
|
||||||
|
Commits: models.ListToPushCommits(l).ToAPIPayloadCommits(pr.BaseRepo.HTMLURL()),
|
||||||
|
Repo: pr.BaseRepo.APIFormat(mode),
|
||||||
|
Pusher: pr.HeadRepo.MustOwner().APIFormat(),
|
||||||
|
Sender: doer.APIFormat(),
|
||||||
|
}
|
||||||
|
if err := models.PrepareWebhooks(pr.BaseRepo, models.HookEventPush, p); err != nil {
|
||||||
|
log.Error(4, "PrepareWebhooks: %v", err)
|
||||||
|
} else {
|
||||||
|
go models.HookQueue.Add(pr.BaseRepo.ID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *webhookNotifier) NotifyNewPullRequest(pr *models.PullRequest) {
|
||||||
|
mode, _ := models.AccessLevel(pr.Issue.Poster.ID, pr.Issue.Repo)
|
||||||
|
if err := models.PrepareWebhooks(pr.Issue.Repo, models.HookEventPullRequest, &api.PullRequestPayload{
|
||||||
|
Action: api.HookIssueOpened,
|
||||||
|
Index: pr.Issue.Index,
|
||||||
|
PullRequest: pr.APIFormat(),
|
||||||
|
Repository: pr.Issue.Repo.APIFormat(mode),
|
||||||
|
Sender: pr.Issue.Poster.APIFormat(),
|
||||||
|
}); err != nil {
|
||||||
|
log.Error(4, "PrepareWebhooks: %v", err)
|
||||||
|
} else {
|
||||||
|
go models.HookQueue.Add(pr.Issue.Repo.ID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *webhookNotifier) NotifyUpdateComment(doer *models.User, c *models.Comment, oldContent string) {
|
||||||
|
if err := c.LoadIssue(); err != nil {
|
||||||
|
log.Error(2, "LoadIssue [comment_id: %d]: %v", c.ID, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := c.Issue.LoadAttributes(); err != nil {
|
||||||
|
log.Error(2, "Issue.LoadAttributes [comment_id: %d]: %v", c.ID, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
mode, _ := models.AccessLevel(doer.ID, c.Issue.Repo)
|
||||||
|
if err := models.PrepareWebhooks(c.Issue.Repo, models.HookEventIssueComment, &api.IssueCommentPayload{
|
||||||
|
Action: api.HookIssueCommentEdited,
|
||||||
|
Issue: c.Issue.APIFormat(),
|
||||||
|
Comment: c.APIFormat(),
|
||||||
|
Changes: &api.ChangesPayload{
|
||||||
|
Body: &api.ChangesFromPayload{
|
||||||
|
From: oldContent,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Repository: c.Issue.Repo.APIFormat(mode),
|
||||||
|
Sender: doer.APIFormat(),
|
||||||
|
}); err != nil {
|
||||||
|
log.Error(2, "PrepareWebhooks [comment_id: %d]: %v", c.ID, err)
|
||||||
|
} else {
|
||||||
|
go models.HookQueue.Add(c.Issue.Repo.ID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *webhookNotifier) NotifyDeleteComment(doer *models.User, comment *models.Comment) {
|
||||||
|
if err := comment.LoadIssue(); err != nil {
|
||||||
|
log.Error(2, "LoadIssue [comment_id: %d]: %v", comment.ID, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
mode, _ := models.AccessLevel(doer.ID, comment.Issue.Repo)
|
||||||
|
|
||||||
|
if err := models.PrepareWebhooks(comment.Issue.Repo, models.HookEventIssueComment, &api.IssueCommentPayload{
|
||||||
|
Action: api.HookIssueCommentDeleted,
|
||||||
|
Issue: comment.Issue.APIFormat(),
|
||||||
|
Comment: comment.APIFormat(),
|
||||||
|
Repository: comment.Issue.Repo.APIFormat(mode),
|
||||||
|
Sender: doer.APIFormat(),
|
||||||
|
}); err != nil {
|
||||||
|
log.Error(2, "PrepareWebhooks [comment_id: %d]: %v", comment.ID, err)
|
||||||
|
} else {
|
||||||
|
go models.HookQueue.Add(comment.Issue.Repo.ID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *webhookNotifier) NotifyDeleteRepository(doer *models.User, repo *models.Repository) {
|
||||||
|
org, err := models.GetUserByID(repo.OwnerID)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(2, "GetUserByID [repo_id: %d]: %v", repo.ID, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if org.IsOrganization() {
|
||||||
|
if err := models.PrepareWebhooks(repo, models.HookEventRepository, &api.RepositoryPayload{
|
||||||
|
Action: api.HookRepoDeleted,
|
||||||
|
Repository: repo.APIFormat(models.AccessModeOwner),
|
||||||
|
Organization: org.APIFormat(),
|
||||||
|
Sender: doer.APIFormat(),
|
||||||
|
}); err != nil {
|
||||||
|
log.Error(2, "PrepareWebhooks [repo_id: %d]: %v", repo.ID, err)
|
||||||
|
} else {
|
||||||
|
go models.HookQueue.Add(repo.ID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *webhookNotifier) NotifyForkRepository(doer *models.User, oldRepo, repo *models.Repository) {
|
||||||
|
oldMode, _ := models.AccessLevel(doer.ID, oldRepo)
|
||||||
|
mode, _ := models.AccessLevel(doer.ID, repo)
|
||||||
|
|
||||||
|
if err := models.PrepareWebhooks(oldRepo, models.HookEventFork, &api.ForkPayload{
|
||||||
|
Forkee: oldRepo.APIFormat(oldMode),
|
||||||
|
Repo: repo.APIFormat(mode),
|
||||||
|
Sender: doer.APIFormat(),
|
||||||
|
}); err != nil {
|
||||||
|
log.Error(2, "PrepareWebhooks [repo_id: %d]: %v", oldRepo.ID, err)
|
||||||
|
} else {
|
||||||
|
go models.HookQueue.Add(oldRepo.ID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *webhookNotifier) NotifyNewRelease(rel *models.Release) {
|
||||||
|
if rel.IsDraft {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := rel.LoadAttributes(); err != nil {
|
||||||
|
log.Error(2, "LoadAttributes: %v", err)
|
||||||
|
} else {
|
||||||
|
mode, _ := models.AccessLevel(rel.PublisherID, rel.Repo)
|
||||||
|
if err := models.PrepareWebhooks(rel.Repo, models.HookEventRelease, &api.ReleasePayload{
|
||||||
|
Action: api.HookReleasePublished,
|
||||||
|
Release: rel.APIFormat(),
|
||||||
|
Repository: rel.Repo.APIFormat(mode),
|
||||||
|
Sender: rel.Publisher.APIFormat(),
|
||||||
|
}); err != nil {
|
||||||
|
log.Error(2, "PrepareWebhooks: %v", err)
|
||||||
|
} else {
|
||||||
|
go models.HookQueue.Add(rel.Repo.ID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *webhookNotifier) NotifyUpdateRelease(doer *models.User, rel *models.Release) {
|
||||||
|
mode, _ := models.AccessLevel(doer.ID, rel.Repo)
|
||||||
|
if err := models.PrepareWebhooks(rel.Repo, models.HookEventRelease, &api.ReleasePayload{
|
||||||
|
Action: api.HookReleaseUpdated,
|
||||||
|
Release: rel.APIFormat(),
|
||||||
|
Repository: rel.Repo.APIFormat(mode),
|
||||||
|
Sender: rel.Publisher.APIFormat(),
|
||||||
|
}); err != nil {
|
||||||
|
log.Error(2, "PrepareWebhooks: %v", err)
|
||||||
|
} else {
|
||||||
|
go models.HookQueue.Add(rel.Repo.ID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *webhookNotifier) NotifyDeleteRelease(doer *models.User, rel *models.Release) {
|
||||||
|
if err := rel.LoadAttributes(); err != nil {
|
||||||
|
log.Error(2, "rel.LoadAttributes: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
mode, _ := models.AccessLevel(doer.ID, rel.Repo)
|
||||||
|
if err := models.PrepareWebhooks(rel.Repo, models.HookEventRelease, &api.ReleasePayload{
|
||||||
|
Action: api.HookReleaseDeleted,
|
||||||
|
Release: rel.APIFormat(),
|
||||||
|
Repository: rel.Repo.APIFormat(mode),
|
||||||
|
Sender: rel.Publisher.APIFormat(),
|
||||||
|
}); err != nil {
|
||||||
|
log.Error(2, "PrepareWebhooks: %v", err)
|
||||||
|
} else {
|
||||||
|
go models.HookQueue.Add(rel.Repo.ID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *webhookNotifier) NotifyChangeMilestone(doer *models.User, issue *models.Issue) {
|
||||||
|
var hookAction api.HookIssueAction
|
||||||
|
if issue.MilestoneID > 0 {
|
||||||
|
hookAction = api.HookIssueMilestoned
|
||||||
|
} else {
|
||||||
|
hookAction = api.HookIssueDemilestoned
|
||||||
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
|
if err = issue.LoadAttributes(); err != nil {
|
||||||
|
log.Error(2, "LoadAttributes: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
mode, _ := models.AccessLevel(doer.ID, issue.Repo)
|
||||||
|
if issue.IsPull {
|
||||||
|
err = issue.PullRequest.LoadIssue()
|
||||||
|
if err != nil {
|
||||||
|
log.Error(2, "LoadIssue: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = models.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 = models.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(2, "PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)
|
||||||
|
} else {
|
||||||
|
go models.HookQueue.Add(issue.RepoID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *webhookNotifier) NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string) {
|
||||||
|
mode, _ := models.AccessLevel(doer.ID, 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(4, "PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)
|
||||||
|
} else {
|
||||||
|
go models.HookQueue.Add(issue.RepoID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *webhookNotifier) NotifyIssueClearLabels(doer *models.User, issue *models.Issue) {
|
||||||
|
var err error
|
||||||
|
mode, _ := models.AccessLevel(doer.ID, issue.Repo)
|
||||||
|
if issue.IsPull {
|
||||||
|
err = issue.PullRequest.LoadIssue()
|
||||||
|
if err != nil {
|
||||||
|
log.Error(4, "LoadIssue: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = models.PrepareWebhooks(issue.Repo, models.HookEventPullRequest, &api.PullRequestPayload{
|
||||||
|
Action: api.HookIssueLabelCleared,
|
||||||
|
Index: issue.Index,
|
||||||
|
PullRequest: issue.PullRequest.APIFormat(),
|
||||||
|
Repository: issue.Repo.APIFormat(mode),
|
||||||
|
Sender: doer.APIFormat(),
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
err = models.PrepareWebhooks(issue.Repo, models.HookEventIssues, &api.IssuePayload{
|
||||||
|
Action: api.HookIssueLabelCleared,
|
||||||
|
Index: issue.Index,
|
||||||
|
Issue: issue.APIFormat(),
|
||||||
|
Repository: issue.Repo.APIFormat(mode),
|
||||||
|
Sender: doer.APIFormat(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
log.Error(4, "PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)
|
||||||
|
} else {
|
||||||
|
go models.HookQueue.Add(issue.RepoID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *webhookNotifier) NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) {
|
||||||
|
mode, _ := models.AccessLevel(doer.ID, 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{
|
||||||
|
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(4, "PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)
|
||||||
|
} else {
|
||||||
|
go models.HookQueue.Add(issue.RepoID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
func (w *webhookNotifier) NotifyIssueChangeStatus(doer *models.User, issue *models.Issue, isClosed bool) {
|
||||||
|
mode, _ := models.AccessLevel(doer.ID, issue.Repo)
|
||||||
|
var err error
|
||||||
|
if issue.IsPull {
|
||||||
|
// Merge pull request calls issue.changeStatus so we need to handle separately.
|
||||||
|
issue.PullRequest.Issue = issue
|
||||||
|
apiPullRequest := &api.PullRequestPayload{
|
||||||
|
Index: issue.Index,
|
||||||
|
PullRequest: issue.PullRequest.APIFormat(),
|
||||||
|
Repository: issue.Repo.APIFormat(mode),
|
||||||
|
Sender: doer.APIFormat(),
|
||||||
|
}
|
||||||
|
if isClosed {
|
||||||
|
apiPullRequest.Action = api.HookIssueClosed
|
||||||
|
} else {
|
||||||
|
apiPullRequest.Action = api.HookIssueReOpened
|
||||||
|
}
|
||||||
|
err = models.PrepareWebhooks(issue.Repo, models.HookEventPullRequest, apiPullRequest)
|
||||||
|
} else {
|
||||||
|
apiIssue := &api.IssuePayload{
|
||||||
|
Index: issue.Index,
|
||||||
|
Issue: issue.APIFormat(),
|
||||||
|
Repository: issue.Repo.APIFormat(mode),
|
||||||
|
Sender: doer.APIFormat(),
|
||||||
|
}
|
||||||
|
if isClosed {
|
||||||
|
apiIssue.Action = api.HookIssueClosed
|
||||||
|
} else {
|
||||||
|
apiIssue.Action = api.HookIssueReOpened
|
||||||
|
}
|
||||||
|
err = models.PrepareWebhooks(issue.Repo, models.HookEventIssues, apiIssue)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
log.Error(4, "PrepareWebhooks [is_pull: %v, is_closed: %v]: %v", issue.IsPull, isClosed, err)
|
||||||
|
} else {
|
||||||
|
go models.HookQueue.Add(issue.Repo.ID)
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
func (w *webhookNotifier) NotifyIssueChangeLabels(doer *models.User, issue *models.Issue,
|
||||||
|
addedLabels []*models.Label, removedLabels []*models.Label) {
|
||||||
|
var err error
|
||||||
|
if err = issue.LoadRepo(); err != nil {
|
||||||
|
log.Error(4, "LoadRepo: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
mode, _ := models.AccessLevel(doer.ID, issue.Repo)
|
||||||
|
if issue.IsPull {
|
||||||
|
if err = issue.LoadPullRequest(); err != nil {
|
||||||
|
log.Error(4, "LoadPullRequest: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = issue.PullRequest.LoadIssue(); err != nil {
|
||||||
|
log.Error(4, "LoadIssue: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = models.PrepareWebhooks(issue.Repo, models.HookEventPullRequest, &api.PullRequestPayload{
|
||||||
|
Action: api.HookIssueLabelUpdated,
|
||||||
|
Index: issue.Index,
|
||||||
|
PullRequest: issue.PullRequest.APIFormat(),
|
||||||
|
Repository: issue.Repo.APIFormat(mode),
|
||||||
|
Sender: doer.APIFormat(),
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
err = models.PrepareWebhooks(issue.Repo, models.HookEventIssues, &api.IssuePayload{
|
||||||
|
Action: api.HookIssueLabelUpdated,
|
||||||
|
Index: issue.Index,
|
||||||
|
Issue: issue.APIFormat(),
|
||||||
|
Repository: issue.Repo.APIFormat(mode),
|
||||||
|
Sender: doer.APIFormat(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
log.Error(4, "PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)
|
||||||
|
} else {
|
||||||
|
go models.HookQueue.Add(issue.RepoID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *webhookNotifier) NotifyCreateRepository(doer *models.User, u *models.User, repo *models.Repository) {
|
||||||
|
if err := models.PrepareWebhooks(repo, models.HookEventRepository, &api.RepositoryPayload{
|
||||||
|
Action: api.HookRepoCreated,
|
||||||
|
Repository: repo.APIFormat(models.AccessModeOwner),
|
||||||
|
Organization: u.APIFormat(),
|
||||||
|
Sender: doer.APIFormat(),
|
||||||
|
}); err != nil {
|
||||||
|
log.Error(4, "PrepareWebhooks: %v", err)
|
||||||
|
} else {
|
||||||
|
go models.HookQueue.Add(repo.ID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *webhookNotifier) NotifyMigrateRepository(doer *models.User, u *models.User, repo *models.Repository) {
|
||||||
|
if err := models.PrepareWebhooks(repo, models.HookEventRepository, &api.RepositoryPayload{
|
||||||
|
Action: api.HookRepoCreated,
|
||||||
|
Repository: repo.APIFormat(models.AccessModeOwner),
|
||||||
|
Organization: u.APIFormat(),
|
||||||
|
Sender: doer.APIFormat(),
|
||||||
|
}); err != nil {
|
||||||
|
log.Error(4, "PrepareWebhooks: %v", err)
|
||||||
|
} else {
|
||||||
|
go models.HookQueue.Add(repo.ID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -10,15 +10,16 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Unknwon/com"
|
|
||||||
"gopkg.in/macaron.v1"
|
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
"code.gitea.io/gitea/modules/base"
|
"code.gitea.io/gitea/modules/base"
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
"code.gitea.io/gitea/modules/cron"
|
"code.gitea.io/gitea/modules/cron"
|
||||||
|
"code.gitea.io/gitea/modules/notification"
|
||||||
"code.gitea.io/gitea/modules/process"
|
"code.gitea.io/gitea/modules/process"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
|
||||||
|
"github.com/Unknwon/com"
|
||||||
|
"gopkg.in/macaron.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -146,7 +147,7 @@ func Dashboard(ctx *context.Context) {
|
||||||
err = models.DeleteRepositoryArchives()
|
err = models.DeleteRepositoryArchives()
|
||||||
case cleanMissingRepos:
|
case cleanMissingRepos:
|
||||||
success = ctx.Tr("admin.dashboard.delete_missing_repos_success")
|
success = ctx.Tr("admin.dashboard.delete_missing_repos_success")
|
||||||
err = models.DeleteMissingRepositories(ctx.User)
|
err = models.DeleteMissingRepositories(ctx.User, notification.NotifyDeleteRepository)
|
||||||
case gitGCRepos:
|
case gitGCRepos:
|
||||||
success = ctx.Tr("admin.dashboard.git_gc_repos_success")
|
success = ctx.Tr("admin.dashboard.git_gc_repos_success")
|
||||||
err = models.GitGcRepos()
|
err = models.GitGcRepos()
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"code.gitea.io/gitea/modules/base"
|
"code.gitea.io/gitea/modules/base"
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
|
"code.gitea.io/gitea/modules/notification"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
"code.gitea.io/gitea/routers"
|
"code.gitea.io/gitea/routers"
|
||||||
)
|
)
|
||||||
|
|
@ -42,6 +43,7 @@ func DeleteRepo(ctx *context.Context) {
|
||||||
ctx.ServerError("DeleteRepository", err)
|
ctx.ServerError("DeleteRepository", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
notification.NotifyDeleteRepository(ctx.User, repo)
|
||||||
log.Trace("Repository deleted: %s/%s", repo.MustOwner().Name, repo.Name)
|
log.Trace("Repository deleted: %s/%s", repo.MustOwner().Name, repo.Name)
|
||||||
|
|
||||||
ctx.Flash.Success(ctx.Tr("repo.settings.deletion_success"))
|
ctx.Flash.Success(ctx.Tr("repo.settings.deletion_success"))
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ package repo
|
||||||
import (
|
import (
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
|
"code.gitea.io/gitea/modules/notification"
|
||||||
"code.gitea.io/gitea/routers/api/v1/utils"
|
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||||
|
|
||||||
api "code.gitea.io/sdk/gitea"
|
api "code.gitea.io/sdk/gitea"
|
||||||
|
|
@ -104,5 +105,7 @@ func CreateFork(ctx *context.APIContext, form api.CreateForkOption) {
|
||||||
ctx.Error(500, "ForkRepository", err)
|
ctx.Error(500, "ForkRepository", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
notification.NotifyForkRepository(ctx.User, repo, fork)
|
||||||
|
|
||||||
ctx.JSON(202, fork.APIFormat(models.AccessModeOwner))
|
ctx.JSON(202, fork.APIFormat(models.AccessModeOwner))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
"code.gitea.io/gitea/modules/indexer"
|
"code.gitea.io/gitea/modules/indexer"
|
||||||
|
"code.gitea.io/gitea/modules/notification"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
"code.gitea.io/gitea/modules/util"
|
"code.gitea.io/gitea/modules/util"
|
||||||
|
|
||||||
|
|
@ -207,6 +208,8 @@ func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notification.NotifyNewIssue(issue)
|
||||||
|
|
||||||
if form.Closed {
|
if form.Closed {
|
||||||
if err := issue.ChangeStatus(ctx.User, ctx.Repo.Repository, true); err != nil {
|
if err := issue.ChangeStatus(ctx.User, ctx.Repo.Repository, true); err != nil {
|
||||||
if models.IsErrDependenciesLeft(err) {
|
if models.IsErrDependenciesLeft(err) {
|
||||||
|
|
@ -322,6 +325,8 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) {
|
||||||
ctx.Error(500, "ChangeMilestoneAssign", err)
|
ctx.Error(500, "ChangeMilestoneAssign", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notification.NotifyChangeMilestone(ctx.User, issue)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = models.UpdateIssue(issue); err != nil {
|
if err = models.UpdateIssue(issue); err != nil {
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import (
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
|
"code.gitea.io/gitea/modules/notification"
|
||||||
|
|
||||||
api "code.gitea.io/sdk/gitea"
|
api "code.gitea.io/sdk/gitea"
|
||||||
)
|
)
|
||||||
|
|
@ -163,6 +164,8 @@ func CreateIssueComment(ctx *context.APIContext, form api.CreateIssueCommentOpti
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notification.NotifyCreateIssueComment(ctx.User, ctx.Repo.Repository, issue, comment)
|
||||||
|
|
||||||
ctx.JSON(201, comment.APIFormat())
|
ctx.JSON(201, comment.APIFormat())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -263,10 +266,13 @@ func editIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption)
|
||||||
|
|
||||||
oldContent := comment.Content
|
oldContent := comment.Content
|
||||||
comment.Content = form.Body
|
comment.Content = form.Body
|
||||||
if err := models.UpdateComment(ctx.User, comment, oldContent); err != nil {
|
if err := models.UpdateComment(ctx.User, comment); err != nil {
|
||||||
ctx.Error(500, "UpdateComment", err)
|
ctx.Error(500, "UpdateComment", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notification.NotifyUpdateComment(ctx.User, comment, oldContent)
|
||||||
|
|
||||||
ctx.JSON(200, comment.APIFormat())
|
ctx.JSON(200, comment.APIFormat())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -353,5 +359,8 @@ func deleteIssueComment(ctx *context.APIContext) {
|
||||||
ctx.Error(500, "DeleteCommentByID", err)
|
ctx.Error(500, "DeleteCommentByID", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notification.NotifyDeleteComment(ctx.User, comment)
|
||||||
|
|
||||||
ctx.Status(204)
|
ctx.Status(204)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ package repo
|
||||||
import (
|
import (
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
|
"code.gitea.io/gitea/modules/notification"
|
||||||
|
|
||||||
api "code.gitea.io/sdk/gitea"
|
api "code.gitea.io/sdk/gitea"
|
||||||
)
|
)
|
||||||
|
|
@ -113,6 +114,7 @@ func AddIssueLabels(ctx *context.APIContext, form api.IssueLabelsOption) {
|
||||||
ctx.Error(500, "AddLabels", err)
|
ctx.Error(500, "AddLabels", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
notification.NotifyIssueChangeLabels(ctx.User, issue, labels, nil)
|
||||||
|
|
||||||
labels, err = models.GetLabelsByIssueID(issue.ID)
|
labels, err = models.GetLabelsByIssueID(issue.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -308,5 +310,7 @@ func ClearIssueLabels(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notification.NotifyIssueClearLabels(ctx.User, issue)
|
||||||
|
|
||||||
ctx.Status(204)
|
ctx.Status(204)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import (
|
||||||
"code.gitea.io/gitea/modules/auth"
|
"code.gitea.io/gitea/modules/auth"
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
|
"code.gitea.io/gitea/modules/notification"
|
||||||
"code.gitea.io/gitea/modules/util"
|
"code.gitea.io/gitea/modules/util"
|
||||||
|
|
||||||
api "code.gitea.io/sdk/gitea"
|
api "code.gitea.io/sdk/gitea"
|
||||||
|
|
@ -371,6 +372,8 @@ func EditPullRequest(ctx *context.APIContext, form api.EditPullRequestOption) {
|
||||||
ctx.Error(500, "ChangeMilestoneAssign", err)
|
ctx.Error(500, "ChangeMilestoneAssign", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notification.NotifyChangeMilestone(ctx.User, issue)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = models.UpdateIssue(issue); err != nil {
|
if err = models.UpdateIssue(issue); err != nil {
|
||||||
|
|
@ -543,6 +546,8 @@ func MergePullRequest(ctx *context.APIContext, form auth.MergePullRequestForm) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notification.NotifyMergePullRequest(pr, ctx.User, ctx.Repo.GitRepo)
|
||||||
|
|
||||||
log.Trace("Pull request merged: %d", pr.ID)
|
log.Trace("Pull request merged: %d", pr.ID)
|
||||||
ctx.Status(200)
|
ctx.Status(200)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ package repo
|
||||||
import (
|
import (
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
|
"code.gitea.io/gitea/modules/notification"
|
||||||
|
|
||||||
api "code.gitea.io/sdk/gitea"
|
api "code.gitea.io/sdk/gitea"
|
||||||
)
|
)
|
||||||
|
|
@ -156,6 +157,7 @@ func CreateRelease(ctx *context.APIContext, form api.CreateReleaseOption) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
notification.NotifyNewRelease(rel)
|
||||||
} else {
|
} else {
|
||||||
if !rel.IsTag {
|
if !rel.IsTag {
|
||||||
ctx.Status(409)
|
ctx.Status(409)
|
||||||
|
|
@ -175,6 +177,8 @@ func CreateRelease(ctx *context.APIContext, form api.CreateReleaseOption) {
|
||||||
ctx.ServerError("UpdateRelease", err)
|
ctx.ServerError("UpdateRelease", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notification.NotifyUpdateRelease(ctx.User, rel)
|
||||||
}
|
}
|
||||||
ctx.JSON(201, rel.APIFormat())
|
ctx.JSON(201, rel.APIFormat())
|
||||||
}
|
}
|
||||||
|
|
@ -250,6 +254,8 @@ func EditRelease(ctx *context.APIContext, form api.EditReleaseOption) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notification.NotifyUpdateRelease(ctx.User, rel)
|
||||||
|
|
||||||
rel, err = models.GetReleaseByID(id)
|
rel, err = models.GetReleaseByID(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(500, "GetReleaseByID", err)
|
ctx.Error(500, "GetReleaseByID", err)
|
||||||
|
|
@ -301,9 +307,11 @@ func DeleteRelease(ctx *context.APIContext) {
|
||||||
ctx.Status(404)
|
ctx.Status(404)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := models.DeleteReleaseByID(id, ctx.User, false); err != nil {
|
rel, err = models.DeleteReleaseByID(id, ctx.User, false)
|
||||||
|
if err != nil {
|
||||||
ctx.Error(500, "DeleteReleaseByID", err)
|
ctx.Error(500, "DeleteReleaseByID", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
notification.NotifyDeleteRelease(ctx.User, rel)
|
||||||
ctx.Status(204)
|
ctx.Status(204)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"code.gitea.io/gitea/modules/auth"
|
"code.gitea.io/gitea/modules/auth"
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
|
"code.gitea.io/gitea/modules/notification"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
"code.gitea.io/gitea/modules/util"
|
"code.gitea.io/gitea/modules/util"
|
||||||
"code.gitea.io/gitea/routers/api/v1/convert"
|
"code.gitea.io/gitea/routers/api/v1/convert"
|
||||||
|
|
@ -193,6 +194,8 @@ func CreateUserRepo(ctx *context.APIContext, owner *models.User, opt api.CreateR
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notification.NotifyCreateRepository(ctx.User, owner, repo)
|
||||||
|
|
||||||
ctx.JSON(201, repo.APIFormat(models.AccessModeOwner))
|
ctx.JSON(201, repo.APIFormat(models.AccessModeOwner))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -366,6 +369,8 @@ func Migrate(ctx *context.APIContext, form auth.MigrateRepoForm) {
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Trace("Repository migrated: %s/%s", ctxUser.Name, form.RepoName)
|
log.Trace("Repository migrated: %s/%s", ctxUser.Name, form.RepoName)
|
||||||
|
|
||||||
|
notification.NotifyMigrateRepository(ctx.User, ctxUser, repo)
|
||||||
ctx.JSON(201, repo.APIFormat(models.AccessModeAdmin))
|
ctx.JSON(201, repo.APIFormat(models.AccessModeAdmin))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -476,6 +481,8 @@ func Delete(ctx *context.APIContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notification.NotifyDeleteRepository(ctx.User, repo)
|
||||||
|
|
||||||
log.Trace("Repository deleted: %s/%s", owner.Name, repo.Name)
|
log.Trace("Repository deleted: %s/%s", owner.Name, repo.Name)
|
||||||
ctx.Status(204)
|
ctx.Status(204)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Unknwon/com"
|
|
||||||
"github.com/Unknwon/paginater"
|
|
||||||
|
|
||||||
"code.gitea.io/git"
|
"code.gitea.io/git"
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
"code.gitea.io/gitea/modules/auth"
|
"code.gitea.io/gitea/modules/auth"
|
||||||
|
|
@ -29,6 +26,9 @@ import (
|
||||||
"code.gitea.io/gitea/modules/notification"
|
"code.gitea.io/gitea/modules/notification"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
"code.gitea.io/gitea/modules/util"
|
"code.gitea.io/gitea/modules/util"
|
||||||
|
|
||||||
|
"github.com/Unknwon/com"
|
||||||
|
"github.com/Unknwon/paginater"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -488,7 +488,7 @@ func NewIssuePost(ctx *context.Context, form auth.CreateIssueForm) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
notification.Service.NotifyIssue(issue, ctx.User.ID)
|
notification.NotifyNewIssue(issue)
|
||||||
|
|
||||||
log.Trace("Issue created: %d/%d", repo.ID, issue.ID)
|
log.Trace("Issue created: %d/%d", repo.ID, issue.ID)
|
||||||
ctx.Redirect(ctx.Repo.RepoLink + "/issues/" + com.ToStr(issue.Index))
|
ctx.Redirect(ctx.Repo.RepoLink + "/issues/" + com.ToStr(issue.Index))
|
||||||
|
|
@ -877,11 +877,14 @@ func UpdateIssueTitle(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
oldTitle := issue.Title
|
||||||
if err := issue.ChangeTitle(ctx.User, title); err != nil {
|
if err := issue.ChangeTitle(ctx.User, title); err != nil {
|
||||||
ctx.ServerError("ChangeTitle", err)
|
ctx.ServerError("ChangeTitle", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notification.NotifyIssueChangeTitle(ctx.User, issue, oldTitle)
|
||||||
|
|
||||||
ctx.JSON(200, map[string]interface{}{
|
ctx.JSON(200, map[string]interface{}{
|
||||||
"title": issue.Title,
|
"title": issue.Title,
|
||||||
})
|
})
|
||||||
|
|
@ -900,11 +903,14 @@ func UpdateIssueContent(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
content := ctx.Query("content")
|
content := ctx.Query("content")
|
||||||
|
oldContent := issue.Content
|
||||||
if err := issue.ChangeContent(ctx.User, content); err != nil {
|
if err := issue.ChangeContent(ctx.User, content); err != nil {
|
||||||
ctx.ServerError("ChangeContent", err)
|
ctx.ServerError("ChangeContent", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notification.NotifyIssueChangeContent(ctx.User, issue, oldContent)
|
||||||
|
|
||||||
ctx.JSON(200, map[string]interface{}{
|
ctx.JSON(200, map[string]interface{}{
|
||||||
"content": string(markdown.Render([]byte(issue.Content), ctx.Query("context"), ctx.Repo.Repository.ComposeMetas())),
|
"content": string(markdown.Render([]byte(issue.Content), ctx.Query("context"), ctx.Repo.Repository.ComposeMetas())),
|
||||||
})
|
})
|
||||||
|
|
@ -928,6 +934,8 @@ func UpdateIssueMilestone(ctx *context.Context) {
|
||||||
ctx.ServerError("ChangeMilestoneAssign", err)
|
ctx.ServerError("ChangeMilestoneAssign", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notification.NotifyChangeMilestone(ctx.User, issue)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.JSON(200, map[string]interface{}{
|
ctx.JSON(200, map[string]interface{}{
|
||||||
|
|
@ -1070,7 +1078,7 @@ func NewComment(ctx *context.Context, form auth.CreateCommentForm) {
|
||||||
} else {
|
} else {
|
||||||
log.Trace("Issue [%d] status changed to closed: %v", issue.ID, issue.IsClosed)
|
log.Trace("Issue [%d] status changed to closed: %v", issue.ID, issue.IsClosed)
|
||||||
|
|
||||||
notification.Service.NotifyIssue(issue, ctx.User.ID)
|
notification.NotifyCloseIssue(issue, ctx.User)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1098,7 +1106,7 @@ func NewComment(ctx *context.Context, form auth.CreateCommentForm) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
notification.Service.NotifyIssue(issue, ctx.User.ID)
|
notification.NotifyCreateIssueComment(ctx.User, ctx.Repo.Repository, issue, comment)
|
||||||
|
|
||||||
log.Trace("Comment created: %d/%d/%d", ctx.Repo.Repository.ID, issue.ID, comment.ID)
|
log.Trace("Comment created: %d/%d/%d", ctx.Repo.Repository.ID, issue.ID, comment.ID)
|
||||||
}
|
}
|
||||||
|
|
@ -1127,11 +1135,13 @@ func UpdateCommentContent(ctx *context.Context) {
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = models.UpdateComment(ctx.User, comment, oldContent); err != nil {
|
if err = models.UpdateComment(ctx.User, comment); err != nil {
|
||||||
ctx.ServerError("UpdateComment", err)
|
ctx.ServerError("UpdateComment", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notification.NotifyUpdateComment(ctx.User, comment, oldContent)
|
||||||
|
|
||||||
ctx.JSON(200, map[string]interface{}{
|
ctx.JSON(200, map[string]interface{}{
|
||||||
"content": string(markdown.Render([]byte(comment.Content), ctx.Query("context"), ctx.Repo.Repository.ComposeMetas())),
|
"content": string(markdown.Render([]byte(comment.Content), ctx.Query("context"), ctx.Repo.Repository.ComposeMetas())),
|
||||||
})
|
})
|
||||||
|
|
@ -1158,6 +1168,8 @@ func DeleteComment(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notification.NotifyDeleteComment(ctx.User, comment)
|
||||||
|
|
||||||
ctx.Status(200)
|
ctx.Status(200)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"code.gitea.io/gitea/modules/base"
|
"code.gitea.io/gitea/modules/base"
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
|
"code.gitea.io/gitea/modules/notification"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -145,6 +146,7 @@ func UpdateIssueLabel(ctx *context.Context) {
|
||||||
ctx.ServerError("ClearLabels", err)
|
ctx.ServerError("ClearLabels", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
notification.NotifyIssueClearLabels(ctx.User, issue)
|
||||||
}
|
}
|
||||||
case "attach", "detach", "toggle":
|
case "attach", "detach", "toggle":
|
||||||
label, err := models.GetLabelByID(ctx.QueryInt64("id"))
|
label, err := models.GetLabelByID(ctx.QueryInt64("id"))
|
||||||
|
|
@ -168,21 +170,29 @@ func UpdateIssueLabel(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var addedLabels = make(map[int][]*models.Label)
|
||||||
|
var removedLabels = make(map[int][]*models.Label)
|
||||||
if action == "attach" {
|
if action == "attach" {
|
||||||
for _, issue := range issues {
|
for i, issue := range issues {
|
||||||
if err = issue.AddLabel(ctx.User, label); err != nil {
|
if err = issue.AddLabel(ctx.User, label); err != nil {
|
||||||
ctx.ServerError("AddLabel", err)
|
ctx.ServerError("AddLabel", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
addedLabels[i] = append(addedLabels[i], label)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for _, issue := range issues {
|
for i, issue := range issues {
|
||||||
if err = issue.RemoveLabel(ctx.User, label); err != nil {
|
if err = issue.RemoveLabel(ctx.User, label); err != nil {
|
||||||
ctx.ServerError("RemoveLabel", err)
|
ctx.ServerError("RemoveLabel", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
removedLabels[i] = append(removedLabels[i], label)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for i, issue := range issues {
|
||||||
|
notification.NotifyIssueChangeLabels(ctx.User, issue, addedLabels[i], removedLabels[i])
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
log.Warn("Unrecognized action: %s", action)
|
log.Warn("Unrecognized action: %s", action)
|
||||||
ctx.Error(500)
|
ctx.Error(500)
|
||||||
|
|
|
||||||
|
|
@ -203,6 +203,8 @@ func ForkPost(ctx *context.Context, form auth.CreateRepoForm) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notification.NotifyForkRepository(ctx.User, forkRepo, repo)
|
||||||
|
|
||||||
log.Trace("Repository forked[%d]: %s/%s", forkRepo.ID, ctxUser.Name, repo.Name)
|
log.Trace("Repository forked[%d]: %s/%s", forkRepo.ID, ctxUser.Name, repo.Name)
|
||||||
ctx.Redirect(setting.AppSubURL + "/" + ctxUser.Name + "/" + repo.Name)
|
ctx.Redirect(setting.AppSubURL + "/" + ctxUser.Name + "/" + repo.Name)
|
||||||
}
|
}
|
||||||
|
|
@ -546,7 +548,7 @@ func MergePullRequest(ctx *context.Context, form auth.MergePullRequestForm) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
notification.Service.NotifyIssue(pr.Issue, ctx.User.ID)
|
notification.NotifyMergePullRequest(pr, ctx.User, ctx.Repo.GitRepo)
|
||||||
|
|
||||||
log.Trace("Pull request merged: %d", pr.ID)
|
log.Trace("Pull request merged: %d", pr.ID)
|
||||||
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
|
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
|
||||||
|
|
@ -836,6 +838,7 @@ func CompareAndPullRequestPost(ctx *context.Context, form auth.CreateIssueForm)
|
||||||
BaseRepo: repo,
|
BaseRepo: repo,
|
||||||
MergeBase: prInfo.MergeBase,
|
MergeBase: prInfo.MergeBase,
|
||||||
Type: models.PullRequestGitea,
|
Type: models.PullRequestGitea,
|
||||||
|
Issue: pullIssue,
|
||||||
}
|
}
|
||||||
// FIXME: check error in the case two people send pull request at almost same time, give nice error prompt
|
// FIXME: check error in the case two people send pull request at almost same time, give nice error prompt
|
||||||
// instead of 500.
|
// instead of 500.
|
||||||
|
|
@ -852,7 +855,7 @@ func CompareAndPullRequestPost(ctx *context.Context, form auth.CreateIssueForm)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
notification.Service.NotifyIssue(pullIssue, ctx.User.ID)
|
notification.NotifyNewPullRequest(pullRequest)
|
||||||
|
|
||||||
log.Trace("Pull request created: %d/%d", repo.ID, pullIssue.ID)
|
log.Trace("Pull request created: %d/%d", repo.ID, pullIssue.ID)
|
||||||
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pullIssue.Index))
|
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pullIssue.Index))
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/markup/markdown"
|
"code.gitea.io/gitea/modules/markup/markdown"
|
||||||
|
"code.gitea.io/gitea/modules/notification"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
|
||||||
"github.com/Unknwon/paginater"
|
"github.com/Unknwon/paginater"
|
||||||
|
|
@ -182,6 +183,7 @@ func NewReleasePost(ctx *context.Context, form auth.NewReleaseForm) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
notification.NotifyNewRelease(rel)
|
||||||
} else {
|
} else {
|
||||||
if !rel.IsTag {
|
if !rel.IsTag {
|
||||||
ctx.Data["Err_TagName"] = true
|
ctx.Data["Err_TagName"] = true
|
||||||
|
|
@ -202,6 +204,8 @@ func NewReleasePost(ctx *context.Context, form auth.NewReleaseForm) {
|
||||||
ctx.ServerError("UpdateRelease", err)
|
ctx.ServerError("UpdateRelease", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notification.NotifyUpdateRelease(ctx.User, rel)
|
||||||
}
|
}
|
||||||
log.Trace("Release created: %s/%s:%s", ctx.User.LowerName, ctx.Repo.Repository.Name, form.TagName)
|
log.Trace("Release created: %s/%s:%s", ctx.User.LowerName, ctx.Repo.Repository.Name, form.TagName)
|
||||||
|
|
||||||
|
|
@ -280,14 +284,19 @@ func EditReleasePost(ctx *context.Context, form auth.EditReleaseForm) {
|
||||||
ctx.ServerError("UpdateRelease", err)
|
ctx.ServerError("UpdateRelease", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notification.NotifyUpdateRelease(ctx.User, rel)
|
||||||
|
|
||||||
ctx.Redirect(ctx.Repo.RepoLink + "/releases")
|
ctx.Redirect(ctx.Repo.RepoLink + "/releases")
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteRelease delete a release
|
// DeleteRelease delete a release
|
||||||
func DeleteRelease(ctx *context.Context) {
|
func DeleteRelease(ctx *context.Context) {
|
||||||
if err := models.DeleteReleaseByID(ctx.QueryInt64("id"), ctx.User, true); err != nil {
|
rel, err := models.DeleteReleaseByID(ctx.QueryInt64("id"), ctx.User, true)
|
||||||
|
if err != nil {
|
||||||
ctx.Flash.Error("DeleteReleaseByID: " + err.Error())
|
ctx.Flash.Error("DeleteReleaseByID: " + err.Error())
|
||||||
} else {
|
} else {
|
||||||
|
notification.NotifyDeleteRelease(ctx.User, rel)
|
||||||
ctx.Flash.Success(ctx.Tr("repo.release.deletion_success"))
|
ctx.Flash.Success(ctx.Tr("repo.release.deletion_success"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,17 +10,17 @@ import (
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/Unknwon/com"
|
|
||||||
|
|
||||||
"code.gitea.io/git"
|
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
"code.gitea.io/gitea/modules/auth"
|
"code.gitea.io/gitea/modules/auth"
|
||||||
"code.gitea.io/gitea/modules/base"
|
"code.gitea.io/gitea/modules/base"
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
|
"code.gitea.io/gitea/modules/notification"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
"code.gitea.io/gitea/modules/util"
|
"code.gitea.io/gitea/modules/util"
|
||||||
|
|
||||||
|
"code.gitea.io/git"
|
||||||
|
"github.com/Unknwon/com"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -176,6 +176,8 @@ func CreatePost(ctx *context.Context, form auth.CreateRepoForm) {
|
||||||
AutoInit: form.AutoInit,
|
AutoInit: form.AutoInit,
|
||||||
})
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
notification.NotifyCreateRepository(ctx.User, ctxUser, repo)
|
||||||
|
|
||||||
log.Trace("Repository created [%d]: %s/%s", repo.ID, ctxUser.Name, repo.Name)
|
log.Trace("Repository created [%d]: %s/%s", repo.ID, ctxUser.Name, repo.Name)
|
||||||
ctx.Redirect(setting.AppSubURL + "/" + ctxUser.Name + "/" + repo.Name)
|
ctx.Redirect(setting.AppSubURL + "/" + ctxUser.Name + "/" + repo.Name)
|
||||||
return
|
return
|
||||||
|
|
@ -252,6 +254,9 @@ func MigratePost(ctx *context.Context, form auth.MigrateRepoForm) {
|
||||||
})
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
log.Trace("Repository migrated [%d]: %s/%s", repo.ID, ctxUser.Name, form.RepoName)
|
log.Trace("Repository migrated [%d]: %s/%s", repo.ID, ctxUser.Name, form.RepoName)
|
||||||
|
|
||||||
|
notification.NotifyMigrateRepository(ctx.User, ctxUser, repo)
|
||||||
|
|
||||||
ctx.Redirect(setting.AppSubURL + "/" + ctxUser.Name + "/" + form.RepoName)
|
ctx.Redirect(setting.AppSubURL + "/" + ctxUser.Name + "/" + form.RepoName)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import (
|
||||||
"code.gitea.io/gitea/modules/base"
|
"code.gitea.io/gitea/modules/base"
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
|
"code.gitea.io/gitea/modules/notification"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
"code.gitea.io/gitea/modules/util"
|
"code.gitea.io/gitea/modules/util"
|
||||||
"code.gitea.io/gitea/routers/utils"
|
"code.gitea.io/gitea/routers/utils"
|
||||||
|
|
@ -321,6 +322,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
|
||||||
ctx.ServerError("DeleteRepository", err)
|
ctx.ServerError("DeleteRepository", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
notification.NotifyDeleteRepository(ctx.User, repo)
|
||||||
log.Trace("Repository deleted: %s/%s", ctx.Repo.Owner.Name, repo.Name)
|
log.Trace("Repository deleted: %s/%s", ctx.Repo.Owner.Name, repo.Name)
|
||||||
|
|
||||||
ctx.Flash.Success(ctx.Tr("repo.settings.deletion_success"))
|
ctx.Flash.Success(ctx.Tr("repo.settings.deletion_success"))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user