Esempio n. 1
0
def merge_pull_request(pull_request: Box) -> Error:
    error = Error()
    if blconfig.is_test or get_test_name_from_callstack():
        log.info('Skipping pr merge in test')
    else:
        log.info(f'Merging pull request ' f'{box2json(pull_request)}')
        github_client = Github(blconfig.github_token)
        repo = github_client.get_repo(pull_request.base_full_name)
        pr = repo.get_pull(pull_request.number)
        if dbox(pr.raw_data).mergeable_state == 'draft':
            log.info('Pull request is draft, not trying to merge')
        else:
            try:
                merge_status = pr.merge('Automatically merged by Botleague')
                if not merge_status.merged:
                    error.message = merge_status.message
                    error.http_status_code = 400
            except GithubException as e:
                error.message = str(e)
                error.http_status_code = e.status

    if error:
        log.error(f'Error merging pull request '
                  f'{box2json(pull_request)} '
                  f'Error: {box2json(error)}')

    return error
Esempio n. 2
0
def post_results_to_gist(db, results) -> Optional[github.Gist.Gist]:
    # Posts to botleague-results gist
    if blconfig.is_test or get_test_name_from_callstack():
        log.info('DETECTED TEST MODE: Not uploading results.')
        ret = None
    else:
        github_client = Github(
            decrypt_symmetric(
                db.get(constants.BOTLEAGUE_RESULTS_GITHUB_TOKEN_NAME)))
        # TODO: Need to use access_token header instead of query param by
        #  July!
        ret = github_client.get_user().create_gist(
            public=True,
            files={
                'results.json':
                github.InputFileContent(results.to_json(indent=2))
            },
            description='Automatically uploaded by botleague liaison')
    return ret
Esempio n. 3
0
def get_bot_eval(use_mock):
    if use_mock or blconfig.is_test or get_test_name_from_callstack():
        # Redundant guard rails
        return BotEvalMock
    else:
        return BotEval
Esempio n. 4
0
 def __init__(self, pr_event):
     if get_test_name_from_callstack():
         raise RuntimeError('Should not be using this class in tests!')
     super().__init__()
     self.pr_event = pr_event
Esempio n. 5
0
 def read_test_box(cls, relative_path):
     test_name = get_test_name_from_callstack()
     file_path = cls.get_test_filename_from_test_name(test_name,
                                                      relative_path)
     ret = Box.from_json(filename=file_path)
     return ret
Esempio n. 6
0
 def __init__(self):
     self.test_name = get_test_name_from_callstack()
     self.is_mock = True