summaryrefslogtreecommitdiffstats
path: root/.github
diff options
context:
space:
mode:
authorMichael Kubacki <michael.kubacki@microsoft.com>2024-07-22 17:42:43 -0400
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2024-07-25 02:28:49 +0000
commit6271b617b4e653029246152871cde93f3926e144 (patch)
tree5abc66c10031cf97d2e184fe98cdc12890af8258 /.github
parent89a06a245bd27c6a83fa2b2ed80cfe186dab0029 (diff)
downloadedk2-6271b617b4e653029246152871cde93f3926e144.tar.gz
.github/workflows/request-reviews.yml: Add workflow
Adds a new GitHub workflow to automatically add reviewers to pull requests when they are opened, reopened, synchronized, and if a draft pull request is marked as ready for review. The workflow will not run on draft pull requests. The workflow is meant to be simple to understand and modify, relying on existing logic in GetMaintainer.py to determine the relevant reviewers and using simple Python GitHub REST API wrappers with the default GitHub token for authentication. Future changes may optimize the workflow. Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Diffstat (limited to '.github')
-rw-r--r--.github/workflows/request-reviews.yml73
1 files changed, 73 insertions, 0 deletions
diff --git a/.github/workflows/request-reviews.yml b/.github/workflows/request-reviews.yml
new file mode 100644
index 0000000000..4f43d56122
--- /dev/null
+++ b/.github/workflows/request-reviews.yml
@@ -0,0 +1,73 @@
+
+# This workflow automatically adds the appropriate reviewers to a pull request.
+#
+# The workflow directly reuses logic in the BaseTools/Scripts/GetMaintainer.py script
+# to determine the appropriate reviewers, so it matches what a user would see running
+# the script locally.
+#
+# Copyright (c) Microsoft Corporation.
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+
+name: Add Pull Request Reviewers
+
+on:
+ pull_request:
+ branches:
+ - master
+ types: [opened, ready_for_review, reopened, synchronize]
+
+env:
+ GET_MAINTAINER_REL_PATH: "BaseTools/Scripts/GetMaintainer.py"
+
+jobs:
+ auto-request-review:
+ name: Add Pull Request Reviewers
+ # Do not run on draft PRs and only run on PRs in the tianocore organization
+ if: ${{ github.event.pull_request.draft == false && github.repository_owner == 'tianocore' }}
+ runs-on: ubuntu-latest
+
+ permissions:
+ contents: read
+ issues: write
+ pull-requests: write
+
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v4
+ with:
+ fetch-depth: 0
+
+ - name: Set up Python
+ uses: actions/setup-python@v5
+ with:
+ python-version: '3.x'
+
+ - name: Install PIP Modules
+ run: pip install edk2-pytool-library edk2-pytool-extensions requests
+
+ - name: Add Reviewers to Pull Request
+ shell: python
+ env:
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ ORG_NAME: ${{ github.repository_owner }}
+ PR_NUMBER: ${{ github.event.number}}
+ REPO_NAME: ${{ github.event.pull_request.base.repo.name }}
+ TARGET_BRANCH: ${{ github.event.pull_request.base.ref }}
+ WORKSPACE_PATH: ${{ github.workspace }}
+ run: |
+ import os
+ import sys
+ sys.path.append(os.path.join(os.environ['WORKSPACE_PATH'], ".github"))
+ from scripts import GitHub
+
+ WORKSPACE_PATH = os.environ['WORKSPACE_PATH']
+ GET_MAINTAINER_LOCAL_PATH = os.path.join(WORKSPACE_PATH, os.environ['GET_MAINTAINER_REL_PATH'])
+
+ reviewers = GitHub.get_reviewers_for_current_branch(WORKSPACE_PATH, GET_MAINTAINER_LOCAL_PATH, f"origin/{os.environ['TARGET_BRANCH']}")
+ if not reviewers:
+ print("::notice title=No Reviewers Found!::No reviewers found for this PR.")
+ sys.exit(1)
+
+ print(f"::notice title=Reviewer List::Reviewers found for PR {os.environ['PR_NUMBER']}:\n{', '.join(reviewers)}")
+
+ GitHub.add_reviewers_to_pr(os.environ['GH_TOKEN'], os.environ['ORG_NAME'], os.environ['REPO_NAME'], os.environ['PR_NUMBER'], reviewers)