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
Next Next commit
started work on allowing pr approval/rejection... Untested though
  • Loading branch information
adelowo committed Oct 6, 2018
commit 17f9a8776ce32bcf913dff21de5d026edd43df89
29 changes: 29 additions & 0 deletions models/review.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/util"
api "code.gitea.io/sdk/gitea"
"github.com/go-xorm/xorm"

"github.com/go-xorm/builder"
Expand Down Expand Up @@ -216,6 +217,34 @@ func createReview(e Engine, opts CreateReviewOptions) (*Review, error) {
if _, err := e.Insert(review); err != nil {
return nil, err
}

var reviewHookType HookEventType
var action api.HookIssueAction

if opts.Type == ReviewTypeApprove {
reviewHookType = HookEventPullRequestApproved
action = api.HookPullRequestApproved
} else if opts.Type == ReviewTypeReject {
reviewHookType = HookEventPullRequestRejected
action = api.HookPullRequestRejected
} else {
// Webhook for a review comment does not exists
return review, nil
}

mode, _ := AccessLevel(opts.Issue.Poster.ID, opts.Issue.Repo)
if err := PrepareWebhooks(opts.Issue.Repo, reviewHookType, &api.PullRequestPayload{
Action: action,
Index: opts.Issue.Index,
PullRequest: opts.Issue.PullRequest.APIFormat(),
Repository: opts.Issue.Repo.APIFormat(mode),
Sender: opts.Reviewer.APIFormat(),
}); err != nil {
return nil, err
} else {
go HookQueue.Add(opts.Issue.Repo.RepoID)
}

return review, nil
}

Expand Down
20 changes: 11 additions & 9 deletions models/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,15 +425,17 @@ type HookEventType string

// Types of hook events
const (
HookEventCreate HookEventType = "create"
HookEventDelete HookEventType = "delete"
HookEventFork HookEventType = "fork"
HookEventPush HookEventType = "push"
HookEventIssues HookEventType = "issues"
HookEventIssueComment HookEventType = "issue_comment"
HookEventPullRequest HookEventType = "pull_request"
HookEventRepository HookEventType = "repository"
HookEventRelease HookEventType = "release"
HookEventCreate HookEventType = "create"
HookEventDelete HookEventType = "delete"
HookEventFork HookEventType = "fork"
HookEventPush HookEventType = "push"
HookEventIssues HookEventType = "issues"
HookEventIssueComment HookEventType = "issue_comment"
HookEventPullRequest HookEventType = "pull_request"
HookEventRepository HookEventType = "repository"
HookEventRelease HookEventType = "release"
HookEventPullRequestApproved HookEventType = "pr_approved"
HookEventPullRequestRejected HookEventType = "pr_rejected"
)

// HookRequest represents hook task request information.
Expand Down
2 changes: 1 addition & 1 deletion options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ settings.event_issue_comment_desc = Issue comment created, edited, or deleted.
settings.event_release = Release
settings.event_release_desc = Release published, updated or deleted in a repository.
settings.event_pull_request = Pull Request
settings.event_pull_request_desc = Pull request opened, closed, reopened, edited, assigned, unassigned, label updated, label cleared or synchronized.
settings.event_pull_request_desc = Pull request opened, closed, reopened, edited, approved, rejected, assigned, unassigned, label updated, label cleared or synchronized.
adelowo marked this conversation as resolved.
Show resolved Hide resolved
settings.event_push = Push
settings.event_push_desc = Git push to a repository.
settings.event_repository = Repository
Expand Down
6 changes: 6 additions & 0 deletions vendor/code.gitea.io/sdk/gitea/hook.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.