|
4 | 4 | # License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | 5 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
6 | 6 |
|
| 7 | +import enum |
| 8 | + |
7 | 9 | from github import Auth, GithubIntegration |
8 | 10 | from github.PullRequest import ReviewComment |
9 | 11 |
|
10 | 12 | from code_review_bot import Issue |
11 | 13 | from code_review_bot.revisions import GithubRevision |
12 | 14 |
|
13 | 15 |
|
| 16 | +class ReviewEvent(enum.Enum): |
| 17 | + """ |
| 18 | + Review action you want to perform. |
| 19 | + https://docs.github.com/en/rest/pulls/reviews?apiVersion=2022-11-28#create-a-review-for-a-pull-request--parameters |
| 20 | + """ |
| 21 | + |
| 22 | + Pending = "PENDING" |
| 23 | + Approved = "APPROVE" |
| 24 | + RequestChanges = "REQUEST_CHANGES" |
| 25 | + Comment = "COMMENT" |
| 26 | + |
| 27 | + |
14 | 28 | class GithubClient: |
15 | 29 | def __init__(self, client_id: str, pem_key_path: str, installation_id: str): |
16 | 30 | self.client_id = client_id |
@@ -42,17 +56,22 @@ def _build_review_comment(self, issue): |
42 | 56 | ) |
43 | 57 |
|
44 | 58 | def publish_review( |
45 | | - self, issues: list[Issue], revision: GithubRevision, message: str |
| 59 | + self, |
| 60 | + issues: list[Issue], |
| 61 | + revision: GithubRevision, |
| 62 | + message: str, |
| 63 | + event: ReviewEvent, |
46 | 64 | ): |
47 | 65 | """ |
48 | 66 | Publish a review from a list of publishable issues, requesting changes to the author. |
49 | 67 | """ |
50 | 68 | repo = self.api.get_repo(revision.repo_name) |
51 | 69 | pull_request = repo.get_pull(revision.pull_number) |
| 70 | + |
52 | 71 | pull_request.create_review( |
53 | 72 | commit=repo.get_commit(revision.pull_head_sha), |
54 | 73 | body=message, |
55 | 74 | comments=[self._build_review_comment(issue) for issue in issues], |
56 | 75 | # https://docs.github.com/en/rest/pulls/reviews?apiVersion=2022-11-28#create-a-review-for-a-pull-request |
57 | | - event="REQUEST_CHANGES", |
| 76 | + event=event.value, |
58 | 77 | ) |
0 commit comments