From 087c1770ff45c1511c11965bbd66c8c92f5963fb Mon Sep 17 00:00:00 2001 From: "Federico M. Facca" Date: Thu, 28 Sep 2023 14:57:54 +0200 Subject: [PATCH] add-to-project workflow: automatically add reviewers without need of CODEOWNERS (#37) ## Description automatically add reviewers without need of CODEOWNERS, reviewers are added if and only if the PR is not in draft mode. The recommendation is to start the PR in draft mode, and move it to ready only when actually ready for review. While CODEOWNERS is very powerful, it would require to add such file to all repositories. ## Changes Made * add specified team as collaborator (default team is `backend-devs`) * add rowi1de/auto-assign-review-teams@v1.1.3 to add-to-project workflow ## Related Issues Fixes #38 ## Checklist - [x] I have used a PR title that is descriptive enough for a release note. - [x] I have tested these changes locally. - [x] I have added appropriate tests or updated existing tests. - [ ] I have tested these changes on a dedicated VM or a customer VM [name of the VM] - [x] I have added appropriate documentation or updated existing documentation. --------- Co-authored-by: Bot --- .github/workflows/add-to-project.yaml | 34 +++++++++++++++++++++++++++ README.MD | 4 +++- RELEASE_NOTES.md | 2 ++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/.github/workflows/add-to-project.yaml b/.github/workflows/add-to-project.yaml index 42555ab1..8133eaf6 100644 --- a/.github/workflows/add-to-project.yaml +++ b/.github/workflows/add-to-project.yaml @@ -7,6 +7,7 @@ on: branches: [ main ] types: - labeled + - ready_for_review workflow_call: inputs: labeled: @@ -16,6 +17,13 @@ on: project-url: required: false type: string + reviewers-team: + required: false + default: 'backend-devs' + type: string + reviewers-individuals: + required: false + type: string jobs: add-to-project: name: Add issue/PR to a project @@ -37,3 +45,29 @@ jobs: if: github.event_name == 'pull_request' with: repo-token: ${{ secrets.GITHUB_TOKEN }} + add-reviewer-to-pr: + name: Assign Reviewer to PR + runs-on: ubuntu-latest + permissions: write-all + steps: + - if: github.event_name == 'pull_request' + run: | + gh api \ + --method PUT \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + /orgs/$OWNER/teams/$TEAM/repos/$OWNER/$REPO \ + -f permission='push' + env: + GITHUB_TOKEN: ${{ secrets.REPO_PAT }} + OWNER: ${{ github.repository_owner }} + REPO: ${{ github.event.repository.name }} + TEAM: ${{ inputs.reviewers-team != '' && inputs.reviewers-team || 'backend-devs' }} + - if: github.event_name == 'pull_request' + uses: rowi1de/auto-assign-review-teams@v1.1.3 + with: + repo-token: ${{ secrets.REPO_PAT }} + teams: ${{ inputs.reviewers-team != '' && inputs.reviewers-team || 'backend-devs' }} # only works for GitHub Organisation/Teams + persons: ${{ inputs.reviewers-individuals }} # add individual persons here + include-draft: false # Draft PRs will be skipped (default: false) + skip-with-manual-reviewers: 1 # Skip this action, if the number of reviwers was already assigned (default: 0) diff --git a/README.MD b/README.MD index bba90c07..d3277d78 100644 --- a/README.MD +++ b/README.MD @@ -8,7 +8,9 @@ The repository includes: issue or PR is added to a repository, it is also added - by default - to the [SynchroHub platform project](https://github.com/orgs/zaphiro-technologies/projects/2) or to the project defined by `project-url` input parameter with status `new`. - When a new PR is added, the PR is assigned to its creator. + When a new PR is added, the PR is assigned to its creator. When a PR is set to + ready, reviewers from `reviewers-team` input parameter (default value + 'backend-devs') or `reviewers-individuals` (comma separated) are added. - [check-pr](.github/workflows/check-pr.yaml) workflow: when a new PR is added to a repository or any change occurs to the pr, the pr is validated to be sure that labels are valid. diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 385d9651..7c41a36e 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -4,6 +4,8 @@ ### Features +- add-to-project workflow: automatically add reviewers without need of + CODEOWNERS (PR #37 by @chicco785) - add-to-project workflow: automatically assign pr to its creator (PR #36 by @chicco785) - add-to-project workflow: make project url configurable as input parameter (PR