paddlenlp

Форк
0
/
check_pr_approval.py 
55 строк · 1.8 Кб
1
# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
6
#
7
#     http://www.apache.org/licenses/LICENSE-2.0
8
#
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
14

15
import json
16
import sys
17

18

19
def check_approval(count, required_reviewers):
20
    json_buff = ""
21
    for line in sys.stdin:
22
        json_buff = "".join([json_buff, line])
23
    json_resp = json.loads(json_buff)
24
    approves = 0
25
    approved_user_ids = []
26
    approved_user_logins = set()
27
    for review in json_resp:
28
        if review["state"] == "APPROVED":
29
            approves += 1
30
            approved_user_ids.append(review["user"]["id"])
31
            approved_user_logins.add(review["user"]["login"])
32

33
    # convert to int
34
    required_reviewers_int = set()
35
    required_reviewers_login = set()
36
    for rr in required_reviewers:
37
        if rr.isdigit():
38
            required_reviewers_int.add(int(rr))
39
        else:
40
            required_reviewers_login.add(rr)
41

42
    if (
43
        len(set(approved_user_ids) & required_reviewers_int) + len(approved_user_logins & required_reviewers_login)
44
        >= count
45
    ):
46
        print("TRUE")
47
    else:
48
        print("FALSE")
49

50

51
if __name__ == "__main__":
52
    if len(sys.argv) > 1 and sys.argv[1].isdigit():
53
        check_approval(int(sys.argv[1]), sys.argv[2:])
54
    else:
55
        print("Usage: python check_pr_approval.py [count] [required reviewer id] ...")
56

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

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

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

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