-
-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: Added workflow to check project assignment
- Loading branch information
1 parent
27542eb
commit 2519489
Showing
1 changed file
with
46 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,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 |