Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send tag create and push webhook when release created on UI #8671

Merged
merged 18 commits into from
Nov 22, 2019
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/notification/base/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Notifier interface {
NotifyDeleteComment(*models.User, *models.Comment)

NotifyNewRelease(rel *models.Release)
NotifyNewReleaseTag(gitRepo *git.Repository, rel *models.Release)
NotifyUpdateRelease(doer *models.User, rel *models.Release)
NotifyDeleteRelease(doer *models.User, rel *models.Release)

Expand Down
4 changes: 4 additions & 0 deletions modules/notification/base/null.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ func (*NullNotifier) NotifyRenameRepository(doer *models.User, repo *models.Repo
func (*NullNotifier) NotifyNewRelease(rel *models.Release) {
}

// NotifyNewReleaseTag places a place holder function
func (m *NullNotifier) NotifyNewReleaseTag(gitRepo *git.Repository, rel *models.Release) {
}

// NotifyUpdateRelease places a place holder function
func (*NullNotifier) NotifyUpdateRelease(doer *models.User, rel *models.Release) {
}
Expand Down
7 changes: 7 additions & 0 deletions modules/notification/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ func NotifyNewRelease(rel *models.Release) {
}
}

// NotifyNewReleaseTag notifies new tag for release to notifiers
func NotifyNewReleaseTag(gitRepo *git.Repository, rel *models.Release) {
for _, notifier := range notifiers {
notifier.NotifyNewReleaseTag(gitRepo, rel)
}
}

// NotifyUpdateRelease notifies update release to notifiers
func NotifyUpdateRelease(doer *models.User, rel *models.Release) {
for _, notifier := range notifiers {
Expand Down
39 changes: 39 additions & 0 deletions modules/notification/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,45 @@ func sendReleaseHook(doer *models.User, rel *models.Release, action api.HookRele
}
}

func (m *webhookNotifier) NotifyNewReleaseTag(gitRepo *git.Repository, rel *models.Release) {
if err := rel.LoadAttributes(); err != nil {
log.Error("LoadAttributes: %v", err)
return
}
// Prepare Webhook
var shaSum string
mode, _ := models.AccessLevel(rel.Publisher, rel.Repo)
apiRepo := rel.Repo.APIFormat(mode)
apiPusher := rel.Publisher.APIFormat()
shaSum, err := gitRepo.GetTagCommitID(rel.TagName)
if err != nil {
log.Error("GetTagCommitID[%s]: %v", rel.TagName, err)
}
// Tag Create
if err = webhook_module.PrepareWebhooks(rel.Repo, models.HookEventCreate, &api.CreatePayload{
Ref: git.TagPrefix + rel.TagName,
Sha: shaSum,
RefType: "tag",
Repo: apiRepo,
Sender: apiPusher,
}); err != nil {
log.Error("PrepareWebhooks: %v", err)
}
// Tag Push
if err = webhook_module.PrepareWebhooks(rel.Repo, models.HookEventPush, &api.PushPayload{
Ref: git.TagPrefix + rel.TagName,
Before: git.EmptySHA,
After: shaSum,
CompareURL: setting.AppURL,
Commits: make([]*api.PayloadCommit, 0),
Repo: apiRepo,
Pusher: apiPusher,
Sender: apiPusher,
}); err != nil {
log.Error("PrepareWebhooks: %v", err)
}
}

func (m *webhookNotifier) NotifyNewRelease(rel *models.Release) {
sendReleaseHook(rel.Publisher, rel, api.HookReleasePublished)
}
Expand Down
2 changes: 1 addition & 1 deletion services/release/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func CreateRelease(gitRepo *git.Repository, rel *models.Release, attachmentUUIDs
if err = createTag(gitRepo, rel); err != nil {
return err
}

notification.NotifyNewReleaseTag(gitRepo, rel)
lafriks marked this conversation as resolved.
Show resolved Hide resolved
rel.LowerTagName = strings.ToLower(rel.TagName)
if err = models.InsertRelease(rel); err != nil {
return err
Expand Down