From 8118787f9e6098298646b9d34e1ea446b2af96f9 Mon Sep 17 00:00:00 2001 From: Ondrej Hajek Date: Wed, 11 Dec 2024 13:13:01 +0100 Subject: [PATCH] ci: Added workflow to check project assignment --- .github/workflows/bot-project-check.yml | 48 +++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 .github/workflows/bot-project-check.yml diff --git a/.github/workflows/bot-project-check.yml b/.github/workflows/bot-project-check.yml new file mode 100644 index 000000000000..08fde33fa7d2 --- /dev/null +++ b/.github/workflows/bot-project-check.yml @@ -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 \ No newline at end of file