Esempio n. 1
0
def updater_main(
    repo_url: str,
    refspec: str,
    target_branch: str,
    push_map: str,
    updater_func: Callable[[], None],
    logger: Logger,
    execute_commit: bool = False,
):
    """Run the actual logic to update the upstream source and push the changes

    :param repo_url: midstream repository URL
    :param refspec: refspec to fetch
    :param target_branch: branch to push the changes to
    :param push_map: path to pusher push map
    :param updater_func: A callable that is called with the root of the
        repository as the first argument and run the actual update.
    :param logger: logger instance that will be used to log messages
    """
    repo_name = get_name_from_repo_url(repo_url)
    repo_root = os.path.join(os.getcwd(), repo_name)
    logger.info('adding repo url: %s', repo_url)
    _, fetch_sha = prep_git_repo(repo_root, repo_url, refspec, checkout=True)
    with file_utils.workdir(repo_root):
        ret = updater_func()
        if execute_commit:
            commit_files(['.'])
        push_upstream_sources(dst_branch=target_branch,
                              push_map=push_map,
                              if_not_exists=True,
                              unless_hash=fetch_sha)

    return ret
Esempio n. 2
0
def updater_main(repo_url: str, refspec: str, target_branch: str,
                 push_map: str):
    """Run the actual logic to update the upstream source and push the changes

    :param repo_url: midstream repository URL
    :param refspec: refspec to fetch
    :param target_branch: branch to push the changes to
    :param push_map: path to pusher push map
    """
    repo_name = get_name_from_repo_url(repo_url)
    repo_root = os.path.join(os.getcwd(), repo_name)
    logger.info('adding repo url: %s', repo_url)
    git_func, fetch_sha = prep_git_repo(repo_root,
                                        repo_url,
                                        refspec,
                                        checkout=True)
    run_upstream_source_updater(repo_root)
    push_changes(repo_root=repo_root,
                 repo_url=repo_url,
                 push_branch=target_branch,
                 unless_hash=fetch_sha,
                 push_map=push_map)
Esempio n. 3
0
def test_get_name_from_repo_url_exception(repo_url):
    with pytest.raises(CouldNotParseRepoURL):
        get_name_from_repo_url(repo_url)
Esempio n. 4
0
def test_get_name_from_repo_url(repo_url, expected_name):
    assert get_name_from_repo_url(repo_url) == expected_name