From 33fc690f899f42347cb63ce0c39e66fac48c7225 Mon Sep 17 00:00:00 2001 From: chalsliu <45041955+chalsliu@users.noreply.github.com> Date: Mon, 25 May 2020 19:18:35 +0800 Subject: [PATCH] Add pr checker for ut (#24628) * Add pr checker for ut test=develop * Change approvers for ut spec checking test=document_fix * Change approvers for ut spec checking test=develop test=document_fix * Add comments test=develop test=document_fix * Refine error message test=develop test=document_fix --- tools/check_api_approvals.sh | 10 +++++++ tools/check_ut.py | 54 ++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 tools/check_ut.py diff --git a/tools/check_api_approvals.sh b/tools/check_api_approvals.sh index e6d41c11ce1..ca698887c30 100644 --- a/tools/check_api_approvals.sh +++ b/tools/check_api_approvals.sh @@ -283,6 +283,16 @@ if [ "${ADDED_OP_USE_DEFAULT_GRAD_MAKER}" != "" ]; then check_approval 1 32832641 6836917 fi +# Get the list of PR authors with unresolved unit test issues +pip install PyGithub +# For getting PR related data +wget https://paddle-ci.gz.bcebos.com/blk/block.txt +HASUTFIXED=`python ${PADDLE_ROOT}/tools/check_ut.py | grep "has unit-test to be fixed" || true` +if [ "${HASUTFIXED}" != "" ]; then + echo_line="${HASUTFIXED} You must have one RD (chalsliu (Recommend) or kolinwei) approval.\n" + check_approval 1 45041955 22165420 +fi + if [ -n "${echo_list}" ];then echo "****************" echo -e "${echo_list[@]}" diff --git a/tools/check_ut.py b/tools/check_ut.py new file mode 100644 index 00000000000..6e507d6543f --- /dev/null +++ b/tools/check_ut.py @@ -0,0 +1,54 @@ +#!/bin/env python +# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +""" Get pull requests. """ + +import os +import time +import os.path +from github import Github + + +class PRChecker(object): + """ PR Checker. """ + + def __init__(self): + self.github = Github(os.getenv('GITHUB_API_TOKEN'), timeout=60) + self.repo = None + + def check(self): + """ check pr """ + filename = 'block.txt' + pr_id = os.getenv('GIT_PR_ID') + if not pr_id: + print('No PR ID') + exit(0) + print(pr_id) + if not os.path.isfile(filename): + print('No author to check') + exit(0) + self.repo = self.github.get_repo('PaddlePaddle/Paddle') + pr = self.repo.get_pull(int(pr_id)) + user = pr.user.login + with open(filename) as f: + for l in f: + if l.rstrip('\r\n') == user: + print('{} has UT to be fixed, so CI failed.'.format(user)) + exit(1) + exit(0) + + +if __name__ == '__main__': + pr_checker = PRChecker() + pr_checker.check() -- GitLab