def test_checkout_pr(tmpdir): t = Path(str(tmpdir)) os.chdir(t) repo_name = "hello-world" namespace = "packit-service" fork_ssh_url = f"[email protected]:TomasTomecek/{repo_name}" repo_clone_url = f"https://github.com/{namespace}/{repo_name}" pr = "1" clone_repo_and_cd_inside(repo_name, fork_ssh_url, namespace) set_upstream_remote(repo_clone_url, fork_ssh_url, "pull") call_upsint(["checkout-pr", pr]) assert (subprocess.check_output( ["git", "rev-parse", "--abbrev-ref", "HEAD"]) == b"pr/1\n") commit = b"1e89e7e23d408506f7b192c07014e27572990a0f\n" assert subprocess.check_output(["git", "rev-parse", "HEAD"]) == commit # now let's change head, call co-pr again and see if we still get the same result subprocess.check_output(["git", "reset", "--hard", "HEAD^"]) call_upsint(["checkout-pr", pr]) assert (subprocess.check_output( ["git", "rev-parse", "--abbrev-ref", "HEAD"]) == b"pr/1\n") assert subprocess.check_output(["git", "rev-parse", "HEAD"]) == commit
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()
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()
def test_list_branches(tmp_path): os.chdir(tmp_path) repo_name = "research" namespace = "packit-service" repo_clone_url = f"https://github.com/{namespace}/{repo_name}" clone_repo_and_cd_inside(repo_name, repo_clone_url, namespace) out = call_upsint(["list-branches"], return_output=True) assert "╒═" in out assert "│ main" in out
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()