diff --git a/.github/scripts/label_community_user.py b/.github/scripts/label_community_user.py index d95f1bf372d7..06664aed9c72 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 = { @@ -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: @@ -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: diff --git a/.github/workflows/label_community_pr.yml b/.github/workflows/label_community_pr.yml index 6ae9322c4bf4..ff9fe61b9d3c 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: @@ -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: "invalid" run: python .github/scripts/label_community_user.py