5
from github import Github
9
token = os.environ.get("GITHUB_TOKEN")
11
repo_owner = "pytorch"
13
pull_request_number = int(sys.argv[1])
16
repo = g.get_repo(f"{repo_owner}/{repo_name}")
17
pull_request = repo.get_pull(pull_request_number)
18
pull_request_body = pull_request.body
20
if pull_request_body is None:
24
if not re.search(r"#\d{1,6}", pull_request_body):
25
print("The pull request does not mention an issue.")
27
issue_number = int(re.findall(r"#(\d{1,6})", pull_request_body)[0])
28
issue = repo.get_issue(issue_number)
29
issue_labels = issue.labels
30
docathon_label_present = any(
31
label.name == "docathon-h1-2024" for label in issue_labels
35
if not docathon_label_present:
36
print("The 'docathon-h1-2024' label is not present in the issue.")
38
pull_request_labels = pull_request.get_labels()
39
pull_request_label_names = [label.name for label in pull_request_labels]
40
issue_label_names = [label.name for label in issue_labels]
42
label for label in issue_label_names if label not in pull_request_label_names
45
print("The pull request already has the same labels.")
47
pull_request.add_to_labels(*labels_to_add)
48
print("Labels added to the pull request!")
51
if __name__ == "__main__":