예제 #1
0
    def test_commits_from_logs(self):
        logs = []
        self.assertEqual([], commits_from_logs(logs))

        logs = [
            'commit-id1\x00subject1\x00message1',
            '\ncommit-id2\x00subject2\x00message2', '\n', 'random text'
        ]
        actual_commits = commits_from_logs(logs)
        expected_commits = [
            Commit(hash='commit-id1', subject='subject1', message='message1'),
            Commit(hash='commit-id2', subject='subject2', message='message2'),
        ]
        self.assertEqual(expected_commits, actual_commits)
예제 #2
0
    def test_fetch_release_notes_from_commits(self):
        commits = [
            Commit(hash='commit-id1', subject='subject1', message='message1'),
            Commit(
                hash='commit-id2',
                subject='subject2',
                message='```improvement user\nrelease note text in commit\n```'
            ),
            Commit(
                hash='commit-id3',
                subject='subject2',
                message=
                'foo\n```improvement user\nrelease note text in commit 2\n```\nbar'
            )
        ]
        actual_rls_note_objs = fetch_release_notes_from_commits(
            commits, CURRENT_REPO)
        expected_rls_note_objs = [
            release_note_block_with_defaults(
                category_id=CATEGORY_IMPROVEMENT_ID,
                target_group_id=TARGET_GROUP_USER_ID,
                text='release note text in commit',
                reference_type=REF_TYPE_COMMIT,
                reference_id='commit-id2',
                user_login=None,
                source_repo=CURRENT_REPO.name(),
                cn_current_repo=CURRENT_REPO),
            release_note_block_with_defaults(
                category_id=CATEGORY_IMPROVEMENT_ID,
                target_group_id=TARGET_GROUP_USER_ID,
                text='release note text in commit 2',
                reference_type=REF_TYPE_COMMIT,
                reference_id='commit-id3',
                user_login=None,
                source_repo=CURRENT_REPO.name(),
                cn_current_repo=CURRENT_REPO),
        ]

        self.assertEqual(expected_rls_note_objs, actual_rls_note_objs)
예제 #3
0
파일: util.py 프로젝트: gardener/cc-utils
def commits_from_logs(git_logs: typing.List[str]) -> typing.List[Commit]:
    r = re.compile(
        r"(?P<commit_hash>\S+?)\x00(?P<commit_subject>.*)\x00(?P<commit_message>.*)",
        re.MULTILINE | re.DOTALL)
    commits = _\
        .chain(git_logs) \
        .map(lambda c: r.search(c)) \
        .filter(lambda m: m is not None) \
        .map(lambda m: m.groupdict()) \
        .map(lambda g: Commit(
            hash=g['commit_hash'],
            subject=g['commit_subject'],
            message=g['commit_message']
        )) \
        .value()
    return commits