示例#1
0
 def concatenate(cls,
                 changelogs: t.List['ChangelogData']) -> 'ChangelogData':
     return cls(changelogs[0].paths,
                changelogs[0].config,
                ChangesData.concatenate(
                    [changelog.changes for changelog in changelogs]),
                flatmap=changelogs[0].generator_flatmap)
示例#2
0
    def ansible(cls, directory: t.Optional[str],
                output_directory: t.Optional[str] = None) -> 'ChangelogData':
        paths = PathsConfig.force_ansible('')

        config = ChangelogConfig.default(paths, CollectionDetails(paths), 'Ansible')
        # TODO: adjust the following lines once Ansible switches to semantic versioning
        config.use_semantic_versioning = False
        config.release_tag_re = r'''(v(?:[\d.ab\-]|rc)+)'''
        config.pre_release_tag_re = r'''(?P<pre_release>(?:[ab]|rc)+\d*)$'''

        changelog_path = ''
        if directory is not None:
            changelog_path = os.path.join(directory, 'changelog.yaml')
        changes = ChangesData(config, changelog_path)
        if output_directory is not None:
            changes.path = os.path.join(output_directory, 'changelog.yaml')
        return cls(paths, config, changes, flatmap=True)
示例#3
0
 def ansible_base(cls,
                  changelog_data: t.Optional[t.Any] = None
                  ) -> 'ChangelogData':
     paths = PathsConfig.force_ansible('')
     collection_details = CollectionDetails(paths)
     config = ChangelogConfig.default(paths, collection_details)
     return cls(paths,
                config,
                ChangesData(config, '', changelog_data),
                flatmap=False)
示例#4
0
 def collection(cls, collection_name: str, version: str,
                changelog_data: t.Optional[t.Any] = None) -> 'ChangelogData':
     paths = PathsConfig.force_collection('')
     collection_details = CollectionDetails(paths)
     collection_details.namespace, collection_details.name = collection_name.split('.', 1)
     collection_details.version = version
     collection_details.flatmap = False  # TODO!
     config = ChangelogConfig.default(paths, collection_details)
     return cls(paths,
                config,
                ChangesData(config, '', changelog_data),
                flatmap=True)  # TODO!
def test_changes_data():
    paths = PathsConfig.force_collection('/')
    details = CollectionDetails(paths)
    config = ChangelogConfig.default(paths, details)

    data = {
        'ancestor': None,
        'releases': {},
    }

    changes = ChangesData(config,
                          os.path.join(config.paths.changelog_dir,
                                       config.changes_file),
                          data_override=data)
    changes.ancestor = '0.1.0'

    assert not changes.has_release
    assert sorted(changes.releases.keys()) == []

    changes.add_release('1.1.0', None, datetime.date(2020, 2, 1))

    assert changes.has_release
    assert sorted(changes.releases.keys()) == ['1.1.0']
    assert changes.latest_version == '1.1.0'

    changes.add_release('1.0.0', None, datetime.date(2020, 1, 1))

    assert changes.has_release
    assert sorted(changes.releases.keys()) == ['1.0.0', '1.1.0']
    assert changes.latest_version == '1.1.0'

    changes.add_release('1.2.0', None, datetime.date(2020, 3, 1))

    assert changes.has_release
    assert sorted(changes.releases.keys()) == ['1.0.0', '1.1.0', '1.2.0']
    assert changes.latest_version == '1.2.0'

    changes.add_release('1.2.1', None, datetime.date(2020, 3, 2))
    changes.add_release('1.3.0-alpha', None, datetime.date(2020, 3, 3))
    changes.add_release('1.3.0-beta', None, datetime.date(2020, 3, 4))
    changes.add_release('1.3.0', None, datetime.date(2020, 3, 5))
    changes.add_release('1.3.1-alpha', None, datetime.date(2020, 3, 6))

    assert sorted(changes.releases.keys()) == [
        '1.0.0',
        '1.1.0',
        '1.2.0',
        '1.2.1',
        '1.3.0',
        '1.3.0-alpha',
        '1.3.0-beta',
        '1.3.1-alpha',
    ]

    changes2 = ChangesData(config,
                           os.path.join(config.paths.changelog_dir,
                                        config.changes_file),
                           data_override=ChangesBase.empty())
    changes2.ancestor = '1.3.1-alpha'
    changes2.add_release('1.3.2', None, datetime.date(2020, 3, 10))
    changes2.add_release('1.3.3', None, datetime.date(2020, 3, 10))
    assert sorted(changes2.releases.keys()) == [
        '1.3.2',
        '1.3.3',
    ]

    changes3 = ChangesData(config,
                           os.path.join(config.paths.changelog_dir,
                                        config.changes_file),
                           data_override=ChangesBase.empty())
    changes3.add_release('0.1.0', None, datetime.date(2019, 7, 30))
    changes3.add_release('0.2.0', None, datetime.date(2019, 12, 31))
    assert sorted(changes3.releases.keys()) == [
        '0.1.0',
        '0.2.0',
    ]

    for order in [
        [changes, changes2],
        [changes2, changes],
    ]:
        changes_concat = ChangesData.concatenate(order)
        assert sorted(changes_concat.releases.keys()) == [
            '1.0.0',
            '1.1.0',
            '1.2.0',
            '1.2.1',
            '1.3.0',
            '1.3.0-alpha',
            '1.3.0-beta',
            '1.3.1-alpha',
            '1.3.2',
            '1.3.3',
        ]
        assert changes_concat.ancestor == '0.1.0'

    for order in [
        [changes, changes2, changes3],
        [changes, changes3, changes2],
        [changes2, changes, changes3],
        [changes2, changes3, changes],
        [changes3, changes, changes2],
        [changes3, changes2, changes],
    ]:
        changes_concat = ChangesData.concatenate(order)
        assert sorted(changes_concat.releases.keys()) == [
            '0.1.0',
            '0.2.0',
            '1.0.0',
            '1.1.0',
            '1.2.0',
            '1.2.1',
            '1.3.0',
            '1.3.0-alpha',
            '1.3.0-beta',
            '1.3.1-alpha',
            '1.3.2',
            '1.3.3',
        ]
        assert changes_concat.ancestor is None

    changes_concat.ancestor = '0.0.1'

    changes_concat.prune_versions(versions_after='0.1.0', versions_until=None)
    assert sorted(changes_concat.releases.keys()) == [
        '0.2.0',
        '1.0.0',
        '1.1.0',
        '1.2.0',
        '1.2.1',
        '1.3.0',
        '1.3.0-alpha',
        '1.3.0-beta',
        '1.3.1-alpha',
        '1.3.2',
        '1.3.3',
    ]
    assert changes_concat.ancestor == '0.1.0'

    changes_concat.prune_versions(versions_after=None, versions_until='1.3.2')
    assert sorted(changes_concat.releases.keys()) == [
        '0.2.0',
        '1.0.0',
        '1.1.0',
        '1.2.0',
        '1.2.1',
        '1.3.0',
        '1.3.0-alpha',
        '1.3.0-beta',
        '1.3.1-alpha',
        '1.3.2',
    ]
    assert changes_concat.ancestor == '0.1.0'

    changes_concat.prune_versions(versions_after='1.1.0',
                                  versions_until='1.3.0')
    assert sorted(changes_concat.releases.keys()) == [
        '1.2.0',
        '1.2.1',
        '1.3.0',
        '1.3.0-alpha',
        '1.3.0-beta',
    ]
    assert changes_concat.ancestor == '1.1.0'