예제 #1
0
def fork(repo):
    """
    Fork selected repository
    """
    app = App()

    target_repo_org, target_repo_name = repo.split("/", 1)
    # let's default to github if there is only 1 slash in repo

    if "/" in target_repo_name:
        git_project = app.get_git_project(repo)
    else:
        git_project = app.get_git_project(f"https://github.com/{repo}")
    username = git_project.service.user.get_username()
    forked_repo = git_project.fork_create()
    # FIXME: haxxxxx
    forked_repo.repo = target_repo_name
    forked_repo.namespace = username

    forked_repo_ssh_url = forked_repo.get_git_urls()["ssh"]

    clone_repo_and_cd_inside(target_repo_name, forked_repo_ssh_url, target_repo_org)

    set_upstream_remote(
        clone_url=git_project.get_git_urls()["git"],
        ssh_url=git_project.get_git_urls()["ssh"],
        pull_merge_name="pull",
    )
    set_origin_remote(forked_repo_ssh_url, pull_merge_name="pull")
    fetch_all()
예제 #2
0
    def fork(self, target_repo):

        target_repo_org, target_repo_name = target_repo.split("/", 1)

        target_repo_gh = self.g.get_repo(target_repo)

        try:
            # is it already forked?
            user_repo = self.user.get_repo(target_repo_name)
            if not self.is_fork_of(user_repo, target_repo):
                raise RuntimeError("repo %s is not a fork of %s" %
                                   (user_repo, target_repo_gh))
        except github.UnknownObjectException:
            # nope
            user_repo = None

        if self.user.login == target_repo_org:
            # user wants to fork its own repo; let's just set up remotes 'n stuff
            if not user_repo:
                raise RuntimeError("repo %s not found" % target_repo_name)
            clone_repo_and_cd_inside(user_repo.name, user_repo.ssh_url,
                                     target_repo_org)
        else:
            user_repo = self._fork_gracefully(target_repo_gh)

            clone_repo_and_cd_inside(user_repo.name, user_repo.ssh_url,
                                     target_repo_org)

            set_upstream_remote(
                clone_url=target_repo_gh.clone_url,
                ssh_url=target_repo_gh.ssh_url,
                pull_merge_name="pull",
            )
        set_origin_remote(user_repo.ssh_url, pull_merge_name="pull")
        fetch_all()
예제 #3
0
    def fork(self, target_repo):
        target_repo_org, target_repo_name = target_repo.split("/", 1)

        target_repo_gl = self.g.projects.get(target_repo)

        try:
            # is it already forked?
            user_repo = self.g.projects.get("{}/{}".format(
                self.user.username, target_repo_name))
            if not self.is_fork_of(user_repo, target_repo_gl):
                raise RuntimeError("repo %s is not a fork of %s" %
                                   (user_repo, target_repo_gl))
        except Exception:
            # nope
            user_repo = None

        if self.user.username == target_repo_org:
            # user wants to fork its own repo; let's just set up remotes 'n stuff
            if not user_repo:
                raise RuntimeError("repo %s not found" % target_repo_name)
            clone_repo_and_cd_inside(user_repo.path,
                                     user_repo.attributes["ssh_url_to_repo"],
                                     target_repo_org)
        else:
            user_repo = user_repo or self._fork_gracefully(target_repo_gl)

            clone_repo_and_cd_inside(user_repo.path,
                                     user_repo.attributes["ssh_url_to_repo"],
                                     target_repo_org)

            set_upstream_remote(
                clone_url=target_repo_gl.attributes["http_url_to_repo"],
                ssh_url=target_repo_gl.attributes["ssh_url_to_repo"],
                pull_merge_name="merge-requests",
            )
        set_origin_remote(user_repo.attributes["ssh_url_to_repo"],
                          pull_merge_name="merge-requests")
        fetch_all()