diff options
author | 谈笑风生间 <makonike@anyview.fun> | 2023-05-25 10:06:27 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-24 22:06:27 -0400 |
commit | 309354c70ee994a1e8f261d7bc24e7473e601d02 (patch) | |
tree | 89a96f611eef8b37e17dcead9767ff8d9ba976ef /modules | |
parent | 93c6a9a652460f89fc719024c435cacbb235d302 (diff) | |
download | gitea-309354c70ee994a1e8f261d7bc24e7473e601d02.tar.gz gitea-309354c70ee994a1e8f261d7bc24e7473e601d02.zip |
New webhook trigger for receiving Pull Request review requests (#24481)
close https://github.com/go-gitea/gitea/issues/16321
Provided a webhook trigger for requesting someone to review the Pull
Request.
Some modifications have been made to the returned `PullRequestPayload`
based on the GitHub webhook settings, including:
- add a description of the current reviewer object as
`RequestedReviewer` .
- setting the action to either **review_requested** or
**review_request_removed** based on the operation.
- adding the `RequestedReviewers` field to the issues_model.PullRequest.
This field will be loaded into the PullRequest through
`LoadRequestedReviewers()` when `ToAPIPullRequest` is called.
After the Pull Request is merged, I will supplement the relevant
documentation.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/structs/hook.go | 21 | ||||
-rw-r--r-- | modules/structs/pull.go | 27 | ||||
-rw-r--r-- | modules/webhook/structs.go | 41 | ||||
-rw-r--r-- | modules/webhook/type.go | 3 |
4 files changed, 50 insertions, 42 deletions
diff --git a/modules/structs/hook.go b/modules/structs/hook.go index df5da6790f..cd91d4bc46 100644 --- a/modules/structs/hook.go +++ b/modules/structs/hook.go @@ -342,6 +342,10 @@ const ( HookIssueDemilestoned HookIssueAction = "demilestoned" // HookIssueReviewed is an issue action for when a pull request is reviewed HookIssueReviewed HookIssueAction = "reviewed" + // HookIssueReviewRequested is an issue action for when a reviewer is requested for a pull request. + HookIssueReviewRequested HookIssueAction = "review_requested" + // HookIssueReviewRequestRemoved is an issue action for removing a review request to someone on a pull request. + HookIssueReviewRequestRemoved HookIssueAction = "review_request_removed" ) // IssuePayload represents the payload information that is sent along with an issue event. @@ -381,14 +385,15 @@ type ChangesPayload struct { // PullRequestPayload represents a payload information of pull request event. type PullRequestPayload struct { - Action HookIssueAction `json:"action"` - Index int64 `json:"number"` - Changes *ChangesPayload `json:"changes,omitempty"` - PullRequest *PullRequest `json:"pull_request"` - Repository *Repository `json:"repository"` - Sender *User `json:"sender"` - CommitID string `json:"commit_id"` - Review *ReviewPayload `json:"review"` + Action HookIssueAction `json:"action"` + Index int64 `json:"number"` + Changes *ChangesPayload `json:"changes,omitempty"` + PullRequest *PullRequest `json:"pull_request"` + RequestedReviewer *User `json:"requested_reviewer"` + Repository *Repository `json:"repository"` + Sender *User `json:"sender"` + CommitID string `json:"commit_id"` + Review *ReviewPayload `json:"review"` } // JSONPayload FIXME diff --git a/modules/structs/pull.go b/modules/structs/pull.go index f64bb83af9..a4a6f60b05 100644 --- a/modules/structs/pull.go +++ b/modules/structs/pull.go @@ -9,19 +9,20 @@ import ( // PullRequest represents a pull request type PullRequest struct { - ID int64 `json:"id"` - URL string `json:"url"` - Index int64 `json:"number"` - Poster *User `json:"user"` - Title string `json:"title"` - Body string `json:"body"` - Labels []*Label `json:"labels"` - Milestone *Milestone `json:"milestone"` - Assignee *User `json:"assignee"` - Assignees []*User `json:"assignees"` - State StateType `json:"state"` - IsLocked bool `json:"is_locked"` - Comments int `json:"comments"` + ID int64 `json:"id"` + URL string `json:"url"` + Index int64 `json:"number"` + Poster *User `json:"user"` + Title string `json:"title"` + Body string `json:"body"` + Labels []*Label `json:"labels"` + Milestone *Milestone `json:"milestone"` + Assignee *User `json:"assignee"` + Assignees []*User `json:"assignees"` + RequestedReviewers []*User `json:"requested_reviewers"` + State StateType `json:"state"` + IsLocked bool `json:"is_locked"` + Comments int `json:"comments"` HTMLURL string `json:"html_url"` DiffURL string `json:"diff_url"` diff --git a/modules/webhook/structs.go b/modules/webhook/structs.go index 96012de352..927a91a74c 100644 --- a/modules/webhook/structs.go +++ b/modules/webhook/structs.go @@ -5,26 +5,27 @@ package webhook // HookEvents is a set of web hook events type HookEvents struct { - Create bool `json:"create"` - Delete bool `json:"delete"` - Fork bool `json:"fork"` - Issues bool `json:"issues"` - IssueAssign bool `json:"issue_assign"` - IssueLabel bool `json:"issue_label"` - IssueMilestone bool `json:"issue_milestone"` - IssueComment bool `json:"issue_comment"` - Push bool `json:"push"` - PullRequest bool `json:"pull_request"` - PullRequestAssign bool `json:"pull_request_assign"` - PullRequestLabel bool `json:"pull_request_label"` - PullRequestMilestone bool `json:"pull_request_milestone"` - PullRequestComment bool `json:"pull_request_comment"` - PullRequestReview bool `json:"pull_request_review"` - PullRequestSync bool `json:"pull_request_sync"` - Wiki bool `json:"wiki"` - Repository bool `json:"repository"` - Release bool `json:"release"` - Package bool `json:"package"` + Create bool `json:"create"` + Delete bool `json:"delete"` + Fork bool `json:"fork"` + Issues bool `json:"issues"` + IssueAssign bool `json:"issue_assign"` + IssueLabel bool `json:"issue_label"` + IssueMilestone bool `json:"issue_milestone"` + IssueComment bool `json:"issue_comment"` + Push bool `json:"push"` + PullRequest bool `json:"pull_request"` + PullRequestAssign bool `json:"pull_request_assign"` + PullRequestLabel bool `json:"pull_request_label"` + PullRequestMilestone bool `json:"pull_request_milestone"` + PullRequestComment bool `json:"pull_request_comment"` + PullRequestReview bool `json:"pull_request_review"` + PullRequestSync bool `json:"pull_request_sync"` + PullRequestReviewRequest bool `json:"pull_request_review_request"` + Wiki bool `json:"wiki"` + Repository bool `json:"repository"` + Release bool `json:"release"` + Package bool `json:"package"` } // HookEvent represents events that will delivery hook. diff --git a/modules/webhook/type.go b/modules/webhook/type.go index db4ab17931..7042d391b7 100644 --- a/modules/webhook/type.go +++ b/modules/webhook/type.go @@ -26,6 +26,7 @@ const ( HookEventPullRequestReviewRejected HookEventType = "pull_request_review_rejected" HookEventPullRequestReviewComment HookEventType = "pull_request_review_comment" HookEventPullRequestSync HookEventType = "pull_request_sync" + HookEventPullRequestReviewRequest HookEventType = "pull_request_review_request" HookEventWiki HookEventType = "wiki" HookEventRepository HookEventType = "repository" HookEventRelease HookEventType = "release" @@ -46,7 +47,7 @@ func (h HookEventType) Event() string { case HookEventIssues, HookEventIssueAssign, HookEventIssueLabel, HookEventIssueMilestone: return "issues" case HookEventPullRequest, HookEventPullRequestAssign, HookEventPullRequestLabel, HookEventPullRequestMilestone, - HookEventPullRequestSync: + HookEventPullRequestSync, HookEventPullRequestReviewRequest: return "pull_request" case HookEventIssueComment, HookEventPullRequestComment: return "issue_comment" |