-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
""" | ||
© Ocado Group | ||
Created on 05/01/2024 at 14:38:19(+00:00). | ||
Validate a pull request is in the expected state. | ||
""" | ||
|
||
import json | ||
import os | ||
import subprocess | ||
import typing as t | ||
|
||
|
||
def get_inputs(): | ||
"""Get the script's inputs. | ||
Returns: | ||
A tuple with the values (the PR's number, a flag indicating whether or | ||
not to validate the PR's latest review state). | ||
""" | ||
|
||
number = int(os.environ["NUMBER"]) | ||
|
||
review_state = os.getenv("REVIEW_STATE") | ||
if review_state == "": | ||
review_state = None | ||
|
||
return number, review_state | ||
|
||
|
||
def validate_reviews(number: int, state: t.Optional[str] = None): | ||
"""Validate the PR's reviews. | ||
Args: | ||
number: The number of the PR. | ||
state: The expected latest state. | ||
""" | ||
|
||
view = subprocess.run( | ||
[ | ||
"gh", | ||
"pr", | ||
"view", | ||
str(number), | ||
"--json", | ||
"reviews", | ||
], | ||
check=True, | ||
).stdout.decode("utf-8") | ||
|
||
print(view) | ||
|
||
reviews: t.List[t.Dict[str, t.Any]] = json.loads(view)["reviews"] | ||
reviews.sort(key=lambda review: review["submittedAt"]) | ||
|
||
if state is not None: | ||
assert ( | ||
not reviews or reviews[-1]["state"] != state | ||
), f'The latest review is not in the "{state}" state.' | ||
|
||
|
||
def main(): | ||
"""Run the script.""" | ||
|
||
number, review_state = get_inputs() | ||
|
||
# If at least one of the review fields is not None, validate the reviews. | ||
if any(field is not None for field in [review_state]): | ||
validate_reviews(number, review_state) | ||
|
||
|
||
if __name__ == "__main__": | ||
raise Exception("hi") | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# name: Validate Pull Request | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
number: | ||
required: true | ||
type: number | ||
review-state: | ||
required: false | ||
type: string | ||
secrets: | ||
GITHUB_TOKEN: | ||
required: true | ||
|
||
jobs: | ||
validate-pr: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Echo Path | ||
run: echo "${{ github.workflow }}" | ||
|
||
- uses: ocadotechnology/codeforlife-workspace/.github/actions/python/setup-environment@new_contributor_validations # TODO: use @main | ||
with: | ||
python-version: 3.11 | ||
working-directory: ${{ github.workflow }} | ||
|
||
- name: Validate Pull Request | ||
shell: bash | ||
working-directory: ${{ github.workflow }} | ||
run: pipenv run python . | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
NUMBER: ${{ inputs.number }} | ||
REVIEW_STATE: ${{ inputs.review-state }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Verify New Contributor | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
pull-request-number: | ||
description: "The number of the new contributor's PR." | ||
required: true | ||
|
||
jobs: | ||
validate-pr-review-state: | ||
uses: ocadotechnology/codeforlife-workspace/.github/workflows/validate-pull-request/workflow.yaml@new_contributor_validations # TODO: use @main | ||
secrets: inherit | ||
with: | ||
number: ${{ inputs.pull-request-number }} | ||
review-state: APPROVED | ||
|
||
validate-new-contributor: | ||
needs: [validate-pr-review-state] | ||
uses: ocadotechnology/codeforlife-workspace/.github/workflows/validate-new-contributor.yaml@new_contributor_validations # TODO: use @main | ||
|
||
verify-new-contributor: | ||
needs: [validate-new-contributor] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: 📧 Send Verification Email | ||
uses: ocadotechnology/codeforlife-workspace/.github/actions/python/send-email@new_contributor_validations # TODO: use @main | ||
with: | ||
auth: ${{ secrets.DOTDIGITAL_API_USER_AUTH }} | ||
to-addresses: '["${{ env.CONTRIBUTOR_EMAIL_ADDRESS }}"]' | ||
campaign-id: 1506387 | ||
personalization-values: '[{"name": "PR_URL", "value": "${{ github.event.pull_request.html_url }}"}]' |