From 2208a24c72a0a86a2f09f7ed30d97729925791ac Mon Sep 17 00:00:00 2001 From: Josh Hunt Date: Wed, 16 Apr 2025 14:48:34 +0100 Subject: [PATCH] Chore: Action to add issues to Skye project board (#104102) * Chore: Action to add issues to Skye project board * codeowners --- .github/CODEOWNERS | 1 + .github/workflows/skye-add-to-project.yml | 75 +++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 .github/workflows/skye-add-to-project.yml diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 153689c4e27..963e31af5d7 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -828,6 +828,7 @@ embed.go @grafana/grafana-as-code /.github/workflows/analytics-events-report.yml @grafana/grafana-frontend-platform /.github/workflows/pr-e2e-tests.yml @grafana/grafana-developer-enablement-squad /.github/workflows/run-e2e-suite.yml @grafana/grafana-developer-enablement-squad +/.github/workflows/skye-add-to-project.yml @grafana/grafana-frontend-platform # Generated files not requiring owner approval /packages/grafana-data/src/types/featureToggles.gen.ts @grafanabot diff --git a/.github/workflows/skye-add-to-project.yml b/.github/workflows/skye-add-to-project.yml new file mode 100644 index 00000000000..ba70b22a2b5 --- /dev/null +++ b/.github/workflows/skye-add-to-project.yml @@ -0,0 +1,75 @@ +name: Add new issues/PRs to project +on: + issues: + types: [opened] + pull_request: + types: [opened] + +# permissions: +# contents: read +# id-token: write + +env: + ORGANIZATION: grafana + REPO: grafana + PROJECT_ID: "PVT_kwDOAG3Mbc4AxfcI" # Retrieved manually from GitHub GraphQL Explorer + +concurrency: + group: skye-add-to-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: + # Vault secret paths: + # - ci/repo/grafana/grafana/plugins_platform_issue_commands_github_bot + # - ci/repo/grafana/grafana/frontend_platform_skye_usernames (comma separated list of usernames) + repo_secrets: | + GH_APP_ID=plugins_platform_issue_commands_github_bot:app_id + GH_APP_PEM=plugins_platform_issue_commands_github_bot:app_pem + ALLOWED_USERS=frontend_platform_skye_usernames:allowed_users + + - name: "Generate token" + id: generate_token + uses: tibdex/github-app-token@b62528385c34dbc9f38e5f4225ac829252d1ea92 + with: + app_id: ${{ env.GH_APP_ID }} + private_key: ${{ env.GH_APP_PEM }} + + - name: Check if user is allowed + id: check_user + run: | + # Convert the comma-separated list to an array + IFS=',' read -ra ALLOWED_USERS <<< "${{ env.ALLOWED_USERS }}" + USERNAME="${{ github.event.sender.login }}" + + # Check if user is in the allowed list + for allowed_user in "${ALLOWED_USERS[@]}"; do + if [ "$allowed_user" = "$USERNAME" ]; then + echo "user_allowed=true" >> $GITHUB_OUTPUT + exit 0 + fi + done + echo "user_allowed=false" >> $GITHUB_OUTPUT + + - name: Add to project board + if: steps.check_user.outputs.user_allowed == 'true' + uses: octokit/graphql-action@v2.x + with: + projectid: ${{ env.PROJECT_ID }} + itemid: ${{ env.PULL_REQUEST_ID }} + query: | + mutation addPullRequestToProject($projectid: ID!, $itemid: ID!){ + addProjectV2ItemById(input: {projectId: $projectid, contentId: $itemid}) { + item { + id + } + } + } + env: + GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }} \ No newline at end of file