Exemple #1
0
def main(cli_args):
    """Main entry point for Auto-Tag module."""

    parser = cli.get_parser()
    args = parser.parse_args(cli_args)

    logger = logging.getLogger(__name__)
    # pylint:disable=no-member, protected-access
    logger.setLevel(logging._nameToLevel[args.logging])
    console_handler = logging.StreamHandler()
    console_handler.setLevel(logging.DEBUG)

    # create formatter
    formatter = logging.Formatter('%(asctime)s: %(message)s')

    # add formatter to console_handler
    console_handler.setFormatter(formatter)

    # add console_handler to logger
    logger.addHandler(console_handler)

    if args.config:
        config = detectors_config.DetectorsConfig.from_file(args.config)
    else:
        config = detectors_config.DetectorsConfig.from_default()
    autotag = core.AutoTag(repo=args.repo,
                           branch=args.branch,
                           upstream_remotes=args.upstream_remote,
                           detectors=config.detectors,
                           git_name=args.name,
                           git_email=args.email,
                           append_v=args.append_v_to_tag,
                           skip_if_exists=args.skip_tag_if_one_already_present,
                           logger=logger)
    autotag.work()
Exemple #2
0
def test_multiple_commits(simple_repo, default_detectors):
    """Test to see if multiple commits with minor and major impact are handled
       properly."""
    repo = git.Repo(simple_repo, odbt=git.GitDB)

    for message in [
            'feature(m1): this is a feature it trigger a minor update',
            'fix(m1): a fix is triggering a patch',
            'fix(m1): fix with a breaking change \n BREAKING_CHANGE'
    ]:
        file_path = os.path.join(repo.working_dir, 'f_{}'.format(message[:4]))
        open(file_path, 'w+').close()
        repo.index.commit(message)

    repo.create_tag('1.2.3', ref=list(repo.iter_commits())[-1])

    autotag = core.AutoTag(repo=simple_repo,
                           branch='master',
                           upstream_remotes=None,
                           detectors=default_detectors,
                           git_name=TEST_NAME,
                           git_email=TEST_EMAIL)
    autotag.work()

    assert '2.0.0' in repo.tags
Exemple #3
0
def test_tag_message_user_exists_and_specify_make_sure_clean_env(
        simple_repo, default_detectors):
    """Test to see if the tag message has all the commit headings."""
    repo = git.Repo(simple_repo, odbt=git.GitDB)

    with repo.config_writer() as config_writer:
        config_writer.set_value('user', 'name', TEST_NAME)
        config_writer.set_value('user', 'email', TEST_EMAIL)

    autotag = core.AutoTag(repo=simple_repo,
                           branch='master',
                           detectors=default_detectors,
                           git_email=TEST_EMAIL_2,
                           upstream_remotes=None)
    autotag.work()
    assert '0.0.1' in repo.tags
    assert TEST_NAME == repo.tags['0.0.1'].tag.tagger.name
    assert TEST_EMAIL_2 == repo.tags['0.0.1'].tag.tagger.email

    with repo.config_writer() as config_writer:
        repo_config_name = config_writer.get_value('user', 'name')
        repo_config_email = config_writer.get_value('user', 'email')

    assert TEST_NAME == repo_config_name
    assert TEST_EMAIL == repo_config_email
Exemple #4
0
def test_tag_message_has_heading(simple_repo, default_detectors):
    """Test to see if the tag message has all the commit headings."""
    repo = git.Repo(simple_repo, odbt=git.GitDB)
    repo.create_tag('1.2.3', ref=list(repo.iter_commits())[0])

    messages = [
        'feature(m1): this is a feature it trigger a minor update \n text',
        'fix(m1): a fix is triggering a patch \n more text',
        'fix(m1): with a breaking change \n BREAKING_CHANGE \n even more'
    ]
    for message in messages:
        file_path = os.path.join(repo.working_dir, 'f_{}'.format(message[:4]))
        open(file_path, 'w+').close()
        repo.index.commit(message)

    autotag = core.AutoTag(repo=simple_repo,
                           branch='master',
                           upstream_remotes=None,
                           detectors=default_detectors,
                           git_name=TEST_NAME,
                           git_email=TEST_EMAIL)
    autotag.work()

    assert '2.0.0' in repo.tags
    for message in messages:
        assert message.split('\n')[0].strip() in repo.tags['2.0.0'].tag.message
