pytorch

Форк
0
/
docathon-label-sync.py 
52 строки · 1.6 Кб
1
import os
2
import re
3
import sys
4

5
from github import Github
6

7

8
def main() -> None:
9
    token = os.environ.get("GITHUB_TOKEN")
10

11
    repo_owner = "pytorch"
12
    repo_name = "pytorch"
13
    pull_request_number = int(sys.argv[1])
14

15
    g = Github(token)
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
19
    # PR without description
20
    if pull_request_body is None:
21
        return
22

23
    # get issue number from the PR body
24
    if not re.search(r"#\d{1,6}", pull_request_body):
25
        print("The pull request does not mention an issue.")
26
        return
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
32
    )
33

34
    # if the issue has a docathon label, add all labels from the issue to the PR.
35
    if not docathon_label_present:
36
        print("The 'docathon-h1-2024' label is not present in the issue.")
37
        return
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]
41
    labels_to_add = [
42
        label for label in issue_label_names if label not in pull_request_label_names
43
    ]
44
    if not labels_to_add:
45
        print("The pull request already has the same labels.")
46
        return
47
    pull_request.add_to_labels(*labels_to_add)
48
    print("Labels added to the pull request!")
49

50

51
if __name__ == "__main__":
52
    main()
53

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.