Esempio n. 1
0
    def test_disallows_multiple_h1s(self):
        with temp_directory():
            touch('CHANGELOG.md', '# My Changelog\n# Current Release\n')

            with self.assertRaisesRegexp(
                    Exception, 'Changelog has multiple level 1 headings.'):
                parse_changelog('CHANGELOG.md')
Esempio n. 2
0
    def test_disallows_heading_level_jump(self):
        with temp_directory():
            touch('CHANGELOG.md', '# H1\n#### H3\n')

            with self.assertRaisesRegexp(
                    Exception,
                    'Changelog heading level jumps from level 1 to level 4. Must jump one level per heading.'
            ):
                parse_changelog('CHANGELOG.md')
Esempio n. 3
0
    def test_disallows_heading_level_3_without_release(self):
        with temp_directory():
            touch('CHANGELOG.md', '# H1\n### H3\n')

            with self.assertRaisesRegexp(
                    Exception,
                    'Level 3 heading was not found within a release \(level 2 heading\)'
            ):
                parse_changelog('CHANGELOG.md')
Esempio n. 4
0
    def test_disallows_missing_h1(self):
        with temp_directory():
            touch('CHANGELOG.md', 'Hello World')

            with self.assertRaisesRegexp(
                    Exception,
                    'Changelog does not start with a level 1 heading, including the changelog name.'
            ):
                parse_changelog('CHANGELOG.md')
Esempio n. 5
0
    def determine_current_version(self):
        changelog = parse_changelog(self.path)
        for release in changelog.releases:
            if release.name == 'Master':
                continue

            return Version(release.name)
Esempio n. 6
0
    def test_parse_changelog(self):
        fixture_path = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                                    'release', 'fixtures')
        changelog_path = os.path.join(fixture_path, 'CHANGELOG.md')

        changelog = parse_changelog(changelog_path)

        self.assertEqual(changelog.name, 'swiftenv Changelog')
        self.assertEqual(len(changelog.releases), 2)
        self.assertEqual(changelog.releases[0].name, 'Master')
        self.assertEqual(changelog.releases[1].name, '1.0.0')
Esempio n. 7
0
    def __init__(self, config=None):
        self.sections = {
            'breaking': 'major',
            'enhancements': 'minor',
            'bug fixes': 'patch',
        }

        if config:
            sections = config.get('sections', {})
            if len(sections) > 0:
                self.sections = {}

                for section in sections:
                    self.sections[section.lower()] = sections[section]

        changelog = parse_changelog(self.path)
        self.validate_changelog(changelog)
Esempio n. 8
0
    def bump(self, new_version):
        changelog = parse_changelog(self.path)

        if len(changelog.releases) > 0:
            release = changelog.releases[0]
            if release.name == 'Master':
                with open(self.path) as fp:
                    content = fp.read()

                heading = '## {} ({})'.format(new_version, date.today().isoformat())
                content = re.sub(r'^## Master$', heading, content, flags=re.MULTILINE)

                with open('CHANGELOG.md', 'w') as fp:
                    fp.write(content)
            else:
                raise Exception('Last changelog release was `{}` and not `Master`.'.format(release.name))
        else:
            raise Exception('Changelog is missing a master release.')
Esempio n. 9
0
    def determine_next_version(self):
        current_version = self.determine_current_version()
        if current_version.prerelease or current_version.build:
            return None

        changelog = parse_changelog(self.path)

        for release in changelog.releases:
            if release.name != 'Master':
                continue

            major = False
            minor = False
            patch = False

            for section in self.sections:
                if release.find_section(section):
                    if self.sections[section] == self.MAJOR:
                        major = True
                    elif self.sections[section] == self.MINOR:
                        minor = True
                    if self.sections[section] == self.PATCH:
                        patch = True

            if major:
                if current_version.major == 0:
                    return current_version.next_minor()

                return current_version.next_major()

            if minor:
                return current_version.next_minor()

            if patch:
                return current_version.next_patch()

        return None