Exemple #5
0
def test_push_to_multiple_remotes(
    simple_repo: str, tmpdir: LocalPath,
    default_detectors: List[Union[CommitMessageContainsDetector,
                                  CommitMessageHeadStartsWithDetector]]
) -> None:
    """Test the ability to push to remotes."""
    repo = git.Repo(simple_repo, odbt=git.GitDB)
    cloned_repo_path = os.path.join(tmpdir, 'cloned-repo')
    second_remote_path = os.path.join(tmpdir, 'second_remote')

    cloned_repo = repo.clone(cloned_repo_path)
    second_remote = git.Repo.init(second_remote_path, odbt=git.GitDB)

    cloned_repo.create_remote('second_remote', second_remote.common_dir)
    autotag = core.AutoTag(repo=cloned_repo_path,
                           branch='master',
                           upstream_remotes=['origin', 'second_remote'],
                           detectors=default_detectors,
                           git_name=TEST_NAME,
                           git_email=TEST_EMAIL)
    autotag.work()

    assert '0.0.1' in cloned_repo.tags
    assert '0.0.1' in repo.tags
    assert '0.0.1' in second_remote.tags
Exemple #6
0
def test_simple_flow_no_existing_tag(simple_repo, default_detectors):
    """Test a simple flow locally."""
    repo = git.Repo(simple_repo, odbt=git.GitDB)

    autotag = core.AutoTag(repo=simple_repo,
                           branch='master',
                           upstream_remotes=None,
                           detectors=default_detectors,
                           git_name=TEST_NAME,
                           git_email=TEST_EMAIL)
    autotag.work()
    assert '0.0.1' in repo.tags
Exemple #7
0
def test_simple_flow_existing_tag(existing_tag, next_tag, simple_repo,
                                  default_detectors):
    """Test a simple flow locally."""
    repo = git.Repo(simple_repo, odbt=git.GitDB)
    repo.create_tag(existing_tag, ref=list(repo.iter_commits())[-1])

    autotag = core.AutoTag(repo=simple_repo,
                           branch='master',
                           upstream_remotes=None,
                           detectors=default_detectors,
                           git_name=TEST_NAME,
                           git_email=TEST_EMAIL)

    autotag.work()
    assert next_tag in repo.tags
Exemple #8
0
def test_tag_message_user_does_not_exists_and_specified(
        simple_repo, default_detectors):
    """Test to see if the tag message has all the commit headings."""
    repo = git.Repo(simple_repo, odbt=git.GitDB)

    autotag = core.AutoTag(repo=simple_repo,
                           branch='master',
                           detectors=default_detectors,
                           git_name=TEST_NAME_2,
                           git_email=TEST_EMAIL_2,
                           upstream_remotes=None)
    autotag.work()
    assert '0.0.1' in repo.tags
    assert TEST_NAME_2 == repo.tags['0.0.1'].tag.tagger.name
    assert TEST_EMAIL_2 == repo.tags['0.0.1'].tag.tagger.email
Exemple #9
0
def test_push_to_remote(simple_repo, tmpdir, default_detectors):
    """Test the ability to push to remotes."""
    repo = git.Repo(simple_repo, odbt=git.GitDB)
    cloned_repo_path = os.path.join(tmpdir, 'cloned-repo')

    cloned_repo = repo.clone(cloned_repo_path)

    autotag = core.AutoTag(repo=cloned_repo_path,
                           branch='master',
                           upstream_remotes=['origin'],
                           detectors=default_detectors,
                           git_name=TEST_NAME,
                           git_email=TEST_EMAIL)
    autotag.work()

    assert '0.0.1' in repo.tags
    assert '0.0.1' in cloned_repo.tags
Exemple #10
0
def test_simple_flow_existing_tag_major_bump(
    existing_tag: str, next_tag: str, simple_repo_major_commit: str,
    default_detectors: List[Union[CommitMessageContainsDetector,
                                  CommitMessageHeadStartsWithDetector]]
) -> None:
    """Test a simple flow locally."""
    repo = git.Repo(simple_repo_major_commit, odbt=git.GitDB)
    repo.create_tag(existing_tag, ref=list(repo.iter_commits())[-1])

    autotag = core.AutoTag(repo=simple_repo_major_commit,
                           branch='master',
                           upstream_remotes=None,
                           detectors=default_detectors,
                           git_name=TEST_NAME,
                           git_email=TEST_EMAIL)

    autotag.work()
    assert next_tag in repo.tags
