def version_repo(self):
        config_file = ""
        with open(".bumpversion.cfg", "r") as file:
            config_file = file.read()

        # version repo
        logger.debug("Running bumpversion of type: " +
                     str(self.version_type.name))
        bump_version(get_tag_version(), self.version_type)
        return self
 def test_minor_bump(self):
     self.assertEqual("0.1.0", bump.bump_version("0.0.0", semver.VersionType.MINOR, False))
     self.assertEqual("0.1.0", bump.bump_version("0.0.1", semver.VersionType.MINOR, False))
     self.assertEqual("0.2.0", bump.bump_version("0.1.0", semver.VersionType.MINOR, False))
     self.assertEqual("1.1.0", bump.bump_version("1.0.0", semver.VersionType.MINOR, False))
     self.assertEqual("1.3.0", bump.bump_version("1.2.3", semver.VersionType.MINOR, False))
     self.assertEqual("0.1.0", bump.bump_version("0.0.10", semver.VersionType.MINOR, False))
     self.assertEqual("0.11.0", bump.bump_version("0.10.0", semver.VersionType.MINOR, False))
     self.assertEqual("10.1.0", bump.bump_version("10.0.0", semver.VersionType.MINOR, False))
 def test_major_bump(self):
     self.assertEqual("1.0.0", bump.bump_version("0.0.0", semver.VersionType.MAJOR, False))
     self.assertEqual("1.0.0", bump.bump_version("0.0.1", semver.VersionType.MAJOR, False))
     self.assertEqual("1.0.0", bump.bump_version("0.1.0", semver.VersionType.MAJOR, False))
     self.assertEqual("2.0.0", bump.bump_version("1.0.0", semver.VersionType.MAJOR, False))
     self.assertEqual("2.0.0", bump.bump_version("1.2.3", semver.VersionType.MAJOR, False))
     self.assertEqual("1.0.0", bump.bump_version("0.0.10", semver.VersionType.MAJOR, False))
     self.assertEqual("1.0.0", bump.bump_version("0.10.0", semver.VersionType.MAJOR, False))
     self.assertEqual("11.0.0", bump.bump_version("10.0.0", semver.VersionType.MAJOR, False))
 def test_patch_bump(self):
     self.assertEqual("0.0.1", bump.bump_version("0.0.0", semver.VersionType.PATCH, False))
     self.assertEqual("0.0.2", bump.bump_version("0.0.1", semver.VersionType.PATCH, False))
     self.assertEqual("0.1.1", bump.bump_version("0.1.0", semver.VersionType.PATCH, False))
     self.assertEqual("1.0.1", bump.bump_version("1.0.0", semver.VersionType.PATCH, False))
     self.assertEqual("1.2.4", bump.bump_version("1.2.3", semver.VersionType.PATCH, False))
     self.assertEqual("0.0.11", bump.bump_version("0.0.10", semver.VersionType.PATCH, False))
     self.assertEqual("0.10.1", bump.bump_version("0.10.0", semver.VersionType.PATCH, False))
     self.assertEqual("10.0.1", bump.bump_version("10.0.0", semver.VersionType.PATCH, False))
Beispiel #5
0
def get_version(build=0, version_format=None, dot=False):
    version = get_tag_version()

    # Get the commit hash of the version
    v_hash = subprocess.Popen(['git', 'rev-list', '-n', '1', version],
                              stdout=subprocess.PIPE,
                              stderr=DEVNULL,
                              cwd='.').stdout.read().decode('utf-8').rstrip()
    # Get the current commit hash
    c_hash = subprocess.Popen(['git', 'rev-parse', 'HEAD'],
                              stdout=subprocess.PIPE,
                              stderr=DEVNULL,
                              cwd='.').stdout.read().decode('utf-8').rstrip()

    # If the version commit hash and current commit hash
    # do not match return the branch name else return the version
    if v_hash != c_hash:
        logger.debug("v_hash and c_hash do not match!")
        branch = subprocess.Popen(
            ['git', 'rev-parse', '--abbrev-ref', 'HEAD'],
            stdout=subprocess.PIPE,
            stderr=DEVNULL,
            cwd='.').stdout.read().decode('utf-8').rstrip()
        semver = SemVer()
        semver.merged_branch = branch
        logger.debug("merged branch is: {}".format(semver.merged_branch))
        version_type = semver.get_version_type()
        logger.debug("version type is: {}".format(version_type))
        if version_type:

            next_version = bump_version(get_tag_version(), version_type, False,
                                        False)

            if version_format in ('npm', 'docker'):
                return "{}-{}.{}".format(next_version,
                                         re.sub(r'[/_]', '-', branch), build)
            if version_format == 'maven':
                qualifier = 'SNAPSHOT' if build == 0 else build
                return "{}-{}-{}".format(next_version,
                                         re.sub(r'[/_]', '-', branch),
                                         qualifier)
        if dot:
            branch = branch.replace('/', '.')
        return branch
    return version