From caff90cf0f80adc109893c889a3d514ec0517650 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Thu, 13 Jun 2024 11:00:37 +1200 Subject: [PATCH] NEW Create GitHub Action for adding PRs to the new project --- README.md | 29 +++++++++++++++++++++++++++++ action.yml | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 action.yml diff --git a/README.md b/README.md index e69de29..9ddf59a 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,29 @@ +# GitHub Actions - Add PR to project + +Add community-created pull requests to the [Community Contributions project](https://github.com/orgs/silverstripe/projects/4) when they're opened. + +## Usage + +**.github/workflows/add-pr-to-project.yml** +```yml +name: Add new pull requests to a github project + +on: + pull_request: + types: + - opened + - ready_for_review + +permissions: {} + +jobs: + addprtoproject: + # Only run on the silverstripe account + if: github.repository_owner == 'silverstripe' + runs-on: ubuntu-latest + steps: + - name: Add PR to github project + uses: silverstripe/add-pr-to-project@v1 +``` + +This action has no inputs. diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..05a4a53 --- /dev/null +++ b/action.yml @@ -0,0 +1,44 @@ +name: Add pull request to project +description: GitHub Action to add new pull requests to the Community Contributions GitHub project + +runs: + using: composite + steps: + + - name: Check if should be added + id: check-if-should-add + env: + PR_AUTHOR: ${{ github.event.pull_request.user.login }} + IS_DRAFT: ${{ github.event.pull_request.draft }} + run: | + if [[ $IS_DRAFT == 'true' ]]; then + echo "PR is draft. Skipping." + echo "should_add_to_project=false" >> $GITHUB_OUTPUT + exit 0 + fi + # We don't want CMS Squad member PRs to clutter the project board + echo "Author is $PR_AUTHOR" + for squad_member in 'GuySartorelli' 'emteknetnz' 'maxime-rainville'; do + if [[ $PR_AUTHOR == $squad_member ]]; then + echo "Author is in CMS Squad. Skipping." + echo "should_add_to_project=false" >> $GITHUB_OUTPUT + exit 0 + fi + done + echo "should_add_to_project=true" >> $GITHUB_OUTPUT + + - name: Generate token + id: generate-token + if: steps.check-if-should-add.outputs.should_add_to_project == 'true' && github.repository_owner == 'silverstripe' + uses: actions/create-github-app-token@v1 + with: + app-id: ${{ vars.PROJECT_PERMISSIONS_APP_ID }} + private-key: ${{ secrets.PROJECT_PERMISSIONS_APP_PRIVATE_KEY }} + + - name: Add to project + if: steps.check-if-should-add.outputs.should_add_to_project == 'true' + uses: actions/add-to-project@v1.0.1 + with: + # Add to the Community Contributions project + project-url: https://github.com/orgs/silverstripe/projects/4 + github-token: ${{ steps.generate-token.outputs.token }}