def run(args: argparse.Namespace) -> None: """ :param args: parsed arguments """ repo: Repo = Utils.get_cwd_repo() remote_url = repo.git.remote("get-url", args.remote) ssh_url = Utils.ssh_url_from_http(Utils.normalize_url(remote_url)) repo.git.remote("set-url", args.remote, ssh_url)
def fork(self) -> None: """ Try to create a fork of the remote repository. If the fork already exists, no new fork will be created. """ if "fork" in self._local_repo.remotes: # Fork already exists fork_str_id: str = Utils.str_id_for_url( self._local_repo.remotes.fork.url) # Try to retrieve the remote project object, if it doesn't exist on the server, # go on with the logic to create a new fork. try: self.__remote_fork = self._connection.projects.get(fork_str_id) return except GitlabGetError: pass try: self.__remote_fork = self._remote_project.forks.create({}) # WORKAROUND: the return of create() is unreliable, # and sometimes doesn't allow to create merge requests, # so request a fresh project object. self.__remote_fork = self._connection.projects.get( self.__remote_fork.id) self._local_repo.create_remote( "fork", url=self.__remote_fork.ssh_url_to_repo) except GitlabCreateError: Utils.log( LogType.INFO, "Fork exists, but no fork remote exists locally, trying to guess the url", ) # Detect ssh url url = Utils.ssh_url_from_http(self._connection.user.web_url + "/" + self._remote_project.path) self._local_repo.create_remote("fork", url=url) str_id: str = Utils.str_id_for_url( self._local_repo.remotes.fork.url) self.__remote_fork = self._connection.projects.get(str_id)
def test_ssh_url_from_http(self): url: str = "http://invent.kde.org/KDE/kaidan" ssh_url: str = Utils.ssh_url_from_http(url) self.assertEqual(ssh_url, "ssh://[email protected]/KDE/kaidan")