diff options
author | TSRBerry <20988865+TSRBerry@users.noreply.github.com> | 2023-08-16 23:01:34 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-16 23:01:34 +0200 |
commit | 9b8625d999102df7ac8f8772bd1738778cf4b776 (patch) | |
tree | 419c6e39b4c8b86436d4209b18555a7ca7e3d443 | |
parent | b12ea343d00d5325c95975afa55a3b1e41986f86 (diff) |
Introduce Mako to fix pr_triage workflow (#5574)
* pr_triage: Fix invalid workflow
* Don't assign reviewers to draft PRs
* Add team review request for developers team
* Introduce Mako to make team reviewers work
-rw-r--r-- | .github/reviewers.yml | 2 | ||||
-rw-r--r-- | .github/update_reviewers.py | 24 | ||||
-rw-r--r-- | .github/workflows/pr_triage.yml | 8 |
3 files changed, 22 insertions, 12 deletions
diff --git a/.github/reviewers.yml b/.github/reviewers.yml index c0dc59dd..f50755cc 100644 --- a/.github/reviewers.yml +++ b/.github/reviewers.yml @@ -29,4 +29,4 @@ infra: - TSRBerry default: - - marysaka + - @developers diff --git a/.github/update_reviewers.py b/.github/update_reviewers.py index 14c0cc28..dd1b1e56 100644 --- a/.github/update_reviewers.py +++ b/.github/update_reviewers.py @@ -1,9 +1,10 @@ from pathlib import Path from typing import List, Set -from github import Github +from github import Auth, Github from github.Repository import Repository from github.GithubException import GithubException +import os import sys import yaml @@ -25,6 +26,10 @@ def update_reviewers(config, repo: Repository, pr_id: int) -> int: sys.stderr.writable(f"Unknown PR #{pr_id}\n") return 1 + if pull_request.draft: + print("Not assigning reviewers for draft PRs") + return 0 + pull_request_author = pull_request.user.login reviewers = set() team_reviewers = set() @@ -53,16 +58,19 @@ def update_reviewers(config, repo: Repository, pr_id: int) -> int: if __name__ == "__main__": - if len(sys.argv) != 5: - sys.stderr.write("usage: <token> <repo_path> <pr_id> <config_path>\n") + if len(sys.argv) != 7: + sys.stderr.write("usage: <app_id> <private_key_env_name> <installation_id> <repo_path> <pr_id> <config_path>\n") sys.exit(1) - token = sys.argv[1] - repo_path = sys.argv[2] - pr_id = int(sys.argv[3]) - config_path = Path(sys.argv[4]) + app_id = sys.argv[1] + private_key = os.environ[sys.argv[2]] + installation_id = sys.argv[3] + repo_path = sys.argv[4] + pr_id = int(sys.argv[5]) + config_path = Path(sys.argv[6]) - g = Github(token) + auth = Auth.AppAuth(app_id, private_key).get_installation_auth(installation_id) + g = Github(auth=auth) repo = g.get_repo(repo_path) if not repo: diff --git a/.github/workflows/pr_triage.yml b/.github/workflows/pr_triage.yml index cd90e645..448e2c7d 100644 --- a/.github/workflows/pr_triage.yml +++ b/.github/workflows/pr_triage.yml @@ -27,9 +27,11 @@ jobs: sync-labels: true dot: true + - run: pip3 install PyGithub + - name: Assign reviewers - if: ! github.event.pull_request.draft run: | - pip3 install PyGithub - python3 .github/update_reviewers.py ${{ secrets.GITHUB_TOKEN }} ${{ github.repository }} ${{ github.event.pull_request.number }} .github/reviewers.yml + python3 .github/update_reviewers.py ${{ secrets.MAKO_APP_ID }} "MAKO_PRIVATE_KEY" ${{ secrets.MAKO_INSTALLATION_ID }} ${{ github.repository }} ${{ github.event.pull_request.number }} .github/reviewers.yml shell: bash + env: + MAKO_PRIVATE_KEY: ${{ secrets.MAKO_PRIVATE_KEY }} |