Skip to content

Commit

Permalink
ci: use git diff to add M-database-changes label for pr that contai…
Browse files Browse the repository at this point in the history
…ns migrations and schema changes (#4625)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
  • Loading branch information
ShankarSinghC and hyperswitch-bot[bot] committed Jun 10, 2024
1 parent 894560f commit 49c9f19
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/pr-convention-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,60 @@ jobs:
exit 1
fi
done <<< "${linked_issues}"
pr_labeler:
name: Attach suitable labels to PR
if: ${{ github.event_name == 'pull_request_target' }}
runs-on: ubuntu-latest

steps:
- name: Generate GitHub app token
id: generate_app_token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.HYPERSWITCH_BOT_APP_ID }}
private-key: ${{ secrets.HYPERSWITCH_BOT_APP_PRIVATE_KEY }}
owner: ${{ github.event.repository.owner.login }}

- name: Get files changed
env:
GH_TOKEN: ${{ steps.generate_app_token.outputs.token }}
shell: bash
run: |
migration_and_schema_changes=false
openapi_changes=false
files_changed="$(gh api --header "Accept: application/vnd.github+json" --header "X-GitHub-Api-Version: 2022-11-28" --paginate https://api.github.com/repos/juspay/hyperswitch/pulls/${{ github.event.pull_request.number }}/files --jq '.[] | .filename')"
if echo "${files_changed}" | grep --quiet --extended-regexp '(^migrations/.*/(up|down)\.sql$|^crates/diesel_models/src/schema.rs$)' ; then
migration_and_schema_changes='true'
fi
if echo "${files_changed}" | grep --quiet --extended-regexp '^(api-reference/openapi_spec.json)$'; then
openapi_changes='true'
fi
echo "migration_and_schema_changes=${migration_and_schema_changes}" >> "${GITHUB_ENV}"
echo "openapi_changes=${openapi_changes}" >> "${GITHUB_ENV}"
- name: Add/Remove 'M-database-changes' based on Migration or Schema changes
shell: bash
env:
GH_TOKEN: ${{ steps.generate_app_token.outputs.token }}
run: |
if ${{ env.migration_and_schema_changes == 'true' }}; then
gh --repo ${{ github.event.repository.full_name }} pr edit --add-label 'M-database-changes' ${{ github.event.pull_request.number }}
else
gh --repo ${{ github.event.repository.full_name }} pr edit --remove-label 'M-database-changes' ${{ github.event.pull_request.number }}
fi
- name: Add/Remove 'M-api-contract-changes' based on OpenAPI Spec changes
shell: bash
env:
GH_TOKEN: ${{ steps.generate_app_token.outputs.token }}
run: |
if ${{ env.openapi_changes == 'true' }}; then
gh --repo ${{ github.event.repository.full_name }} pr edit --add-label 'M-api-contract-changes' ${{ github.event.pull_request.number }}
else
gh --repo ${{ github.event.repository.full_name }} pr edit --remove-label 'M-api-contract-changes' ${{ github.event.pull_request.number }}
fi

0 comments on commit 49c9f19

Please sign in to comment.