def test_main_deb_fakerepo(self):
        """
        Generate a changelog from a well known and defined repository
        which we control ourselves - DEB
        """
        input_messages = [
            "First",
            "Second",
        ]

        (path, repo, client) = prepare_git_repo(self.tmp_dir,
                                                messages=input_messages)
        assert not repo.bare
        assert client

        out_file = os.path.join(self.tmp_dir, 'outfile')
        assert err.SUCCESS == gcg.entrypoint.main([
            'xyz', '-p', path, '-O', 'deb', '-o', out_file, '-n', 'foopkg',
            '-D', 'xenial'
        ])
        assert os.path.exists(out_file)

        lines = [line.rstrip('\n') for line in open(out_file)]
        lines = filter(len, lines)
        assert lines[0] == 'foopkg (current) xenial; urgency=low'
        assert lines[1].startswith('  * Second')
        assert lines[2].startswith('  * First')
    def test_merge_repo(self):
        input_messages = ["1", "2", "3"]

        (path, repo, client) = prepare_git_repo(self.tmp_dir,
                                                messages=input_messages)
        test_branch = repo.create_head('test_branch', 'HEAD~1')

        repo.head.reference = test_branch
        repo.index.commit('4')
        repo.head.reference = repo.heads.master
        repo.index.commit('5')
        client.merge('--no-ff', '-m 6', 'test_branch')

        out_file = os.path.join(self.tmp_dir, 'outfile')
        assert err.SUCCESS == gcg.entrypoint.main(
            ['xyz', '-p', path, '-O', 'rpm', '-o', out_file])
        assert os.path.exists(out_file)

        lines = [line.rstrip('\n') for line in open(out_file)]
        lines = filter(len, lines)
        print(lines)

        count = len(lines)
        for i in range(1, count):
            assert lines[count - i].startswith('- {}'.format(i))
    def test_main_rpm_fakerepo(self):
        """
        Generate a changelog from a well known and defined repository
        which we control ourselves.
        """

        input_messages = [
            "Initial commit",
            "And then a second commit",
            "ISSUE-1 And a third commit\nThis time with a Jira ticket",
        ]

        (path, repo, client) = prepare_git_repo(self.tmp_dir,
                                                messages=input_messages)
        assert not repo.bare
        assert not client.tag()

        out_file = os.path.join(self.tmp_dir, 'outfile')
        assert err.SUCCESS == gcg.entrypoint.main(
            ['xyz', '-p', path, '-O', 'rpm', '-o', out_file])
        assert os.path.exists(out_file)

        lines = [line.rstrip('\n') for line in open(out_file)]
        assert lines[0].endswith('{} <{}> - current'.format(
            AUTHOR.name, AUTHOR.email))
        assert lines[1].startswith('- ISSUE-1 And a third commit')
        assert lines[2].startswith('- And then a second commit')
        assert lines[3].startswith('- Initial commit')
    def test_main_only_jira_issues(self):
        """
        Validate that with -b option, only commits containing
        JIRA issues (default) are included
        """

        input_messages = [
            "Initial commit",
            "And then a second commit",
            "ISSUE-1 And a third commit\nThis time with a Jira ticket",
        ]

        # pylint: disable=unused-variable
        (path, repo, client) = prepare_git_repo(self.tmp_dir,
                                                messages=input_messages)

        out_file = os.path.join(self.tmp_dir, 'outfile')
        assert err.SUCCESS == gcg.entrypoint.main(
            ['xyz', '-p', path, '-O', 'rpm', '-o', out_file, '-b'])
        assert os.path.exists(out_file)

        lines = [line.rstrip('\n') for line in open(out_file)]
        assert len(lines) == 3
        assert lines[0].endswith('> - current')
        assert lines[1].startswith('- ISSUE-1 And a third commit')
    def test_only_gitlab_issues(self):
        """
        Validate that with -b option, only commits containing
        gitlab issues by passing in a -B and a custom pattern
        """

        input_messages = [
            "Initial commit",
            "Issue #312 Resolve the bug",
        ]

        # pylint: disable=unused-variable
        (path, repo, client) = prepare_git_repo(self.tmp_dir,
                                                messages=input_messages)

        out_file = os.path.join(self.tmp_dir, 'outfile')
        assert err.SUCCESS == gcg.entrypoint.main([
            'xyz', '-p', path, '-O', 'rpm', '-o', out_file, '-b', '-B',
            r'Issue #\d+\b'
        ])

        lines = [line.rstrip('\n') for line in open(out_file)]
        assert len(lines) == 3
        assert lines[0].endswith('> - current')
        assert lines[1].startswith('- Issue #312 Resolve the bug')
示例#6
0
 def test_with_prefix(self):
     input_data = [("1st", None), ("2nd", None), ("3rd", "v1.0.0"),
                   ("4th", None), ("5th", "v1.0.1"), ("6th", None)]
     # pylint: disable=unused-variable
     (path, repo, client) = prepare_git_repo(self.tmp_dir,
                                             messages_and_tags=input_data)
     out_file = os.path.join(self.tmp_dir, 'outfilexx')
     assert err.SUCCESS == gcg.entrypoint.main(
         ['xyz', '-p', path, '-O', 'rpm', '-o', out_file, '-P', 'v'])
     assert os.path.exists(out_file)
     lines = [line.rstrip('\n') for line in open(out_file)]
     assert len(lines) == 12
     assert lines[0].endswith('> - current')
     assert lines[3].endswith('> - 1.0.1')
     assert lines[7].endswith('> - 1.0.0')
