From e6358cb37f61bc6887f7e90f79ec4ab194e62b39 Mon Sep 17 00:00:00 2001 From: "Po-Wei Wang (Vincent)" Date: Mon, 2 Jun 2025 21:17:01 -0700 Subject: [PATCH 1/9] add write permission Signed-off-by: Po-Wei Wang (Vincent) --- .github/workflows/label_community_pr.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/label_community_pr.yml b/.github/workflows/label_community_pr.yml index 6ae9322c4bf4..5230637636e0 100644 --- a/.github/workflows/label_community_pr.yml +++ b/.github/workflows/label_community_pr.yml @@ -3,6 +3,8 @@ name: Label Community PR on: pull_request: types: [opened] +permissions: + pull-requests: write jobs: label_pr: From c4aac018ffc64778947ba8bee1d8a40abe94303f Mon Sep 17 00:00:00 2001 From: "Po-Wei Wang (Vincent)" Date: Mon, 2 Jun 2025 21:25:08 -0700 Subject: [PATCH 2/9] add members permission Signed-off-by: Po-Wei Wang (Vincent) --- .github/workflows/label_community_pr.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/label_community_pr.yml b/.github/workflows/label_community_pr.yml index 5230637636e0..eb461bb6c55a 100644 --- a/.github/workflows/label_community_pr.yml +++ b/.github/workflows/label_community_pr.yml @@ -5,6 +5,7 @@ on: types: [opened] permissions: pull-requests: write + members: read jobs: label_pr: From f33c570c600ac5640ec412742790b131b240ac99 Mon Sep 17 00:00:00 2001 From: "Po-Wei Wang (Vincent)" Date: Mon, 2 Jun 2025 21:31:25 -0700 Subject: [PATCH 3/9] use my github token Signed-off-by: Po-Wei Wang (Vincent) --- .github/scripts/label_community_user.py | 2 +- .github/workflows/label_community_pr.yml | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/scripts/label_community_user.py b/.github/scripts/label_community_user.py index d95f1bf372d7..9b04367ee487 100644 --- a/.github/scripts/label_community_user.py +++ b/.github/scripts/label_community_user.py @@ -4,7 +4,7 @@ import requests GITHUB_API_URL = "https://api.github.com" -GITHUB_TOKEN = os.environ.get("GITHUB_TOKEN") +GITHUB_TOKEN = os.environ.get("MY_GITHUB_TOKEN") assert GITHUB_TOKEN, "GITHUB_TOKEN environment variable not set" HEADERS = { diff --git a/.github/workflows/label_community_pr.yml b/.github/workflows/label_community_pr.yml index eb461bb6c55a..b6eaa37a79cb 100644 --- a/.github/workflows/label_community_pr.yml +++ b/.github/workflows/label_community_pr.yml @@ -5,7 +5,6 @@ on: types: [opened] permissions: pull-requests: write - members: read jobs: label_pr: @@ -24,7 +23,7 @@ jobs: - name: Run labeling script env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + MY_GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }} PR_AUTHOR: ${{ github.event.pull_request.user.login }} PR_NUMBER: ${{ github.event.pull_request.number }} REPO_NAME: ${{ github.event.repository.name }} From 48e75e103fd9ed39080746fe819ca2cb0ebda0a9 Mon Sep 17 00:00:00 2001 From: "Po-Wei Wang (Vincent)" Date: Mon, 2 Jun 2025 21:43:36 -0700 Subject: [PATCH 4/9] oppposite Signed-off-by: Po-Wei Wang (Vincent) --- .github/scripts/label_community_user.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/scripts/label_community_user.py b/.github/scripts/label_community_user.py index 9b04367ee487..4a31e96711d6 100644 --- a/.github/scripts/label_community_user.py +++ b/.github/scripts/label_community_user.py @@ -95,9 +95,9 @@ def main(): is_member = pr_author.lower() in nvidia_members print(f"User '{pr_author}' is a member of NVIDIA: {is_member}") - if not is_member: + if is_member: print( - f"User '{pr_author}' is a community user. Adding label '{community_label}'." + f"User '{pr_author}' is not a community user. Adding label '{community_label}'." ) add_label_to_pr(repo_name, pr_number, community_label) else: From 356694c975d9f6895c64ac978cdd9ccd6aab61b4 Mon Sep 17 00:00:00 2001 From: "Po-Wei Wang (Vincent)" Date: Mon, 2 Jun 2025 21:46:44 -0700 Subject: [PATCH 5/9] oppposite Signed-off-by: Po-Wei Wang (Vincent) --- .github/workflows/label_community_pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/label_community_pr.yml b/.github/workflows/label_community_pr.yml index b6eaa37a79cb..ff9fe61b9d3c 100644 --- a/.github/workflows/label_community_pr.yml +++ b/.github/workflows/label_community_pr.yml @@ -27,5 +27,5 @@ jobs: PR_AUTHOR: ${{ github.event.pull_request.user.login }} PR_NUMBER: ${{ github.event.pull_request.number }} REPO_NAME: ${{ github.event.repository.name }} - COMMUNITY_LABEL: "Community want to contribute" + COMMUNITY_LABEL: "invalid" run: python .github/scripts/label_community_user.py From f8b45fd6b25f2d29e7bfa8559ed7c04edcd2bae9 Mon Sep 17 00:00:00 2001 From: "Po-Wei Wang (Vincent)" Date: Mon, 2 Jun 2025 21:58:01 -0700 Subject: [PATCH 6/9] oppposite Signed-off-by: Po-Wei Wang (Vincent) --- .github/scripts/label_community_user.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/scripts/label_community_user.py b/.github/scripts/label_community_user.py index 4a31e96711d6..06664aed9c72 100644 --- a/.github/scripts/label_community_user.py +++ b/.github/scripts/label_community_user.py @@ -63,8 +63,16 @@ def add_label_to_pr(repo_name: str, pr_number: str, label: str): """Adds a label to a pull request.""" url = f"{GITHUB_API_URL}/repos/NVIDIA/{repo_name}/issues/{pr_number}/labels" payload = {"labels": [label]} + print(f"Attempting to add label. URL: {url}, Payload: {payload}") try: response = requests.post(url, headers=HEADERS, json=payload) + print(f"API Response Status Code: {response.status_code}") + try: + response_json = response.json() + print(f"API Response JSON: {response_json}") + except requests.exceptions.JSONDecodeError: + print(f"API Response Text (not JSON): {response.text}") + response.raise_for_status() print(f"Successfully added label '{label}' to PR #{pr_number}.") except requests.exceptions.RequestException as e: From 9409e6f9641617f174ddda49fc510e38dc992f12 Mon Sep 17 00:00:00 2001 From: "Po-Wei Wang (Vincent)" Date: Mon, 2 Jun 2025 22:06:00 -0700 Subject: [PATCH 7/9] oppposite Signed-off-by: Po-Wei Wang (Vincent) --- .github/workflows/label_community_pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/label_community_pr.yml b/.github/workflows/label_community_pr.yml index ff9fe61b9d3c..7e46ebdc4c9c 100644 --- a/.github/workflows/label_community_pr.yml +++ b/.github/workflows/label_community_pr.yml @@ -27,5 +27,5 @@ jobs: PR_AUTHOR: ${{ github.event.pull_request.user.login }} PR_NUMBER: ${{ github.event.pull_request.number }} REPO_NAME: ${{ github.event.repository.name }} - COMMUNITY_LABEL: "invalid" + COMMUNITY_LABEL: "ggtest" run: python .github/scripts/label_community_user.py From 2dfa07b2d61811aea7c3872898556903a5d7b98e Mon Sep 17 00:00:00 2001 From: "Po-Wei Wang (Vincent)" Date: Mon, 2 Jun 2025 22:16:04 -0700 Subject: [PATCH 8/9] oppposite Signed-off-by: Po-Wei Wang (Vincent) --- .github/scripts/label_community_user.py | 9 ++++++--- .github/workflows/label_community_pr.yml | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/scripts/label_community_user.py b/.github/scripts/label_community_user.py index 06664aed9c72..1df61cec6df5 100644 --- a/.github/scripts/label_community_user.py +++ b/.github/scripts/label_community_user.py @@ -59,9 +59,10 @@ def get_nvidia_members() -> list[str]: return members -def add_label_to_pr(repo_name: str, pr_number: str, label: str): +def add_label_to_pr(repo_owner: str, repo_name: str, pr_number: str, + label: str): """Adds a label to a pull request.""" - url = f"{GITHUB_API_URL}/repos/NVIDIA/{repo_name}/issues/{pr_number}/labels" + url = f"{GITHUB_API_URL}/repos/{repo_owner}/{repo_name}/issues/{pr_number}/labels" payload = {"labels": [label]} print(f"Attempting to add label. URL: {url}, Payload: {payload}") try: @@ -86,6 +87,8 @@ def main(): assert pr_author, "PR_AUTHOR environment variable not set" pr_number = os.environ.get("PR_NUMBER") assert pr_number, "PR_NUMBER environment variable not set" + repo_owner = os.environ.get("REPO_OWNER") + assert repo_owner, "REPO_OWNER environment variable not set" repo_name = os.environ.get("REPO_NAME") assert repo_name, "REPO_NAME environment variable not set" community_label = os.environ.get("COMMUNITY_LABEL") @@ -107,7 +110,7 @@ def main(): print( f"User '{pr_author}' is not a community user. Adding label '{community_label}'." ) - add_label_to_pr(repo_name, pr_number, community_label) + add_label_to_pr(repo_owner, repo_name, pr_number, community_label) else: print( f"User '{pr_author}' is an NVIDIA member. No label will be added.") diff --git a/.github/workflows/label_community_pr.yml b/.github/workflows/label_community_pr.yml index 7e46ebdc4c9c..58a5e9388ea1 100644 --- a/.github/workflows/label_community_pr.yml +++ b/.github/workflows/label_community_pr.yml @@ -26,6 +26,7 @@ jobs: MY_GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }} PR_AUTHOR: ${{ github.event.pull_request.user.login }} PR_NUMBER: ${{ github.event.pull_request.number }} + REPO_OWNER: ${{ github.event.repository.owner.name }} REPO_NAME: ${{ github.event.repository.name }} COMMUNITY_LABEL: "ggtest" run: python .github/scripts/label_community_user.py From 67c3b611201f6b8b28a4e6d486ba24af4c06f168 Mon Sep 17 00:00:00 2001 From: "Po-Wei Wang (Vincent)" Date: Mon, 2 Jun 2025 22:19:22 -0700 Subject: [PATCH 9/9] oppposite Signed-off-by: Po-Wei Wang (Vincent) --- .github/workflows/label_community_pr.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/label_community_pr.yml b/.github/workflows/label_community_pr.yml index 58a5e9388ea1..4e08b779e05e 100644 --- a/.github/workflows/label_community_pr.yml +++ b/.github/workflows/label_community_pr.yml @@ -26,7 +26,7 @@ jobs: MY_GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }} PR_AUTHOR: ${{ github.event.pull_request.user.login }} PR_NUMBER: ${{ github.event.pull_request.number }} - REPO_OWNER: ${{ github.event.repository.owner.name }} + REPO_OWNER: ${{ github.event.repository.owner.login }} REPO_NAME: ${{ github.event.repository.name }} - COMMUNITY_LABEL: "ggtest" + COMMUNITY_LABEL: "test_label" run: python .github/scripts/label_community_user.py