MCPcopy
hub / github.com/coderamp-labs/gitingest / _parse_github_url

Function _parse_github_url

src/gitingest/utils/git_utils.py:160–195  ·  view source on GitHub ↗

Parse a GitHub URL and return (hostname, owner, repo). Parameters ---------- url : str The URL of the GitHub repository to parse. Returns ------- tuple[str, str, str] A tuple containing the hostname, owner, and repository name. Raises ------ Val

(url: str)

Source from the content-addressed store, hash-verified

158
159
160def _parse_github_url(url: str) -> tuple[str, str, str]:
161 """Parse a GitHub URL and return (hostname, owner, repo).
162
163 Parameters
164 ----------
165 url : str
166 The URL of the GitHub repository to parse.
167
168 Returns
169 -------
170 tuple[str, str, str]
171 A tuple containing the hostname, owner, and repository name.
172
173 Raises
174 ------
175 ValueError
176 If the URL is not a valid GitHub repository URL.
177
178 """
179 parsed = urlparse(url)
180 if parsed.scheme not in {"http", "https"}:
181 msg = f"URL must start with http:// or https://: {url!r}"
182 raise ValueError(msg)
183
184 if not parsed.hostname or not parsed.hostname.startswith("github."):
185 msg = f"Un-recognised GitHub hostname: {parsed.hostname!r}"
186 raise ValueError(msg)
187
188 parts = removesuffix(parsed.path, ".git").strip("/").split("/")
189 expected_path_length = 2
190 if len(parts) != expected_path_length:
191 msg = f"Path must look like /<owner>/<repo>: {parsed.path!r}"
192 raise ValueError(msg)
193
194 owner, repo = parts
195 return parsed.hostname, owner, repo
196
197
198async def fetch_remote_branches_or_tags(url: str, *, ref_type: str, token: str | None = None) -> list[str]:

Callers 1

check_repo_existsFunction · 0.85

Calls 1

removesuffixFunction · 0.90

Tested by

no test coverage detected