Skip to content

Commit a1b022c

Browse files
tianshuo78520axsrobin
authored andcommitted
Test fluid (PaddlePaddle#1023)
* ok * ok * ok * add check_approval * check approval * check approval * check approval * check approval * check approval * check approval * add check_approval * add check_approval * add check_approval * add check_approval * add check_approval
1 parent bed7149 commit a1b022c

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

scripts/check_pr_approval.py

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

scripts/checkapproval.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
API_FILES=("doc/fluid")
4+
for API_FILE in ${API_FILES[*]}; do
5+
API_CHANGE=`git diff --name-only upstream/$BRANCH | grep "${API_FILE}" || true`
6+
if [ "${API_CHANGE}" ];then
7+
approval_line=`curl -H "Authorization: token ${GITHUB_API_TOKEN}" https://api.github.com/repos/PaddlePaddle/FluidDoc/pulls/${GIT_PR_ID}/reviews?per_page=10000`
8+
if [ "${API_FILE}" == "doc/fluid" ];then
9+
APPROVALS=`echo ${approval_line}|python ./scripts/check_pr_approval.py 2 7534971 14105589 12605721 3064195 328693 47554610 39645414 11195205 20274488 45024560 `
10+
fi
11+
fi
12+
if [ "${APPROVALS}" == "FALSE" ]; then
13+
if [ "${API_FILE}" == "doc/fluid" ];then
14+
echo "You must have two RD (wanghaoshuang or guoshengCS or heavengate or kuke or Superjomn or lanxianghit or cyj1986 or hutuxian or frankwhzhang or nepeplwu) approval for the api change! ${API_FILE} for the management reason of API interface and API document."
15+
fi
16+
exit 1
17+
fi
18+
done

0 commit comments

Comments
 (0)