From 77a957206bceef5df226173e684f7398c738fa1e Mon Sep 17 00:00:00 2001 From: Jack Zhang Date: Mon, 18 Nov 2024 22:21:03 -0800 Subject: [PATCH 1/7] Label checker fix --- .github/scripts/check_labels.py | 6 ++++++ .github/scripts/label_utils.py | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/.github/scripts/check_labels.py b/.github/scripts/check_labels.py index 10be42c3fd5..efedc20db54 100644 --- a/.github/scripts/check_labels.py +++ b/.github/scripts/check_labels.py @@ -42,6 +42,9 @@ def main() -> None: repo = GitRepo(get_git_repo_dir(), get_git_remote_name()) org, project = repo.gh_owner_and_name() pr = GitHubPR(org, project, args.pr_num) + print(f"repo: {repo}") + print(f"org, project: {org}, {project}") + print(f"pr: {pr}") try: if not has_required_labels(pr): @@ -50,11 +53,14 @@ def main() -> None: if args.exit_non_zero: sys.exit(1) else: + print("pass") delete_all_label_err_comments(pr) except Exception as e: + print("general exception") if args.exit_non_zero: sys.exit(1) + print("success") sys.exit(0) diff --git a/.github/scripts/label_utils.py b/.github/scripts/label_utils.py index 81668dad0cb..62a1ba9c05e 100644 --- a/.github/scripts/label_utils.py +++ b/.github/scripts/label_utils.py @@ -64,6 +64,7 @@ def get_last_page_num_from_header(header: Any) -> int: @lru_cache def gh_get_labels(org: str, repo: str) -> List[str]: prefix = f"https://api.github.com/repos/{org}/{repo}/labels?per_page=100" + print(f"prefix: {prefix}") header, info = request_for_labels(prefix + "&page=1") labels: List[str] = [] update_labels(labels, info) @@ -76,6 +77,8 @@ def gh_get_labels(org: str, repo: str) -> List[str]: _, info = request_for_labels(prefix + f"&page={page_number}") update_labels(labels, info) + print(f"all labels on gh: {labels}") + return labels @@ -112,11 +115,15 @@ def get_release_notes_labels(org: str, repo: str) -> List[str]: def has_required_labels(pr: "GitHubPR") -> bool: + print(f"pr: {pr}, pr.org: {pr.org}, pr.project: {pr.project}") pr_labels = pr.get_labels() + print(f"pr_labels: {pr_labels}") # Check if PR is not user facing is_not_user_facing_pr = any( label.strip() == "topic: not user facing" for label in pr_labels ) + print(f"is_not_user_facing_pr: {is_not_user_facing_pr}") + print(f"release note labels: {get_release_notes_labels(pr.org, pr.project)}") return is_not_user_facing_pr or any( label.strip() in get_release_notes_labels(pr.org, pr.project) for label in pr_labels From 03fa80edee7ae8858d5ffc3cf20f7caabac77898 Mon Sep 17 00:00:00 2001 From: Jack Zhang Date: Mon, 18 Nov 2024 22:29:06 -0800 Subject: [PATCH 2/7] Try on this pr --- .github/workflows/check-labels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-labels.yml b/.github/workflows/check-labels.yml index 19c70c820a8..bf37090afa6 100644 --- a/.github/workflows/check-labels.yml +++ b/.github/workflows/check-labels.yml @@ -16,7 +16,7 @@ on: # a PR that targets a gh/**/base branch. pull_request: types: [opened, synchronize, reopened, labeled, unlabeled] - branches: [gh/**/base] + branches: [gh/**/base, main] workflow_dispatch: inputs: From 1440c88448c800fadf432417e3a01bf8386e4f48 Mon Sep 17 00:00:00 2001 From: Jack Zhang Date: Mon, 18 Nov 2024 22:36:26 -0800 Subject: [PATCH 3/7] See what's up with topic not user facing --- .github/scripts/check_labels.py | 4 ++++ .github/scripts/github_utils.py | 3 +++ 2 files changed, 7 insertions(+) diff --git a/.github/scripts/check_labels.py b/.github/scripts/check_labels.py index efedc20db54..71a7ad6afbe 100644 --- a/.github/scripts/check_labels.py +++ b/.github/scripts/check_labels.py @@ -12,7 +12,10 @@ def delete_all_label_err_comments(pr: "GitHubPR") -> None: for comment in pr.get_comments(): + print(f"comment: {comment}") if is_label_err_comment(comment): + print("is label err comment") + print(f"comment.database_id: {comment.database_id}") gh_delete_comment(pr.org, pr.project, comment.database_id) @@ -57,6 +60,7 @@ def main() -> None: delete_all_label_err_comments(pr) except Exception as e: print("general exception") + print(e) if args.exit_non_zero: sys.exit(1) diff --git a/.github/scripts/github_utils.py b/.github/scripts/github_utils.py index 1650b93df52..22d77993cbf 100644 --- a/.github/scripts/github_utils.py +++ b/.github/scripts/github_utils.py @@ -74,6 +74,7 @@ def gh_fetch_url( method: Optional[str] = None, reader: Callable[[Any], Any] = lambda x: x.read(), ) -> Any: + print(f"api return conent: {gh_fetch_url_and_headers(url, headers=headers, data=data, reader=json.load, method=method)}") return gh_fetch_url_and_headers( url, headers=headers, data=data, reader=json.load, method=method )[1] @@ -168,7 +169,9 @@ def gh_post_commit_comment( def gh_delete_comment(org: str, repo: str, comment_id: int) -> None: + print("deleting comment") url = f"{GITHUB_API_URL}/repos/{org}/{repo}/issues/comments/{comment_id}" + print(f"url: {url}") gh_fetch_url(url, method="DELETE") From dd9fe34c6e613d7e3b81521a9e82a52786b01bb7 Mon Sep 17 00:00:00 2001 From: Jack Zhang Date: Mon, 18 Nov 2024 22:50:30 -0800 Subject: [PATCH 4/7] Git rebase on torch main --- .github/scripts/check_labels.py | 6 +++--- .github/scripts/github_utils.py | 28 ++++++++++++++++++++++------ 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/.github/scripts/check_labels.py b/.github/scripts/check_labels.py index 71a7ad6afbe..6d9d57ce1ae 100644 --- a/.github/scripts/check_labels.py +++ b/.github/scripts/check_labels.py @@ -51,10 +51,10 @@ def main() -> None: try: if not has_required_labels(pr): - print(LABEL_ERR_MSG) + print(LABEL_ERR_MSG, flush=True) add_label_err_comment(pr) if args.exit_non_zero: - sys.exit(1) + raise RuntimeError("PR does not have required labels") else: print("pass") delete_all_label_err_comments(pr) @@ -62,7 +62,7 @@ def main() -> None: print("general exception") print(e) if args.exit_non_zero: - sys.exit(1) + raise RuntimeError(f"Error checking labels: {e}") from e print("success") sys.exit(0) diff --git a/.github/scripts/github_utils.py b/.github/scripts/github_utils.py index 22d77993cbf..932450490d7 100644 --- a/.github/scripts/github_utils.py +++ b/.github/scripts/github_utils.py @@ -66,17 +66,29 @@ def gh_fetch_url_and_headers( raise +# def gh_fetch_url( +# url: str, +# *, +# headers: Optional[Dict[str, str]] = None, +# data: Union[Optional[Dict[str, Any]], str] = None, +# method: Optional[str] = None, +# reader: Callable[[Any], Any] = lambda x: x.read(), +# ) -> Any: +# print(f"api return conent: {gh_fetch_url_and_headers(url, headers=headers, data=data, reader=json.load, method=method)}") +# return gh_fetch_url_and_headers( +# url, headers=headers, data=data, reader=json.load, method=method +# )[1] + def gh_fetch_url( url: str, *, headers: Optional[Dict[str, str]] = None, data: Union[Optional[Dict[str, Any]], str] = None, method: Optional[str] = None, - reader: Callable[[Any], Any] = lambda x: x.read(), + reader: Callable[[Any], Any] = json.load, ) -> Any: - print(f"api return conent: {gh_fetch_url_and_headers(url, headers=headers, data=data, reader=json.load, method=method)}") return gh_fetch_url_and_headers( - url, headers=headers, data=data, reader=json.load, method=method + url, headers=headers, data=data, reader=reader, method=method )[1] @@ -168,11 +180,15 @@ def gh_post_commit_comment( ) +# def gh_delete_comment(org: str, repo: str, comment_id: int) -> None: +# print("deleting comment") +# url = f"{GITHUB_API_URL}/repos/{org}/{repo}/issues/comments/{comment_id}" +# print(f"url: {url}") +# gh_fetch_url(url, method="DELETE") + def gh_delete_comment(org: str, repo: str, comment_id: int) -> None: - print("deleting comment") url = f"{GITHUB_API_URL}/repos/{org}/{repo}/issues/comments/{comment_id}" - print(f"url: {url}") - gh_fetch_url(url, method="DELETE") + gh_fetch_url(url, method="DELETE", reader=lambda x: x.read()) def gh_fetch_merge_base(org: str, repo: str, base: str, head: str) -> str: From 3a5c6a963bf0121ec5081f41f7ce4c0537624fc5 Mon Sep 17 00:00:00 2001 From: Jack Zhang Date: Mon, 18 Nov 2024 23:08:01 -0800 Subject: [PATCH 5/7] only main --- .github/scripts/check_labels.py | 1 + .github/workflows/check-labels.yml | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/scripts/check_labels.py b/.github/scripts/check_labels.py index 6d9d57ce1ae..997989fcc2f 100644 --- a/.github/scripts/check_labels.py +++ b/.github/scripts/check_labels.py @@ -41,6 +41,7 @@ def parse_args() -> Any: def main() -> None: + print("main") args = parse_args() repo = GitRepo(get_git_repo_dir(), get_git_remote_name()) org, project = repo.gh_owner_and_name() diff --git a/.github/workflows/check-labels.yml b/.github/workflows/check-labels.yml index bf37090afa6..01e08ae1842 100644 --- a/.github/workflows/check-labels.yml +++ b/.github/workflows/check-labels.yml @@ -6,9 +6,9 @@ on: # # Make sure to don't introduce explicit checking out and installing/running # untrusted user code into this workflow! - pull_request_target: - types: [opened, synchronize, reopened, labeled, unlabeled] - branches: [main] + # pull_request_target: + # types: [opened, synchronize, reopened, labeled, unlabeled] + # branches: [main] # To check labels on ghstack PRs. # Note: as pull_request doesn't trigger on PRs targeting main, From 436fc4b58a552b028d4cbbaa272210629ab5abdf Mon Sep 17 00:00:00 2001 From: Jack Zhang Date: Mon, 18 Nov 2024 23:16:06 -0800 Subject: [PATCH 6/7] back --- .github/workflows/check-labels.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/check-labels.yml b/.github/workflows/check-labels.yml index 01e08ae1842..bf37090afa6 100644 --- a/.github/workflows/check-labels.yml +++ b/.github/workflows/check-labels.yml @@ -6,9 +6,9 @@ on: # # Make sure to don't introduce explicit checking out and installing/running # untrusted user code into this workflow! - # pull_request_target: - # types: [opened, synchronize, reopened, labeled, unlabeled] - # branches: [main] + pull_request_target: + types: [opened, synchronize, reopened, labeled, unlabeled] + branches: [main] # To check labels on ghstack PRs. # Note: as pull_request doesn't trigger on PRs targeting main, From 4a4e5dd1c23c0e0ff81edddb5fa9ab9982a8d2cf Mon Sep 17 00:00:00 2001 From: Jack Zhang Date: Mon, 18 Nov 2024 23:25:17 -0800 Subject: [PATCH 7/7] Remove all print statements --- .github/scripts/check_labels.py | 11 ----------- .github/scripts/github_utils.py | 19 ------------------- .github/scripts/label_utils.py | 7 ------- .github/workflows/check-labels.yml | 2 +- 4 files changed, 1 insertion(+), 38 deletions(-) diff --git a/.github/scripts/check_labels.py b/.github/scripts/check_labels.py index 997989fcc2f..0075050155e 100644 --- a/.github/scripts/check_labels.py +++ b/.github/scripts/check_labels.py @@ -12,10 +12,7 @@ def delete_all_label_err_comments(pr: "GitHubPR") -> None: for comment in pr.get_comments(): - print(f"comment: {comment}") if is_label_err_comment(comment): - print("is label err comment") - print(f"comment.database_id: {comment.database_id}") gh_delete_comment(pr.org, pr.project, comment.database_id) @@ -41,14 +38,10 @@ def parse_args() -> Any: def main() -> None: - print("main") args = parse_args() repo = GitRepo(get_git_repo_dir(), get_git_remote_name()) org, project = repo.gh_owner_and_name() pr = GitHubPR(org, project, args.pr_num) - print(f"repo: {repo}") - print(f"org, project: {org}, {project}") - print(f"pr: {pr}") try: if not has_required_labels(pr): @@ -57,15 +50,11 @@ def main() -> None: if args.exit_non_zero: raise RuntimeError("PR does not have required labels") else: - print("pass") delete_all_label_err_comments(pr) except Exception as e: - print("general exception") - print(e) if args.exit_non_zero: raise RuntimeError(f"Error checking labels: {e}") from e - print("success") sys.exit(0) diff --git a/.github/scripts/github_utils.py b/.github/scripts/github_utils.py index 932450490d7..1583639b1f9 100644 --- a/.github/scripts/github_utils.py +++ b/.github/scripts/github_utils.py @@ -66,19 +66,6 @@ def gh_fetch_url_and_headers( raise -# def gh_fetch_url( -# url: str, -# *, -# headers: Optional[Dict[str, str]] = None, -# data: Union[Optional[Dict[str, Any]], str] = None, -# method: Optional[str] = None, -# reader: Callable[[Any], Any] = lambda x: x.read(), -# ) -> Any: -# print(f"api return conent: {gh_fetch_url_and_headers(url, headers=headers, data=data, reader=json.load, method=method)}") -# return gh_fetch_url_and_headers( -# url, headers=headers, data=data, reader=json.load, method=method -# )[1] - def gh_fetch_url( url: str, *, @@ -180,12 +167,6 @@ def gh_post_commit_comment( ) -# def gh_delete_comment(org: str, repo: str, comment_id: int) -> None: -# print("deleting comment") -# url = f"{GITHUB_API_URL}/repos/{org}/{repo}/issues/comments/{comment_id}" -# print(f"url: {url}") -# gh_fetch_url(url, method="DELETE") - def gh_delete_comment(org: str, repo: str, comment_id: int) -> None: url = f"{GITHUB_API_URL}/repos/{org}/{repo}/issues/comments/{comment_id}" gh_fetch_url(url, method="DELETE", reader=lambda x: x.read()) diff --git a/.github/scripts/label_utils.py b/.github/scripts/label_utils.py index 62a1ba9c05e..81668dad0cb 100644 --- a/.github/scripts/label_utils.py +++ b/.github/scripts/label_utils.py @@ -64,7 +64,6 @@ def get_last_page_num_from_header(header: Any) -> int: @lru_cache def gh_get_labels(org: str, repo: str) -> List[str]: prefix = f"https://api.github.com/repos/{org}/{repo}/labels?per_page=100" - print(f"prefix: {prefix}") header, info = request_for_labels(prefix + "&page=1") labels: List[str] = [] update_labels(labels, info) @@ -77,8 +76,6 @@ def gh_get_labels(org: str, repo: str) -> List[str]: _, info = request_for_labels(prefix + f"&page={page_number}") update_labels(labels, info) - print(f"all labels on gh: {labels}") - return labels @@ -115,15 +112,11 @@ def get_release_notes_labels(org: str, repo: str) -> List[str]: def has_required_labels(pr: "GitHubPR") -> bool: - print(f"pr: {pr}, pr.org: {pr.org}, pr.project: {pr.project}") pr_labels = pr.get_labels() - print(f"pr_labels: {pr_labels}") # Check if PR is not user facing is_not_user_facing_pr = any( label.strip() == "topic: not user facing" for label in pr_labels ) - print(f"is_not_user_facing_pr: {is_not_user_facing_pr}") - print(f"release note labels: {get_release_notes_labels(pr.org, pr.project)}") return is_not_user_facing_pr or any( label.strip() in get_release_notes_labels(pr.org, pr.project) for label in pr_labels diff --git a/.github/workflows/check-labels.yml b/.github/workflows/check-labels.yml index bf37090afa6..19c70c820a8 100644 --- a/.github/workflows/check-labels.yml +++ b/.github/workflows/check-labels.yml @@ -16,7 +16,7 @@ on: # a PR that targets a gh/**/base branch. pull_request: types: [opened, synchronize, reopened, labeled, unlabeled] - branches: [gh/**/base, main] + branches: [gh/**/base] workflow_dispatch: inputs: