From 4620fa3cf580b7e4f4545972437b26cb38c8533c Mon Sep 17 00:00:00 2001 From: Faith Kangai Date: Wed, 12 Jun 2024 12:36:15 +0300 Subject: [PATCH] Chore: Sync Language label on project with language label on the issue --- .github/workflows/project-auto-add.yml | 41 +++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/.github/workflows/project-auto-add.yml b/.github/workflows/project-auto-add.yml index a6ebb10d30..3edae2d3b9 100644 --- a/.github/workflows/project-auto-add.yml +++ b/.github/workflows/project-auto-add.yml @@ -86,7 +86,7 @@ jobs: echo 'ITEM_ID='$item_id >> $GITHUB_ENV - - name: Set Language + - name: Set Language to Project env: GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }} run: | @@ -108,3 +108,42 @@ jobs: } } }' -f project=$PROJECT_ID -f item=$ITEM_ID -f language_field=$LANGUAGE_FIELD_ID -f language_value=${{ env.LANGUAGE_OPTION_ID }} --silent + + - name: Get label for selected language in repository + if: ${{ env.SELECTED_LANGUAGE != 'Multiple Languages'}} + env: + GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }} + run: | + gh api graphql -f query=' + query($repoOwner: String!, $repoName: String!) { + repository(owner: $repoOwner, name: $repoName) { + id, + labels(first: 100) { + nodes{ + id, + name + } + } + } + }' -f repoOwner=${{github.repository_owner}} -f repoName=${{github.event.repository.name}} > issue_data.json + + echo 'LANGUAGELABEL_ID='$(jq --arg lang "$SELECTED_LANGUAGE" '.data.repository.labels.nodes[] | select(.name==$lang) | .id' issue_data.json) >> $GITHUB_ENV + + - name: Add label to issue + if: ${{ env.SELECTED_LANGUAGE != 'Multiple Languages'}} + env: + GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }} + ISSUE_ID: ${{ github.event_name == 'issues' && github.event.issue.node_id || github.event.pull_request.node_id }} + run: | + gh api graphql -f query=' + mutation ( + $issue: ID! + $label: ID! + ) { + addLabelsToLabelable(input: { + labelableId: $issue + labelIds : [$label] + }) { + clientMutationId + } + }' -f issue=$ISSUE_ID -f label=$LANGUAGELABEL_ID --silent