-
-
Notifications
You must be signed in to change notification settings - Fork 267
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 8118787
Showing
1 changed file
with
48 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,48 @@ | ||
name: Check Project Assignment | ||
|
||
on: | ||
pull_request: | ||
types: | ||
- opened | ||
|
||
jobs: | ||
check-project: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Check if PR is assigned to a project or has "no-project" label | ||
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 "The PR has the 'no-project' label. Check passed." | ||
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." | ||
exit 1 | ||
else | ||
echo "Success: This PR is assigned to a project." | ||
fi |