Skip to content

Instantly share code, notes, and snippets.

@ferreiratiago
Created April 18, 2023 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ferreiratiago/f6041b68f7cd9946bcf5a97e710dc764 to your computer and use it in GitHub Desktop.
Save ferreiratiago/f6041b68f7cd9946bcf5a97e710dc764 to your computer and use it in GitHub Desktop.
Use case based on file paths
# Define the groups of reviewers to use in the workflows.
groups:
- name: cloudplatform-admin
groups: '["@myorg/cloudplatform-admin"]'
- name: appteam1
groups: '["@myorg/appteam1"]'
# Define the rules to use in the workflows.
# This is useful to avoid repeating the same logic in multiple workflows.
rules:
- name: only-changes-platform-dev
spec: '$all($filesPath(), ($fp: String => $matchString("^platform\/dev\/.*", $fp)))'
# Define the workflows to run on pull requests.
workflows:
# Assign reviewers for every pull request based on the files changed.
- name: assign-reviewers
run:
# Run the workflow only if there are changes that go beyond the platform/dev files.
- if: '!$rule("only-changes-platform-dev")'
then:
- $assignTeamReviewer($groups("cloudplatform-admin"))
# Also assign the app team if there are changes to the platform/test folder.
- if: $hasFilePattern("platform/test/**")
then: $assignTeamReviewer(["@myorg/appteam1"])
# Verify that the required reviewers have approved the pull request based on the files changed.
- name: required-reviews
run:
# Run the workflow only if there are changes that go beyond the platform/dev files.
- if: '!$rule(only-changes-platform-dev)'
then:
- if: '!$hasRequiredTeamApprovals($group("cloudplatform-admin"))'
# Fail the workflow if the required reviewers have not approved the pull request.
# This allows us to block the merge button using the GitHub branch protection rules. This is done by setting the required status checks for "reviewpad".
then: $fail($sprintf("The team %s needs to review the pull request", [$join($group("cloudplatform-admin"), ", ")]))
- if: '!$hasFilePattern("platform/test/**") && $hasRequiredTeamApprovals($group("appteam1"))'
then: $fail($sprintf("The team %s needs to review the pull request", [$join($group("appteam1"), ", ")]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment