Unverified Commit 0822fc05 authored by moto's avatar moto Committed by GitHub
Browse files

Update PR label notifier (#1964)

Include the list of labels.
parent 8a93717c
#!/usr/bin/env python3
""" """
This script finds the merger responsible for labeling a PR by a commit SHA. It is used by the workflow in This script finds the merger responsible for labeling a PR by a commit SHA. It is used by the workflow in
'.github/workflows/pr-labels.yml'. If there exists no PR associated with the commit or the PR is properly labeled, '.github/workflows/pr-labels.yml'. If there exists no PR associated with the commit or the PR is properly labeled,
...@@ -60,14 +61,26 @@ def get_pr_merger_and_labels(pr_number: int) -> Tuple[str, Set[str]]: ...@@ -60,14 +61,26 @@ def get_pr_merger_and_labels(pr_number: int) -> Tuple[str, Set[str]]:
return merger, labels return merger, labels
if __name__ == "__main__": def _get_formatted(l):
return ', '.join(f'`{i}`' for i in l)
def _main():
commit_hash = sys.argv[1] commit_hash = sys.argv[1]
pr_number = get_pr_number(commit_hash) pr_number = get_pr_number(commit_hash)
if not pr_number: if not pr_number:
sys.exit(0) return
merger, labels = get_pr_merger_and_labels(pr_number) merger, labels = get_pr_merger_and_labels(pr_number)
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}") print(f"""Hi @{merger}
You merged this PR, but one or more labels are missing.
Please include a primary label ({_get_formatted(PRIMARY_LABELS)}) and a secondary label ({_get_formatted(SECONDARY_LABELS)}).
""") # noqa: E501
if __name__ == "__main__":
_main()
...@@ -21,15 +21,12 @@ jobs: ...@@ -21,15 +21,12 @@ 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 }})" run: echo "::set-output name=message::$(python .github/process_commit.py ${{ github.sha }})"
- name: Ping merger responsible for labeling if necessary - name: Ping merger responsible for labeling if necessary
if: ${{ steps.commit.outputs.merger != '' }} if: ${{ steps.commit.outputs.message != '' }}
uses: mshick/add-pr-comment@v1 uses: mshick/add-pr-comment@v1
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with: with:
message: | message: ${{ steps.commit.outputs.message }}
Hey ${{ steps.commit.outputs.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)
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