cilium

Форк
0
/
set-labels.py 
84 строки · 2.6 Кб
1
#!/usr/bin/env python3
2

3
"""
4
This script requires PyGithub to be installed
5
`pip install pygithub`
6

7
GITHUB_TOKEN env variable is used to access GH API
8
"""
9

10
import argparse
11
import os
12
import sys
13

14
try:
15
    from github import Github
16
except ImportError:
17
    print("pygithub not found you can install it by running 'pip3 install --user PyGithub'")
18
    sys.exit(-1)
19

20
parser = argparse.ArgumentParser()
21
parser.add_argument('pr_number', type=int)
22
actions = ["pending", "done"]
23
parser.add_argument('action', type=str, choices=actions)
24
parser.add_argument('version', type=str, default="1.0", nargs='?')
25

26
args = parser.parse_args()
27

28
token = os.environ["GITHUB_TOKEN"]
29
pr_number = args.pr_number
30
action = args.action
31
version = args.version
32

33
g = Github(token)
34
cilium = g.get_repo("cilium/cilium")
35
pr = cilium.get_pull(pr_number)
36
pr_labels = list(pr.get_labels())
37
old_label_len = len(pr_labels)
38

39
cilium_labels = cilium.get_labels()
40

41
# After the introduction of the "Update labels of backported PRs" GH
42
# workflow and all the workflows in the stable branches that calls it,
43
# there is no need to use this script to update the backported PRs label.
44
# Specifically, this script shouldn't be used with the `action` parameter
45
# set to `done` anymore.
46
# However, since there might still be in-flight backporting PRs relying on
47
# the old backporting workflow (based on this script to update the labels),
48
# we leave the code here.
49
#
50
# This can be updated once all the new workflows will be in place and the
51
# "old" backport PRs will have their labels updated.
52

53
print("Setting labels for PR {}... ".format(pr_number), end="")
54
if action == "pending":
55
    pr_labels = [l for l in pr_labels
56
                 if l.name != "needs-backport/"+version]
57
    if old_label_len - 1 != len(pr_labels):
58
        print("needs-backport/"+version+" label not found in PR, exiting")
59
        sys.exit(1)
60

61
    pr_labels.append(
62
        [l for l in cilium_labels if l.name == "backport-pending/"+version][0])
63

64
    if old_label_len != len(pr_labels):
65
        print("error adding backport-pending/"+version+" label to PR, exiting")
66
        sys.exit(2)
67
    pr.set_labels(*pr_labels)
68

69
if action == "done":
70
    pr_labels = [l for l in pr_labels
71
                 if l.name != "backport-pending/"+version]
72
    if old_label_len - 1 != len(pr_labels):
73
        print("backport-pending/"+version+" label not found in PR, exiting")
74
        sys.exit(1)
75

76
    pr_labels.append(
77
        [l for l in cilium_labels if l.name == "backport-done/"+version][0])
78

79
    if old_label_len != len(pr_labels):
80
        print("error adding backport-done/"+version+" label to PR, exiting")
81
        sys.exit(2)
82
    pr.set_labels(*pr_labels)
83

84
print("✓")
85

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

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

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

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