Пример #1
0
 def test_get_commit_details(self):
     git_executor = MockGitExecutor('''log --show-notes=test-ref -n 1 --pretty=format:"hash,%H,shorthash,%h,commiter,%an <%ae>,date,%at|__NOTE__|%N" 1111''',
         ['hash,1111,shorthash,2222,commiter,Unit Test <*****@*****.**>,date,1371047821|__NOTE__|test note'])
     git_utils = GitUtils(git_executor)
     commit_details = git_utils.get_commit_details('test-ref', '1111')
     expected_details = {'date': '1371047821', 'note': 'test note', 'commiter': 'Unit Test <*****@*****.**>', 'shorthash': '2222', 'hash': '1111'};
     self.assertDictEqual(expected_details, commit_details)
Пример #2
0
    def exclusion_note(self, metrics_in_error: dict, git: GitUtils, logger: Logger):
        logger.info('Please consult the above warnings and errors concerning discrepancies in your build compared to '
                    'latest build.')
        answer = input('Do you want to accept the violations (Yes/No)? [No]: ')
        if not answer.upper() == 'YES':
            logger.info('I am treating this as a No (you typed: "%s").' % answer)
            logger.error('Failing because of metrics increase.')
            return Callable.do_not_proceed

        reason = ''
        while not reason.strip():
            reason = input('Provide a nonempty commit message (reason) for the increase [""]: ')

        username = '******' % (git.get_config_by_key('user.name'), git.get_config_by_key('user.email'))
        metrics = {}
        for key, value in metrics_in_error.items():
            metrics[key] = value['is']
        exclusion = {'reason': reason,
                     'committer': username,
                     'exclusion': metrics}

        note = JSONEncoder().encode(exclusion)

        if git.put_notes(note, STATS_EXCLUSION_REF_NAME, 'HEAD') != Callable.success:
            logger.error('Error encountered while setting note. Consult above messages if any.')
            return Callable.do_not_proceed

        if git.push_notes(STATS_EXCLUSION_REF_NAME) != Callable.success:
            logger.error('Error encountered while pushing notes. Consult above messages if any.')
            return Callable.do_not_proceed

        logger.info('The exclusion note has been pushed.')
        logger.warn('Remember to push your commit. DO NOT rebase (use merge instead) or the exclusion will be lost.')

        return Callable.success
Пример #3
0
    def test_get_notes_with_commit(self):
        test_note = 'test note'

        git_executor = MockGitExecutor('notes --ref=test-ref show notes_commit1',[test_note])

        git_utils = GitUtils(git_executor)
        retrieved_note = git_utils.get_notes('test-ref', 'notes_commit1')

        self.assertEqual(test_note, retrieved_note)
Пример #4
0
    def test_get_config_by_key(self):
        git_log_cmd = 'config --get {}'

        key = 'just.a.key'
        git_executor = MockGitExecutor() \
            .expect_call(git_log_cmd.format(key), ['a value'])

        git_utils = GitUtils(git_executor)
        data = git_utils.get_config_by_key(key)

        self.assertEqual('a value', data)
Пример #5
0
    def test_get_latest_annotated_commit(self):
        git_log_cmd = 'log --show-notes=test-ref -n {0} --pretty=format:"hash,%H,shorthash,%h,commiter,%an <%ae>,date,%at|__NOTE__|%N"'

        git_executor = MockGitExecutor() \
            .expect_call(git_log_cmd.format(30000), ['', 'key01,value01,key02,value02|__NOTE__|note01', 'ignore me',
                                                   'no,note,here,dude|__NOTE__|', 'key11,value11,key12,value12|__NOTE__|note02'])

        git_utils = GitUtils(git_executor)
        commit = git_utils.latest_annotated_commit_with_details('test-ref')

        self.assertDictEqual({'note': 'note01', 'key01':'value01', 'key02': 'value02'}, commit)
Пример #6
0
    def test_generate_annotated_commits_with_details(self):
        git_log_cmd = 'log --show-notes=test-ref -n {0} --pretty=format:"hash,%H,shorthash,%h,commiter,%an <%ae>,date,%at|__NOTE__|%N"'

        git_executor = MockGitExecutor()\
            .expect_call(git_log_cmd.format(100), ['key01,value01,key02,value02|__NOTE__|note01', 'key11,value11,key12,value12|__NOTE__|note02'])

        git_utils = GitUtils(git_executor)
        commits_generator = git_utils.generate_annotated_commits_with_details('test-ref', 100)

        self.assertDictEqual({'note': 'note01', 'key01':'value01', 'key02': 'value02'}, next(commits_generator))
        self.assertDictEqual({'note': 'note02', 'key11':'value11', 'key12': 'value12'}, next(commits_generator))
        self.assertIteratorFinished(commits_generator)
