-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into Neokish-1943-issue
- Loading branch information
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import os | ||
from github import Github | ||
import sys | ||
import re | ||
|
||
def main(): | ||
token = os.environ.get('GITHUB_TOKEN') | ||
|
||
repo_owner = "pytorch" | ||
repo_name = "tutorials" | ||
pull_request_number = int(sys.argv[1]) | ||
|
||
g = Github(token) | ||
repo = g.get_repo(f'{repo_owner}/{repo_name}') | ||
pull_request = repo.get_pull(pull_request_number) | ||
pull_request_body = pull_request.body | ||
|
||
# get issue number from the PR body | ||
if not re.search(r'#\d{1,5}', pull_request_body): | ||
print("The pull request does not mention an issue.") | ||
return | ||
issue_number = int(re.findall(r'#(\d{1,5})', pull_request_body)[0]) | ||
issue = repo.get_issue(issue_number) | ||
issue_labels = issue.labels | ||
docathon_label_present = any(label.name == 'docathon-h1-2023' for label in issue_labels) | ||
|
||
# if the issue has a docathon label, add all labels from the issue to the PR. | ||
if not docathon_label_present: | ||
print("The 'docathon-h1-2023' label is not present in the issue.") | ||
return | ||
pull_request_labels = pull_request.get_labels() | ||
issue_label_names = [label.name for label in issue_labels] | ||
labels_to_add = [label for label in issue_label_names if label not in pull_request_labels] | ||
if not labels_to_add: | ||
print("The pull request already has the same labels.") | ||
return | ||
pull_request.set_labels(*labels_to_add) | ||
print("Labels added to the pull request!") | ||
|
||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Docathon Labels Sync | ||
|
||
on: | ||
pull_request: | ||
types: [opened, synchronize, edited] | ||
|
||
jobs: | ||
check-labels: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Check if PR mentions an issue and get labels | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.x | ||
- name: Install dependencies | ||
run: | | ||
pip install requests | ||
pip install PyGithub | ||
- name: Run Python script | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: python ./.github/scripts/docathon-label-sync.py ${{ github.event.pull_request.number }} |