Esempio n. 1
0
async def pull_request_event_template(event, gh, repo, *args, **kwargs):
    pr_num = event.data['number']
    url = event.data["pull_request"]["comments_url"]
    BODY = event.data["pull_request"]["body"]
    sha = event.data["pull_request"]["head"]["sha"]
    await create_check_run(sha, gh, repo)
    if repo not in [
            'PaddlePaddle/Paddle', 'PaddlePaddle/benchmark',
            'lelelelelez/leetcode', 'PaddlePaddle/FluidDoc'
    ]:
        repo = 'Others'
    CHECK_TEMPLATE = localConfig.cf.get(repo, 'CHECK_TEMPLATE')
    global check_pr_template
    global check_pr_template_message
    check_pr_template, check_pr_template_message = checkPRTemplate(
        repo, BODY, CHECK_TEMPLATE)
    if check_pr_template == False:
        message = localConfig.cf.get(repo, 'NOT_USING_TEMPLATE')
        logger.error("%s Not Follow Template." % pr_num)
        if event.data['action'] == "opened":
            await gh.post(url, data={"body": message})
    else:
        comment_list = checkComments(url)
        for i in range(len(comment_list)):
            comment_sender = comment_list[i]['user']['login']
            comment_body = comment_list[i]['body']
            if comment_sender == "paddle-bot[bot]" and comment_body.startswith(
                    '❌'):
                message = localConfig.cf.get(repo, 'PR_CORRECT_DESCRIPTION')
                logger.info("%s Correct PR Description and Meet Template" %
                            pr_num)
                update_url = comment_list[i]['url']
                await gh.patch(update_url, data={"body": message})
Esempio n. 2
0
async def clean_parent_comment_list(gh, url, pr_num):
    parent_comment_list = checkComments(url)
    if len(parent_comment_list) != 0:
        count = 0
        for i in range(len(parent_comment_list)):
            parent_comment_sender = parent_comment_list[i]['user']['login']
            if parent_comment_sender == "paddle-bot[bot]":
                delete_url = parent_comment_list[i]['url']
                count += 1
                logger.info(
                    "REMOVE: %s comment(s) from parent commit; sender: %s; pr num: %s"
                    % (count, parent_comment_sender, pr_num))
                await gh.delete(delete_url)
            else:
                logger.info("Comment from User: %s, stop cleaning." %
                            parent_comment_sender)
Esempio n. 3
0
async def check_ci_failure(event, gh, repo, *args, **kwargs):
    """check commits whether passed all CI or contain failed CI"""
    if repo in ['PaddlePaddle/Paddle', 'PaddlePaddle/benchmark']:
        state = event.data['state']
        context = event.data['context']
        commit_url = event.data["commit"]["url"]
        combined_statuses_url = commit_url + "/status"
        comment_url = event.data["commit"]["comments_url"]
        ci_link = event.data['target_url']
        ifCancel = ifCancelXly(ci_link)
        if ifCancel == True:
            logger.info("cancel ci_link: %s" % ci_link)
        else:
            commitId = event.data['sha']
            shortId = commitId[0:7]
            pr_search_url = "https://api.github.com/search/issues?q=sha:" + commitId
            required_ci_list = localConfig.cf.get(repo, 'REQUIRED_CI')
            sender = event.data['commit']['author']['login']
            if sender in [
                    'lelelelelez', 'randytli', 'lanxianghit', 'zhiqiu',
                    'chenwhql', 'GaoWei8', 'gfwm2013', 'phlrain', 'Xreki',
                    'liym27', 'luotao1', 'pangyoki', 'tianshuo78520a', 'iducn',
                    'feng626', 'wangchaochaohu', 'wanghuancoder', 'wzzju',
                    'joejiong', 'Aurelius84', 'zhangting2020', 'zhhsplendid',
                    'zhouwei25'
            ]:
                pr_num = getPRNum(pr_search_url)
                commits_url = "https://api.github.com/repos/" + repo + "/pulls/" + str(
                    pr_num) + "/commits?per_page=250"
                comment_list = checkComments(comment_url)
                combined_ci_status, required_all_passed = await checkCIState(
                    combined_statuses_url, required_ci_list)
                if state in ['success', 'failure', 'error']:
                    if state == 'success':
                        if combined_ci_status != 'success':
                            await update_ci_failure_summary(
                                gh, context, ci_link, comment_list, pr_num,
                                shortId)
                        if combined_ci_status == 'success' or required_all_passed is True:
                            if len(comment_list) == 0:
                                message = localConfig.cf.get(
                                    repo, 'STATUS_CI_SUCCESS')
                                logger.info(
                                    "Successful trigger logic for CREATE success comment: %s; sha: %s"
                                    % (pr_num, shortId))
                                await gh.post(comment_url,
                                              data={"body": message})
                                await clean_parent_comment_list(
                                    gh, commits_url, pr_num, shortId)
                            else:
                                for i in range(len(comment_list)):
                                    comment_sender = comment_list[i]['user'][
                                        'login']
                                    comment_body = comment_list[i]['body']
                                    update_url = comment_list[i]['url']
                                    if comment_sender == "paddle-bot[bot]" and comment_body.startswith(
                                            '## 🕵️'):
                                        update_message = localConfig.cf.get(
                                            repo, 'STATUS_CI_SUCCESS')
                                        logger.info(
                                            "Successful trigger logic for CORRECT failed comment: %s; sha: %s"
                                            % (pr_num, shortId))
                                        await gh.delete(update_url)
                                        await gh.post(
                                            comment_url,
                                            data={"body": update_message})
                    else:
                        await create_add_ci_failure_summary(
                            gh, context, comment_url, ci_link, shortId, pr_num,
                            comment_list, commits_url)