Exemple #11
0
def test_simple_flow_existing_tag_mixed_tag(
    simple_repo: str,
    default_detectors: List[Union[CommitMessageContainsDetector,
                                  CommitMessageHeadStartsWithDetector]]
) -> None:
    """Test the support for mixed tags."""
    repo = git.Repo(simple_repo, odbt=git.GitDB)
    repo.create_tag('2.0.1', ref=list(repo.iter_commits())[0])

    repo.create_tag('v2.0.1', ref=list(repo.iter_commits())[0])

    autotag = core.AutoTag(repo=simple_repo,
                           branch='master',
                           upstream_remotes=None,
                           detectors=default_detectors,
                           git_name=TEST_NAME,
                           git_email=TEST_EMAIL)

    autotag.work()
    assert '2.0.2' in repo.tags
Exemple #12
0
def test_tag_message_user_exists_and_only_email_specified(
    simple_repo: str,
    default_detectors: List[Union[CommitMessageContainsDetector,
                                  CommitMessageHeadStartsWithDetector]]
) -> None:
    """Test to see if the tag message has all the commit headings."""
    repo = git.Repo(simple_repo, odbt=git.GitDB)

    with repo.config_writer() as config_writer:
        config_writer.set_value('user', 'name', TEST_NAME)
        config_writer.set_value('user', 'email', TEST_EMAIL)

    autotag = core.AutoTag(repo=simple_repo,
                           branch='master',
                           detectors=default_detectors,
                           git_email=TEST_EMAIL_2,
                           upstream_remotes=None)
    autotag.work()
    assert '0.0.1' in repo.tags
    assert TEST_NAME == repo.tags['0.0.1'].tag.tagger.name
    assert TEST_EMAIL_2 == repo.tags['0.0.1'].tag.tagger.email
Exemple #13
0
def test_simple_flow_existing_tag_and_extra_tag_on_separate_branch(
    existing_tag: str, next_tag: str, simple_repo: str,
    default_detectors: List[Union[CommitMessageContainsDetector,
                                  CommitMessageHeadStartsWithDetector]]
) -> None:
    """Test to see if only specified branch is evaluated.

    Idea:
        If we already have tags on a another branch (let's say `new_branch`)
        if we want to auto-tag branch `master` then we should only look
        at tags on this branch.
    Scenario:
        Branch `master` has `current_tag` and `new_branch` has tag `BIG_TAG`.
        `BIG_TAG` is bigger then `current_tag`.
    Output:
        When we auto-tag the `master` branch then it should apply `next_tag`
    """
    repo = git.Repo(simple_repo, odbt=git.GitDB)
    repo.create_tag(existing_tag, ref=list(repo.iter_commits())[-1])

    # create a bigger tag on a new branch
    new_branch = repo.create_head('new_branch', force=True)
    repo.head.reference = new_branch
    # repo.head.reset(index=False, working_tree=False)

    file_path = os.path.join(simple_repo, 'extra_file')
    commit_text = 'commit an extra file'
    open(file_path, 'w+').close()
    extra_commit = repo.index.commit(commit_text)
    repo.create_tag(BIG_TAG, extra_commit)

    autotag = core.AutoTag(repo=simple_repo,
                           branch='master',
                           upstream_remotes=None,
                           detectors=default_detectors,
                           git_name=TEST_NAME,
                           git_email=TEST_EMAIL)

    autotag.work()
    assert next_tag in repo.tags
Exemple #14
0
def test_simple_flow_no_existing_tag(
    simple_repo: str,
    default_detectors: List[Union[CommitMessageContainsDetector,
                                  CommitMessageHeadStartsWithDetector]]
) -> None:
    """Test a simple flow.

    Scenario:
        A repository with a few commits but no tag.
    Outcome:
        Tag 0.0.1 should be created.

    """
    repo = git.Repo(simple_repo, odbt=git.GitDB)

    autotag = core.AutoTag(repo=simple_repo,
                           branch='master',
                           upstream_remotes=None,
                           detectors=default_detectors,
                           git_name=TEST_NAME,
                           git_email=TEST_EMAIL)
    autotag.work()
    assert '0.0.1' in repo.tags