Commit 3184aebc authored by Caroline Chen's avatar Caroline Chen Committed by Facebook GitHub Bot
Browse files

Update release notes labeling (#2249)

Summary:
- fix retrieve PR script to handle commits with unrecognized/invalid PR numbers, such as in 7b6b2d00
- add modifications similar to pytorch's [#71917](https://github.com/pytorch/pytorch/pull/71917), [#72085](https://github.com/pytorch/pytorch/pull/72085)

Pull Request resolved: https://github.com/pytorch/audio/pull/2249

Reviewed By: nateanl, mthrok

Differential Revision: D34304210

Pulled By: carolineechen

fbshipit-source-id: 245784219317e355b5cece4a139dee71d65bfdd1
parent 9cf59e75
...@@ -5,6 +5,8 @@ Note: we only ping the person who pulls the pr, not the reviewers, as the review ...@@ -5,6 +5,8 @@ Note: we only ping the person who pulls the pr, not the reviewers, as the review
to torchaudio with no labeling responsibility, so we don't want to bother them. to torchaudio with no labeling responsibility, so we don't want to bother them.
""" """
import json
import os
import sys import sys
from typing import Any, Optional, Set, Tuple from typing import Any, Optional, Set, Tuple
...@@ -36,15 +38,18 @@ SECONDARY_LABELS = { ...@@ -36,15 +38,18 @@ SECONDARY_LABELS = {
"perf", "perf",
"other", "other",
} }
GITHUB_TOKEN = os.environ.get("GITHUB_TOKEN")
REQUEST_HEADERS = {"Accept": "application/vnd.github.v3+json", "Authorization": f"token {GITHUB_TOKEN}"}
TORCHAUDIO_REPO = "https://api.github.com/repos/pytorch/audio"
def query_torchaudio(cmd: str, *, accept) -> Any: def query_torchaudio(cmd: str) -> Any:
response = requests.get(f"https://api.github.com/repos/pytorch/audio/{cmd}", headers=dict(Accept=accept)) response = requests.get(f"{TORCHAUDIO_REPO}/{cmd}", headers=REQUEST_HEADERS)
return response.json() return response.json()
def get_pr_merger_and_number(commit_hash: str) -> Optional[str]: def get_pr_merger_and_number(commit_hash: str) -> Optional[str]:
data = query_torchaudio(f"commits/{commit_hash}", accept="application/vnd.github.v3+json") data = query_torchaudio(f"commits/{commit_hash}")
commit_message = data["commit"]["message"] commit_message = data["commit"]["message"]
pulled_by = commit_message.split("Pulled By: ") pulled_by = commit_message.split("Pulled By: ")
...@@ -57,11 +62,25 @@ def get_pr_merger_and_number(commit_hash: str) -> Optional[str]: ...@@ -57,11 +62,25 @@ def get_pr_merger_and_number(commit_hash: str) -> Optional[str]:
def get_labels(pr_number: int) -> Set[str]: def get_labels(pr_number: int) -> Set[str]:
data = query_torchaudio(f"pulls/{pr_number}", accept="application/vnd.github.v3+json") data = query_torchaudio(f"pulls/{pr_number}")
labels = {label["name"] for label in data["labels"]} labels = {label["name"] for label in data["labels"]}
return labels return labels
def post_github_comment(pr_number: int, merger: str) -> Any:
message = {
"body": f"Hey @{merger}."
+ """
You merged this PR, but labels were not properly added. Please add a primary and secondary label \
(See https://github.com/pytorch/audio/blob/main/.github/process_commit.py)"""
}
response = requests.post(
f"{TORCHAUDIO_REPO}/issues/{pr_number}/comments", json.dumps(message), headers=REQUEST_HEADERS
)
return response.json()
if __name__ == "__main__": if __name__ == "__main__":
commit_hash = sys.argv[1] commit_hash = sys.argv[1]
...@@ -71,4 +90,4 @@ if __name__ == "__main__": ...@@ -71,4 +90,4 @@ if __name__ == "__main__":
is_properly_labeled = bool(PRIMARY_LABELS.intersection(labels) and SECONDARY_LABELS.intersection(labels)) is_properly_labeled = bool(PRIMARY_LABELS.intersection(labels) and SECONDARY_LABELS.intersection(labels))
if not is_properly_labeled: if not is_properly_labeled:
print(f"@{merger}") post_github_comment(pr_number, merger)
name: pr-labels name: pr-labels
on: on:
pull_request: push:
types: branches:
- closed - main
jobs: jobs:
is-properly-labeled: is-properly-labeled:
...@@ -21,15 +21,11 @@ jobs: ...@@ -21,15 +21,11 @@ jobs:
- name: Process commit and find merger responsible for labeling - name: Process commit and find merger responsible for labeling
id: commit id: commit
run: echo "::set-output name=merger::$(python .github/process_commit.py ${{ github.sha }})"
- name: Ping merger responsible for labeling if necessary
if: ${{ steps.commit.outputs.merger != '' }}
uses: mshick/add-pr-comment@v1
env: env:
SHA1: ${{ github.sha }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with: run: python .github/process_commit.py "${SHA1}"
message: |
Hey ${{ steps.commit.outputs.merger }}! concurrency:
You merged this PR, but labels were not properly added. Please add a primary and secondary label group: pr-labels-${{ github.event.pull_request.number || github.sha }}-${{ github.event_name == 'workflow_dispatch' }}
(See https://github.com/pytorch/audio/blob/main/.github/process_commit.py) cancel-in-progress: true
...@@ -81,7 +81,11 @@ def gh_labels(pr_number): ...@@ -81,7 +81,11 @@ def gh_labels(pr_number):
}} }}
""" """
query = run_query(query) query = run_query(query)
edges = query["data"]["repository"]["pullRequest"]["labels"]["edges"] pr = query["data"]["repository"]["pullRequest"]
if not pr:
# to account for unrecognized PR numbers from commits originating from fb internal
return []
edges = pr["labels"]["edges"]
return [edge["node"]["name"] for edge in edges] return [edge["node"]["name"] for edge in edges]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment