NotifyNewRelease(rel *models.Release)
NotifyUpdateRelease(doer *models.User, rel *models.Release)
NotifyDeleteRelease(doer *models.User, rel *models.Release)
+
+ NotifyPushCommits(pusher *models.User, repo *models.Repository, refName, oldCommitID, newCommitID string, commits *models.PushCommits)
}
// NotifyMigrateRepository places a place holder function
func (*NullNotifier) NotifyMigrateRepository(doer *models.User, u *models.User, repo *models.Repository) {
}
+
+// NotifyPushCommits notifies commits pushed to notifiers
+func (*NullNotifier) NotifyPushCommits(pusher *models.User, repo *models.Repository, refName, oldCommitID, newCommitID string, commits *models.PushCommits) {
+}
notifier.NotifyMigrateRepository(doer, u, repo)
}
}
+
+// NotifyPushCommits notifies commits pushed to notifiers
+func NotifyPushCommits(pusher *models.User, repo *models.Repository, refName, oldCommitID, newCommitID string, commits *models.PushCommits) {
+ for _, notifier := range notifiers {
+ notifier.NotifyPushCommits(pusher, repo, refName, oldCommitID, newCommitID, commits)
+ }
+}
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification/base"
+ "code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
webhook_module "code.gitea.io/gitea/modules/webhook"
)
log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)
}
}
+
+func (m *webhookNotifier) NotifyPushCommits(pusher *models.User, repo *models.Repository, refName, oldCommitID, newCommitID string, commits *models.PushCommits) {
+ apiPusher := pusher.APIFormat()
+ apiCommits, err := commits.ToAPIPayloadCommits(repo.RepoPath(), repo.HTMLURL())
+ if err != nil {
+ log.Error("commits.ToAPIPayloadCommits failed: %v", err)
+ return
+ }
+
+ if err := webhook_module.PrepareWebhooks(repo, models.HookEventPush, &api.PushPayload{
+ Ref: refName,
+ Before: oldCommitID,
+ After: newCommitID,
+ CompareURL: setting.AppURL + commits.CompareURL,
+ Commits: apiCommits,
+ Repo: repo.APIFormat(models.AccessModeOwner),
+ Pusher: apiPusher,
+ Sender: apiPusher,
+ }); err != nil {
+ log.Error("PrepareWebhooks: %v", err)
+ }
+}
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
+ "code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/webhook"
}
if isHookEventPush {
- commits, err := opts.Commits.ToAPIPayloadCommits(repo.RepoPath(), repo.HTMLURL())
- if err != nil {
- return err
- }
- if err = webhook.PrepareWebhooks(repo, models.HookEventPush, &api.PushPayload{
- Ref: opts.RefFullName,
- Before: opts.OldCommitID,
- After: opts.NewCommitID,
- CompareURL: setting.AppURL + opts.Commits.CompareURL,
- Commits: commits,
- Repo: apiRepo,
- Pusher: apiPusher,
- Sender: apiPusher,
- }); err != nil {
- return fmt.Errorf("PrepareWebhooks: %v", err)
- }
+ notification.NotifyPushCommits(pusher, repo, opts.RefFullName, opts.OldCommitID, opts.NewCommitID, opts.Commits)
}
return nil
"fmt"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/setting"
- api "code.gitea.io/gitea/modules/structs"
- "code.gitea.io/gitea/modules/webhook"
)
func syncAction(opType models.ActionType, repo *models.Repository, refName string, data []byte) error {
opts.Commits.Commits = opts.Commits.Commits[:setting.UI.FeedMaxCommitNum]
}
- apiCommits, err := opts.Commits.ToAPIPayloadCommits(repo.RepoPath(), repo.HTMLURL())
- if err != nil {
- return err
- }
-
opts.Commits.CompareURL = repo.ComposeCompareURL(opts.OldCommitID, opts.NewCommitID)
- apiPusher := repo.MustOwner().APIFormat()
- if err := webhook.PrepareWebhooks(repo, models.HookEventPush, &api.PushPayload{
- Ref: opts.RefName,
- Before: opts.OldCommitID,
- After: opts.NewCommitID,
- CompareURL: setting.AppURL + opts.Commits.CompareURL,
- Commits: apiCommits,
- Repo: repo.APIFormat(models.AccessModeOwner),
- Pusher: apiPusher,
- Sender: apiPusher,
- }); err != nil {
- return fmt.Errorf("PrepareWebhooks: %v", err)
- }
+
+ notification.NotifyPushCommits(repo.MustOwner(), repo, opts.RefName, opts.OldCommitID, opts.NewCommitID, opts.Commits)
data, err := json.Marshal(opts.Commits)
if err != nil {