check_ut.py 1.7 KB
Newer Older
C
chalsliu 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#!/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 os.path
from github import Github


class PRChecker(object):
23
    """PR Checker."""
C
chalsliu 已提交
24 25

    def __init__(self):
26
        self.github = Github(os.getenv('GITHUB_API_TOKEN'), timeout=60)
C
chalsliu 已提交
27 28
        self.repo = None

C
chalsliu 已提交
29
    def check(self, filename, msg):
30
        """
C
chalsliu 已提交
31
        Args:
32 33
            filename (str): File to get block names.
            msg (str): Error message.
C
chalsliu 已提交
34
        """
C
chalsliu 已提交
35 36 37 38 39 40 41 42 43 44 45 46 47 48
        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:
C
chalsliu 已提交
49
                    print('{} {}'.format(user, msg))
C
chalsliu 已提交
50 51 52 53


if __name__ == '__main__':
    pr_checker = PRChecker()
C
chalsliu 已提交
54 55
    pr_checker.check('block.txt', 'has unit-test to be fixed, so CI failed.')
    pr_checker.check('bk.txt', 'has benchmark issue to be fixed, so CI failed.')