Пример #7
0
    def exclusion_note(self, metrics_in_error: dict, git: GitUtils,
                       logger: Logger):
        logger.info(
            'Please consult the above warnings and errors concerning discrepancies in your build compared to '
            'latest build.')
        answer = input('Do you want to accept the violations (Yes/No)? [No]: ')
        if not answer.upper() == 'YES':
            logger.info('I am treating this as a No (you typed: "%s").' %
                        answer)
            logger.error('Failing because of metrics increase.')
            return Callable.do_not_proceed

        reason = ''
        while not reason.strip():
            reason = input(
                'Provide a nonempty commit message (reason) for the increase [""]: '
            )

        username = '******' % (git.get_config_by_key('user.name'),
                                git.get_config_by_key('user.email'))
        metrics = {}
        for key, value in metrics_in_error.items():
            metrics[key] = value['is']
        exclusion = {
            'reason': reason,
            'committer': username,
            'exclusion': metrics
        }

        note = JSONEncoder().encode(exclusion)

        if git.put_notes(note, STATS_EXCLUSION_REF_NAME,
                         'HEAD') != Callable.success:
            logger.error(
                'Error encountered while setting note. Consult above messages if any.'
            )
            return Callable.do_not_proceed

        if git.push_notes(STATS_EXCLUSION_REF_NAME) != Callable.success:
            logger.error(
                'Error encountered while pushing notes. Consult above messages if any.'
            )
            return Callable.do_not_proceed

        logger.info('The exclusion note has been pushed.')
        logger.warn(
            'Remember to push your commit. DO NOT rebase (use merge instead) or the exclusion will be lost.'
        )

        return Callable.success
Пример #8
0
    def serverinfo(world_session, args):
        os_platform = f'{platform.system()} {platform.release()} ({platform.version()})'
        message = f'Platform: {os_platform}.\n'

        server_time = f'{datetime.now()}'
        message += f'Server Time: {server_time}.\n'

        server_uptime = timedelta(seconds=WorldManager.get_seconds_since_startup())
        message += f'Uptime: {server_uptime}.\n'

        current_commit_hash = GitUtils.get_current_commit_hash()
        current_branch = GitUtils.get_current_branch()
        message += f'Commit: [{current_branch}] {current_commit_hash}.'

        return 0, message
Пример #9
0
 def __generate_data_points_for_last_commits(self, log: Logger, git: GitUtils):
     last_data_points = {'metrics': {}}
     for commit in list(git.generate_annotated_commits_with_details(STATS_REF_NAME))[::-1]:
         decoded_stats = JSONDecoder().decode(commit['note'])
         current_data_points = self.__generate_data_point_for_commit(decoded_stats, commit, log)
         if not current_data_points['metrics'] == last_data_points['metrics']:
             last_data_points = current_data_points
             yield last_data_points
Пример #10
0
    def test_get_notes_with_commit_when_git_fails(self):
        git_executor = MockGitExecutor('notes --ref=test-ref show notes_commit1',
            ['error: No note found for object notes_commit1.'], 1)

        git_utils = GitUtils(git_executor)

        self.assertRaisesRegex(MockedGitException, 'Return code expected to be 0 but was 1.',
            git_utils.get_notes,'test-ref', 'notes_commit1')
Пример #11
0
 def __generate_data_points_for_last_commits(self, log: Logger,
                                             git: GitUtils):
     last_data_points = {'metrics': {}}
     for commit in list(
             git.generate_annotated_commits_with_details(
                 STATS_REF_NAME))[::-1]:
         decoded_stats = JSONDecoder().decode(commit['note'])
         current_data_points = self.__generate_data_point_for_commit(
             decoded_stats, commit, log)
         if not current_data_points['metrics'] == last_data_points[
                 'metrics']:
             last_data_points = current_data_points
             yield last_data_points
Пример #12
0
 def __init__(self,
              git: GitUtils = GitUtils(),
              fs: FileUtils = FileUtils(),
              metrics_processor=MetricsProcessor(),
              json_writer=JsonWriter()):
     super().__init__()
     self.command = 'eh-metrics'
     self.prevent_post_diagnostics = True
     self.description = 'Gathers engineering health metrics from the JIRA code. If any violations occur, you will be ' \
                        'able to add exclusion information interactively. You should pull all latest changes ' \
                        'before you run this.'
     self.git = git
     self.fs = fs
     self.metrics_processor = metrics_processor
     self.json_writer = json_writer
Пример #13
0
 def __generate_data_points(self, log: Logger, metrics, git: GitUtils):
     for x in list(self.__generate_data_points_for_last_commits(log, git))[-99:]:
         yield x
     yield self.__generate_data_point_for_commit(metrics.__dict__, git.get_commit_details(STATS_REF_NAME), log)
Пример #14
0
 def __generate_data_points(self, log: Logger, metrics, git: GitUtils):
     for x in list(self.__generate_data_points_for_last_commits(log,
                                                                git))[-99:]:
         yield x
     yield self.__generate_data_point_for_commit(
         metrics.__dict__, git.get_commit_details(STATS_REF_NAME), log)