Test dashboards squad action #13
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
name: When an issue changes and it's part of the dashboards project, add the dashboards squad label | |
on: | |
issues: | |
types: [opened, closed, edited, reopened, assigned, unassigned, labeled, unlabeled] | |
permissions: | |
contents: read | |
id-token: write | |
env: | |
ORGANIZATION: ${{ github.repository_owner }} | |
REPO: ${{ github.event.repository.name }} | |
TARGET_PROJECT: 202 | |
LABEL_IDs: "LA_kwDOEhD3Oc8AAAAByyy3KQ" | |
concurrency: | |
group: issue-label-when-in-project-${{ github.event.number }} | |
jobs: | |
main: | |
# if: github.repository == 'grafana/grafana' | |
runs-on: ubuntu-latest | |
steps: | |
- name: "Get vault secrets" | |
id: vault-secrets | |
uses: grafana/shared-workflows/actions/get-vault-secrets@main | |
with: | |
# Secrets placed in the ci/repo/grafana/<repo>/<path> path in Vault | |
repo_secrets: | | |
APP_ID=triager_bot_github:app_id | |
APP_PEM=triager_bot_github:app_pem | |
- name: "Generate token" | |
id: generate_token | |
uses: tibdex/github-app-token@b62528385c34dbc9f38e5f4225ac829252d1ea92 | |
with: | |
app_id: ${{ env.APP_ID }} | |
private_key: ${{ env.APP_PEM }} | |
- name: Check if issue is in target project | |
env: | |
GH_TOKEN: ${{ steps.generate_token.outputs.token }} | |
run: | | |
gh api graphql -f query=' | |
query($org: String!, $repo: String!) { | |
repository(name: $repo, owner: $org) { | |
issue (number: ${{ github.event.issue.number }}) { | |
id | |
projectItems(first:20) { | |
nodes { | |
project { | |
number, | |
}, | |
} | |
} | |
} | |
} | |
}' -f org=$ORGANIZATION -f repo=$REPO > projects_data.json | |
echo 'IN_TARGET_PROJ='$(jq '.data.repository.issue.projectItems.nodes[] | select(.project.number==${{ env.TARGET_PROJECT }}) | .project != null' projects_data.json) >> $GITHUB_ENV | |
echo 'ITEM_ID='$(jq '.data.repository.issue.id' projects_data.json) >> $GITHUB_ENV | |
- name: Set up label array | |
if: env.IN_TARGET_PROJ | |
run: | | |
IFS=',' read -ra LABEL_IDs <<< "${{ env.LABEL_IDs }}" | |
for item in "${LABEL_IDs[@]}"; do | |
echo "Item: $item" | |
done | |
- name: Add label to issue | |
if: env.IN_TARGET_PROJ | |
env: | |
GH_TOKEN: ${{ steps.generate_token.outputs.token }} | |
run: | | |
gh api graphql -f query=' | |
mutation ($labelableId: ID!, $labelIds: [ID!]!) { | |
addLabelsToLabelable( | |
input: {labelableId: $labelableId, labelIds: $labelIds} | |
) { | |
clientMutationId | |
} | |
}' -f labelableId=$ITEM_ID -f labelIds=${{ env.LABEL_IDs }} |