|
|
|
@@ -45,6 +45,10 @@ func NewNotifier() base.Notifier {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func notify(repo *repo_model.Repository, doer *user_model.User, ref string, evt webhook.HookEventType, payload api.Payloader) error {
|
|
|
|
|
return notifyWithPR(repo, doer, ref, evt, payload, nil)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func notifyWithPR(repo *repo_model.Repository, doer *user_model.User, ref string, evt webhook.HookEventType, payload api.Payloader, pr *issues_model.PullRequest) error {
|
|
|
|
|
if unit.TypeBots.UnitGlobalDisabled() {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
@@ -83,16 +87,17 @@ func notify(repo *repo_model.Repository, doer *user_model.User, ref string, evt
|
|
|
|
|
|
|
|
|
|
for id, content := range workflows {
|
|
|
|
|
run := bots_model.Run{
|
|
|
|
|
Title: commit.Message(),
|
|
|
|
|
RepoID: repo.ID,
|
|
|
|
|
OwnerID: repo.OwnerID,
|
|
|
|
|
WorkflowID: id,
|
|
|
|
|
TriggerUserID: doer.ID,
|
|
|
|
|
Ref: ref,
|
|
|
|
|
CommitSHA: commit.ID.String(),
|
|
|
|
|
Event: evt,
|
|
|
|
|
EventPayload: string(p),
|
|
|
|
|
Status: bots_model.StatusWaiting,
|
|
|
|
|
Title: commit.Message(),
|
|
|
|
|
RepoID: repo.ID,
|
|
|
|
|
OwnerID: repo.OwnerID,
|
|
|
|
|
WorkflowID: id,
|
|
|
|
|
TriggerUserID: doer.ID,
|
|
|
|
|
Ref: ref,
|
|
|
|
|
CommitSHA: commit.ID.String(),
|
|
|
|
|
IsForkPullRequest: pr != nil && pr.IsFromFork(),
|
|
|
|
|
Event: evt,
|
|
|
|
|
EventPayload: string(p),
|
|
|
|
|
Status: bots_model.StatusWaiting,
|
|
|
|
|
}
|
|
|
|
|
if len(run.Title) > 255 {
|
|
|
|
|
run.Title = run.Title[:255] // FIXME: we should use a better method to cut title
|
|
|
|
@@ -110,22 +115,22 @@ func notify(repo *repo_model.Repository, doer *user_model.User, ref string, evt
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NotifyNewIssue notifies issue created event
|
|
|
|
|
func (a *botsNotifier) NotifyNewIssue(issue *issues_model.Issue, mentions []*user_model.User) {
|
|
|
|
|
if err := issue.LoadRepo(db.DefaultContext); err != nil {
|
|
|
|
|
func (a *botsNotifier) 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)
|
|
|
|
|
mode, _ := access_model.AccessLevel(ctx, issue.Poster, issue.Repo)
|
|
|
|
|
if err := notify(issue.Repo, issue.Poster, issue.Repo.DefaultBranch,
|
|
|
|
|
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 {
|
|
|
|
@@ -134,11 +139,11 @@ func (a *botsNotifier) NotifyNewIssue(issue *issues_model.Issue, mentions []*use
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NotifyIssueChangeStatus notifies close or reopen issue to notifiers
|
|
|
|
|
func (a *botsNotifier) NotifyIssueChangeStatus(doer *user_model.User, issue *issues_model.Issue, actionComment *issues_model.Comment, isClosed bool) {
|
|
|
|
|
mode, _ := access_model.AccessLevel(issue.Poster, issue.Repo)
|
|
|
|
|
func (a *botsNotifier) 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
|
|
|
|
|
}
|
|
|
|
@@ -158,7 +163,7 @@ func (a *botsNotifier) NotifyIssueChangeStatus(doer *user_model.User, issue *iss
|
|
|
|
|
} 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),
|
|
|
|
|
}
|
|
|
|
@@ -174,34 +179,34 @@ func (a *botsNotifier) NotifyIssueChangeStatus(doer *user_model.User, issue *iss
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *botsNotifier) NotifyIssueChangeLabels(doer *user_model.User, issue *issues_model.Issue,
|
|
|
|
|
func (a *botsNotifier) NotifyIssueChangeLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue,
|
|
|
|
|
addedLabels []*issues_model.Label, removedLabels []*issues_model.Label,
|
|
|
|
|
) {
|
|
|
|
|
var err error
|
|
|
|
|
if err = issue.LoadRepo(db.DefaultContext); err != nil {
|
|
|
|
|
if err = issue.LoadRepo(ctx); err != nil {
|
|
|
|
|
log.Error("LoadRepo: %v", err)
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
err = notify(issue.Repo, doer, issue.Repo.DefaultBranch, webhook.HookEventPullRequestLabel, &api.PullRequestPayload{
|
|
|
|
|
Action: api.HookIssueLabelUpdated,
|
|
|
|
|
Index: issue.Index,
|
|
|
|
|
PullRequest: convert.ToAPIPullRequest(db.DefaultContext, issue.PullRequest, nil),
|
|
|
|
|
PullRequest: convert.ToAPIPullRequest(ctx, issue.PullRequest, nil),
|
|
|
|
|
Repository: convert.ToRepo(issue.Repo, perm.AccessModeNone),
|
|
|
|
|
Sender: convert.ToUser(doer, nil),
|
|
|
|
|
})
|
|
|
|
@@ -209,7 +214,7 @@ func (a *botsNotifier) NotifyIssueChangeLabels(doer *user_model.User, issue *iss
|
|
|
|
|
err = notify(issue.Repo, doer, issue.Repo.DefaultBranch, 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),
|
|
|
|
|
})
|
|
|
|
@@ -220,16 +225,16 @@ func (a *botsNotifier) NotifyIssueChangeLabels(doer *user_model.User, issue *iss
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NotifyCreateIssueComment notifies comment on an issue to notifiers
|
|
|
|
|
func (a *botsNotifier) NotifyCreateIssueComment(doer *user_model.User, repo *repo_model.Repository,
|
|
|
|
|
func (a *botsNotifier) NotifyCreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository,
|
|
|
|
|
issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User,
|
|
|
|
|
) {
|
|
|
|
|
mode, _ := access_model.AccessLevel(doer, repo)
|
|
|
|
|
mode, _ := access_model.AccessLevel(ctx, doer, repo)
|
|
|
|
|
|
|
|
|
|
var err error
|
|
|
|
|
if issue.IsPull {
|
|
|
|
|
err = notify(issue.Repo, doer, issue.Repo.DefaultBranch, webhook.HookEventPullRequestComment, &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),
|
|
|
|
@@ -238,7 +243,7 @@ func (a *botsNotifier) NotifyCreateIssueComment(doer *user_model.User, repo *rep
|
|
|
|
|
} else {
|
|
|
|
|
err = notify(issue.Repo, doer, issue.Repo.DefaultBranch, webhook.HookEventIssueComment, &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),
|
|
|
|
@@ -251,39 +256,39 @@ func (a *botsNotifier) NotifyCreateIssueComment(doer *user_model.User, repo *rep
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *botsNotifier) NotifyNewPullRequest(pull *issues_model.PullRequest, mentions []*user_model.User) {
|
|
|
|
|
if err := pull.LoadIssue(); err != nil {
|
|
|
|
|
func (a *botsNotifier) 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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mode, _ := access_model.AccessLevel(pull.Issue.Poster, pull.Issue.Repo)
|
|
|
|
|
if err := notify(pull.Issue.Repo, pull.Issue.Poster, pull.Issue.Repo.DefaultBranch, webhook.HookEventPullRequest, &api.PullRequestPayload{
|
|
|
|
|
mode, _ := access_model.AccessLevel(ctx, pull.Issue.Poster, pull.Issue.Repo)
|
|
|
|
|
if err := notifyWithPR(pull.Issue.Repo, pull.Issue.Poster, pull.Issue.Repo.DefaultBranch, webhook.HookEventPullRequest, &api.PullRequestPayload{
|
|
|
|
|
Action: api.HookIssueOpened,
|
|
|
|
|
Index: pull.Issue.Index,
|
|
|
|
|
PullRequest: convert.ToAPIPullRequest(db.DefaultContext, pull, nil),
|
|
|
|
|
PullRequest: convert.ToAPIPullRequest(ctx, pull, nil),
|
|
|
|
|
Repository: convert.ToRepo(pull.Issue.Repo, mode),
|
|
|
|
|
Sender: convert.ToUser(pull.Issue.Poster, nil),
|
|
|
|
|
}); err != nil {
|
|
|
|
|
}, pull); err != nil {
|
|
|
|
|
log.Error("PrepareWebhooks: %v", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *botsNotifier) NotifyRenameRepository(doer *user_model.User, repo *repo_model.Repository, oldRepoName string) {
|
|
|
|
|
func (a *botsNotifier) NotifyRenameRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldRepoName string) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *botsNotifier) NotifyTransferRepository(doer *user_model.User, repo *repo_model.Repository, oldOwnerName string) {
|
|
|
|
|
func (a *botsNotifier) NotifyTransferRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldOwnerName string) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *botsNotifier) NotifyCreateRepository(doer *user_model.User, u *user_model.User, repo *repo_model.Repository) {
|
|
|
|
|
func (a *botsNotifier) NotifyCreateRepository(ctx context.Context, doer *user_model.User, u *user_model.User, repo *repo_model.Repository) {
|
|
|
|
|
if err := notify(repo, doer, repo.DefaultBranch,
|
|
|
|
|
webhook.HookEventRepository,
|
|
|
|
|
&api.RepositoryPayload{
|
|
|
|
@@ -296,9 +301,9 @@ func (a *botsNotifier) NotifyCreateRepository(doer *user_model.User, u *user_mod
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *botsNotifier) NotifyForkRepository(doer *user_model.User, oldRepo, repo *repo_model.Repository) {
|
|
|
|
|
oldMode, _ := access_model.AccessLevel(doer, oldRepo)
|
|
|
|
|
mode, _ := access_model.AccessLevel(doer, repo)
|
|
|
|
|
func (a *botsNotifier) 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 := notify(oldRepo, doer, oldRepo.DefaultBranch, webhook.HookEventFork, &api.ForkPayload{
|
|
|
|
@@ -309,7 +314,7 @@ func (a *botsNotifier) NotifyForkRepository(doer *user_model.User, oldRepo, repo
|
|
|
|
|
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() {
|
|
|
|
@@ -324,7 +329,7 @@ func (a *botsNotifier) NotifyForkRepository(doer *user_model.User, oldRepo, repo
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *botsNotifier) NotifyPullRequestReview(pr *issues_model.PullRequest, review *issues_model.Review, comment *issues_model.Comment, mentions []*user_model.User) {
|
|
|
|
|
func (a *botsNotifier) 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 {
|
|
|
|
@@ -340,17 +345,17 @@ func (a *botsNotifier) NotifyPullRequestReview(pr *issues_model.PullRequest, rev
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := pr.LoadIssue(); err != nil {
|
|
|
|
|
if err := pr.LoadIssue(ctx); err != nil {
|
|
|
|
|
log.Error("pr.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
|
|
|
|
|
}
|
|
|
|
|
if err := notify(review.Issue.Repo, review.Reviewer, review.CommitID, reviewHookType, &api.PullRequestPayload{
|
|
|
|
|
if err := notifyWithPR(review.Issue.Repo, review.Reviewer, review.CommitID, reviewHookType, &api.PullRequestPayload{
|
|
|
|
|
Action: api.HookIssueReviewed,
|
|
|
|
|
Index: review.Issue.Index,
|
|
|
|
|
PullRequest: convert.ToAPIPullRequest(db.DefaultContext, pr, nil),
|
|
|
|
@@ -360,19 +365,19 @@ func (a *botsNotifier) NotifyPullRequestReview(pr *issues_model.PullRequest, rev
|
|
|
|
|
Type: string(reviewHookType),
|
|
|
|
|
Content: review.Content,
|
|
|
|
|
},
|
|
|
|
|
}); err != nil {
|
|
|
|
|
}, pr); err != nil {
|
|
|
|
|
log.Error("PrepareWebhooks: %v", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (*botsNotifier) NotifyMergePullRequest(pr *issues_model.PullRequest, doer *user_model.User) {
|
|
|
|
|
func (*botsNotifier) 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 {
|
|
|
|
|
if err := pr.LoadIssue(ctx); err != nil {
|
|
|
|
|
log.Error("LoadAttributes: %v", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
@@ -382,7 +387,7 @@ func (*botsNotifier) NotifyMergePullRequest(pr *issues_model.PullRequest, doer *
|
|
|
|
|
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
|
|
|
|
@@ -397,13 +402,13 @@ func (*botsNotifier) NotifyMergePullRequest(pr *issues_model.PullRequest, doer *
|
|
|
|
|
Action: api.HookIssueClosed,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = notify(pr.Issue.Repo, doer, pr.MergedCommitID, webhook.HookEventPullRequest, apiPullRequest)
|
|
|
|
|
err = notifyWithPR(pr.Issue.Repo, doer, pr.MergedCommitID, webhook.HookEventPullRequest, apiPullRequest, pr)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Error("PrepareWebhooks: %v", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *botsNotifier) NotifyPushCommits(pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
|
|
|
|
|
func (a *botsNotifier) NotifyPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
|
|
|
|
|
ctx, _, finished := process.GetManager().AddContext(graceful.GetManager().HammerContext(), fmt.Sprintf("botsNofiter.NotifyPushCommits User: %s[%d] in %s[%d]", pusher.Name, pusher.ID, repo.FullName(), repo.ID))
|
|
|
|
|
defer finished()
|
|
|
|
|
|
|
|
|
@@ -427,7 +432,7 @@ func (a *botsNotifier) NotifyPushCommits(pusher *user_model.User, repo *repo_mod
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *botsNotifier) NotifyCreateRef(pusher *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) {
|
|
|
|
|
func (a *botsNotifier) 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)
|
|
|
|
@@ -443,7 +448,7 @@ func (a *botsNotifier) NotifyCreateRef(pusher *user_model.User, repo *repo_model
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *botsNotifier) NotifyDeleteRef(pusher *user_model.User, repo *repo_model.Repository, refType, refFullName string) {
|
|
|
|
|
func (a *botsNotifier) 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)
|
|
|
|
@@ -459,7 +464,7 @@ func (a *botsNotifier) NotifyDeleteRef(pusher *user_model.User, repo *repo_model
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *botsNotifier) NotifySyncPushCommits(pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
|
|
|
|
|
func (a *botsNotifier) 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(db.DefaultContext, repo.RepoPath(), repo.HTMLURL())
|
|
|
|
|
if err != nil {
|
|
|
|
@@ -483,21 +488,21 @@ func (a *botsNotifier) NotifySyncPushCommits(pusher *user_model.User, repo *repo
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *botsNotifier) NotifySyncCreateRef(pusher *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) {
|
|
|
|
|
a.NotifyCreateRef(pusher, repo, refType, refFullName, refID)
|
|
|
|
|
func (a *botsNotifier) NotifySyncCreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName, refID string) {
|
|
|
|
|
a.NotifyCreateRef(ctx, pusher, repo, refType, refFullName, refID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *botsNotifier) NotifySyncDeleteRef(pusher *user_model.User, repo *repo_model.Repository, refType, refFullName string) {
|
|
|
|
|
a.NotifyDeleteRef(pusher, repo, refType, refFullName)
|
|
|
|
|
func (a *botsNotifier) NotifySyncDeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refType, refFullName string) {
|
|
|
|
|
a.NotifyDeleteRef(ctx, pusher, repo, refType, refFullName)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func sendReleaseNofiter(doer *user_model.User, rel *repo_model.Release, ref string, action api.HookReleaseAction) {
|
|
|
|
|
if err := rel.LoadAttributes(); err != nil {
|
|
|
|
|
func sendReleaseNofiter(ctx context.Context, doer *user_model.User, rel *repo_model.Release, ref string, action api.HookReleaseAction) {
|
|
|
|
|
if err := rel.LoadAttributes(ctx); err != nil {
|
|
|
|
|
log.Error("LoadAttributes: %v", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mode, _ := access_model.AccessLevel(doer, rel.Repo)
|
|
|
|
|
mode, _ := access_model.AccessLevel(ctx, doer, rel.Repo)
|
|
|
|
|
if err := notify(rel.Repo, doer, ref, webhook.HookEventRelease, &api.ReleasePayload{
|
|
|
|
|
Action: action,
|
|
|
|
|
Release: convert.ToRelease(rel),
|
|
|
|
@@ -508,23 +513,23 @@ func sendReleaseNofiter(doer *user_model.User, rel *repo_model.Release, ref stri
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *botsNotifier) NotifyNewRelease(rel *repo_model.Release) {
|
|
|
|
|
sendReleaseNofiter(rel.Publisher, rel, rel.Sha1, api.HookReleasePublished)
|
|
|
|
|
func (a *botsNotifier) NotifyNewRelease(ctx context.Context, rel *repo_model.Release) {
|
|
|
|
|
sendReleaseNofiter(ctx, rel.Publisher, rel, rel.Sha1, api.HookReleasePublished)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *botsNotifier) NotifyUpdateRelease(doer *user_model.User, rel *repo_model.Release) {
|
|
|
|
|
sendReleaseNofiter(doer, rel, rel.Sha1, api.HookReleaseUpdated)
|
|
|
|
|
func (a *botsNotifier) NotifyUpdateRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) {
|
|
|
|
|
sendReleaseNofiter(ctx, doer, rel, rel.Sha1, api.HookReleaseUpdated)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *botsNotifier) NotifyDeleteRelease(doer *user_model.User, rel *repo_model.Release) {
|
|
|
|
|
sendReleaseNofiter(doer, rel, rel.Sha1, api.HookReleaseDeleted)
|
|
|
|
|
func (a *botsNotifier) NotifyDeleteRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) {
|
|
|
|
|
sendReleaseNofiter(ctx, doer, rel, rel.Sha1, api.HookReleaseDeleted)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *botsNotifier) NotifyPackageCreate(doer *user_model.User, pd *packages_model.PackageDescriptor) {
|
|
|
|
|
func (a *botsNotifier) NotifyPackageCreate(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) {
|
|
|
|
|
notifyPackage(doer, pd, api.HookPackageCreated)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *botsNotifier) NotifyPackageDelete(doer *user_model.User, pd *packages_model.PackageDescriptor) {
|
|
|
|
|
func (a *botsNotifier) NotifyPackageDelete(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) {
|
|
|
|
|
notifyPackage(doer, pd, api.HookPackageDeleted)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|