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

Webhook for Pull Request approval/rejection #5027

Merged
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
17f9a87
started work on allowing pr approval/rejection... Untested though
adelowo Oct 6, 2018
1d478c9
whoops
adelowo Oct 6, 2018
b5564d6
fix pr#Issue being nil
adelowo Oct 6, 2018
e92bef5
updated hook name
adelowo Oct 6, 2018
b549837
properly format webhook for slack
adelowo Oct 6, 2018
d2cfc93
remove redundant newline
adelowo Oct 6, 2018
8969baf
remove redundant comment
adelowo Oct 6, 2018
5ed0dbc
fix make lint
adelowo Oct 6, 2018
59f4f5a
fix build
adelowo Oct 6, 2018
1923bd9
add webhook formatting for discord
adelowo Oct 6, 2018
50f4846
add webhook formatting for dingtalk
adelowo Oct 6, 2018
ce77646
try to fix naming
adelowo Oct 6, 2018
d517038
Merge branch 'master' of https://github.com/go-gitea/gitea into webho…
adelowo Oct 6, 2018
73fc34e
Merge remote-tracking branch 'origin/master' into webhook_for_pr_appr…
adelowo Oct 9, 2018
d1c234c
add error handling
adelowo Oct 9, 2018
67259f0
fix style guide
adelowo Oct 9, 2018
0770f77
add support for pull request comment webhooks
adelowo Oct 23, 2018
745c619
Merge branch 'master' of https://github.com/go-gitea/gitea into webho…
adelowo Oct 23, 2018
0f698bb
fix naming
adelowo Oct 23, 2018
d2577fc
remove redundant comment and update translations
adelowo Oct 24, 2018
50e0ae1
fix merge conflicts
adelowo Dec 11, 2018
c03bd6f
Merge branch 'master' into webhook_for_pr_approval_rejection
techknowlogick Dec 27, 2018
25f4aac
Merge branch 'master' into webhook_for_pr_approval_rejection
techknowlogick Dec 27, 2018
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
Prev Previous commit
Next Next commit
properly format webhook for slack
  • Loading branch information
adelowo committed Oct 6, 2018
commit b549837ec40aac424274b379d0c3e652a9068825
34 changes: 34 additions & 0 deletions models/webhook_slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,38 @@ func getSlackPullRequestPayload(p *api.PullRequestPayload, slack *SlackMeta) (*S
}, nil
}

func getSlackPullRequestApprovalPayload(p *api.PullRequestPayload, slack *SlackMeta, event HookEventType) (*SlackPayload, error) {
senderLink := SlackLinkFormatter(setting.AppURL+p.Sender.UserName, p.Sender.UserName)
titleLink := SlackLinkFormatter(fmt.Sprintf("%s/pulls/%d", p.Repository.HTMLURL, p.Index),
fmt.Sprintf("#%d %s", p.Index, p.PullRequest.Title))
var text, title, attachmentText string
switch p.Action {
case api.HookIssueSynchronized:
var action string
if event == HookEventPullRequestRejected {
action = "rejected"
} else if event == HookEventPullRequestApproved {
action = "approved"
} else {
return nil, errors.New("unkown event type")
}

text = fmt.Sprintf("[%s] Review on pull request %s : %s by %s", p.Repository.FullName, action, titleLink, senderLink)
}

return &SlackPayload{
Channel: slack.Channel,
Text: text,
Username: slack.Username,
IconURL: slack.IconURL,
Attachments: []SlackAttachment{{
Color: slack.Color,
Title: title,
Text: attachmentText,
}},
}, 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
Expand Down Expand Up @@ -376,6 +408,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 HookEventPullRequestRejected, HookEventPullRequestApproved:
return getSlackPullRequestApprovalPayload(p.(*api.PullRequestPayload), slack, event)
case HookEventRepository:
return getSlackRepositoryPayload(p.(*api.RepositoryPayload), slack)
case HookEventRelease:
Expand Down