Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions .github/scripts/label_community_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -95,9 +103,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:
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/label_community_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: Label Community PR
on:
pull_request:
types: [opened]
permissions:
pull-requests: write

jobs:
label_pr:
Expand All @@ -21,9 +23,9 @@ 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 }}
COMMUNITY_LABEL: "Community want to contribute"
COMMUNITY_LABEL: "ggtest"
run: python .github/scripts/label_community_user.py
Loading