From 1c8f938942487de534b918e32ac870db5888af34 Mon Sep 17 00:00:00 2001 From: driazati Date: Wed, 19 Jan 2022 13:17:01 -0800 Subject: [PATCH 1/2] [skip ci] Make cc bot skip errors This adds some better logging and ignores errors (this job shouldn't ever show up as a PR failure) so we can diagnose things like https://github.com/apache/tvm/runs/4873810315?check_suite_focus=true --- .github/workflows/cc_bot.yml | 2 +- tests/scripts/git_utils.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/cc_bot.yml b/.github/workflows/cc_bot.yml index dd50eba79358..873fafa82a60 100644 --- a/.github/workflows/cc_bot.yml +++ b/.github/workflows/cc_bot.yml @@ -43,4 +43,4 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | set -eux - python tests/scripts/github_cc_reviewers.py + python tests/scripts/github_cc_reviewers.py || echo step failed diff --git a/tests/scripts/git_utils.py b/tests/scripts/git_utils.py index f2927f1e3ab7..530abe8029a6 100644 --- a/tests/scripts/git_utils.py +++ b/tests/scripts/git_utils.py @@ -39,7 +39,7 @@ def graphql(self, query: str) -> Dict[str, Any]: return self._post("https://api.github.com/graphql", {"query": query}) def _post(self, full_url: str, body: Dict[str, Any]) -> Dict[str, Any]: - print("Requesting", full_url) + print("Requesting POST to", full_url, "with", body) req = request.Request(full_url, headers=self.headers(), method="POST") req.add_header("Content-Type", "application/json; charset=utf-8") data = json.dumps(body) @@ -55,7 +55,7 @@ def post(self, url: str, data: Dict[str, Any]) -> Dict[str, Any]: def get(self, url: str) -> Dict[str, Any]: url = self.base + url - print("Requesting", url) + print("Requesting GET to", url) req = request.Request(url, headers=self.headers()) with request.urlopen(req) as response: response = json.loads(response.read()) @@ -63,7 +63,7 @@ def get(self, url: str) -> Dict[str, Any]: def delete(self, url: str) -> Dict[str, Any]: url = self.base + url - print("Requesting", url) + print("Requesting DELETE to", url) req = request.Request(url, headers=self.headers(), method="DELETE") with request.urlopen(req) as response: response = json.loads(response.read()) From f22c5490957202a8f22b9b00819e9f5d8bdd6760 Mon Sep 17 00:00:00 2001 From: driazati Date: Wed, 19 Jan 2022 14:08:20 -0800 Subject: [PATCH 2/2] Submit cc'ed reviewers one at a time --- tests/scripts/github_cc_reviewers.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/scripts/github_cc_reviewers.py b/tests/scripts/github_cc_reviewers.py index 48420822ad55..8e7198aa7b8f 100755 --- a/tests/scripts/github_cc_reviewers.py +++ b/tests/scripts/github_cc_reviewers.py @@ -20,6 +20,7 @@ import json import argparse import re +from urllib import error from typing import Dict, Any, List @@ -70,4 +71,11 @@ def find_reviewers(body: str) -> List[str]: if not args.dry_run: github = GitHubRepo(token=os.environ["GITHUB_TOKEN"], user=user, repo=repo) - github.post(f"pulls/{number}/requested_reviewers", {"reviewers": to_add}) + + # Add reviewers 1 by 1 since GitHub will error out if any of the + # requested reviewers aren't members / contributors + for reviewer in to_add: + try: + github.post(f"pulls/{number}/requested_reviewers", {"reviewers": [reviewer]}) + except error.HTTPError as e: + print(f"Failed to add reviewer {reviewer}: {e}")