diff options
author | Ethan Koenig <ethantkoenig@gmail.com> | 2017-09-03 01:20:24 -0700 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2017-09-03 11:20:24 +0300 |
commit | b689bb61804fddfd2df8df7250522b0fc227484e (patch) | |
tree | 6cd96dfc3c0c7b2a0b265217f2893aa606307b0a /models/webhook_slack.go | |
parent | 79f7839633167bbb146a7b0d17ce0ec1c990d085 (diff) | |
download | gitea-b689bb61804fddfd2df8df7250522b0fc227484e.tar.gz gitea-b689bb61804fddfd2df8df7250522b0fc227484e.zip |
Webhooks for repo creation/deletion (#1663)
* Webhooks for repo creation/deletion
* add createHookTask
* Add handles for GetSlackPayload and GetDiscordPayload
Diffstat (limited to 'models/webhook_slack.go')
-rw-r--r-- | models/webhook_slack.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/models/webhook_slack.go b/models/webhook_slack.go index b297fefd66..ca43cfd427 100644 --- a/models/webhook_slack.go +++ b/models/webhook_slack.go @@ -189,6 +189,30 @@ func getSlackPullRequestPayload(p *api.PullRequestPayload, slack *SlackMeta) (*S }, nil } +func getSlackRepositoryPayload(p *api.RepositoryPayload, slack *SlackMeta) (*SlackPayload, error) { + senderLink := SlackLinkFormatter(setting.AppURL+p.Sender.UserName, p.Sender.UserName) + var text, title, attachmentText string + switch p.Action { + case api.HookRepoCreated: + text = fmt.Sprintf("[%s] Repository created by %s", p.Repository.FullName, senderLink) + title = p.Repository.HTMLURL + case api.HookRepoDeleted: + text = fmt.Sprintf("[%s] Repository deleted by %s", p.Repository.FullName, senderLink) + } + + return &SlackPayload{ + Channel: slack.Channel, + Text: text, + Username: slack.Username, + IconURL: slack.IconURL, + Attachments: []SlackAttachment{{ + Color: slack.Color, + Title: title, + Text: attachmentText, + }}, + }, nil +} + // GetSlackPayload converts a slack webhook into a SlackPayload func GetSlackPayload(p api.Payloader, event HookEventType, meta string) (*SlackPayload, error) { s := new(SlackPayload) @@ -205,6 +229,8 @@ func GetSlackPayload(p api.Payloader, event HookEventType, meta string) (*SlackP return getSlackPushPayload(p.(*api.PushPayload), slack) case HookEventPullRequest: return getSlackPullRequestPayload(p.(*api.PullRequestPayload), slack) + case HookEventRepository: + return getSlackRepositoryPayload(p.(*api.RepositoryPayload), slack) } return s, nil |