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 __init__(self) -> None: self._local_repo = Utils.get_cwd_repo() self.__config = Config() try: origin = self._local_repo.remote(name="origin") except ValueError: Utils.log(LogType.ERROR, "No origin remote exists") sys.exit(1) repository: str = next(origin.urls) if repository.startswith("http"): Utils.log( LogType.INFO, "Found http remote, if you want to switch this " + "repository to ssh, run `git lab rewrite-remote " + "origin`", ) print() gitlab_url = Utils.gitlab_instance_url(repository) gitlab_hostname: Optional[str] = urlparse(gitlab_url).hostname if not gitlab_hostname: Utils.log(LogType.ERROR, "Failed to detect GitLab hostname") sys.exit(1) auth_token: Optional[str] = self.__config.token(gitlab_hostname) if not auth_token: Utils.log(LogType.ERROR, "No authentication token found. ") print( "Please create a token with the api and write_repository scopes on {}/-/{}." .format(gitlab_url, "profile/personal_access_tokens")) print('Afterwards use "git lab login --host {} --token t0k3n"'. format(gitlab_hostname)) sys.exit(1) self.__login(gitlab_url, auth_token) if not self._connection: Utils.log(LogType.ERROR, "Failed to connect to GitLab") sys.exit(1) try: self._remote_project = self._connection.projects.get( Utils.str_id_for_url(repository)) except (GitlabHttpError, GitlabGetError): Utils.log( LogType.ERROR, "The repository could not be found on the GitLab instance.", ) print( "If the repository was recently moved, please update the origin remote using git." ) sys.exit(1)
def __init__(self) -> None: self.__repo = Utils.get_cwd_repo() self.__git = self.__repo.git