paddlenlp
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
15import json
16import sys
17
18
19def check_approval(count, required_reviewers):
20json_buff = ""
21for line in sys.stdin:
22json_buff = "".join([json_buff, line])
23json_resp = json.loads(json_buff)
24approves = 0
25approved_user_ids = []
26approved_user_logins = set()
27for review in json_resp:
28if review["state"] == "APPROVED":
29approves += 1
30approved_user_ids.append(review["user"]["id"])
31approved_user_logins.add(review["user"]["login"])
32
33# convert to int
34required_reviewers_int = set()
35required_reviewers_login = set()
36for rr in required_reviewers:
37if rr.isdigit():
38required_reviewers_int.add(int(rr))
39else:
40required_reviewers_login.add(rr)
41
42if (
43len(set(approved_user_ids) & required_reviewers_int) + len(approved_user_logins & required_reviewers_login)
44>= count
45):
46print("TRUE")
47else:
48print("FALSE")
49
50
51if __name__ == "__main__":
52if len(sys.argv) > 1 and sys.argv[1].isdigit():
53check_approval(int(sys.argv[1]), sys.argv[2:])
54else:
55print("Usage: python check_pr_approval.py [count] [required reviewer id] ...")
56