示例#7
0
 def test_without_prefix(self):
     input_data = [("1st", None), ("2nd", None), ("3rd", "v1.0.0"),
                   ("4th", None), ("5th", "v1.0.1"), ("6th", None)]
     # pylint: disable=unused-variable
     (path, repo, client) = prepare_git_repo(self.tmp_dir,
                                             messages_and_tags=input_data)
     out_file = os.path.join(self.tmp_dir, 'outfilexx')
     assert err.SUCCESS == gcg.entrypoint.main(
         ['xyz', '-p', path, '-O', 'rpm', '-o', out_file])
     assert os.path.exists(out_file)
     lines = [line.rstrip('\n') for line in open(out_file)]
     count = len(lines) - 1
     assert count == 7
     assert lines[0].endswith('> - current')
     for i in range(1, count):
         assert lines[count - i].startswith('- {}'.format(i))
示例#8
0
    def test_timeformat_deb(self):
        """
        Verify the format of the timestamp in the deb changelog
        """
        input_messages = [
            "First",
        ]
        # pylint: disable=unused-variable
        (path, repo, client) = prepare_git_repo(self.tmp_dir,
                                                messages=input_messages)
        assert not repo.bare
        assert client

        out_file = os.path.join(self.tmp_dir, 'outfile')
        assert err.SUCCESS == gcg.entrypoint.main([
            'xyz', '-p', path, '-O', 'deb', '-o', out_file, '-n', 'package',
            '-D', 'unstable'
        ])
        assert os.path.exists(out_file)

        lines = [line.rstrip('\n') for line in open(out_file)]
        lines = list(filter(len, lines))
        assert len(lines) == 3
        assert lines[0] == 'package (current) unstable; urgency=low'
        assert lines[1].startswith('  * First')
        mobj = re.search(
            r'([a-z]{3}), (\d\d) ([a-z]{3}) (\d{4}) ' +
            r'(\d\d):(\d\d):(\d\d) [+-](\d{4})$', lines[2], re.I)
        assert mobj
        grp = mobj.groups()
        dnames = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
        mnames = [
            'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
            'Oct', 'Nov', 'Dec'
        ]
        assert len(grp) == 8
        assert grp[0] in dnames
        assert int(grp[1]) > 0 and int(grp[1]) < 32
        assert grp[2] in mnames
        assert int(grp[3]) > 1969 and int(grp[3]) < 2039
        assert int(grp[4]) >= 0 and int(grp[4]) < 24
        assert int(grp[5]) >= 0 and int(grp[5]) < 60
        assert int(grp[6]) >= 0 and int(grp[6]) < 60
        assert int(grp[7]) >= 0 and int(grp[7]) <= 1400
    def test_main_deb_custom_urgency(self):
        """
        Verify the deb urgency is recorded as appropriate
        """
        input_messages = [
            "First",
        ]

        (path, repo, client) = prepare_git_repo(self.tmp_dir,
                                                messages=input_messages)
        assert not repo.bare
        assert client

        out_file = os.path.join(self.tmp_dir, 'outfile')
        assert err.SUCCESS == gcg.entrypoint.main([
            'xyz', '-p', path, '-O', 'deb', '-o', out_file, '-n', 'package',
            '-D', 'xenial', '-U', 'high'
        ])
        assert os.path.exists(out_file)

        lines = [line.rstrip('\n') for line in open(out_file)]
        lines = filter(len, lines)
        assert lines[0] == 'package (current) xenial; urgency=high'
        assert lines[1].startswith('  * First')
示例#10
0
    def test_timeformat_rpm(self):
        """
        Verify the format of the timestamp in the rpm changelog
        """
        input_messages = [
            "First",
        ]
        # pylint: disable=unused-variable
        (path, repo, client) = prepare_git_repo(self.tmp_dir,
                                                messages=input_messages)
        assert not repo.bare
        assert client

        out_file = os.path.join(self.tmp_dir, 'outfile')
        assert err.SUCCESS == gcg.entrypoint.main(
            ['xyz', '-p', path, '-O', 'rpm', '-o', out_file])
        assert os.path.exists(out_file)

        lines = [line.rstrip('\n') for line in open(out_file)]
        lines = list(filter(len, lines))
        assert len(lines) == 2
        assert lines[1].startswith('- First')
        mobj = re.search(r'^\* ([a-z]{3}) ([a-z]{3}) (\d\d) (\d{4})', lines[0],
                         re.I)
        assert mobj
        grp = mobj.groups()
        dnames = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
        mnames = [
            'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
            'Oct', 'Nov', 'Dec'
        ]
        assert len(grp) == 4
        assert grp[0] in dnames
        assert grp[1] in mnames
        assert int(grp[2]) > 0 and int(grp[2]) < 32
        assert int(grp[3]) > 1969 and int(grp[3]) < 2039