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
Show file tree
Hide file tree
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
add support for pull request comment webhooks
  • Loading branch information
adelowo committed Oct 23, 2018
commit 0770f7714c5e21245b7d1cf2463884cac0554136
12 changes: 7 additions & 5 deletions models/review.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/util"
api "code.gitea.io/sdk/gitea"

"github.com/go-xorm/builder"
"github.com/go-xorm/xorm"
adelowo marked this conversation as resolved.
Show resolved Hide resolved
)
Expand Down Expand Up @@ -220,12 +219,15 @@ func createReview(e Engine, opts CreateReviewOptions) (*Review, error) {

var reviewHookType HookEventType

if opts.Type == ReviewTypeApprove {
switch opts.Type {
case ReviewTypeApprove:
reviewHookType = HookEventPullRequestApproved
} else if opts.Type == ReviewTypeReject {
case ReviewTypeComment:
reviewHookType = HookEventPullRequestComment
case ReviewTypeReject:
reviewHookType = HookEventPullRequestRejected
} else {
// Webhook for a review comment does not exists
default:
// unsupported review webhook type here
return review, nil
}

Expand Down
2 changes: 1 addition & 1 deletion models/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"code.gitea.io/gitea/modules/sync"
"code.gitea.io/gitea/modules/util"
api "code.gitea.io/sdk/gitea"

"github.com/Unknwon/com"
gouuid "github.com/satori/go.uuid"
)
Expand Down Expand Up @@ -436,6 +435,7 @@ const (
HookEventRelease HookEventType = "release"
HookEventPullRequestApproved HookEventType = "pull_request_approved"
HookEventPullRequestRejected HookEventType = "pull_request_rejected"
HookEventPullRequestComment HookEventType = "pull_request_commented"
)

// HookRequest represents hook task request information.
Expand Down
5 changes: 2 additions & 3 deletions models/webhook_dingtalk.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

"code.gitea.io/git"
api "code.gitea.io/sdk/gitea"

dingtalk "github.com/lunny/dingtalk_webhook"
)

Expand Down Expand Up @@ -280,7 +279,7 @@ func getDingtalkPullRequestApprovalPayload(p *api.PullRequestPayload, event Hook
return nil, err
}

title = fmt.Sprintf("[%s] Review on pull request %s : #%d %s", p.Repository.FullName, action, p.Index, p.PullRequest.Title)
title = fmt.Sprintf("[%s] Pull request review %s : #%d %s", p.Repository.FullName, action, p.Index, p.PullRequest.Title)
text = p.PullRequest.Body

}
Expand Down Expand Up @@ -396,7 +395,7 @@ func GetDingtalkPayload(p api.Payloader, event HookEventType, meta string) (*Din
return getDingtalkPushPayload(p.(*api.PushPayload))
case HookEventPullRequest:
return getDingtalkPullRequestPayload(p.(*api.PullRequestPayload))
case HookEventPullRequestApproved, HookEventPullRequestRejected:
case HookEventPullRequestApproved, HookEventPullRequestRejected, HookEventPullRequestComment:
return getDingtalkPullRequestApprovalPayload(p.(*api.PullRequestPayload), event)
case HookEventRepository:
return getDingtalkRepositoryPayload(p.(*api.RepositoryPayload))
Expand Down
18 changes: 12 additions & 6 deletions models/webhook_discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ func getDiscordPullRequestApprovalPayload(p *api.PullRequestPayload, meta *Disco
return nil, err
}

title = fmt.Sprintf("[%s] Review on pull request %s: #%d %s", p.Repository.FullName, action, p.Index, p.PullRequest.Title)
title = fmt.Sprintf("[%s] Pull request review %s: #%d %s", p.Repository.FullName, action, p.Index, p.PullRequest.Title)
text = p.PullRequest.Body
color = warnColor
}
Expand Down Expand Up @@ -526,7 +526,7 @@ func GetDiscordPayload(p api.Payloader, event HookEventType, meta string) (*Disc
return getDiscordPushPayload(p.(*api.PushPayload), discord)
case HookEventPullRequest:
return getDiscordPullRequestPayload(p.(*api.PullRequestPayload), discord)
case HookEventPullRequestRejected, HookEventPullRequestApproved:
case HookEventPullRequestRejected, HookEventPullRequestApproved, HookEventPullRequestComment:
return getDiscordPullRequestApprovalPayload(p.(*api.PullRequestPayload), discord, event)
case HookEventRepository:
return getDiscordRepositoryPayload(p.(*api.RepositoryPayload), discord)
Expand All @@ -538,11 +538,17 @@ func GetDiscordPayload(p api.Payloader, event HookEventType, meta string) (*Disc
}

func parseHookPullRequestEventType(event HookEventType) (string, error) {
if event == HookEventPullRequestApproved {

switch event {

case HookEventPullRequestApproved:
return "approved", nil
} else if event == HookEventPullRequestRejected {
case HookEventPullRequestRejected:
return "rejected", nil
}
case HookEventPullRequestComment:
return "comment", nil

return "", errors.New("unknown event type")
default:
return "", errors.New("unknown event type")
}
}
7 changes: 3 additions & 4 deletions models/webhook_slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ import (
"strings"

"code.gitea.io/git"
api "code.gitea.io/sdk/gitea"

"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/sdk/gitea"
)

// SlackMeta contains the slack metadata
Expand Down Expand Up @@ -340,7 +339,7 @@ func getSlackPullRequestApprovalPayload(p *api.PullRequestPayload, slack *SlackM
return nil, err
}

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

return &SlackPayload{
Expand Down Expand Up @@ -404,7 +403,7 @@ 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:
case HookEventPullRequestRejected, HookEventPullRequestApproved, HookEventPullRequestComment:
return getSlackPullRequestApprovalPayload(p.(*api.PullRequestPayload), slack, event)
case HookEventRepository:
return getSlackRepositoryPayload(p.(*api.RepositoryPayload), slack)
Expand Down