Skip to content

Commit

Permalink
ci: Added workflow to check project assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
HajekOndrej committed Dec 11, 2024
1 parent 27542eb commit 2519489
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/bot-project-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Check Project Assignment

on:
pull_request:
types:
- opened

jobs:
check-project:
runs-on: ubuntu-latest
steps:
- name: Check if PR is assigned to a project
env:
GITHUB_TOKEN: ${{ secrets.TREZOR_BOT_TOKEN }}
run: |
# Fetch PR labels
PR_LABELS=$(gh api repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels --jq '.[].name')
# Check for "no-project" label
if echo "$PR_LABELS" | grep -q "^no-project$"; then
echo "Pass: The PR has the 'no-project' label."
exit 0
fi
# Get project items associated with the PR
PROJECT_ITEMS=$(gh api graphql -f query='
query($owner: String!, $repo: String!, $number: Int!) {
repository(owner: $owner, name: $repo) {
pullRequest(number: $number) {
projectItems(first: 10) {
nodes {
id
}
}
}
}
}' -F owner=${{ github.repository_owner }} -F repo=${{ github.event.repository.name }} -F number=${{ github.event.pull_request.number }} --jq '.data.repository.pullRequest.projectItems.nodes')
# Check if projectItems is empty
if [ "$PROJECT_ITEMS" == "[]" ]; then
echo "Error: This PR is not assigned to any project and does not have the 'no-project' label."
echo "Please assign the PR to a corresponding project. If it is not applicable add label 'no-project'"
exit 1
else
echo "Pass: This PR is assigned to a project."
fi

0 comments on commit 2519489

Please sign in to comment.