summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/convert/issue.go29
-rw-r--r--modules/convert/issue_comment.go27
-rw-r--r--modules/convert/pull.go6
-rw-r--r--modules/convert/pull_test.go9
-rw-r--r--modules/doctor/dbconsistency.go22
-rw-r--r--modules/indexer/issues/indexer.go18
-rw-r--r--modules/notification/action/action.go117
-rw-r--r--modules/notification/action/action_test.go3
-rw-r--r--modules/notification/base/notifier.go90
-rw-r--r--modules/notification/base/null.go92
-rw-r--r--modules/notification/indexer/indexer.go44
-rw-r--r--modules/notification/mail/mail.go91
-rw-r--r--modules/notification/mirror/mirror.go14
-rw-r--r--modules/notification/notification.go180
-rw-r--r--modules/notification/ui/ui.go47
-rw-r--r--modules/notification/webhook/webhook.go321
-rw-r--r--modules/repository/repo.go2
17 files changed, 525 insertions, 587 deletions
diff --git a/modules/convert/issue.go b/modules/convert/issue.go
index 5364367a80..7c11b2a89f 100644
--- a/modules/convert/issue.go
+++ b/modules/convert/issue.go
@@ -5,6 +5,7 @@
package convert
import (
+ "context"
"fmt"
"net/url"
"strings"
@@ -22,17 +23,17 @@ import (
// it assumes some fields assigned with values:
// Required - Poster, Labels,
// Optional - Milestone, Assignee, PullRequest
-func ToAPIIssue(issue *issues_model.Issue) *api.Issue {
- if err := issue.LoadLabels(db.DefaultContext); err != nil {
+func ToAPIIssue(ctx context.Context, issue *issues_model.Issue) *api.Issue {
+ if err := issue.LoadLabels(ctx); err != nil {
return &api.Issue{}
}
- if err := issue.LoadPoster(); err != nil {
+ if err := issue.LoadPoster(ctx); err != nil {
return &api.Issue{}
}
- if err := issue.LoadRepo(db.DefaultContext); err != nil {
+ if err := issue.LoadRepo(ctx); err != nil {
return &api.Issue{}
}
- if err := issue.Repo.GetOwner(db.DefaultContext); err != nil {
+ if err := issue.Repo.GetOwner(ctx); err != nil {
return &api.Issue{}
}
@@ -64,14 +65,14 @@ func ToAPIIssue(issue *issues_model.Issue) *api.Issue {
apiIssue.Closed = issue.ClosedUnix.AsTimePtr()
}
- if err := issue.LoadMilestone(); err != nil {
+ if err := issue.LoadMilestone(ctx); err != nil {
return &api.Issue{}
}
if issue.Milestone != nil {
apiIssue.Milestone = ToAPIMilestone(issue.Milestone)
}
- if err := issue.LoadAssignees(db.DefaultContext); err != nil {
+ if err := issue.LoadAssignees(ctx); err != nil {
return &api.Issue{}
}
if len(issue.Assignees) > 0 {
@@ -81,7 +82,7 @@ func ToAPIIssue(issue *issues_model.Issue) *api.Issue {
apiIssue.Assignee = ToUser(issue.Assignees[0], nil) // For compatibility, we're keeping the first assignee as `apiIssue.Assignee`
}
if issue.IsPull {
- if err := issue.LoadPullRequest(); err != nil {
+ if err := issue.LoadPullRequest(ctx); err != nil {
return &api.Issue{}
}
apiIssue.PullRequest = &api.PullRequestMeta{
@@ -99,16 +100,16 @@ func ToAPIIssue(issue *issues_model.Issue) *api.Issue {
}
// ToAPIIssueList converts an IssueList to API format
-func ToAPIIssueList(il issues_model.IssueList) []*api.Issue {
+func ToAPIIssueList(ctx context.Context, il issues_model.IssueList) []*api.Issue {
result := make([]*api.Issue, len(il))
for i := range il {
- result[i] = ToAPIIssue(il[i])
+ result[i] = ToAPIIssue(ctx, il[i])
}
return result
}
// ToTrackedTime converts TrackedTime to API format
-func ToTrackedTime(t *issues_model.TrackedTime) (apiT *api.TrackedTime) {
+func ToTrackedTime(ctx context.Context, t *issues_model.TrackedTime) (apiT *api.TrackedTime) {
apiT = &api.TrackedTime{
ID: t.ID,
IssueID: t.IssueID,
@@ -118,7 +119,7 @@ func ToTrackedTime(t *issues_model.TrackedTime) (apiT *api.TrackedTime) {
Created: t.Created,
}
if t.Issue != nil {
- apiT.Issue = ToAPIIssue(t.Issue)
+ apiT.Issue = ToAPIIssue(ctx, t.Issue)
}
if t.User != nil {
apiT.UserName = t.User.Name
@@ -169,10 +170,10 @@ func ToStopWatches(sws []*issues_model.Stopwatch) (api.StopWatches, error) {
}
// ToTrackedTimeList converts TrackedTimeList to API format
-func ToTrackedTimeList(tl issues_model.TrackedTimeList) api.TrackedTimeList {
+func ToTrackedTimeList(ctx context.Context, tl issues_model.TrackedTimeList) api.TrackedTimeList {
result := make([]*api.TrackedTime, 0, len(tl))
for _, t := range tl {
- result = append(result, ToTrackedTime(t))
+ result = append(result, ToTrackedTime(ctx, t))
}
return result
}
diff --git a/modules/convert/issue_comment.go b/modules/convert/issue_comment.go
index 73ad345fa4..c33cf5c111 100644
--- a/modules/convert/issue_comment.go
+++ b/modules/convert/issue_comment.go
@@ -5,7 +5,8 @@
package convert
import (
- "code.gitea.io/gitea/models/db"
+ "context"
+
issues_model "code.gitea.io/gitea/models/issues"
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
@@ -28,8 +29,8 @@ func ToComment(c *issues_model.Comment) *api.Comment {
}
// ToTimelineComment converts a issues_model.Comment to the api.TimelineComment format
-func ToTimelineComment(c *issues_model.Comment, doer *user_model.User) *api.TimelineComment {
- err := c.LoadMilestone()
+func ToTimelineComment(ctx context.Context, c *issues_model.Comment, doer *user_model.User) *api.TimelineComment {
+ err := c.LoadMilestone(ctx)
if err != nil {
log.Error("LoadMilestone: %v", err)
return nil
@@ -107,25 +108,25 @@ func ToTimelineComment(c *issues_model.Comment, doer *user_model.User) *api.Time
return nil
}
- comment.TrackedTime = ToTrackedTime(c.Time)
+ comment.TrackedTime = ToTrackedTime(ctx, c.Time)
}
if c.RefIssueID != 0 {
- issue, err := issues_model.GetIssueByID(db.DefaultContext, c.RefIssueID)
+ issue, err := issues_model.GetIssueByID(ctx, c.RefIssueID)
if err != nil {
log.Error("GetIssueByID(%d): %v", c.RefIssueID, err)
return nil
}
- comment.RefIssue = ToAPIIssue(issue)
+ comment.RefIssue = ToAPIIssue(ctx, issue)
}
if c.RefCommentID != 0 {
- com, err := issues_model.GetCommentByID(db.DefaultContext, c.RefCommentID)
+ com, err := issues_model.GetCommentByID(ctx, c.RefCommentID)
if err != nil {
log.Error("GetCommentByID(%d): %v", c.RefCommentID, err)
return nil
}
- err = com.LoadPoster()
+ err = com.LoadPoster(ctx)
if err != nil {
log.Error("LoadPoster: %v", err)
return nil
@@ -138,17 +139,17 @@ func ToTimelineComment(c *issues_model.Comment, doer *user_model.User) *api.Time
var repo *repo_model.Repository
if c.Label.BelongsToOrg() {
var err error
- org, err = user_model.GetUserByID(c.Label.OrgID)
+ org, err = user_model.GetUserByIDCtx(ctx, c.Label.OrgID)
if err != nil {
- log.Error("GetUserByID(%d): %v", c.Label.OrgID, err)
+ log.Error("GetUserByIDCtx(%d): %v", c.Label.OrgID, err)
return nil
}
}
if c.Label.BelongsToRepo() {
var err error
- repo, err = repo_model.GetRepositoryByID(c.Label.RepoID)
+ repo, err = repo_model.GetRepositoryByIDCtx(ctx, c.Label.RepoID)
if err != nil {
- log.Error("GetRepositoryByID(%d): %v", c.Label.RepoID, err)
+ log.Error("GetRepositoryByIDCtx(%d): %v", c.Label.RepoID, err)
return nil
}
}
@@ -167,7 +168,7 @@ func ToTimelineComment(c *issues_model.Comment, doer *user_model.User) *api.Time
}
if c.DependentIssue != nil {
- comment.DependentIssue = ToAPIIssue(c.DependentIssue)
+ comment.DependentIssue = ToAPIIssue(ctx, c.DependentIssue)
}
return comment
diff --git a/modules/convert/pull.go b/modules/convert/pull.go
index 9c31f9bd2c..ca9a4c39c5 100644
--- a/modules/convert/pull.go
+++ b/modules/convert/pull.go
@@ -33,13 +33,13 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
return nil
}
- apiIssue := ToAPIIssue(pr.Issue)
- if err := pr.LoadBaseRepoCtx(ctx); err != nil {
+ apiIssue := ToAPIIssue(ctx, pr.Issue)
+ if err := pr.LoadBaseRepo(ctx); err != nil {
log.Error("GetRepositoryById[%d]: %v", pr.ID, err)
return nil
}
- if err := pr.LoadHeadRepoCtx(ctx); err != nil {
+ if err := pr.LoadHeadRepo(ctx); err != nil {
log.Error("GetRepositoryById[%d]: %v", pr.ID, err)
return nil
}
diff --git a/modules/convert/pull_test.go b/modules/convert/pull_test.go
index a6ccbaca58..a0a672d3a5 100644
--- a/modules/convert/pull_test.go
+++ b/modules/convert/pull_test.go
@@ -7,6 +7,7 @@ package convert
import (
"testing"
+ "code.gitea.io/gitea/models/db"
issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/models/perm"
repo_model "code.gitea.io/gitea/models/repo"
@@ -22,8 +23,8 @@ func TestPullRequest_APIFormat(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
headRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 1})
- assert.NoError(t, pr.LoadAttributes())
- assert.NoError(t, pr.LoadIssue())
+ assert.NoError(t, pr.LoadAttributes(db.DefaultContext))
+ assert.NoError(t, pr.LoadIssue(db.DefaultContext))
apiPullRequest := ToAPIPullRequest(git.DefaultContext, pr, nil)
assert.NotNil(t, apiPullRequest)
assert.EqualValues(t, &structs.PRBranchInfo{
@@ -36,8 +37,8 @@ func TestPullRequest_APIFormat(t *testing.T) {
// withOut HeadRepo
pr = unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 1})
- assert.NoError(t, pr.LoadIssue())
- assert.NoError(t, pr.LoadAttributes())
+ assert.NoError(t, pr.LoadIssue(db.DefaultContext))
+ assert.NoError(t, pr.LoadAttributes(db.DefaultContext))
// simulate fork deletion
pr.HeadRepo = nil
pr.HeadRepoID = 100000
diff --git a/modules/doctor/dbconsistency.go b/modules/doctor/dbconsistency.go
index 89d974a350..602b2e523e 100644
--- a/modules/doctor/dbconsistency.go
+++ b/modules/doctor/dbconsistency.go
@@ -18,13 +18,13 @@ import (
type consistencyCheck struct {
Name string
- Counter func() (int64, error)
- Fixer func() (int64, error)
+ Counter func(context.Context) (int64, error)
+ Fixer func(context.Context) (int64, error)
FixedMessage string
}
func (c *consistencyCheck) Run(ctx context.Context, logger log.Logger, autofix bool) error {
- count, err := c.Counter()
+ count, err := c.Counter(ctx)
if err != nil {
logger.Critical("Error: %v whilst counting %s", err, c.Name)
return err
@@ -32,7 +32,7 @@ func (c *consistencyCheck) Run(ctx context.Context, logger log.Logger, autofix b
if count > 0 {
if autofix {
var fixed int64
- if fixed, err = c.Fixer(); err != nil {
+ if fixed, err = c.Fixer(ctx); err != nil {
logger.Critical("Error: %v whilst fixing %s", err, c.Name)
return err
}
@@ -54,9 +54,9 @@ func (c *consistencyCheck) Run(ctx context.Context, logger log.Logger, autofix b
return nil
}
-func asFixer(fn func() error) func() (int64, error) {
- return func() (int64, error) {
- err := fn()
+func asFixer(fn func(ctx context.Context) error) func(ctx context.Context) (int64, error) {
+ return func(ctx context.Context) (int64, error) {
+ err := fn(ctx)
return -1, err
}
}
@@ -64,11 +64,11 @@ func asFixer(fn func() error) func() (int64, error) {
func genericOrphanCheck(name, subject, refobject, joincond string) consistencyCheck {
return consistencyCheck{
Name: name,
- Counter: func() (int64, error) {
- return db.CountOrphanedObjects(subject, refobject, joincond)
+ Counter: func(ctx context.Context) (int64, error) {
+ return db.CountOrphanedObjects(ctx, subject, refobject, joincond)
},
- Fixer: func() (int64, error) {
- err := db.DeleteOrphanedObjects(subject, refobject, joincond)
+ Fixer: func(ctx context.Context) (int64, error) {
+ err := db.DeleteOrphanedObjects(ctx, subject, refobject, joincond)
return -1, err
},
}
diff --git a/modules/indexer/issues/indexer.go b/modules/indexer/issues/indexer.go
index da6a200aef..5b0279d1ab 100644
--- a/modules/indexer/issues/indexer.go
+++ b/modules/indexer/issues/indexer.go
@@ -291,7 +291,7 @@ func populateIssueIndexer(ctx context.Context) {
return
default:
}
- repos, _, err := repo_model.SearchRepositoryByName(&repo_model.SearchRepoOptions{
+ repos, _, err := repo_model.SearchRepositoryByName(ctx, &repo_model.SearchRepoOptions{
ListOptions: db.ListOptions{Page: page, PageSize: repo_model.RepositoryListDefaultPageSize},
OrderBy: db.SearchOrderByID,
Private: true,
@@ -313,14 +313,14 @@ func populateIssueIndexer(ctx context.Context) {
return
default:
}
- UpdateRepoIndexer(repo)
+ UpdateRepoIndexer(ctx, repo)
}
}
}
// UpdateRepoIndexer add/update all issues of the repositories
-func UpdateRepoIndexer(repo *repo_model.Repository) {
- is, err := issues_model.Issues(&issues_model.IssuesOptions{
+func UpdateRepoIndexer(ctx context.Context, repo *repo_model.Repository) {
+ is, err := issues_model.Issues(ctx, &issues_model.IssuesOptions{
RepoID: repo.ID,
IsClosed: util.OptionalBoolNone,
IsPull: util.OptionalBoolNone,
@@ -329,8 +329,8 @@ func UpdateRepoIndexer(repo *repo_model.Repository) {
log.Error("Issues: %v", err)
return
}
- if err = issues_model.IssueList(is).LoadDiscussComments(); err != nil {
- log.Error("LoadComments: %v", err)
+ if err = issues_model.IssueList(is).LoadDiscussComments(ctx); err != nil {
+ log.Error("LoadDiscussComments: %v", err)
return
}
for _, issue := range is {
@@ -360,11 +360,11 @@ func UpdateIssueIndexer(issue *issues_model.Issue) {
}
// DeleteRepoIssueIndexer deletes repo's all issues indexes
-func DeleteRepoIssueIndexer(repo *repo_model.Repository) {
+func DeleteRepoIssueIndexer(ctx context.Context, repo *repo_model.Repository) {
var ids []int64
- ids, err := issues_model.GetIssueIDsByRepoID(db.DefaultContext, repo.ID)
+ ids, err := issues_model.GetIssueIDsByRepoID(ctx, repo.ID)
if err != nil {
- log.Error("getIssueIDsByRepoID failed: %v", err)
+ log.Error("GetIssueIDsByRepoID failed: %v", err)
return
}
diff --git a/modules/notification/action/action.go b/modules/notification/action/action.go
index 44d115f3d7..d029405664 100644
--- a/modules/notification/action/action.go
+++ b/modules/notification/action/action.go
@@ -5,20 +5,18 @@
package action
import (
+ "context"
"fmt"
"path"
"strings"
activities_model "code.gitea.io/gitea/models/activities"
- "code.gitea.io/gitea/models/db"
issues_model "code.gitea.io/gitea/models/issues"
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
- "code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification/base"
- "code.gitea.io/gitea/modules/process"
"code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/util"
)
@@ -34,18 +32,18 @@ func NewNotifier() base.Notifier {
return &actionNotifier{}
}
-func (a *actionNotifier) NotifyNewIssue(issue *issues_model.Issue, mentions []*user_model.User) {
- if err := issue.LoadPoster(); err != nil {
+func (a *actionNotifier) NotifyNewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) {
+ if err := issue.LoadPoster(ctx); err != nil {
log.Error("issue.LoadPoster: %v", err)
return
}
- if err := issue.LoadRepo(db.DefaultContext); err != nil {
+ if err := issue.LoadRepo(ctx); err != nil {
log.Error("issue.LoadRepo: %v", err)
return
}
repo := issue.Repo
- if err := activities_model.NotifyWatchers(&activities_model.Action{
+ if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
ActUserID: issue.Poster.ID,
ActUser: issue.Poster,
OpType: activities_model.ActionCreateIssue,
@@ -59,7 +57,7 @@ func (a *actionNotifier) NotifyNewIssue(issue *issues_model.Issue, mentions []*u
}
// NotifyIssueChangeStatus notifies close or reopen issue to notifiers
-func (a *actionNotifier) NotifyIssueChangeStatus(doer *user_model.User, issue *issues_model.Issue, actionComment *issues_model.Comment, closeOrReopen bool) {
+func (a *actionNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, actionComment *issues_model.Comment, closeOrReopen bool) {
// Compose comment action, could be plain comment, close or reopen issue/pull request.
// This object will be used to notify watchers in the end of function.
act := &activities_model.Action{
@@ -86,13 +84,13 @@ func (a *actionNotifier) NotifyIssueChangeStatus(doer *user_model.User, issue *i
}
// Notify watchers for whatever action comes in, ignore if no action type.
- if err := activities_model.NotifyWatchers(act); err != nil {
+ if err := activities_model.NotifyWatchers(ctx, act); err != nil {
log.Error("NotifyWatchers: %v", err)
}
}
// NotifyCreateIssueComment notifies comment on an issue to notifiers
-func (a *actionNotifier) NotifyCreateIssueComment(doer *user_model.User, repo *repo_model.Repository,
+func (a *actionNotifier) NotifyCreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository,
issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User,
) {
act := &activities_model.Action{
@@ -122,26 +120,26 @@ func (a *actionNotifier) NotifyCreateIssueComment(doer *user_model.User, repo *r
}
// Notify watchers for whatever action comes in, ignore if no action type.
- if err := activities_model.NotifyWatchers(act); err != nil {
+ if err := activities_model.NotifyWatchers(ctx, act); err != nil {
log.Error("NotifyWatchers: %v", err)
}
}
-func (a *actionNotifier) NotifyNewPullRequest(pull *issues_model.PullRequest, mentions []*user_model.User) {
- if err := pull.LoadIssue(); err != nil {
+func (a *actionNotifier) NotifyNewPullRequest(ctx context.Context, pull *issues_model.PullRequest, mentions []*user_model.User) {
+ if err := pull.LoadIssue(ctx); err != nil {
log.Error("pull.LoadIssue: %v", err)
return
}
- if err := pull.Issue.LoadRepo(db.DefaultContext); err != nil {
+ if err := pull.Issue.LoadRepo(ctx); err != nil {
log.Error("pull.Issue.LoadRepo: %v", err)
return
}
- if err := pull.Issue.LoadPoster(); err != nil {
+ if err := pull.Issue.LoadPoster(ctx); err != nil {
log.Error("pull.Issue.LoadPoster: %v", err)
return
}
- if err := activities_model.NotifyWatchers(&activities_model.Action{
+ if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
ActUserID: pull.Issue.Poster.ID,
ActUser: pull.Issue.Poster,
OpType: activities_model.ActionCreatePullRequest,
@@ -154,8 +152,8 @@ func (a *actionNotifier) NotifyNewPullRequest(pull *issues_model.PullRequest, me
}
}
-func (a *actionNotifier) NotifyRenameRepository(doer *user_model.User, repo *repo_model.Repository, oldRepoName string) {
- if err := activities_model.NotifyWatchers(&activities_model.Action{
+func (a *actionNotifier) NotifyRenameRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldRepoName string) {
+ if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
ActUserID: doer.ID,
ActUser: doer,
OpType: activities_model.ActionRenameRepo,
@@ -168,8 +166,8 @@ func (a *actionNotifier) NotifyRenameRepository(doer *user_model.User, repo *rep
}
}
-func (a *actionNotifier) NotifyTransferRepository(doer *user_model.User, repo *repo_model.Repository, oldOwnerName string) {
- if err := activities_model.NotifyWatchers(&activities_model.Action{
+func (a *actionNotifier) NotifyTransferRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldOwnerName string) {
+ if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
ActUserID: doer.ID,
ActUser: doer,
OpType: activities_model.ActionTransferRepo,
@@ -182,8 +180,8 @@ func (a *actionNotifier) NotifyTransferRepository(doer *user_model.User, repo *r
}
}
-func (a *actionNotifier) NotifyCreateRepository(doer, u *user_model.User, repo *repo_model.Repository) {
- if err := activities_model.NotifyWatchers(&activities_model.Action{
+func (a *actionNotifier) NotifyCreateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) {
+ if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
ActUserID: doer.ID,
ActUser: doer,
OpType: activities_model.ActionCreateRepo,
@@ -195,8 +193,8 @@ func (a *actionNotifier) NotifyCreateRepository(doer, u *user_model.User, repo *
}
}
-func (a *actionNotifier) NotifyForkRepository(doer *user_model.User, oldRepo, repo *repo_model.Repository) {
- if err := activities_model.NotifyWatchers(&activities_model.Action{
+func (a *actionNotifier) NotifyForkRepository(ctx context.Context, doer *user_model.User, oldRepo, repo *repo_model.Repository) {
+ if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
ActUserID: doer.ID,
ActUser: doer,
OpType: activities_model.ActionCreateRepo,
@@ -208,11 +206,8 @@ func (a *actionNotifier) NotifyForkRepository(doer *user_model.User, oldRepo, re
}
}
-func (a *actionNotifier) NotifyPullRequestReview(pr *issues_model.PullRequest, review *issues_model.Review, comment *issues_model.Comment, mentions []*user_model.User) {
- ctx, _, finished := process.GetManager().AddContext(graceful.GetManager().HammerContext(), fmt.Sprintf("actionNotifier.NotifyPullRequestReview Pull[%d] #%d in [%d]", pr.ID, pr.Index, pr.BaseRepoID))
- defer finished()
-
- if err := review.LoadReviewer(); err != nil {
+func (a *actionNotifier) NotifyPullRequestReview(ctx context.Context, pr *issues_model.PullRequest, review *issues_model.Review, comment *issues_model.Comment, mentions []*user_model.User) {
+ if err := review.LoadReviewer(ctx); err != nil {
log.Error("LoadReviewer '%d/%d': %v", review.ID, review.ReviewerID, err)
return
}
@@ -269,8 +264,8 @@ func (a *actionNotifier) NotifyPullRequestReview(pr *issues_model.PullRequest, r
}
}
-func (*actionNotifier) NotifyMergePullRequest(pr *issues_model.PullRequest, doer *user_model.User) {
- if err := activities_model.NotifyWatchers(&activities_model.Action{
+func (*actionNotifier) NotifyMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
+ if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
ActUserID: doer.ID,
ActUser: doer,
OpType: activities_model.ActionMergePullRequest,
@@ -283,8 +278,8 @@ func (*actionNotifier) NotifyMergePullRequest(pr *issues_model.PullRequest, doer
}
}
-func (*actionNotifier) NotifyAutoMergePullRequest(pr *issues_model.PullRequest, doer *user_model.User) {
- if err := activities_model.NotifyWatchers(&activities_model.Action{
+func (*actionNotifier) NotifyAutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
+ if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
ActUserID: doer.ID,
ActUser: doer,
OpType: activities_model.ActionAutoMergePullRequest,
@@ -297,12 +292,12 @@ func (*actionNotifier) NotifyAutoMergePullRequest(pr *issues_model.PullRequest,
}
}
-func (*actionNotifier) NotifyPullRevieweDismiss(doer *user_model.User, review *issues_model.Review, comment *issues_model.Comment) {
+func (*actionNotifier) NotifyPullRevieweDismiss(ctx context.Context, doer *user_model.User, review *issues_model.Review, comment *issues_model.Comment) {
reviewerName := review.Reviewer.Name
if len(review.OriginalAuthor) > 0 {
reviewerName = review.OriginalAuthor
}
- if err := activities_model.NotifyWatchers(&activities_model.Action{
+ if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
ActUserID: doer.ID,
ActUser: doer,
OpType: activities_model.ActionPullReviewDismissed,
@@ -317,7 +312,7 @@ func (*actionNotifier) NotifyPullRevieweDismiss(doer *user_model.User, review *i
}
}
-func (a *actionNotifier) NotifyPushCommits(pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
+func (a *actionNotifier) NotifyPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
data, err := json.Marshal(commits)
if err != nil {
log.Error("Marshal: %v", err)
@@ -336,7 +331,7 @@ func (a *actionNotifier) NotifyPushCommits(pusher *user_model.User, repo *repo_m
opType = activities_model.ActionDeleteBranch
}
- if err = activities_model.NotifyWatchers(&activities_model.Action{
+ if err = activities_model.NotifyWatchers(ctx, &activities_model.Action{
ActUserID: pusher.ID,
ActUser: pusher,
OpType: opType,
@@ -346,17 +341,17 @@ func (a *actionNotifier) NotifyPushCommits(pusher *user_model.User, repo *repo_m
RefName: opts.RefFullName,
IsPrivate: repo.IsPrivate,
}); err != nil {
- log.Error("notifyWatchers: %v", err)
+ log.Error("NotifyWatchers: %v", err)
}
}
-func (a *actionNotifier) NotifyCreateRef(doer *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) {
+func (a *actionNotifier) NotifyCreateRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) {
opType := activities_model.ActionCommitRepo
if refType == "tag" {
// has sent same action in `NotifyPushCommits`, so skip it.
return
}
- if err := activities_model.NotifyWatchers(&activities_model.Action{
+ if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
ActUserID: doer.ID,
ActUser: doer,
OpType: opType,
@@ -365,17 +360,17 @@ func (a *actionNotifier) NotifyCreateRef(doer *user_model.User, repo *repo_model
IsPrivate: repo.IsPrivate,
RefName: refFullName,
}); err != nil {
- log.Error("notifyWatchers: %v", err)
+ log.Error("NotifyWatchers: %v", err)
}
}
-func (a *actionNotifier) NotifyDeleteRef(doer *user_model.User, repo *repo_model.Repository, refType, refFullName string) {
+func (a *actionNotifier) NotifyDeleteRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refType, refFullName string) {
opType := activities_model.ActionDeleteBranch
if refType == "tag" {
// has sent same action in `NotifyPushCommits`, so skip it.
return
}
- if err := activities_model.NotifyWatchers(&activities_model.Action{
+ if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
ActUserID: doer.ID,
ActUser: doer,
OpType: opType,
@@ -384,20 +379,20 @@ func (a *actionNotifier) NotifyDeleteRef(doer *user_model.User, repo *repo_model
IsPrivate: repo.IsPrivate,
RefName: refFullName,
}); err != nil {
- log.Error("notifyWatchers: %v", err)
+ log.Error("NotifyWatchers: %v", err)
}
}
-func (a *actionNotifier) NotifySyncPushCommits(pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
+func (a *actionNotifier) NotifySyncPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
data, err := json.Marshal(commits)
if err != nil {
log.Error("json.Marshal: %v", err)
return
}
- if err := activities_model.NotifyWatchers(&activities_model.Action{
+ if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
ActUserID: repo.OwnerID,
- ActUser: repo.MustOwner(),
+ ActUser: repo.MustOwner(ctx),
OpType: activities_model.ActionMirrorSyncPush,
RepoID: repo.ID,
Repo: repo,
@@ -405,44 +400,44 @@ func (a *actionNotifier) NotifySyncPushCommits(pusher *user_model.User, repo *re
RefName: opts.RefFullName,
Content: string(data),
}); err != nil {
- log.Error("notifyWatchers: %v", err)
+ log.Error("NotifyWatchers: %v", err)
}
}
-func (a *actionNotifier) NotifySyncCreateRef(doer *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) {
- if err := activities_model.NotifyWatchers(&activities_model.Action{
+func (a *actionNotifier) NotifySyncCreateRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) {
+ if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
ActUserID: repo.OwnerID,
- ActUser: repo.MustOwner(),
+ ActUser: repo.MustOwner(ctx),
OpType: activities_model.ActionMirrorSyncCreate,
RepoID: repo.ID,
Repo: repo,
IsPrivate: repo.IsPrivate,
RefName: refFullName,
}); err != nil {
- log.Error("notifyWatchers: %v", err)
+ log.Error("NotifyWatchers: %v", err)
}
}
-func (a *actionNotifier) NotifySyncDeleteRef(doer *user_model.User, repo *repo_model.Repository, refType, refFullName string) {
- if err := activities_model.NotifyWatchers(&activities_model.Action{
+func (a *actionNotifier) NotifySyncDeleteRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refType, refFullName string) {
+ if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
ActUserID: repo.OwnerID,
- ActUser: repo.MustOwner(),
+ ActUser: repo.MustOwner(ctx),
OpType: activities_model.ActionMirrorSyncDelete,
RepoID: repo.ID,
Repo: repo,
IsPrivate: repo.IsPrivate,
RefName: refFullName,
}); err != nil {
- log.Error("notifyWatchers: %v", err)
+ log.Error("NotifyWatchers: %v", err)
}
}
-func (a *actionNotifier) NotifyNewRelease(rel *repo_model.Release) {
- if err := rel.LoadAttributes(); err != nil {
- log.Error("NotifyNewRelease: %v", err)
+func (a *actionNotifier) NotifyNewRelease(ctx context.Context, rel *repo_model.Release) {
+ if err := rel.LoadAttributes(ctx); err != nil {
+ log.Error("LoadAttributes: %v", err)
return
}
- if err := activities_model.NotifyWatchers(&activities_model.Action{
+ if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
ActUserID: rel.PublisherID,
ActUser: rel.Publisher,
OpType: activities_model.ActionPublishRelease,
@@ -452,6 +447,6 @@ func (a *actionNotifier) NotifyNewRelease(rel *repo_model.Release) {
Content: rel.Title,
RefName: rel.TagName,
}); err != nil {
- log.Error("notifyWatchers: %v", err)
+ log.Error("NotifyWatchers: %v", err)
}
}
diff --git a/modules/notification/action/action_test.go b/modules/notification/action/action_test.go
index 79a938d6cd..dc31b3189b 100644
--- a/modules/notification/action/action_test.go
+++ b/modules/notification/action/action_test.go
@@ -10,6 +10,7 @@ import (
"testing"
activities_model "code.gitea.io/gitea/models/activities"
+ "code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
@@ -46,7 +47,7 @@ func TestRenameRepoAction(t *testing.T) {
}
unittest.AssertNotExistsBean(t, actionBean)
- NewNotifier().NotifyRenameRepository(user, repo, oldRepoName)
+ NewNotifier().NotifyRenameRepository(db.DefaultContext, user, repo, oldRepoName)
unittest.AssertExistsAndLoadBean(t, actionBean)
unittest.CheckConsistencyFor(t, &activities_model.Action{})
diff --git a/modules/notification/base/notifier.go b/modules/notification/base/notifier.go
index 9edab8213f..2f7deac88e 100644
--- a/modules/notification/base/notifier.go
+++ b/modules/notification/base/notifier.go
@@ -5,6 +5,8 @@
package base
import (
+ "context"
+
issues_model "code.gitea.io/gitea/models/issues"
packages_model "code.gitea.io/gitea/models/packages"
repo_model "code.gitea.io/gitea/models/repo"
@@ -15,50 +17,50 @@ import (
// Notifier defines an interface to notify receiver
type Notifier interface {
Run()
- NotifyCreateRepository(doer, u *user_model.User, repo *repo_model.Repository)
- NotifyMigrateRepository(doer, u *user_model.User, repo *repo_model.Repository)
- NotifyDeleteRepository(doer *user_model.User, repo *repo_model.Repository)
- NotifyForkRepository(doer *user_model.User, oldRepo, repo *repo_model.Repository)
- NotifyRenameRepository(doer *user_model.User, repo *repo_model.Repository, oldRepoName string)
- NotifyTransferRepository(doer *user_model.User, repo *repo_model.Repository, oldOwnerName string)
- NotifyNewIssue(issue *issues_model.Issue, mentions []*user_model.User)
- NotifyIssueChangeStatus(*user_model.User, *issues_model.Issue, *issues_model.Comment, bool)
- NotifyDeleteIssue(*user_model.User, *issues_model.Issue)
- NotifyIssueChangeMilestone(doer *user_model.User, issue *issues_model.Issue, oldMilestoneID int64)
- NotifyIssueChangeAssignee(doer *user_model.User, issue *issues_model.Issue, assignee *user_model.User, removed bool, comment *issues_model.Comment)
- NotifyPullReviewRequest(doer *user_model.User, issue *issues_model.Issue, reviewer *user_model.User, isRequest bool, comment *issues_model.Comment)
- NotifyIssueChangeContent(doer *user_model.User, issue *issues_model.Issue, oldContent string)
- NotifyIssueClearLabels(doer *user_model.User, issue *issues_model.Issue)
- NotifyIssueChangeTitle(doer *user_model.User, issue *issues_model.Issue, oldTitle string)
- NotifyIssueChangeRef(doer *user_model.User, issue *issues_model.Issue, oldRef string)
- NotifyIssueChangeLabels(doer *user_model.User, issue *issues_model.Issue,
+ NotifyCreateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository)
+ NotifyMigrateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository)
+ NotifyDeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository)
+ NotifyForkRepository(ctx context.Context, doer *user_model.User, oldRepo, repo *repo_model.Repository)
+ NotifyRenameRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldRepoName string)
+ NotifyTransferRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldOwnerName string)
+ NotifyNewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User)
+ NotifyIssueChangeStatus(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, actionComment *issues_model.Comment, closeOrReopen bool)
+ NotifyDeleteIssue(ctx context.Context, doer *user_model.User, issue *issues_model.Issue)
+ NotifyIssueChangeMilestone(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldMilestoneID int64)
+ NotifyIssueChangeAssignee(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, assignee *user_model.User, removed bool, comment *issues_model.Comment)
+ NotifyPullReviewRequest(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, reviewer *user_model.User, isRequest bool, comment *issues_model.Comment)
+ NotifyIssueChangeContent(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldContent string)
+ NotifyIssueClearLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue)
+ NotifyIssueChangeTitle(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldTitle string)
+ NotifyIssueChangeRef(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldRef string)
+ NotifyIssueChangeLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue,
addedLabels, removedLabels []*issues_model.Label)
- NotifyNewPullRequest(pr *issues_model.PullRequest, mentions []*user_model.User)
- NotifyMergePullRequest(pr *issues_model.PullRequest, doer *user_model.User)
- NotifyAutoMergePullRequest(pr *issues_model.PullRequest, doer *user_model.User)
- NotifyPullRequestSynchronized(doer *user_model.User, pr *issues_model.PullRequest)
- NotifyPullRequestReview(pr *issues_model.PullRequest, review *issues_model.Review, comment *issues_model.Comment, mentions []*user_model.User)
- NotifyPullRequestCodeComment(pr *issues_model.PullRequest, comment *issues_model.Comment, mentions []*user_model.User)
- NotifyPullRequestChangeTargetBranch(doer *user_model.User, pr *issues_model.PullRequest, oldBranch string)
- NotifyPullRequestPushCommits(doer *user_model.User, pr *issues_model.PullRequest, comment *issues_model.Comment)
- NotifyPullRevieweDismiss(doer *user_model.User, review *issues_model.Review, comment *issues_model.Comment)
- NotifyCreateIssueComment(doer *user_model.User, repo *repo_model.Repository,
+ NotifyNewPullRequest(ctx context.Context, pr *issues_model.PullRequest, mentions []*user_model.User)
+ NotifyMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest)
+ NotifyAutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest)
+ NotifyPullRequestSynchronized(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest)
+ NotifyPullRequestReview(ctx context.Context, pr *issues_model.PullRequest, review *issues_model.Review, comment *issues_model.Comment, mentions []*user_model.User)
+ NotifyPullRequestCodeComment(ctx context.Context, pr *issues_model.PullRequest, comment *issues_model.Comment, mentions []*user_model.User)
+ NotifyPullRequestChangeTargetBranch(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, oldBranch string)
+ NotifyPullRequestPushCommits(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, comment *issues_model.Comment)
+ NotifyPullReviewDismiss(ctx context.Context, doer *user_model.User, review *issues_model.Review, comment *issues_model.Comment)
+ NotifyCreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository,
issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User)
- NotifyUpdateComment(*user_model.User, *issues_model.Comment, string)
- NotifyDeleteComment(*user_model.User, *issues_model.Comment)
- NotifyNewWikiPage(doer *user_model.User, repo *repo_model.Repository, page, comment string)
- NotifyEditWikiPage(doer *user_model.User, repo *repo_model.Repository, page, comment string)
- NotifyDeleteWikiPage(doer *user_model.User, repo *repo_model.Repository, page string)
- NotifyNewRelease(rel *repo_model.Release)
- NotifyUpdateRelease(doer *user_model.User, rel *repo_model.Release)
- NotifyDeleteRelease(doer *user_model.User, rel *repo_model.Release)
- NotifyPushCommits(pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits)
- NotifyCreateRef(doer *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string)
- NotifyDeleteRef(doer *user_model.User, repo *repo_model.Repository, refType, refFullName string)
- NotifySyncPushCommits(pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits)
- NotifySyncCreateRef(doer *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string)
- NotifySyncDeleteRef(doer *user_model.User, repo *repo_model.Repository, refType, refFullName string)
- NotifyRepoPendingTransfer(doer, newOwner *user_model.User, repo *repo_model.Repository)
- NotifyPackageCreate(doer *user_model.User, pd *packages_model.PackageDescriptor)
- NotifyPackageDelete(doer *user_model.User, pd *packages_model.PackageDescriptor)
+ NotifyUpdateComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment, oldContent string)
+ NotifyDeleteComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment)
+ NotifyNewWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string)
+ NotifyEditWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string)
+ NotifyDeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page string)
+ NotifyNewRelease(ctx context.Context, rel *repo_model.Release)
+ NotifyUpdateRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release)
+ NotifyDeleteRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release)
+ NotifyPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits)
+ NotifyCreateRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string)
+ NotifyDeleteRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refType, refFullName string)
+ NotifySyncPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits)
+ NotifySyncCreateRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string)
+ NotifySyncDeleteRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refType, refFullName string)
+ NotifyRepoPendingTransfer(ctx context.Context, doer, newOwner *user_model.User, repo *repo_model.Repository)
+ NotifyPackageCreate(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor)
+ NotifyPackageDelete(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor)
}
diff --git a/modules/notification/base/null.go b/modules/notification/base/null.go
index f051fbc26f..88e0c93de1 100644
--- a/modules/notification/base/null.go
+++ b/modules/notification/base/null.go
@@ -5,6 +5,8 @@
package base
import (
+ "context"
+
issues_model "code.gitea.io/gitea/models/issues"
packages_model "code.gitea.io/gitea/models/packages"
repo_model "code.gitea.io/gitea/models/repo"
@@ -22,179 +24,179 @@ func (*NullNotifier) Run() {
}
// NotifyCreateIssueComment places a place holder function
-func (*NullNotifier) NotifyCreateIssueComment(doer *user_model.User, repo *repo_model.Repository,
+func (*NullNotifier) NotifyCreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository,
issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User) {
}
// NotifyNewIssue places a place holder function
-func (*NullNotifier) NotifyNewIssue(issue *issues_model.Issue, mentions []*user_model.User) {
+func (*NullNotifier) NotifyNewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) {
}
// NotifyIssueChangeStatus places a place holder function
-func (*NullNotifier) NotifyIssueChangeStatus(doer *user_model.User, issue *issues_model.Issue, actionComment *issues_model.Comment, isClosed bool) {
+func (*NullNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, actionComment *issues_model.Comment, isClosed bool) {
}
// NotifyDeleteIssue notify when some issue deleted
-func (*NullNotifier) NotifyDeleteIssue(doer *user_model.User, issue *issues_model.Issue) {
+func (*NullNotifier) NotifyDeleteIssue(ctx context.Context, doer *user_model.User, issue *issues_model.Issue) {
}
// NotifyNewPullRequest places a place holder function
-func (*NullNotifier) NotifyNewPullRequest(pr *issues_model.PullRequest, mentions []*user_model.User) {
+func (*NullNotifier) NotifyNewPullRequest(ctx context.Context, pr *issues_model.PullRequest, mentions []*user_model.User) {
}
// NotifyPullRequestReview places a place holder function
-func (*NullNotifier) NotifyPullRequestReview(pr *issues_model.PullRequest, r *issues_model.Review, comment *issues_model.Comment, mentions []*user_model.User) {
+func (*NullNotifier) NotifyPullRequestReview(ctx context.Context, pr *issues_model.PullRequest, r *issues_model.Review, comment *issues_model.Comment, mentions []*user_model.User) {
}
// NotifyPullRequestCodeComment places a place holder function
-func (*NullNotifier) NotifyPullRequestCodeComment(pr *issues_model.PullRequest, comment *issues_model.Comment, mentions []*user_model.User) {
+func (*NullNotifier) NotifyPullRequestCodeComment(ctx context.Context, pr *issues_model.PullRequest, comment *issues_model.Comment, mentions []*user_model.User) {
}
// NotifyMergePullRequest places a place holder function
-func (*NullNotifier) NotifyMergePullRequest(pr *issues_model.PullRequest, doer *user_model.User) {
+func (*NullNotifier) NotifyMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
}
// NotifyAutoMergePullRequest places a place holder function
-func (*NullNotifier) NotifyAutoMergePullRequest(pr *issues_model.PullRequest, doer *user_model.User) {
+func (*NullNotifier) NotifyAutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
}
// NotifyPullRequestSynchronized places a place holder function
-func (*NullNotifier) NotifyPullRequestSynchronized(doer *user_model.User, pr *issues_model.PullRequest) {
+func (*NullNotifier) NotifyPullRequestSynchronized(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
}
// NotifyPullRequestChangeTargetBranch places a place holder function
-func (*NullNotifier) NotifyPullRequestChangeTargetBranch(doer *user_model.User, pr *issues_model.PullRequest, oldBranch string) {
+func (*NullNotifier) NotifyPullRequestChangeTargetBranch(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, oldBranch string) {
}
// NotifyPullRequestPushCommits notifies when push commits to pull request's head branch
-func (*NullNotifier) NotifyPullRequestPushCommits(doer *user_model.User, pr *issues_model.PullRequest, comment *issues_model.Comment) {
+func (*NullNotifier) NotifyPullRequestPushCommits(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, comment *issues_model.Comment) {
}
-// NotifyPullRevieweDismiss notifies when a review was dismissed by repo admin
-func (*NullNotifier) NotifyPullRevieweDismiss(doer *user_model.User, review *issues_model.Review, comment *issues_model.Comment) {
+// NotifyPullReviewDismiss notifies when a review was dismissed by repo admin
+func (*NullNotifier) NotifyPullReviewDismiss(ctx context.Context, doer *user_model.User, review *issues_model.Review, comment *issues_model.Comment) {
}
// NotifyUpdateComment places a place holder function
-func (*NullNotifier) NotifyUpdateComment(doer *user_model.User, c *issues_model.Comment, oldContent string) {
+func (*NullNotifier) NotifyUpdateComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment, oldContent string) {
}
// NotifyDeleteComment places a place holder function
-func (*NullNotifier) NotifyDeleteComment(doer *user_model.User, c *issues_model.Comment) {
+func (*NullNotifier) NotifyDeleteComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment) {
}
// NotifyNewWikiPage places a place holder function
-func (*NullNotifier) NotifyNewWikiPage(doer *user_model.User, repo *repo_model.Repository, page, comment string) {
+func (*NullNotifier) NotifyNewWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) {
}
// NotifyEditWikiPage places a place holder function
-func (*NullNotifier) NotifyEditWikiPage(doer *user_model.User, repo *repo_model.Repository, page, comment string) {
+func (*NullNotifier) NotifyEditWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) {
}
// NotifyDeleteWikiPage places a place holder function
-func (*NullNotifier) NotifyDeleteWikiPage(doer *user_model.User, repo *repo_model.Repository, page string) {
+func (*NullNotifier) NotifyDeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page string) {
}
// NotifyNewRelease places a place holder function
-func (*NullNotifier) NotifyNewRelease(rel *repo_model.Release) {
+func (*NullNotifier) NotifyNewRelease(ctx context.Context, rel *repo_model.Release) {
}
// NotifyUpdateRelease places a place holder function
-func (*NullNotifier) NotifyUpdateRelease(doer *user_model.User, rel *repo_model.Release) {
+func (*NullNotifier) NotifyUpdateRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) {
}
// NotifyDeleteRelease places a place holder function
-func (*NullNotifier) NotifyDeleteRelease(doer *user_model.User, rel *repo_model.Release) {
+func (*NullNotifier) NotifyDeleteRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) {
}
// NotifyIssueChangeMilestone places a place holder function
-func (*NullNotifier) NotifyIssueChangeMilestone(doer *user_model.User, issue *issues_model.Issue, oldMilestoneID int64) {
+func (*NullNotifier) NotifyIssueChangeMilestone(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldMilestoneID int64) {
}
// NotifyIssueChangeContent places a place holder function
-func (*NullNotifier) NotifyIssueChangeContent(doer *user_model.User, issue *issues_model.Issue, oldContent string) {
+func (*NullNotifier) NotifyIssueChangeContent(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldContent string) {
}
// NotifyIssueChangeAssignee places a place holder function
-func (*NullNotifier) NotifyIssueChangeAssignee(doer *user_model.User, issue *issues_model.Issue, assignee *user_model.User, removed bool, comment *issues_model.Comment) {
+func (*NullNotifier) NotifyIssueChangeAssignee(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, assignee *user_model.User, removed bool, comment *issues_model.Comment) {
}
// NotifyPullReviewRequest places a place holder function
-func (*NullNotifier) NotifyPullReviewRequest(doer *user_model.User, issue *issues_model.Issue, reviewer *user_model.User, isRequest bool, comment *issues_model.Comment) {
+func (*NullNotifier) NotifyPullReviewRequest(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, reviewer *user_model.User, isRequest bool, comment *issues_model.Comment) {
}
// NotifyIssueClearLabels places a place holder function
-func (*NullNotifier) NotifyIssueClearLabels(doer *user_model.User, issue *issues_model.Issue) {
+func (*NullNotifier) NotifyIssueClearLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue) {
}
// NotifyIssueChangeTitle places a place holder function
-func (*NullNotifier) NotifyIssueChangeTitle(doer *user_model.User, issue *issues_model.Issue, oldTitle string) {
+func (*NullNotifier) NotifyIssueChangeTitle(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldTitle string) {
}
// NotifyIssueChangeRef places a place holder function
-func (*NullNotifier) NotifyIssueChangeRef(doer *user_model.User, issue *issues_model.Issue, oldTitle string) {
+func (*NullNotifier) NotifyIssueChangeRef(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldTitle string) {
}
// NotifyIssueChangeLabels places a place holder function
-func (*NullNotifier) NotifyIssueChangeLabels(doer *user_model.User, issue *issues_model.Issue,
+func (*NullNotifier) NotifyIssueChangeLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue,
addedLabels, removedLabels []*issues_model.Label) {
}
// NotifyCreateRepository places a place holder function
-func (*NullNotifier) NotifyCreateRepository(doer, u *user_model.User, repo *repo_model.Repository) {
+func (*NullNotifier) NotifyCreateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) {
}
// NotifyDeleteRepository places a place holder function
-func (*NullNotifier) NotifyDeleteRepository(doer *user_model.User, repo *repo_model.Repository) {
+func (*NullNotifier) NotifyDeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository) {
}
// NotifyForkRepository places a place holder function
-func (*NullNotifier) NotifyForkRepository(doer *user_model.User, oldRepo, repo *repo_model.Repository) {
+func (*NullNotifier) NotifyForkRepository(ctx context.Context, doer *user_model.User, oldRepo, repo *repo_model.Repository) {
}
// NotifyMigrateRepository places a place holder function
-func (*NullNotifier) NotifyMigrateRepository(doer, u *user_model.User, repo *repo_model.Repository) {
+func (*NullNotifier) NotifyMigrateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) {
}
// NotifyPushCommits notifies commits pushed to notifiers
-func (*NullNotifier) NotifyPushCommits(pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
+func (*NullNotifier) NotifyPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
}
// NotifyCreateRef notifies branch or tag creation to notifiers
-func (*NullNotifier) NotifyCreateRef(doer *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) {
+func (*NullNotifier) NotifyCreateRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) {
}
// NotifyDeleteRef notifies branch or tag deletion to notifiers
-func (*NullNotifier) NotifyDeleteRef(doer *user_model.User, repo *repo_model.Repository, refType, refFullName string) {
+func (*NullNotifier) NotifyDeleteRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refType, refFullName string) {
}
// NotifyRenameRepository places a place holder function
-func (*NullNotifier) NotifyRenameRepository(doer *user_model.User, repo *repo_model.Repository, oldRepoName string) {
+func (*NullNotifier) NotifyRenameRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldRepoName string) {
}
// NotifyTransferRepository places a place holder function
-func (*NullNotifier) NotifyTransferRepository(doer *user_model.User, repo *repo_model.Repository, oldOwnerName string) {
+func (*NullNotifier) NotifyTransferRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldOwnerName string) {
}
// NotifySyncPushCommits places a place holder function
-func (*NullNotifier) NotifySyncPushCommits(pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
+func (*NullNotifier) NotifySyncPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
}
// NotifySyncCreateRef places a place holder function
-func (*NullNotifier) NotifySyncCreateRef(doer *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) {
+func (*NullNotifier) NotifySyncCreateRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) {
}
// NotifySyncDeleteRef places a place holder function
-func (*NullNotifier) NotifySyncDeleteRef(doer *user_model.User, repo *repo_model.Repository, refType, refFullName string) {
+func (*NullNotifier) NotifySyncDeleteRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refType, refFullName string) {
}
// NotifyRepoPendingTransfer places a place holder function
-func (*NullNotifier) NotifyRepoPendingTransfer(doer, newOwner *user_model.User, repo *repo_model.Repository) {
+func (*NullNotifier) NotifyRepoPendingTransfer(ctx context.Context, doer, newOwner *user_model.User, repo *repo_model.Repository) {
}
// NotifyPackageCreate places a place holder function
-func (*NullNotifier) NotifyPackageCreate(doer *user_model.User, pd *packages_model.PackageDescriptor) {
+func (*NullNotifier) NotifyPackageCreate(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) {
}
// NotifyPackageDelete places a place holder function
-func (*NullNotifier) NotifyPackageDelete(doer *user_model.User, pd *packages_model.PackageDescriptor) {
+func (*NullNotifier) NotifyPackageDelete(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) {
}
diff --git a/modules/notification/indexer/indexer.go b/modules/notification/indexer/indexer.go
index fc9afdd4bc..2bacd5dec0 100644
--- a/modules/notification/indexer/indexer.go
+++ b/modules/notification/indexer/indexer.go
@@ -5,6 +5,8 @@
package indexer
import (
+ "context"
+
issues_model "code.gitea.io/gitea/models/issues"
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
@@ -29,13 +31,13 @@ func NewNotifier() base.Notifier {
return &indexerNotifier{}
}
-func (r *indexerNotifier) NotifyCreateIssueComment(doer *user_model.User, repo *repo_model.Repository,
+func (r *indexerNotifier) NotifyCreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository,
issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User,
) {
if comment.Type == issues_model.CommentTypeComment {
if issue.Comments == nil {
- if err := issue.LoadDiscussComments(); err != nil {
- log.Error("LoadComments failed: %v", err)
+ if err := issue.LoadDiscussComments(ctx); err != nil {
+ log.Error("LoadDiscussComments failed: %v", err)
return
}
} else {
@@ -46,15 +48,15 @@ func (r *indexerNotifier) NotifyCreateIssueComment(doer *user_model.User, repo *
}
}
-func (r *indexerNotifier) NotifyNewIssue(issue *issues_model.Issue, mentions []*user_model.User) {
+func (r *indexerNotifier) NotifyNewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) {
issue_indexer.UpdateIssueIndexer(issue)
}
-func (r *indexerNotifier) NotifyNewPullRequest(pr *issues_model.PullRequest, mentions []*user_model.User) {
+func (r *indexerNotifier) NotifyNewPullRequest(ctx context.Context, pr *issues_model.PullRequest, mentions []*user_model.User) {
issue_indexer.UpdateIssueIndexer(pr.Issue)
}
-func (r *indexerNotifier) NotifyUpdateComment(doer *user_model.User, c *issues_model.Comment, oldContent string) {
+func (r *indexerNotifier) NotifyUpdateComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment, oldContent string) {
if c.Type == issues_model.CommentTypeComment {
var found bool
if c.Issue.Comments != nil {
@@ -68,8 +70,8 @@ func (r *indexerNotifier) NotifyUpdateComment(doer *user_model.User, c *issues_m
}
if !found {
- if err := c.Issue.LoadDiscussComments(); err != nil {
- log.Error("LoadComments failed: %v", err)
+ if err := c.Issue.LoadDiscussComments(ctx); err != nil {
+ log.Error("LoadDiscussComments failed: %v", err)
return
}
}
@@ -78,9 +80,9 @@ func (r *indexerNotifier) NotifyUpdateComment(doer *user_model.User, c *issues_m
}
}
-func (r *indexerNotifier) NotifyDeleteComment(doer *user_model.User, comment *issues_model.Comment) {
+func (r *indexerNotifier) NotifyDeleteComment(ctx context.Context, doer *user_model.User, comment *issues_model.Comment) {
if comment.Type == issues_model.CommentTypeComment {
- if err := comment.LoadIssue(); err != nil {
+ if err := comment.LoadIssue(ctx); err != nil {
log.Error("LoadIssue: %v", err)
return
}
@@ -97,8 +99,8 @@ func (r *indexerNotifier) NotifyDeleteComment(doer *user_model.User, comment *is
}
if !found {
- if err := comment.Issue.LoadDiscussComments(); err != nil {
- log.Error("LoadComments failed: %v", err)
+ if err := comment.Issue.LoadDiscussComments(ctx); err != nil {
+ log.Error("LoadDiscussComments failed: %v", err)
return
}
}
@@ -107,15 +109,15 @@ func (r *indexerNotifier) NotifyDeleteComment(doer *user_model.User, comment *is
}
}
-func (r *indexerNotifier) NotifyDeleteRepository(doer *user_model.User, repo *repo_model.Repository) {
- issue_indexer.DeleteRepoIssueIndexer(repo)
+func (r *indexerNotifier) NotifyDeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository) {
+ issue_indexer.DeleteRepoIssueIndexer(ctx, repo)
if setting.Indexer.RepoIndexerEnabled {
code_indexer.UpdateRepoIndexer(repo)
}
}
-func (r *indexerNotifier) NotifyMigrateRepository(doer, u *user_model.User, repo *repo_model.Repository) {
- issue_indexer.UpdateRepoIndexer(repo)
+func (r *indexerNotifier) NotifyMigrateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) {
+ issue_indexer.UpdateRepoIndexer(ctx, repo)
if setting.Indexer.RepoIndexerEnabled && !repo.IsEmpty {
code_indexer.UpdateRepoIndexer(repo)
}
@@ -124,7 +126,7 @@ func (r *indexerNotifier) NotifyMigrateRepository(doer, u *user_model.User, repo
}
}
-func (r *indexerNotifier) NotifyPushCommits(pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
+func (r *indexerNotifier) NotifyPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
if setting.Indexer.RepoIndexerEnabled && opts.RefFullName == git.BranchPrefix+repo.DefaultBranch {
code_indexer.UpdateRepoIndexer(repo)
}
@@ -133,7 +135,7 @@ func (r *indexerNotifier) NotifyPushCommits(pusher *user_model.User, repo *repo_
}
}
-func (r *indexerNotifier) NotifySyncPushCommits(pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
+func (r *indexerNotifier) NotifySyncPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
if setting.Indexer.RepoIndexerEnabled && opts.RefFullName == git.BranchPrefix+repo.DefaultBranch {
code_indexer.UpdateRepoIndexer(repo)
}
@@ -142,14 +144,14 @@ func (r *indexerNotifier) NotifySyncPushCommits(pusher *user_model.User, repo *r
}
}
-func (r *indexerNotifier) NotifyIssueChangeContent(doer *user_model.User, issue *issues_model.Issue, oldContent string) {
+func (r *indexerNotifier) NotifyIssueChangeContent(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldContent string) {
issue_indexer.UpdateIssueIndexer(issue)
}
-func (r *indexerNotifier) NotifyIssueChangeTitle(doer *user_model.User, issue *issues_model.Issue, oldTitle string) {
+func (r *indexerNotifier) NotifyIssueChangeTitle(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldTitle string) {
issue_indexer.UpdateIssueIndexer(issue)
}
-func (r *indexerNotifier) NotifyIssueChangeRef(doer *user_model.User, issue *issues_model.Issue, oldRef string) {
+func (r *indexerNotifier) NotifyIssueChangeRef(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldRef string) {
issue_indexer.UpdateIssueIndexer(issue)
}
diff --git a/modules/notification/mail/mail.go b/modules/notification/mail/mail.go
index 54f561839d..123fa0e65a 100644
--- a/modules/notification/mail/mail.go
+++ b/modules/notification/mail/mail.go
@@ -5,16 +5,15 @@
package mail
import (
+ "context"
"fmt"
activities_model "code.gitea.io/gitea/models/activities"
issues_model "code.gitea.io/gitea/models/issues"
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
- "code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification/base"
- "code.gitea.io/gitea/modules/process"
"code.gitea.io/gitea/services/mailer"
)
@@ -29,12 +28,9 @@ func NewNotifier() base.Notifier {
return &mailNotifier{}
}
-func (m *mailNotifier) NotifyCreateIssueComment(doer *user_model.User, repo *repo_model.Repository,
+func (m *mailNotifier) NotifyCreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository,
issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User,
) {
- ctx, _, finished := process.GetManager().AddContext(graceful.GetManager().HammerContext(), fmt.Sprintf("mailNotifier.NotifyCreateIssueComment Issue[%d] #%d in [%d]", issue.ID, issue.Index, issue.RepoID))
- defer finished()
-
var act activities_model.ActionType
if comment.Type == issues_model.CommentTypeClose {
act = activities_model.ActionCloseIssue
@@ -53,13 +49,13 @@ func (m *mailNotifier) NotifyCreateIssueComment(doer *user_model.User, repo *rep
}
}
-func (m *mailNotifier) NotifyNewIssue(issue *issues_model.Issue, mentions []*user_model.User) {
- if err := mailer.MailParticipants(issue, issue.Poster, activities_model.ActionCreateIssue, mentions); err != nil {
+func (m *mailNotifier) NotifyNewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) {
+ if err := mailer.MailParticipants(ctx, issue, issue.Poster, activities_model.ActionCreateIssue, mentions); err != nil {
log.Error("MailParticipants: %v", err)
}
}
-func (m *mailNotifier) NotifyIssueChangeStatus(doer *user_model.User, issue *issues_model.Issue, actionComment *issues_model.Comment, isClosed bool) {
+func (m *mailNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, actionComment *issues_model.Comment, isClosed bool) {
var actionType activities_model.ActionType
if issue.IsPull {
if isClosed {
@@ -75,33 +71,30 @@ func (m *mailNotifier) NotifyIssueChangeStatus(doer *user_model.User, issue *iss
}
}
- if err := mailer.MailParticipants(issue, doer, actionType, nil); err != nil {
+ if err := mailer.MailParticipants(ctx, issue, doer, actionType, nil); err != nil {
log.Error("MailParticipants: %v", err)
}
}
-func (m *mailNotifier) NotifyIssueChangeTitle(doer *user_model.User, issue *issues_model.Issue, oldTitle string) {
- if err := issue.LoadPullRequest(); err != nil {
+func (m *mailNotifier) NotifyIssueChangeTitle(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldTitle string) {
+ if err := issue.LoadPullRequest(ctx); err != nil {
log.Error("issue.LoadPullRequest: %v", err)
return
}
if issue.IsPull && issues_model.HasWorkInProgressPrefix(oldTitle) && !issue.PullRequest.IsWorkInProgress() {
- if err := mailer.MailParticipants(issue, doer, activities_model.ActionPullRequestReadyForReview, nil); err != nil {
+ if err := mailer.MailParticipants(ctx, issue, doer, activities_model.ActionPullRequestReadyForReview, nil); err != nil {
log.Error("MailParticipants: %v", err)
}
}
}
-func (m *mailNotifier) NotifyNewPullRequest(pr *issues_model.PullRequest, mentions []*user_model.User) {
- if err := mailer.MailParticipants(pr.Issue, pr.Issue.Poster, activities_model.ActionCreatePullRequest, mentions); err != nil {
+func (m *mailNotifier) NotifyNewPullRequest(ctx context.Context, pr *issues_model.PullRequest, mentions []*user_model.User) {
+ if err := mailer.MailParticipants(ctx, pr.Issue, pr.Issue.Poster, activities_model.ActionCreatePullRequest, mentions); err != nil {
log.Error("MailParticipants: %v", err)
}
}
-func (m *mailNotifier) NotifyPullRequestReview(pr *issues_model.PullRequest, r *issues_model.Review, comment *issues_model.Comment, mentions []*user_model.User) {
- ctx, _, finished := process.GetManager().AddContext(graceful.GetManager().HammerContext(), fmt.Sprintf("mailNotifier.NotifyPullRequestReview Pull[%d] #%d in [%d]", pr.ID, pr.Index, pr.BaseRepoID))
- defer finished()
-
+func (m *mailNotifier) NotifyPullRequestReview(ctx context.Context, pr *issues_model.PullRequest, r *issues_model.Review, comment *issues_model.Comment, mentions []*user_model.User) {
var act activities_model.ActionType
if comment.Type == issues_model.CommentTypeClose {
act = activities_model.ActionCloseIssue
@@ -115,60 +108,54 @@ func (m *mailNotifier) NotifyPullRequestReview(pr *issues_model.PullRequest, r *
}
}
-func (m *mailNotifier) NotifyPullRequestCodeComment(pr *issues_model.PullRequest, comment *issues_model.Comment, mentions []*user_model.User) {
- ctx, _, finished := process.GetManager().AddContext(graceful.GetManager().HammerContext(), fmt.Sprintf("mailNotifier.NotifyPullRequestCodeComment Pull[%d] #%d in [%d]", pr.ID, pr.Index, pr.BaseRepoID))
- defer finished()
-
+func (m *mailNotifier) NotifyPullRequestCodeComment(ctx context.Context, pr *issues_model.PullRequest, comment *issues_model.Comment, mentions []*user_model.User) {
if err := mailer.MailMentionsComment(ctx, pr, comment, mentions); err != nil {
log.Error("MailMentionsComment: %v", err)
}
}
-func (m *mailNotifier) NotifyIssueChangeAssignee(doer *user_model.User, issue *issues_model.Issue, assignee *user_model.User, removed bool, comment *issues_model.Comment) {
+func (m *mailNotifier) NotifyIssueChangeAssignee(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, assignee *user_model.User, removed bool, comment *issues_model.Comment) {
// mail only sent to added assignees and not self-assignee
if !removed && doer.ID != assignee.ID && assignee.EmailNotifications() != user_model.EmailNotificationsDisabled {
ct := fmt.Sprintf("Assigned #%d.", issue.Index)
- if err := mailer.SendIssueAssignedMail(issue, doer, ct, comment, []*user_model.User{assignee}); err != nil {
+ if err := mailer.SendIssueAssignedMail(ctx, issue, doer, ct, comment, []*user_model.User{assignee}); err != nil {
log.Error("Error in SendIssueAssignedMail for issue[%d] to assignee[%d]: %v", issue.ID, assignee.ID, err)
}
}
}
-func (m *mailNotifier) NotifyPullReviewRequest(doer *user_model.User, issue *issues_model.Issue, reviewer *user_model.User, isRequest bool, comment *issues_model.Comment) {
+func (m *mailNotifier) NotifyPullReviewRequest(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, reviewer *user_model.User, isRequest bool, comment *issues_model.Comment) {
if isRequest && doer.ID != reviewer.ID && reviewer.EmailNotifications() != user_model.EmailNotificationsDisabled {
ct := fmt.Sprintf("Requested to review %s.", issue.HTMLURL())
- if err := mailer.SendIssueAssignedMail(issue, doer, ct, comment, []*user_model.User{reviewer}); err != nil {
+ if err := mailer.SendIssueAssignedMail(ctx, issue, doer, ct, comment, []*user_model.User{reviewer}); err != nil {
log.Error("Error in SendIssueAssignedMail for issue[%d] to reviewer[%d]: %v", issue.ID, reviewer.ID, err)
}
}
}
-func (m *mailNotifier) NotifyMergePullRequest(pr *issues_model.PullRequest, doer *user_model.User) {
- if err := pr.LoadIssue(); err != nil {
- log.Error("pr.LoadIssue: %v", err)
+func (m *mailNotifier) NotifyMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
+ if err := pr.LoadIssue(ctx); err != nil {
+ log.Error("LoadIssue: %v", err)
return
}
- if err := mailer.MailParticipants(pr.Issue, doer, activities_model.ActionMergePullRequest, nil); err != nil {
+ if err := mailer.MailParticipants(ctx, pr.Issue, doer, activities_model.ActionMergePullRequest, nil); err != nil {
log.Error("MailParticipants: %v", err)
}
}
-func (m *mailNotifier) NotifyAutoMergePullRequest(pr *issues_model.PullRequest, doer *user_model.User) {
- if err := pr.LoadIssue(); err != nil {
+func (m *mailNotifier) NotifyAutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
+ if err := pr.LoadIssue(ctx); err != nil {
log.Error("pr.LoadIssue: %v", err)
return
}
- if err := mailer.MailParticipants(pr.Issue, doer, activities_model.ActionAutoMergePullRequest, nil); err != nil {
+ if err := mailer.MailParticipants(ctx, pr.Issue, doer, activities_model.ActionAutoMergePullRequest, nil); err != nil {
log.Error("MailParticipants: %v", err)
}
}
-func (m *mailNotifier) NotifyPullRequestPushCommits(doer *user_model.User, pr *issues_model.PullRequest, comment *issues_model.Comment) {
- ctx, _, finished := process.GetManager().AddContext(graceful.GetManager().HammerContext(), fmt.Sprintf("mailNotifier.NotifyPullRequestPushCommits Pull[%d] #%d in [%d]", pr.ID, pr.Index, pr.BaseRepoID))
- defer finished()
-
+func (m *mailNotifier) NotifyPullRequestPushCommits(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, comment *issues_model.Comment) {
var err error
- if err = comment.LoadIssue(); err != nil {
+ if err = comment.LoadIssue(ctx); err != nil {
log.Error("comment.LoadIssue: %v", err)
return
}
@@ -176,35 +163,29 @@ func (m *mailNotifier) NotifyPullRequestPushCommits(doer *user_model.User, pr *i
log.Error("comment.Issue.LoadRepo: %v", err)
return
}
- if err = comment.Issue.LoadPullRequest(); err != nil {
+ if err = comment.Issue.LoadPullRequest(ctx); err != nil {
log.Error("comment.Issue.LoadPullRequest: %v", err)
return
}
- if err = comment.Issue.PullRequest.LoadBaseRepoCtx(ctx); err != nil {
+ if err = comment.Issue.PullRequest.LoadBaseRepo(ctx); err != nil {
log.Error("comment.Issue.PullRequest.LoadBaseRepo: %v", err)
return
}
if err := comment.LoadPushCommits(ctx); err != nil {
log.Error("comment.LoadPushCommits: %v", err)
}
- m.NotifyCreateIssueComment(doer, comment.Issue.Repo, comment.Issue, comment, nil)
+ m.NotifyCreateIssueComment(ctx, doer, comment.Issue.Repo, comment.Issue, comment, nil)
}
-func (m *mailNotifier) NotifyPullRevieweDismiss(doer *user_model.User, review *issues_model.Review, comment *issues_model.Comment) {
- ctx, _, finished := process.GetManager().AddContext(graceful.GetManager().HammerContext(), fmt.Sprintf("mailNotifier.NotifyPullRevieweDismiss Review[%d] in Issue[%d]", review.ID, review.IssueID))
- defer finished()
-
+func (m *mailNotifier) NotifyPullReviewDismiss(ctx context.Context, doer *user_model.User, review *issues_model.Review, comment *issues_model.Comment) {
if err := mailer.MailParticipantsComment(ctx, comment, activities_model.ActionPullReviewDismissed, review.Issue, nil); err != nil {
log.Error("MailParticipantsComment: %v", err)
}
}
-func (m *mailNotifier) NotifyNewRelease(rel *repo_model.Release) {
- ctx, _, finished := process.GetManager().AddContext(graceful.GetManager().HammerContext(), fmt.Sprintf("mailNotifier.NotifyNewRelease rel[%d]%s in [%d]", rel.ID, rel.Title, rel.RepoID))
- defer finished()
-
- if err := rel.LoadAttributes(); err != nil {
- log.Error("NotifyNewRelease: %v", err)
+func (m *mailNotifier) NotifyNewRelease(ctx context.Context, rel *repo_model.Release) {
+ if err := rel.LoadAttributes(ctx); err != nil {
+ log.Error("LoadAttributes: %v", err)
return
}
@@ -215,8 +196,8 @@ func (m *mailNotifier) NotifyNewRelease(rel *repo_model.Release) {
mailer.MailNewRelease(ctx, rel)
}
-func (m *mailNotifier) NotifyRepoPendingTransfer(doer, newOwner *user_model.User, repo *repo_model.Repository) {
- if err := mailer.SendRepoTransferNotifyMail(doer, newOwner, repo); err != nil {
- log.Error("NotifyRepoPendingTransfer: %v", err)
+func (m *mailNotifier) NotifyRepoPendingTransfer(ctx context.Context, doer, newOwner *user_model.User, repo *repo_model.Repository) {
+ if err := mailer.SendRepoTransferNotifyMail(ctx, doer, newOwner, repo); err != nil {
+ log.Error("SendRepoTransferNotifyMail: %v", err)
}
}
diff --git a/modules/notification/mirror/mirror.go b/modules/notification/mirror/mirror.go
index 646b09a4ab..159c44ee6c 100644
--- a/modules/notification/mirror/mirror.go
+++ b/modules/notification/mirror/mirror.go
@@ -5,6 +5,8 @@
package mirror
import (
+ "context"
+
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/log"
@@ -24,16 +26,16 @@ func NewNotifier() base.Notifier {
return &mirrorNotifier{}
}
-func (m *mirrorNotifier) NotifyPushCommits(_ *user_model.User, repo *repo_model.Repository, _ *repository.PushUpdateOptions, _ *repository.PushCommits) {
- syncPushMirrorWithSyncOnCommit(repo.ID)
+func (m *mirrorNotifier) NotifyPushCommits(ctx context.Context, _ *user_model.User, repo *repo_model.Repository, _ *repository.PushUpdateOptions, _ *repository.PushCommits) {
+ syncPushMirrorWithSyncOnCommit(ctx, repo.ID)
}
-func (m *mirrorNotifier) NotifySyncPushCommits(_ *user_model.User, repo *repo_model.Repository, _ *repository.PushUpdateOptions, _ *repository.PushCommits) {
- syncPushMirrorWithSyncOnCommit(repo.ID)
+func (m *mirrorNotifier) NotifySyncPushCommits(ctx context.Context, _ *user_model.User, repo *repo_model.Repository, _ *repository.PushUpdateOptions, _ *repository.PushCommits) {
+ syncPushMirrorWithSyncOnCommit(ctx, repo.ID)
}
-func syncPushMirrorWithSyncOnCommit(repoID int64) {
- pushMirrors, err := repo_model.GetPushMirrorsSyncedOnCommit(repoID)
+func syncPushMirrorWithSyncOnCommit(ctx context.Context, repoID int64) {
+ pushMirrors, err := repo_model.GetPushMirrorsSyncedOnCommit(ctx, repoID)
if err != nil {
log.Error("repo_model.GetPushMirrorsSyncedOnCommit failed: %v", err)
return
diff --git a/modules/notification/notification.go b/modules/notification/notification.go
index 7bdc0a04c4..a117a60815 100644
--- a/modules/notification/notification.go
+++ b/modules/notification/notification.go
@@ -5,6 +5,8 @@
package notification
import (
+ "context"
+
issues_model "code.gitea.io/gitea/models/issues"
packages_model "code.gitea.io/gitea/models/packages"
repo_model "code.gitea.io/gitea/models/repo"
@@ -41,313 +43,313 @@ func NewContext() {
}
// NotifyNewWikiPage notifies creating new wiki pages to notifiers
-func NotifyNewWikiPage(doer *user_model.User, repo *repo_model.Repository, page, comment string) {
+func NotifyNewWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) {
for _, notifier := range notifiers {
- notifier.NotifyNewWikiPage(doer, repo, page, comment)
+ notifier.NotifyNewWikiPage(ctx, doer, repo, page, comment)
}
}
// NotifyEditWikiPage notifies editing or renaming wiki pages to notifiers
-func NotifyEditWikiPage(doer *user_model.User, repo *repo_model.Repository, page, comment string) {
+func NotifyEditWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) {
for _, notifier := range notifiers {
- notifier.NotifyEditWikiPage(doer, repo, page, comment)
+ notifier.NotifyEditWikiPage(ctx, doer, repo, page, comment)
}
}
// NotifyDeleteWikiPage notifies deleting wiki pages to notifiers
-func NotifyDeleteWikiPage(doer *user_model.User, repo *repo_model.Repository, page string) {
+func NotifyDeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page string) {
for _, notifier := range notifiers {
- notifier.NotifyDeleteWikiPage(doer, repo, page)
+ notifier.NotifyDeleteWikiPage(ctx, doer, repo, page)
}
}
// NotifyCreateIssueComment notifies issue comment related message to notifiers
-func NotifyCreateIssueComment(doer *user_model.User, repo *repo_model.Repository,
+func NotifyCreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository,
issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User,
) {
for _, notifier := range notifiers {
- notifier.NotifyCreateIssueComment(doer, repo, issue, comment, mentions)
+ notifier.NotifyCreateIssueComment(ctx, doer, repo, issue, comment, mentions)
}
}
// NotifyNewIssue notifies new issue to notifiers
-func NotifyNewIssue(issue *issues_model.Issue, mentions []*user_model.User) {
+func NotifyNewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) {
for _, notifier := range notifiers {
- notifier.NotifyNewIssue(issue, mentions)
+ notifier.NotifyNewIssue(ctx, issue, mentions)
}
}
// NotifyIssueChangeStatus notifies close or reopen issue to notifiers
-func NotifyIssueChangeStatus(doer *user_model.User, issue *issues_model.Issue, actionComment *issues_model.Comment, closeOrReopen bool) {
+func NotifyIssueChangeStatus(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, actionComment *issues_model.Comment, closeOrReopen bool) {
for _, notifier := range notifiers {
- notifier.NotifyIssueChangeStatus(doer, issue, actionComment, closeOrReopen)
+ notifier.NotifyIssueChangeStatus(ctx, doer, issue, actionComment, closeOrReopen)
}
}
// NotifyDeleteIssue notify when some issue deleted
-func NotifyDeleteIssue(doer *user_model.User, issue *issues_model.Issue) {
+func NotifyDeleteIssue(ctx context.Context, doer *user_model.User, issue *issues_model.Issue) {
for _, notifier := range notifiers {
- notifier.NotifyDeleteIssue(doer, issue)
+ notifier.NotifyDeleteIssue(ctx, doer, issue)
}
}
// NotifyMergePullRequest notifies merge pull request to notifiers
-func NotifyMergePullRequest(pr *issues_model.PullRequest, doer *user_model.User) {
+func NotifyMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
for _, notifier := range notifiers {
- notifier.NotifyMergePullRequest(pr, doer)
+ notifier.NotifyMergePullRequest(ctx, doer, pr)
}
}
// NotifyAutoMergePullRequest notifies merge pull request to notifiers
-func NotifyAutoMergePullRequest(pr *issues_model.PullRequest, doer *user_model.User) {
+func NotifyAutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
for _, notifier := range notifiers {
- notifier.NotifyAutoMergePullRequest(pr, doer)
+ notifier.NotifyAutoMergePullRequest(ctx, doer, pr)
}
}
// NotifyNewPullRequest notifies new pull request to notifiers
-func NotifyNewPullRequest(pr *issues_model.PullRequest, mentions []*user_model.User) {
+func NotifyNewPullRequest(ctx context.Context, pr *issues_model.PullRequest, mentions []*user_model.User) {
for _, notifier := range notifiers {
- notifier.NotifyNewPullRequest(pr, mentions)
+ notifier.NotifyNewPullRequest(ctx, pr, mentions)
}
}
// NotifyPullRequestSynchronized notifies Synchronized pull request
-func NotifyPullRequestSynchronized(doer *user_model.User, pr *issues_model.PullRequest) {
+func NotifyPullRequestSynchronized(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
for _, notifier := range notifiers {
- notifier.NotifyPullRequestSynchronized(doer, pr)
+ notifier.NotifyPullRequestSynchronized(ctx, doer, pr)
}
}
// NotifyPullRequestReview notifies new pull request review
-func NotifyPullRequestReview(pr *issues_model.PullRequest, review *issues_model.Review, comment *issues_model.Comment, mentions []*user_model.User) {
+func NotifyPullRequestReview(ctx context.Context, pr *issues_model.PullRequest, review *issues_model.Review, comment *issues_model.Comment, mentions []*user_model.User) {
for _, notifier := range notifiers {
- notifier.NotifyPullRequestReview(pr, review, comment, mentions)
+ notifier.NotifyPullRequestReview(ctx, pr, review, comment, mentions)
}
}
// NotifyPullRequestCodeComment notifies new pull request code comment
-func NotifyPullRequestCodeComment(pr *issues_model.PullRequest, comment *issues_model.Comment, mentions []*user_model.User) {
+func NotifyPullRequestCodeComment(ctx context.Context, pr *issues_model.PullRequest, comment *issues_model.Comment, mentions []*user_model.User) {
for _, notifier := range notifiers {
- notifier.NotifyPullRequestCodeComment(pr, comment, mentions)
+ notifier.NotifyPullRequestCodeComment(ctx, pr, comment, mentions)
}
}
// NotifyPullRequestChangeTargetBranch notifies when a pull request's target branch was changed
-func NotifyPullRequestChangeTargetBranch(doer *user_model.User, pr *issues_model.PullRequest, oldBranch string) {
+func NotifyPullRequestChangeTargetBranch(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, oldBranch string) {
for _, notifier := range notifiers {
- notifier.NotifyPullRequestChangeTargetBranch(doer, pr, oldBranch)
+ notifier.NotifyPullRequestChangeTargetBranch(ctx, doer, pr, oldBranch)
}
}
// NotifyPullRequestPushCommits notifies when push commits to pull request's head branch
-func NotifyPullRequestPushCommits(doer *user_model.User, pr *issues_model.PullRequest, comment *issues_model.Comment) {
+func NotifyPullRequestPushCommits(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, comment *issues_model.Comment) {
for _, notifier := range notifiers {
- notifier.NotifyPullRequestPushCommits(doer, pr, comment)
+ notifier.NotifyPullRequestPushCommits(ctx, doer, pr, comment)
}
}
-// NotifyPullRevieweDismiss notifies when a review was dismissed by repo admin
-func NotifyPullRevieweDismiss(doer *user_model.User, review *issues_model.Review, comment *issues_model.Comment) {
+// NotifyPullReviewDismiss notifies when a review was dismissed by repo admin
+func NotifyPullReviewDismiss(ctx context.Context, doer *user_model.User, review *issues_model.Review, comment *issues_model.Comment) {
for _, notifier := range notifiers {
- notifier.NotifyPullRevieweDismiss(doer, review, comment)
+ notifier.NotifyPullReviewDismiss(ctx, doer, review, comment)
}
}
// NotifyUpdateComment notifies update comment to notifiers
-func NotifyUpdateComment(doer *user_model.User, c *issues_model.Comment, oldContent string) {
+func NotifyUpdateComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment, oldContent string) {
for _, notifier := range notifiers {
- notifier.NotifyUpdateComment(doer, c, oldContent)
+ notifier.NotifyUpdateComment(ctx, doer, c, oldContent)
}
}
// NotifyDeleteComment notifies delete comment to notifiers
-func NotifyDeleteComment(doer *user_model.User, c *issues_model.Comment) {
+func NotifyDeleteComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment) {
for _, notifier := range notifiers {
- notifier.NotifyDeleteComment(doer, c)
+ notifier.NotifyDeleteComment(ctx, doer, c)
}
}
// NotifyNewRelease notifies new release to notifiers
-func NotifyNewRelease(rel *repo_model.Release) {
+func NotifyNewRelease(ctx context.Context, rel *repo_model.Release) {
for _, notifier := range notifiers {
- notifier.NotifyNewRelease(rel)
+ notifier.NotifyNewRelease(ctx, rel)
}
}
// NotifyUpdateRelease notifies update release to notifiers
-func NotifyUpdateRelease(doer *user_model.User, rel *repo_model.Release) {
+func NotifyUpdateRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) {
for _, notifier := range notifiers {
- notifier.NotifyUpdateRelease(doer, rel)
+ notifier.NotifyUpdateRelease(ctx, doer, rel)
}
}
// NotifyDeleteRelease notifies delete release to notifiers
-func NotifyDeleteRelease(doer *user_model.User, rel *repo_model.Release) {
+func NotifyDeleteRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) {
for _, notifier := range notifiers {
- notifier.NotifyDeleteRelease(doer, rel)
+ notifier.NotifyDeleteRelease(ctx, doer, rel)
}
}
// NotifyIssueChangeMilestone notifies change milestone to notifiers
-func NotifyIssueChangeMilestone(doer *user_model.User, issue *issues_model.Issue, oldMilestoneID int64) {
+func NotifyIssueChangeMilestone(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldMilestoneID int64) {
for _, notifier := range notifiers {
- notifier.NotifyIssueChangeMilestone(doer, issue, oldMilestoneID)
+ notifier.NotifyIssueChangeMilestone(ctx, doer, issue, oldMilestoneID)
}
}
// NotifyIssueChangeContent notifies change content to notifiers
-func NotifyIssueChangeContent(doer *user_model.User, issue *issues_model.Issue, oldContent string) {
+func NotifyIssueChangeContent(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldContent string) {
for _, notifier := range notifiers {
- notifier.NotifyIssueChangeContent(doer, issue, oldContent)
+ notifier.NotifyIssueChangeContent(ctx, doer, issue, oldContent)
}
}
// NotifyIssueChangeAssignee notifies change content to notifiers
-func NotifyIssueChangeAssignee(doer *user_model.User, issue *issues_model.Issue, assignee *user_model.User, removed bool, comment *issues_model.Comment) {
+func NotifyIssueChangeAssignee(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, assignee *user_model.User, removed bool, comment *issues_model.Comment) {
for _, notifier := range notifiers {
- notifier.NotifyIssueChangeAssignee(doer, issue, assignee, removed, comment)
+ notifier.NotifyIssueChangeAssignee(ctx, doer, issue, assignee, removed, comment)
}
}
// NotifyPullReviewRequest notifies Request Review change
-func NotifyPullReviewRequest(doer *user_model.User, issue *issues_model.Issue, reviewer *user_model.User, isRequest bool, comment *issues_model.Comment) {
+func NotifyPullReviewRequest(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, reviewer *user_model.User, isRequest bool, comment *issues_model.Comment) {
for _, notifier := range notifiers {
- notifier.NotifyPullReviewRequest(doer, issue, reviewer, isRequest, comment)
+ notifier.NotifyPullReviewRequest(ctx, doer, issue, reviewer, isRequest, comment)
}
}
// NotifyIssueClearLabels notifies clear labels to notifiers
-func NotifyIssueClearLabels(doer *user_model.User, issue *issues_model.Issue) {
+func NotifyIssueClearLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue) {
for _, notifier := range notifiers {
- notifier.NotifyIssueClearLabels(doer, issue)
+ notifier.NotifyIssueClearLabels(ctx, doer, issue)
}
}
// NotifyIssueChangeTitle notifies change title to notifiers
-func NotifyIssueChangeTitle(doer *user_model.User, issue *issues_model.Issue, oldTitle string) {
+func NotifyIssueChangeTitle(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldTitle string) {
for _, notifier := range notifiers {
- notifier.NotifyIssueChangeTitle(doer, issue, oldTitle)
+ notifier.NotifyIssueChangeTitle(ctx, doer, issue, oldTitle)
}
}
// NotifyIssueChangeRef notifies change reference to notifiers
-func NotifyIssueChangeRef(doer *user_model.User, issue *issues_model.Issue, oldRef string) {
+func NotifyIssueChangeRef(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldRef string) {
for _, notifier := range notifiers {
- notifier.NotifyIssueChangeRef(doer, issue, oldRef)
+ notifier.NotifyIssueChangeRef(ctx, doer, issue, oldRef)
}
}
// NotifyIssueChangeLabels notifies change labels to notifiers
-func NotifyIssueChangeLabels(doer *user_model.User, issue *issues_model.Issue,
+func NotifyIssueChangeLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue,
addedLabels, removedLabels []*issues_model.Label,
) {
for _, notifier := range notifiers {
- notifier.NotifyIssueChangeLabels(doer, issue, addedLabels, removedLabels)
+ notifier.NotifyIssueChangeLabels(ctx, doer, issue, addedLabels, removedLabels)
}
}
// NotifyCreateRepository notifies create repository to notifiers
-func NotifyCreateRepository(doer, u *user_model.User, repo *repo_model.Repository) {
+func NotifyCreateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) {
for _, notifier := range notifiers {
- notifier.NotifyCreateRepository(doer, u, repo)
+ notifier.NotifyCreateRepository(ctx, doer, u, repo)
}
}
// NotifyMigrateRepository notifies create repository to notifiers
-func NotifyMigrateRepository(doer, u *user_model.User, repo *repo_model.Repository) {
+func NotifyMigrateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) {
for _, notifier := range notifiers {
- notifier.NotifyMigrateRepository(doer, u, repo)
+ notifier.NotifyMigrateRepository(ctx, doer, u, repo)
}
}
// NotifyTransferRepository notifies create repository to notifiers
-func NotifyTransferRepository(doer *user_model.User, repo *repo_model.Repository, newOwnerName string) {
+func NotifyTransferRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, newOwnerName string) {
for _, notifier := range notifiers {
- notifier.NotifyTransferRepository(doer, repo, newOwnerName)
+ notifier.NotifyTransferRepository(ctx, doer, repo, newOwnerName)
}
}
// NotifyDeleteRepository notifies delete repository to notifiers
-func NotifyDeleteRepository(doer *user_model.User, repo *repo_model.Repository) {
+func NotifyDeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository) {
for _, notifier := range notifiers {
- notifier.NotifyDeleteRepository(doer, repo)
+ notifier.NotifyDeleteRepository(ctx, doer, repo)
}
}
// NotifyForkRepository notifies fork repository to notifiers
-func NotifyForkRepository(doer *user_model.User, oldRepo, repo *repo_model.Repository) {
+func NotifyForkRepository(ctx context.Context, doer *user_model.User, oldRepo, repo *repo_model.Repository) {
for _, notifier := range notifiers {
- notifier.NotifyForkRepository(doer, oldRepo, repo)
+ notifier.NotifyForkRepository(ctx, doer, oldRepo, repo)
}
}
// NotifyRenameRepository notifies repository renamed
-func NotifyRenameRepository(doer *user_model.User, repo *repo_model.Repository, oldName string) {
+func NotifyRenameRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldName string) {
for _, notifier := range notifiers {
- notifier.NotifyRenameRepository(doer, repo, oldName)
+ notifier.NotifyRenameRepository(ctx, doer, repo, oldName)
}
}
// NotifyPushCommits notifies commits pushed to notifiers
-func NotifyPushCommits(pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
+func NotifyPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
for _, notifier := range notifiers {
- notifier.NotifyPushCommits(pusher, repo, opts, commits)
+ notifier.NotifyPushCommits(ctx, pusher, repo, opts, commits)
}
}
// NotifyCreateRef notifies branch or tag creation to notifiers
-func NotifyCreateRef(pusher *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) {
+func NotifyCreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) {
for _, notifier := range notifiers {
- notifier.NotifyCreateRef(pusher, repo, refType, refFullName, refID)
+ notifier.NotifyCreateRef(ctx, pusher, repo, refType, refFullName, refID)
}
}
// NotifyDeleteRef notifies branch or tag deletion to notifiers
-func NotifyDeleteRef(pusher *user_model.User, repo *repo_model.Repository, refType, refFullName string) {
+func NotifyDeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName string) {
for _, notifier := range notifiers {
- notifier.NotifyDeleteRef(pusher, repo, refType, refFullName)
+ notifier.NotifyDeleteRef(ctx, pusher, repo, refType, refFullName)
}
}
// NotifySyncPushCommits notifies commits pushed to notifiers
-func NotifySyncPushCommits(pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
+func NotifySyncPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
for _, notifier := range notifiers {
- notifier.NotifySyncPushCommits(pusher, repo, opts, commits)
+ notifier.NotifySyncPushCommits(ctx, pusher, repo, opts, commits)
}
}
// NotifySyncCreateRef notifies branch or tag creation to notifiers
-func NotifySyncCreateRef(pusher *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) {
+func NotifySyncCreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) {
for _, notifier := range notifiers {
- notifier.NotifySyncCreateRef(pusher, repo, refType, refFullName, refID)
+ notifier.NotifySyncCreateRef(ctx, pusher, repo, refType, refFullName, refID)
}
}
// NotifySyncDeleteRef notifies branch or tag deletion to notifiers
-func NotifySyncDeleteRef(pusher *user_model.User, repo *repo_model.Repository, refType, refFullName string) {
+func NotifySyncDeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName string) {
for _, notifier := range notifiers {
- notifier.NotifySyncDeleteRef(pusher, repo, refType, refFullName)
+ notifier.NotifySyncDeleteRef(ctx, pusher, repo, refType, refFullName)
}
}
// NotifyRepoPendingTransfer notifies creation of pending transfer to notifiers
-func NotifyRepoPendingTransfer(doer, newOwner *user_model.User, repo *repo_model.Repository) {
+func NotifyRepoPendingTransfer(ctx context.Context, doer, newOwner *user_model.User, repo *repo_model.Repository) {
for _, notifier := range notifiers {
- notifier.NotifyRepoPendingTransfer(doer, newOwner, repo)
+ notifier.NotifyRepoPendingTransfer(ctx, doer, newOwner, repo)
}
}
// NotifyPackageCreate notifies creation of a package to notifiers
-func NotifyPackageCreate(doer *user_model.User, pd *packages_model.PackageDescriptor) {
+func NotifyPackageCreate(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) {
for _, notifier := range notifiers {
- notifier.NotifyPackageCreate(doer, pd)
+ notifier.NotifyPackageCreate(ctx, doer, pd)
}
}
// NotifyPackageDelete notifies deletion of a package to notifiers
-func NotifyPackageDelete(doer *user_model.User, pd *packages_model.PackageDescriptor) {
+func NotifyPackageDelete(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) {
for _, notifier := range notifiers {
- notifier.NotifyPackageDelete(doer, pd)
+ notifier.NotifyPackageDelete(ctx, doer, pd)
}
}
diff --git a/modules/notification/ui/ui.go b/modules/notification/ui/ui.go
index 0e2b3e67c7..a38289c976 100644
--- a/modules/notification/ui/ui.go
+++ b/modules/notification/ui/ui.go
@@ -5,6 +5,8 @@
package ui
import (
+ "context"
+
activities_model "code.gitea.io/gitea/models/activities"
"code.gitea.io/gitea/models/db"
issues_model "code.gitea.io/gitea/models/issues"
@@ -54,7 +56,7 @@ func (ns *notificationService) Run() {
graceful.GetManager().RunWithShutdownFns(ns.issueQueue.Run)
}
-func (ns *notificationService) NotifyCreateIssueComment(doer *user_model.User, repo *repo_model.Repository,
+func (ns *notificationService) NotifyCreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository,
issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User,
) {
opts := issueNotificationOpts{
@@ -78,7 +80,7 @@ func (ns *notificationService) NotifyCreateIssueComment(doer *user_model.User, r
}
}
-func (ns *notificationService) NotifyNewIssue(issue *issues_model.Issue, mentions []*user_model.User) {
+func (ns *notificationService) NotifyNewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) {
_ = ns.issueQueue.Push(issueNotificationOpts{
IssueID: issue.ID,
NotificationAuthorID: issue.Poster.ID,
@@ -92,15 +94,15 @@ func (ns *notificationService) NotifyNewIssue(issue *issues_model.Issue, mention
}
}
-func (ns *notificationService) NotifyIssueChangeStatus(doer *user_model.User, issue *issues_model.Issue, actionComment *issues_model.Comment, isClosed bool) {
+func (ns *notificationService) NotifyIssueChangeStatus(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, actionComment *issues_model.Comment, isClosed bool) {
_ = ns.issueQueue.Push(issueNotificationOpts{
IssueID: issue.ID,
NotificationAuthorID: doer.ID,
})
}
-func (ns *notificationService) NotifyIssueChangeTitle(doer *user_model.User, issue *issues_model.Issue, oldTitle string) {
- if err := issue.LoadPullRequest(); err != nil {
+func (ns *notificationService) NotifyIssueChangeTitle(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldTitle string) {
+ if err := issue.LoadPullRequest(ctx); err != nil {
log.Error("issue.LoadPullRequest: %v", err)
return
}
@@ -112,24 +114,24 @@ func (ns *notificationService) NotifyIssueChangeTitle(doer *user_model.User, iss
}
}
-func (ns *notificationService) NotifyMergePullRequest(pr *issues_model.PullRequest, doer *user_model.User) {
+func (ns *notificationService) NotifyMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
_ = ns.issueQueue.Push(issueNotificationOpts{
IssueID: pr.Issue.ID,
NotificationAuthorID: doer.ID,
})
}
-func (ns *notificationService) NotifyAutoMergePullRequest(pr *issues_model.PullRequest, doer *user_model.User) {
- ns.NotifyMergePullRequest(pr, doer)
+func (ns *notificationService) NotifyAutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
+ ns.NotifyMergePullRequest(ctx, doer, pr)
}
-func (ns *notificationService) NotifyNewPullRequest(pr *issues_model.PullRequest, mentions []*user_model.User) {
- if err := pr.LoadIssue(); err != nil {
+func (ns *notificationService) NotifyNewPullRequest(ctx context.Context, pr *issues_model.PullRequest, mentions []*user_model.User) {
+ if err := pr.LoadIssue(ctx); err != nil {
log.Error("Unable to load issue: %d for pr: %d: Error: %v", pr.IssueID, pr.ID, err)
return
}
toNotify := make(container.Set[int64], 32)
- repoWatchers, err := repo_model.GetRepoWatchersIDs(db.DefaultContext, pr.Issue.RepoID)
+ repoWatchers, err := repo_model.GetRepoWatchersIDs(ctx, pr.Issue.RepoID)
if err != nil {
log.Error("GetRepoWatchersIDs: %v", err)
return
@@ -137,7 +139,7 @@ func (ns *notificationService) NotifyNewPullRequest(pr *issues_model.PullRequest
for _, id := range repoWatchers {
toNotify.Add(id)
}
- issueParticipants, err := issues_model.GetParticipantsIDsByIssueID(pr.IssueID)
+ issueParticipants, err := issues_model.GetParticipantsIDsByIssueID(ctx, pr.IssueID)
if err != nil {
log.Error("GetParticipantsIDsByIssueID: %v", err)
return
@@ -158,7 +160,7 @@ func (ns *notificationService) NotifyNewPullRequest(pr *issues_model.PullRequest
}
}
-func (ns *notificationService) NotifyPullRequestReview(pr *issues_model.PullRequest, r *issues_model.Review, c *issues_model.Comment, mentions []*user_model.User) {
+func (ns *notificationService) NotifyPullRequestReview(ctx context.Context, pr *issues_model.PullRequest, r *issues_model.Review, c *issues_model.Comment, mentions []*user_model.User) {
opts := issueNotificationOpts{
IssueID: pr.Issue.ID,
NotificationAuthorID: r.Reviewer.ID,
@@ -180,7 +182,7 @@ func (ns *notificationService) NotifyPullRequestReview(pr *issues_model.PullRequ
}
}
-func (ns *notificationService) NotifyPullRequestCodeComment(pr *issues_model.PullRequest, c *issues_model.Comment, mentions []*user_model.User) {
+func (ns *notificationService) NotifyPullRequestCodeComment(ctx context.Context, pr *issues_model.PullRequest, c *issues_model.Comment, mentions []*user_model.User) {
for _, mention := range mentions {
_ = ns.issueQueue.Push(issueNotificationOpts{
IssueID: pr.Issue.ID,
@@ -191,7 +193,7 @@ func (ns *notificationService) NotifyPullRequestCodeComment(pr *issues_model.Pul
}
}
-func (ns *notificationService) NotifyPullRequestPushCommits(doer *user_model.User, pr *issues_model.PullRequest, comment *issues_model.Comment) {
+func (ns *notificationService) NotifyPullRequestPushCommits(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, comment *issues_model.Comment) {
opts := issueNotificationOpts{
IssueID: pr.IssueID,
NotificationAuthorID: doer.ID,
@@ -200,7 +202,7 @@ func (ns *notificationService) NotifyPullRequestPushCommits(doer *user_model.Use
_ = ns.issueQueue.Push(opts)
}
-func (ns *notificationService) NotifyPullRevieweDismiss(doer *user_model.User, review *issues_model.Review, comment *issues_model.Comment) {
+func (ns *notificationService) NotifyPullReviewDismiss(ctx context.Context, doer *user_model.User, review *issues_model.Review, comment *issues_model.Comment) {
opts := issueNotificationOpts{
IssueID: review.IssueID,
NotificationAuthorID: doer.ID,
@@ -209,7 +211,7 @@ func (ns *notificationService) NotifyPullRevieweDismiss(doer *user_model.User, r
_ = ns.issueQueue.Push(opts)
}
-func (ns *notificationService) NotifyIssueChangeAssignee(doer *user_model.User, issue *issues_model.Issue, assignee *user_model.User, removed bool, comment *issues_model.Comment) {
+func (ns *notificationService) NotifyIssueChangeAssignee(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, assignee *user_model.User, removed bool, comment *issues_model.Comment) {
if !removed && doer.ID != assignee.ID {
opts := issueNotificationOpts{
IssueID: issue.ID,
@@ -225,7 +227,7 @@ func (ns *notificationService) NotifyIssueChangeAssignee(doer *user_model.User,
}
}
-func (ns *notificationService) NotifyPullReviewRequest(doer *user_model.User, issue *issues_model.Issue, reviewer *user_model.User, isRequest bool, comment *issues_model.Comment) {
+func (ns *notificationService) NotifyPullReviewRequest(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, reviewer *user_model.User, isRequest bool, comment *issues_model.Comment) {
if isRequest {
opts := issueNotificationOpts{
IssueID: issue.ID,
@@ -241,8 +243,11 @@ func (ns *notificationService) NotifyPullReviewRequest(doer *user_model.User, is
}
}
-func (ns *notificationService) NotifyRepoPendingTransfer(doer, newOwner *user_model.User, repo *repo_model.Repository) {
- if err := activities_model.CreateRepoTransferNotification(doer, newOwner, repo); err != nil {
- log.Error("NotifyRepoPendingTransfer: %v", err)
+func (ns *notificationService) NotifyRepoPendingTransfer(ctx context.Context, doer, newOwner *user_model.User, repo *repo_model.Repository) {
+ err := db.AutoTx(ctx, func(ctx context.Context) error {
+ return activities_model.CreateRepoTransferNotification(ctx, doer, newOwner, repo)
+ })
+ if err != nil {
+ log.Error("CreateRepoTransferNotification: %v", err)
}
}
diff --git a/modules/notification/webhook/webhook.go b/modules/notification/webhook/webhook.go
index c591e1e34d..37ce7661f2 100644
--- a/modules/notification/webhook/webhook.go
+++ b/modules/notification/webhook/webhook.go
@@ -5,9 +5,8 @@
package webhook
import (
- "fmt"
+ "context"
- "code.gitea.io/gitea/models/db"
issues_model "code.gitea.io/gitea/models/issues"
packages_model "code.gitea.io/gitea/models/packages"
"code.gitea.io/gitea/models/perm"
@@ -18,10 +17,8 @@ import (
"code.gitea.io/gitea/models/webhook"
"code.gitea.io/gitea/modules/convert"
"code.gitea.io/gitea/modules/git"
- "code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification/base"
- "code.gitea.io/gitea/modules/process"
"code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
@@ -39,12 +36,9 @@ func NewNotifier() base.Notifier {
return &webhookNotifier{}
}
-func (m *webhookNotifier) NotifyIssueClearLabels(doer *user_model.User, issue *issues_model.Issue) {
- ctx, _, finished := process.GetManager().AddContext(graceful.GetManager().HammerContext(), fmt.Sprintf("webhook.NotifyIssueClearLabels User: %s[%d] Issue[%d] #%d in [%d]", doer.Name, doer.ID, issue.ID, issue.Index, issue.RepoID))
- defer finished()
-
- if err := issue.LoadPoster(); err != nil {
- log.Error("loadPoster: %v", err)
+func (m *webhookNotifier) NotifyIssueClearLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue) {
+ if err := issue.LoadPoster(ctx); err != nil {
+ log.Error("LoadPoster: %v", err)
return
}
@@ -53,10 +47,10 @@ func (m *webhookNotifier) NotifyIssueClearLabels(doer *user_model.User, issue *i
return
}
- mode, _ := access_model.AccessLevel(issue.Poster, issue.Repo)
+ mode, _ := access_model.AccessLevel(ctx, issue.Poster, issue.Repo)
var err error
if issue.IsPull {
- if err = issue.LoadPullRequest(); err != nil {
+ if err = issue.LoadPullRequest(ctx); err != nil {
log.Error("LoadPullRequest: %v", err)
return
}
@@ -72,7 +66,7 @@ func (m *webhookNotifier) NotifyIssueClearLabels(doer *user_model.User, issue *i
err = webhook_services.PrepareWebhooks(ctx, webhook_services.EventSource{Repository: issue.Repo}, webhook.HookEventIssueLabel, &api.IssuePayload{
Action: api.HookIssueLabelCleared,
Index: issue.Index,
- Issue: convert.ToAPIIssue(issue),
+ Issue: convert.ToAPIIssue(ctx, issue),
Repository: convert.ToRepo(issue.Repo, mode),
Sender: convert.ToUser(doer, nil),
})
@@ -82,12 +76,12 @@ func (m *webhookNotifier) NotifyIssueClearLabels(doer *user_model.User, issue *i
}
}
-func (m *webhookNotifier) NotifyForkRepository(doer *user_model.User, oldRepo, repo *repo_model.Repository) {
- oldMode, _ := access_model.AccessLevel(doer, oldRepo)
- mode, _ := access_model.AccessLevel(doer, repo)
+func (m *webhookNotifier) NotifyForkRepository(ctx context.Context, doer *user_model.User, oldRepo, repo *repo_model.Repository) {
+ oldMode, _ := access_model.AccessLevel(ctx, doer, oldRepo)
+ mode, _ := access_model.AccessLevel(ctx, doer, repo)
// forked webhook
- if err := webhook_services.PrepareWebhooks(db.DefaultContext, webhook_services.EventSource{Repository: oldRepo}, webhook.HookEventFork, &api.ForkPayload{
+ if err := webhook_services.PrepareWebhooks(ctx, webhook_services.EventSource{Repository: oldRepo}, webhook.HookEventFork, &api.ForkPayload{
Forkee: convert.ToRepo(oldRepo, oldMode),
Repo: convert.ToRepo(repo, mode),
Sender: convert.ToUser(doer, nil),
@@ -95,11 +89,11 @@ func (m *webhookNotifier) NotifyForkRepository(doer *user_model.User, oldRepo, r
log.Error("PrepareWebhooks [repo_id: %d]: %v", oldRepo.ID, err)
}
- u := repo.MustOwner()
+ u := repo.MustOwner(ctx)
// Add to hook queue for created repo after session commit.
if u.IsOrganization() {
- if err := webhook_services.PrepareWebhooks(db.DefaultContext, webhook_services.EventSource{Repository: repo}, webhook.HookEventRepository, &api.RepositoryPayload{
+ if err := webhook_services.PrepareWebhooks(ctx, webhook_services.EventSource{Repository: repo}, webhook.HookEventRepository, &api.RepositoryPayload{
Action: api.HookRepoCreated,
Repository: convert.ToRepo(repo, perm.AccessModeOwner),
Organization: convert.ToUser(u, nil),
@@ -110,9 +104,9 @@ func (m *webhookNotifier) NotifyForkRepository(doer *user_model.User, oldRepo, r
}
}
-func (m *webhookNotifier) NotifyCreateRepository(doer, u *user_model.User, repo *repo_model.Repository) {
+func (m *webhookNotifier) NotifyCreateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) {
// Add to hook queue for created repo after session commit.
- if err := webhook_services.PrepareWebhooks(db.DefaultContext, webhook_services.EventSource{Repository: repo}, webhook.HookEventRepository, &api.RepositoryPayload{
+ if err := webhook_services.PrepareWebhooks(ctx, webhook_services.EventSource{Repository: repo}, webhook.HookEventRepository, &api.RepositoryPayload{
Action: api.HookRepoCreated,
Repository: convert.ToRepo(repo, perm.AccessModeOwner),
Organization: convert.ToUser(u, nil),
@@ -122,22 +116,20 @@ func (m *webhookNotifier) NotifyCreateRepository(doer, u *user_model.User, repo
}
}
-func (m *webhookNotifier) NotifyDeleteRepository(doer *user_model.User, repo *repo_model.Repository) {
- u := repo.MustOwner()
-
- if err := webhook_services.PrepareWebhooks(db.DefaultContext, webhook_services.EventSource{Repository: repo}, webhook.HookEventRepository, &api.RepositoryPayload{
+func (m *webhookNotifier) NotifyDeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository) {
+ if err := webhook_services.PrepareWebhooks(ctx, webhook_services.EventSource{Repository: repo}, webhook.HookEventRepository, &api.RepositoryPayload{
Action: api.HookRepoDeleted,
Repository: convert.ToRepo(repo, perm.AccessModeOwner),
- Organization: convert.ToUser(u, nil),
+ Organization: convert.ToUser(repo.MustOwner(ctx), nil),
Sender: convert.ToUser(doer, nil),
}); err != nil {
log.Error("PrepareWebhooks [repo_id: %d]: %v", repo.ID, err)
}
}
-func (m *webhookNotifier) NotifyMigrateRepository(doer, u *user_model.User, repo *repo_model.Repository) {
+func (m *webhookNotifier) NotifyMigrateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) {
// Add to hook queue for created repo after session commit.
- if err := webhook_services.PrepareWebhooks(db.DefaultContext, webhook_services.EventSource{Repository: repo}, webhook.HookEventRepository, &api.RepositoryPayload{
+ if err := webhook_services.PrepareWebhooks(ctx, webhook_services.EventSource{Repository: repo}, webhook.HookEventRepository, &api.RepositoryPayload{
Action: api.HookRepoCreated,
Repository: convert.ToRepo(repo, perm.AccessModeOwner),
Organization: convert.ToUser(u, nil),
@@ -147,14 +139,11 @@ func (m *webhookNotifier) NotifyMigrateRepository(doer, u *user_model.User, repo
}
}
-func (m *webhookNotifier) NotifyIssueChangeAssignee(doer *user_model.User, issue *issues_model.Issue, assignee *user_model.User, removed bool, comment *issues_model.Comment) {
- ctx, _, finished := process.GetManager().AddContext(graceful.GetManager().HammerContext(), fmt.Sprintf("webhook.NotifyIssueChangeAssignee User: %s[%d] Issue[%d] #%d in [%d] Assignee %s[%d] removed: %t", doer.Name, doer.ID, issue.ID, issue.Index, issue.RepoID, assignee.Name, assignee.ID, removed))
- defer finished()
-
+func (m *webhookNotifier) NotifyIssueChangeAssignee(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, assignee *user_model.User, removed bool, comment *issues_model.Comment) {
if issue.IsPull {
- mode, _ := access_model.AccessLevelUnit(doer, issue.Repo, unit.TypePullRequests)
+ mode, _ := access_model.AccessLevelUnit(ctx, doer, issue.Repo, unit.TypePullRequests)
- if err := issue.LoadPullRequest(); err != nil {
+ if err := issue.LoadPullRequest(ctx); err != nil {
log.Error("LoadPullRequest failed: %v", err)
return
}
@@ -176,10 +165,10 @@ func (m *webhookNotifier) NotifyIssueChangeAssignee(doer *user_model.User, issue
return
}
} else {
- mode, _ := access_model.AccessLevelUnit(doer, issue.Repo, unit.TypeIssues)
+ mode, _ := access_model.AccessLevelUnit(ctx, doer, issue.Repo, unit.TypeIssues)
apiIssue := &api.IssuePayload{
Index: issue.Index,
- Issue: convert.ToAPIIssue(issue),
+ Issue: convert.ToAPIIssue(ctx, issue),
Repository: convert.ToRepo(issue.Repo, mode),
Sender: convert.ToUser(doer, nil),
}
@@ -196,14 +185,11 @@ func (m *webhookNotifier) NotifyIssueChangeAssignee(doer *user_model.User, issue
}
}
-func (m *webhookNotifier) NotifyIssueChangeTitle(doer *user_model.User, issue *issues_model.Issue, oldTitle string) {
- ctx, _, finished := process.GetManager().AddContext(graceful.GetManager().HammerContext(), fmt.Sprintf("webhook.NotifyIssueChangeTitle User: %s[%d] Issue[%d] #%d in [%d]", doer.Name, doer.ID, issue.ID, issue.Index, issue.RepoID))
- defer finished()
-
- mode, _ := access_model.AccessLevel(issue.Poster, issue.Repo)
+func (m *webhookNotifier) NotifyIssueChangeTitle(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldTitle string) {
+ mode, _ := access_model.AccessLevel(ctx, issue.Poster, issue.Repo)
var err error
if issue.IsPull {
- if err = issue.LoadPullRequest(); err != nil {
+ if err = issue.LoadPullRequest(ctx); err != nil {
log.Error("LoadPullRequest failed: %v", err)
return
}
@@ -229,7 +215,7 @@ func (m *webhookNotifier) NotifyIssueChangeTitle(doer *user_model.User, issue *i
From: oldTitle,
},
},
- Issue: convert.ToAPIIssue(issue),
+ Issue: convert.ToAPIIssue(ctx, issue),
Repository: convert.ToRepo(issue.Repo, mode),
Sender: convert.ToUser(doer, nil),
})
@@ -240,14 +226,11 @@ func (m *webhookNotifier) NotifyIssueChangeTitle(doer *user_model.User, issue *i
}
}
-func (m *webhookNotifier) NotifyIssueChangeStatus(doer *user_model.User, issue *issues_model.Issue, actionComment *issues_model.Comment, isClosed bool) {
- ctx, _, finished := process.GetManager().AddContext(graceful.GetManager().HammerContext(), fmt.Sprintf("webhook.NotifyIssueChangeStatus User: %s[%d] Issue[%d] #%d in [%d]", doer.Name, doer.ID, issue.ID, issue.Index, issue.RepoID))
- defer finished()
-
- mode, _ := access_model.AccessLevel(issue.Poster, issue.Repo)
+func (m *webhookNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, actionComment *issues_model.Comment, isClosed bool) {
+ mode, _ := access_model.AccessLevel(ctx, issue.Poster, issue.Repo)
var err error
if issue.IsPull {
- if err = issue.LoadPullRequest(); err != nil {
+ if err = issue.LoadPullRequest(ctx); err != nil {
log.Error("LoadPullRequest: %v", err)
return
}
@@ -267,7 +250,7 @@ func (m *webhookNotifier) NotifyIssueChangeStatus(doer *user_model.User, issue *
} else {
apiIssue := &api.IssuePayload{
Index: issue.Index,
- Issue: convert.ToAPIIssue(issue),
+ Issue: convert.ToAPIIssue(ctx, issue),
Repository: convert.ToRepo(issue.Repo, mode),
Sender: convert.ToUser(doer, nil),
}
@@ -283,21 +266,21 @@ func (m *webhookNotifier) NotifyIssueChangeStatus(doer *user_model.User, issue *
}
}
-func (m *webhookNotifier) NotifyNewIssue(issue *issues_model.Issue, mentions []*user_model.User) {
- if err := issue.LoadRepo(db.DefaultContext); err != nil {
+func (m *webhookNotifier) NotifyNewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) {
+ if err := issue.LoadRepo(ctx); err != nil {
log.Error("issue.LoadRepo: %v", err)
return
}
- if err := issue.LoadPoster(); err != nil {
+ if err := issue.LoadPoster(ctx); err != nil {
log.Error("issue.LoadPoster: %v", err)
return
}
- mode, _ := access_model.AccessLevel(issue.Poster, issue.Repo)
- if err := webhook_services.PrepareWebhooks(db.DefaultContext, webhook_services.EventSource{Repository: issue.Repo}, webhook.HookEventIssues, &api.IssuePayload{
+ mode, _ := access_model.AccessLevel(ctx, issue.Poster, issue.Repo)
+ if err := webhook_services.PrepareWebhooks(ctx, webhook_services.EventSource{Repository: issue.Repo}, webhook.HookEventIssues, &api.IssuePayload{
Action: api.HookIssueOpened,
Index: issue.Index,
- Issue: convert.ToAPIIssue(issue),
+ Issue: convert.ToAPIIssue(ctx, issue),
Repository: convert.ToRepo(issue.Repo, mode),
Sender: convert.ToUser(issue.Poster, nil),
}); err != nil {
@@ -305,11 +288,8 @@ func (m *webhookNotifier) NotifyNewIssue(issue *issues_model.Issue, mentions []*
}
}
-func (m *webhookNotifier) NotifyNewPullRequest(pull *issues_model.PullRequest, mentions []*user_model.User) {
- ctx, _, finished := process.GetManager().AddContext(graceful.GetManager().HammerContext(), fmt.Sprintf("webhook.NotifyNewPullRequest Pull[%d] #%d in [%d]", pull.ID, pull.Index, pull.BaseRepoID))
- defer finished()
-
- if err := pull.LoadIssue(); err != nil {
+func (m *webhookNotifier) NotifyNewPullRequest(ctx context.Context, pull *issues_model.PullRequest, mentions []*user_model.User) {
+ if err := pull.LoadIssue(ctx); err != nil {
log.Error("pull.LoadIssue: %v", err)
return
}
@@ -317,12 +297,12 @@ func (m *webhookNotifier) NotifyNewPullRequest(pull *issues_model.PullRequest, m
log.Error("pull.Issue.LoadRepo: %v", err)
return
}
- if err := pull.Issue.LoadPoster(); err != nil {
+ if err := pull.Issue.LoadPoster(ctx); err != nil {
log.Error("pull.Issue.LoadPoster: %v", err)
return
}
- mode, _ := access_model.AccessLevel(pull.Issue.Poster, pull.Issue.Repo)
+ mode, _ := access_model.AccessLevel(ctx, pull.Issue.Poster, pull.Issue.Repo)
if err := webhook_services.PrepareWebhooks(ctx, webhook_services.EventSource{Repository: pull.Issue.Repo}, webhook.HookEventPullRequest, &api.PullRequestPayload{
Action: api.HookIssueOpened,
Index: pull.Issue.Index,
@@ -334,11 +314,8 @@ func (m *webhookNotifier) NotifyNewPullRequest(pull *issues_model.PullRequest, m
}
}
-func (m *webhookNotifier) NotifyIssueChangeContent(doer *user_model.User, issue *issues_model.Issue, oldContent string) {
- ctx, _, finished := process.GetManager().AddContext(graceful.GetManager().HammerContext(), fmt.Sprintf("webhook.NotifyIssueChangeContent User: %s[%d] Issue[%d] #%d in [%d]", doer.Name, doer.ID, issue.ID, issue.Index, issue.RepoID))
- defer finished()
-
- mode, _ := access_model.AccessLevel(issue.Poster, issue.Repo)
+func (m *webhookNotifier) NotifyIssueChangeContent(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldContent string) {
+ mode, _ := access_model.AccessLevel(ctx, issue.Poster, issue.Repo)
var err error
if issue.IsPull {
issue.PullRequest.Issue = issue
@@ -363,7 +340,7 @@ func (m *webhookNotifier) NotifyIssueChangeContent(doer *user_model.User, issue
From: oldContent,
},
},
- Issue: convert.ToAPIIssue(issue),
+ Issue: convert.ToAPIIssue(ctx, issue),
Repository: convert.ToRepo(issue.Repo, mode),
Sender: convert.ToUser(doer, nil),
})
@@ -373,17 +350,17 @@ func (m *webhookNotifier) NotifyIssueChangeContent(doer *user_model.User, issue
}
}
-func (m *webhookNotifier) NotifyUpdateComment(doer *user_model.User, c *issues_model.Comment, oldContent string) {
- if err := c.LoadPoster(); err != nil {
+func (m *webhookNotifier) NotifyUpdateComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment, oldContent string) {
+ if err := c.LoadPoster(ctx); err != nil {
log.Error("LoadPoster: %v", err)
return
}
- if err := c.LoadIssue(); err != nil {
+ if err := c.LoadIssue(ctx); err != nil {
log.Error("LoadIssue: %v", err)
return
}
- if err := c.Issue.LoadAttributes(db.DefaultContext); err != nil {
+ if err := c.Issue.LoadAttributes(ctx); err != nil {
log.Error("LoadAttributes: %v", err)
return
}
@@ -395,10 +372,10 @@ func (m *webhookNotifier) NotifyUpdateComment(doer *user_model.User, c *issues_m
eventType = webhook.HookEventIssueComment
}
- mode, _ := access_model.AccessLevel(doer, c.Issue.Repo)
- if err := webhook_services.PrepareWebhooks(db.DefaultContext, webhook_services.EventSource{Repository: c.Issue.Repo}, eventType, &api.IssueCommentPayload{
+ mode, _ := access_model.AccessLevel(ctx, doer, c.Issue.Repo)
+ if err := webhook_services.PrepareWebhooks(ctx, webhook_services.EventSource{Repository: c.Issue.Repo}, eventType, &api.IssueCommentPayload{
Action: api.HookIssueCommentEdited,
- Issue: convert.ToAPIIssue(c.Issue),
+ Issue: convert.ToAPIIssue(ctx, c.Issue),
Comment: convert.ToComment(c),
Changes: &api.ChangesPayload{
Body: &api.ChangesFromPayload{
@@ -413,7 +390,7 @@ func (m *webhookNotifier) NotifyUpdateComment(doer *user_model.User, c *issues_m
}
}
-func (m *webhookNotifier) NotifyCreateIssueComment(doer *user_model.User, repo *repo_model.Repository,
+func (m *webhookNotifier) NotifyCreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository,
issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User,
) {
var eventType webhook.HookEventType
@@ -423,10 +400,10 @@ func (m *webhookNotifier) NotifyCreateIssueComment(doer *user_model.User, repo *
eventType = webhook.HookEventIssueComment
}
- mode, _ := access_model.AccessLevel(doer, repo)
- if err := webhook_services.PrepareWebhooks(db.DefaultContext, webhook_services.EventSource{Repository: issue.Repo}, eventType, &api.IssueCommentPayload{
+ mode, _ := access_model.AccessLevel(ctx, doer, repo)
+ if err := webhook_services.PrepareWebhooks(ctx, webhook_services.EventSource{Repository: issue.Repo}, eventType, &api.IssueCommentPayload{
Action: api.HookIssueCommentCreated,
- Issue: convert.ToAPIIssue(issue),
+ Issue: convert.ToAPIIssue(ctx, issue),
Comment: convert.ToComment(comment),
Repository: convert.ToRepo(repo, mode),
Sender: convert.ToUser(doer, nil),
@@ -436,19 +413,19 @@ func (m *webhookNotifier) NotifyCreateIssueComment(doer *user_model.User, repo *
}
}
-func (m *webhookNotifier) NotifyDeleteComment(doer *user_model.User, comment *issues_model.Comment) {
+func (m *webhookNotifier) NotifyDeleteComment(ctx context.Context, doer *user_model.User, comment *issues_model.Comment) {
var err error
- if err = comment.LoadPoster(); err != nil {
+ if err = comment.LoadPoster(ctx); err != nil {
log.Error("LoadPoster: %v", err)
return
}
- if err = comment.LoadIssue(); err != nil {
+ if err = comment.LoadIssue(ctx); err != nil {
log.Error("LoadIssue: %v", err)
return
}
- if err = comment.Issue.LoadAttributes(db.DefaultContext); err != nil {
+ if err = comment.Issue.LoadAttributes(ctx); err != nil {
log.Error("LoadAttributes: %v", err)
return
}
@@ -460,10 +437,10 @@ func (m *webhookNotifier) NotifyDeleteComment(doer *user_model.User, comment *is
eventType = webhook.HookEventIssueComment
}
- mode, _ := access_model.AccessLevel(doer, comment.Issue.Repo)
- if err := webhook_services.PrepareWebhooks(db.DefaultContext, webhook_services.EventSource{Repository: comment.Issue.Repo}, eventType, &api.IssueCommentPayload{
+ mode, _ := access_model.AccessLevel(ctx, doer, comment.Issue.Repo)
+ if err := webhook_services.PrepareWebhooks(ctx, webhook_services.EventSource{Repository: comment.Issue.Repo}, eventType, &api.IssueCommentPayload{
Action: api.HookIssueCommentDeleted,
- Issue: convert.ToAPIIssue(comment.Issue),
+ Issue: convert.ToAPIIssue(ctx, comment.Issue),
Comment: convert.ToComment(comment),
Repository: convert.ToRepo(comment.Issue.Repo, mode),
Sender: convert.ToUser(doer, nil),
@@ -473,9 +450,9 @@ func (m *webhookNotifier) NotifyDeleteComment(doer *user_model.User, comment *is
}
}
-func (m *webhookNotifier) NotifyNewWikiPage(doer *user_model.User, repo *repo_model.Repository, page, comment string) {
+func (m *webhookNotifier) NotifyNewWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) {
// Add to hook queue for created wiki page.
- if err := webhook_services.PrepareWebhooks(db.DefaultContext, webhook_services.EventSource{Repository: repo}, webhook.HookEventWiki, &api.WikiPayload{
+ if err := webhook_services.PrepareWebhooks(ctx, webhook_services.EventSource{Repository: repo}, webhook.HookEventWiki, &api.WikiPayload{
Action: api.HookWikiCreated,
Repository: convert.ToRepo(repo, perm.AccessModeOwner),
Sender: convert.ToUser(doer, nil),
@@ -486,9 +463,9 @@ func (m *webhookNotifier) NotifyNewWikiPage(doer *user_model.User, repo *repo_mo
}
}
-func (m *webhookNotifier) NotifyEditWikiPage(doer *user_model.User, repo *repo_model.Repository, page, comment string) {
+func (m *webhookNotifier) NotifyEditWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) {
// Add to hook queue for edit wiki page.
- if err := webhook_services.PrepareWebhooks(db.DefaultContext, webhook_services.EventSource{Repository: repo}, webhook.HookEventWiki, &api.WikiPayload{
+ if err := webhook_services.PrepareWebhooks(ctx, webhook_services.EventSource{Repository: repo}, webhook.HookEventWiki, &api.WikiPayload{
Action: api.HookWikiEdited,
Repository: convert.ToRepo(repo, perm.AccessModeOwner),
Sender: convert.ToUser(doer, nil),
@@ -499,9 +476,9 @@ func (m *webhookNotifier) NotifyEditWikiPage(doer *user_model.User, repo *repo_m
}
}
-func (m *webhookNotifier) NotifyDeleteWikiPage(doer *user_model.User, repo *repo_model.Repository, page string) {
+func (m *webhookNotifier) NotifyDeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page string) {
// Add to hook queue for edit wiki page.
- if err := webhook_services.PrepareWebhooks(db.DefaultContext, webhook_services.EventSource{Repository: repo}, webhook.HookEventWiki, &api.WikiPayload{
+ if err := webhook_services.PrepareWebhooks(ctx, webhook_services.EventSource{Repository: repo}, webhook.HookEventWiki, &api.WikiPayload{
Action: api.HookWikiDeleted,
Repository: convert.ToRepo(repo, perm.AccessModeOwner),
Sender: convert.ToUser(doer, nil),
@@ -511,12 +488,9 @@ func (m *webhookNotifier) NotifyDeleteWikiPage(doer *user_model.User, repo *repo
}
}
-func (m *webhookNotifier) NotifyIssueChangeLabels(doer *user_model.User, issue *issues_model.Issue,
+func (m *webhookNotifier) NotifyIssueChangeLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue,
addedLabels, removedLabels []*issues_model.Label,
) {
- ctx, _, finished := process.GetManager().AddContext(graceful.GetManager().HammerContext(), fmt.Sprintf("webhook.NotifyIssueChangeLabels User: %s[%d] Issue[%d] #%d in [%d]", doer.Name, doer.ID, issue.ID, issue.Index, issue.RepoID))
- defer finished()
-
var err error
if err = issue.LoadRepo(ctx); err != nil {
@@ -524,18 +498,18 @@ func (m *webhookNotifier) NotifyIssueChangeLabels(doer *user_model.User, issue *
return
}
- if err = issue.LoadPoster(); err != nil {
+ if err = issue.LoadPoster(ctx); err != nil {
log.Error("LoadPoster: %v", err)
return
}
- mode, _ := access_model.AccessLevel(issue.Poster, issue.Repo)
+ mode, _ := access_model.AccessLevel(ctx, issue.Poster, issue.Repo)
if issue.IsPull {
- if err = issue.LoadPullRequest(); err != nil {
+ if err = issue.LoadPullRequest(ctx); err != nil {
log.Error("loadPullRequest: %v", err)
return
}
- if err = issue.PullRequest.LoadIssue(); err != nil {
+ if err = issue.PullRequest.LoadIssue(ctx); err != nil {
log.Error("LoadIssue: %v", err)
return
}
@@ -550,7 +524,7 @@ func (m *webhookNotifier) NotifyIssueChangeLabels(doer *user_model.User, issue *
err = webhook_services.PrepareWebhooks(ctx, webhook_services.EventSource{Repository: issue.Repo}, webhook.HookEventIssueLabel, &api.IssuePayload{
Action: api.HookIssueLabelUpdated,
Index: issue.Index,
- Issue: convert.ToAPIIssue(issue),
+ Issue: convert.ToAPIIssue(ctx, issue),
Repository: convert.ToRepo(issue.Repo, mode),
Sender: convert.ToUser(doer, nil),
})
@@ -560,10 +534,7 @@ func (m *webhookNotifier) NotifyIssueChangeLabels(doer *user_model.User, issue *
}
}
-func (m *webhookNotifier) NotifyIssueChangeMilestone(doer *user_model.User, issue *issues_model.Issue, oldMilestoneID int64) {
- ctx, _, finished := process.GetManager().AddContext(graceful.GetManager().HammerContext(), fmt.Sprintf("webhook.NotifyIssueChangeMilestone User: %s[%d] Issue[%d] #%d in [%d]", doer.Name, doer.ID, issue.ID, issue.Index, issue.RepoID))
- defer finished()
-
+func (m *webhookNotifier) NotifyIssueChangeMilestone(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldMilestoneID int64) {
var hookAction api.HookIssueAction
var err error
if issue.MilestoneID > 0 {
@@ -572,14 +543,14 @@ func (m *webhookNotifier) NotifyIssueChangeMilestone(doer *user_model.User, issu
hookAction = api.HookIssueDemilestoned
}
- if err = issue.LoadAttributes(db.DefaultContext); err != nil {
+ if err = issue.LoadAttributes(ctx); err != nil {
log.Error("issue.LoadAttributes failed: %v", err)
return
}
- mode, _ := access_model.AccessLevel(doer, issue.Repo)
+ mode, _ := access_model.AccessLevel(ctx, doer, issue.Repo)
if issue.IsPull {
- err = issue.PullRequest.LoadIssue()
+ err = issue.PullRequest.LoadIssue(ctx)
if err != nil {
log.Error("LoadIssue: %v", err)
return
@@ -595,7 +566,7 @@ func (m *webhookNotifier) NotifyIssueChangeMilestone(doer *user_model.User, issu
err = webhook_services.PrepareWebhooks(ctx, webhook_services.EventSource{Repository: issue.Repo}, webhook.HookEventIssueMilestone, &api.IssuePayload{
Action: hookAction,
Index: issue.Index,
- Issue: convert.ToAPIIssue(issue),
+ Issue: convert.ToAPIIssue(ctx, issue),
Repository: convert.ToRepo(issue.Repo, mode),
Sender: convert.ToUser(doer, nil),
})
@@ -605,10 +576,7 @@ func (m *webhookNotifier) NotifyIssueChangeMilestone(doer *user_model.User, issu
}
}
-func (m *webhookNotifier) NotifyPushCommits(pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
- ctx, _, finished := process.GetManager().AddContext(graceful.GetManager().HammerContext(), fmt.Sprintf("webhook.NotifyPushCommits User: %s[%d] in %s[%d]", pusher.Name, pusher.ID, repo.FullName(), repo.ID))
- defer finished()
-
+func (m *webhookNotifier) NotifyPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
apiPusher := convert.ToUser(pusher, nil)
apiCommits, apiHeadCommit, err := commits.ToAPIPayloadCommits(ctx, repo.RepoPath(), repo.HTMLURL())
if err != nil {
@@ -632,23 +600,20 @@ func (m *webhookNotifier) NotifyPushCommits(pusher *user_model.User, repo *repo_
}
}
-func (m *webhookNotifier) NotifyAutoMergePullRequest(pr *issues_model.PullRequest, doer *user_model.User) {
+func (m *webhookNotifier) NotifyAutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
// just redirect to the NotifyMergePullRequest
- m.NotifyMergePullRequest(pr, doer)
+ m.NotifyMergePullRequest(ctx, doer, pr)
}
-func (*webhookNotifier) NotifyMergePullRequest(pr *issues_model.PullRequest, doer *user_model.User) {
- ctx, _, finished := process.GetManager().AddContext(graceful.GetManager().HammerContext(), fmt.Sprintf("webhook.NotifyMergePullRequest Pull[%d] #%d in [%d]", pr.ID, pr.Index, pr.BaseRepoID))
- defer finished()
-
+func (*webhookNotifier) NotifyMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
// Reload pull request information.
- if err := pr.LoadAttributes(); err != nil {
+ if err := pr.LoadAttributes(ctx); err != nil {
log.Error("LoadAttributes: %v", err)
return
}
- if err := pr.LoadIssue(); err != nil {
- log.Error("LoadAttributes: %v", err)
+ if err := pr.LoadIssue(ctx); err != nil {
+ log.Error("LoadIssue: %v", err)
return
}
@@ -657,7 +622,7 @@ func (*webhookNotifier) NotifyMergePullRequest(pr *issues_model.PullRequest, doe
return
}
- mode, err := access_model.AccessLevel(doer, pr.Issue.Repo)
+ mode, err := access_model.AccessLevel(ctx, doer, pr.Issue.Repo)
if err != nil {
log.Error("models.AccessLevel: %v", err)
return
@@ -672,29 +637,21 @@ func (*webhookNotifier) NotifyMergePullRequest(pr *issues_model.PullRequest, doe
Action: api.HookIssueClosed,
}
- err = webhook_services.PrepareWebhooks(ctx, webhook_services.EventSource{Repository: pr.Issue.Repo}, webhook.HookEventPullRequest, apiPullRequest)
- if err != nil {
+ if err := webhook_services.PrepareWebhooks(ctx, webhook_services.EventSource{Repository: pr.Issue.Repo}, webhook.HookEventPullRequest, apiPullRequest); err != nil {
log.Error("PrepareWebhooks: %v", err)
}
}
-func (m *webhookNotifier) NotifyPullRequestChangeTargetBranch(doer *user_model.User, pr *issues_model.PullRequest, oldBranch string) {
- ctx, _, finished := process.GetManager().AddContext(graceful.GetManager().HammerContext(), fmt.Sprintf("webhook.NotifyPullRequestChangeTargetBranch Pull[%d] #%d in [%d]", pr.ID, pr.Index, pr.BaseRepoID))
- defer finished()
-
- issue := pr.Issue
- if !issue.IsPull {
+func (m *webhookNotifier) NotifyPullRequestChangeTargetBranch(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, oldBranch string) {
+ if err := pr.LoadIssue(ctx); err != nil {
+ log.Error("LoadIssue: %v", err)
return
}
- var err error
- if err = issue.LoadPullRequest(); err != nil {
- log.Error("LoadPullRequest failed: %v", err)
- return
- }
- issue.PullRequest.Issue = issue
- mode, _ := access_model.AccessLevel(issue.Poster, issue.Repo)
- err = webhook_services.PrepareWebhooks(ctx, webhook_services.EventSource{Repository: issue.Repo}, webhook.HookEventPullRequest, &api.PullRequestPayload{
+ issue := pr.Issue
+
+ mode, _ := access_model.AccessLevel(ctx, issue.Poster, issue.Repo)
+ if err := webhook_services.PrepareWebhooks(ctx, webhook_services.EventSource{Repository: issue.Repo}, webhook.HookEventPullRequest, &api.PullRequestPayload{
Action: api.HookIssueEdited,
Index: issue.Index,
Changes: &api.ChangesPayload{
@@ -702,20 +659,15 @@ func (m *webhookNotifier) NotifyPullRequestChangeTargetBranch(doer *user_model.U
From: oldBranch,
},
},
- PullRequest: convert.ToAPIPullRequest(ctx, issue.PullRequest, nil),
+ PullRequest: convert.ToAPIPullRequest(ctx, pr, nil),
Repository: convert.ToRepo(issue.Repo, mode),
Sender: convert.ToUser(doer, nil),
- })
-
- if err != nil {
- log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)
+ }); err != nil {
+ log.Error("PrepareWebhooks [pr: %d]: %v", pr.ID, err)
}
}
-func (m *webhookNotifier) NotifyPullRequestReview(pr *issues_model.PullRequest, review *issues_model.Review, comment *issues_model.Comment, mentions []*user_model.User) {
- ctx, _, finished := process.GetManager().AddContext(graceful.GetManager().HammerContext(), fmt.Sprintf("webhook.NotifyPullRequestReview Pull[%d] #%d in [%d]", pr.ID, pr.Index, pr.BaseRepoID))
- defer finished()
-
+func (m *webhookNotifier) NotifyPullRequestReview(ctx context.Context, pr *issues_model.PullRequest, review *issues_model.Review, comment *issues_model.Comment, mentions []*user_model.User) {
var reviewHookType webhook.HookEventType
switch review.Type {
@@ -731,12 +683,12 @@ func (m *webhookNotifier) NotifyPullRequestReview(pr *issues_model.PullRequest,
return
}
- if err := pr.LoadIssue(); err != nil {
- log.Error("pr.LoadIssue: %v", err)
+ if err := pr.LoadIssue(ctx); err != nil {
+ log.Error("LoadIssue: %v", err)
return
}
- mode, err := access_model.AccessLevel(review.Issue.Poster, review.Issue.Repo)
+ mode, err := access_model.AccessLevel(ctx, review.Issue.Poster, review.Issue.Repo)
if err != nil {
log.Error("models.AccessLevel: %v", err)
return
@@ -756,12 +708,12 @@ func (m *webhookNotifier) NotifyPullRequestReview(pr *issues_model.PullRequest,
}
}
-func (m *webhookNotifier) NotifyCreateRef(pusher *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) {
+func (m *webhookNotifier) NotifyCreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) {
apiPusher := convert.ToUser(pusher, nil)
apiRepo := convert.ToRepo(repo, perm.AccessModeNone)
refName := git.RefEndName(refFullName)
- if err := webhook_services.PrepareWebhooks(db.DefaultContext, webhook_services.EventSource{Repository: repo}, webhook.HookEventCreate, &api.CreatePayload{
+ if err := webhook_services.PrepareWebhooks(ctx, webhook_services.EventSource{Repository: repo}, webhook.HookEventCreate, &api.CreatePayload{
Ref: refName,
Sha: refID,
RefType: refType,
@@ -772,15 +724,12 @@ func (m *webhookNotifier) NotifyCreateRef(pusher *user_model.User, repo *repo_mo
}
}
-func (m *webhookNotifier) NotifyPullRequestSynchronized(doer *user_model.User, pr *issues_model.PullRequest) {
- ctx, _, finished := process.GetManager().AddContext(graceful.GetManager().HammerContext(), fmt.Sprintf("webhook.NotifyPullRequestSynchronized Pull[%d] #%d in [%d]", pr.ID, pr.Index, pr.BaseRepoID))
- defer finished()
-
- if err := pr.LoadIssue(); err != nil {
- log.Error("pr.LoadIssue: %v", err)
+func (m *webhookNotifier) NotifyPullRequestSynchronized(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
+ if err := pr.LoadIssue(ctx); err != nil {
+ log.Error("LoadIssue: %v", err)
return
}
- if err := pr.Issue.LoadAttributes(db.DefaultContext); err != nil {
+ if err := pr.Issue.LoadAttributes(ctx); err != nil {
log.Error("LoadAttributes: %v", err)
return
}
@@ -796,12 +745,12 @@ func (m *webhookNotifier) NotifyPullRequestSynchronized(doer *user_model.User, p
}
}
-func (m *webhookNotifier) NotifyDeleteRef(pusher *user_model.User, repo *repo_model.Repository, refType, refFullName string) {
+func (m *webhookNotifier) NotifyDeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName string) {
apiPusher := convert.ToUser(pusher, nil)
apiRepo := convert.ToRepo(repo, perm.AccessModeNone)
refName := git.RefEndName(refFullName)
- if err := webhook_services.PrepareWebhooks(db.DefaultContext, webhook_services.EventSource{Repository: repo}, webhook.HookEventDelete, &api.DeletePayload{
+ if err := webhook_services.PrepareWebhooks(ctx, webhook_services.EventSource{Repository: repo}, webhook.HookEventDelete, &api.DeletePayload{
Ref: refName,
RefType: refType,
PusherType: api.PusherTypeUser,
@@ -812,14 +761,14 @@ func (m *webhookNotifier) NotifyDeleteRef(pusher *user_model.User, repo *repo_mo
}
}
-func sendReleaseHook(doer *user_model.User, rel *repo_model.Release, action api.HookReleaseAction) {
- if err := rel.LoadAttributes(); err != nil {
+func sendReleaseHook(ctx context.Context, doer *user_model.User, rel *repo_model.Release, action api.HookReleaseAction) {
+ if err := rel.LoadAttributes(ctx); err != nil {
log.Error("LoadAttributes: %v", err)
return
}
- mode, _ := access_model.AccessLevel(doer, rel.Repo)
- if err := webhook_services.PrepareWebhooks(db.DefaultContext, webhook_services.EventSource{Repository: rel.Repo}, webhook.HookEventRelease, &api.ReleasePayload{
+ mode, _ := access_model.AccessLevel(ctx, doer, rel.Repo)
+ if err := webhook_services.PrepareWebhooks(ctx, webhook_services.EventSource{Repository: rel.Repo}, webhook.HookEventRelease, &api.ReleasePayload{
Action: action,
Release: convert.ToRelease(rel),
Repository: convert.ToRepo(rel.Repo, mode),
@@ -829,22 +778,19 @@ func sendReleaseHook(doer *user_model.User, rel *repo_model.Release, action api.
}
}
-func (m *webhookNotifier) NotifyNewRelease(rel *repo_model.Release) {
- sendReleaseHook(rel.Publisher, rel, api.HookReleasePublished)
+func (m *webhookNotifier) NotifyNewRelease(ctx context.Context, rel *repo_model.Release) {
+ sendReleaseHook(ctx, rel.Publisher, rel, api.HookReleasePublished)
}
-func (m *webhookNotifier) NotifyUpdateRelease(doer *user_model.User, rel *repo_model.Release) {
- sendReleaseHook(doer, rel, api.HookReleaseUpdated)
+func (m *webhookNotifier) NotifyUpdateRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) {
+ sendReleaseHook(ctx, doer, rel, api.HookReleaseUpdated)
}
-func (m *webhookNotifier) NotifyDeleteRelease(doer *user_model.User, rel *repo_model.Release) {
- sendReleaseHook(doer, rel, api.HookReleaseDeleted)
+func (m *webhookNotifier) NotifyDeleteRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) {
+ sendReleaseHook(ctx, doer, rel, api.HookReleaseDeleted)
}
-func (m *webhookNotifier) NotifySyncPushCommits(pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
- ctx, _, finished := process.GetManager().AddContext(graceful.GetManager().HammerContext(), fmt.Sprintf("webhook.NotifySyncPushCommits User: %s[%d] in %s[%d]", pusher.Name, pusher.ID, repo.FullName(), repo.ID))
- defer finished()
-
+func (m *webhookNotifier) NotifySyncPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
apiPusher := convert.ToUser(pusher, nil)
apiCommits, apiHeadCommit, err := commits.ToAPIPayloadCommits(ctx, repo.RepoPath(), repo.HTMLURL())
if err != nil {
@@ -868,31 +814,28 @@ func (m *webhookNotifier) NotifySyncPushCommits(pusher *user_model.User, repo *r
}
}
-func (m *webhookNotifier) NotifySyncCreateRef(pusher *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) {
- m.NotifyCreateRef(pusher, repo, refType, refFullName, refID)
+func (m *webhookNotifier) NotifySyncCreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) {
+ m.NotifyCreateRef(ctx, pusher, repo, refType, refFullName, refID)
}
-func (m *webhookNotifier) NotifySyncDeleteRef(pusher *user_model.User, repo *repo_model.Repository, refType, refFullName string) {
- m.NotifyDeleteRef(pusher, repo, refType, refFullName)
+func (m *webhookNotifier) NotifySyncDeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName string) {
+ m.NotifyDeleteRef(ctx, pusher, repo, refType, refFullName)
}
-func (m *webhookNotifier) NotifyPackageCreate(doer *user_model.User, pd *packages_model.PackageDescriptor) {
- notifyPackage(doer, pd, api.HookPackageCreated)
+func (m *webhookNotifier) NotifyPackageCreate(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) {
+ notifyPackage(ctx, doer, pd, api.HookPackageCreated)
}
-func (m *webhookNotifier) NotifyPackageDelete(doer *user_model.User, pd *packages_model.PackageDescriptor) {
- notifyPackage(doer, pd, api.HookPackageDeleted)
+func (m *webhookNotifier) NotifyPackageDelete(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) {
+ notifyPackage(ctx, doer, pd, api.HookPackageDeleted)
}
-func notifyPackage(sender *user_model.User, pd *packages_model.PackageDescriptor, action api.HookPackageAction) {
+func notifyPackage(ctx context.Context, sender *user_model.User, pd *packages_model.PackageDescriptor, action api.HookPackageAction) {
source := webhook_services.EventSource{
Repository: pd.Repository,
Owner: pd.Owner,
}
- ctx, _, finished := process.GetManager().AddContext(graceful.GetManager().HammerContext(), fmt.Sprintf("webhook.notifyPackage Package: %s[%d]", pd.Package.Name, pd.Package.ID))
- defer finished()
-
apiPackage, err := convert.ToPackage(ctx, pd, sender)
if err != nil {
log.Error("Error converting package: %v", err)
diff --git a/modules/repository/repo.go b/modules/repository/repo.go
index 1d3a4658c2..f1360f4478 100644
--- a/modules/repository/repo.go
+++ b/modules/repository/repo.go
@@ -288,7 +288,7 @@ func SyncReleasesWithTags(repo *repo_model.Repository, gitRepo *git.Repository)
}
for page := 1; ; page++ {
opts.Page = page
- rels, err := repo_model.GetReleasesByRepoID(repo.ID, opts)
+ rels, err := repo_model.GetReleasesByRepoID(gitRepo.Ctx, repo.ID, opts)
if err != nil {
return fmt.Errorf("unable to GetReleasesByRepoID in Repo[%d:%s/%s]: %w", repo.ID, repo.OwnerName, repo.Name, err)
}