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

Function create_git_auth_header

src/gitingest/utils/git_utils.py:282–310  ·  view source on GitHub ↗

Create a Basic authentication header for GitHub git operations. Parameters ---------- token : str GitHub personal access token (PAT) for accessing private repositories. url : str The GitHub URL to create the authentication header for. Defaults to "https://git

(token: str, url: str = "https://github.com")

Source from the content-addressed store, hash-verified

280
281
282def create_git_auth_header(token: str, url: str = "https://github.com") -> str:
283 """Create a Basic authentication header for GitHub git operations.
284
285 Parameters
286 ----------
287 token : str
288 GitHub personal access token (PAT) for accessing private repositories.
289 url : str
290 The GitHub URL to create the authentication header for.
291 Defaults to "https://github.com" if not provided.
292
293 Returns
294 -------
295 str
296 The git config command for setting the authentication header.
297
298 Raises
299 ------
300 ValueError
301 If the URL is not a valid GitHub repository URL.
302
303 """
304 hostname = urlparse(url).hostname
305 if not hostname:
306 msg = f"Invalid GitHub URL: {url!r}"
307 raise ValueError(msg)
308
309 basic = base64.b64encode(f"x-oauth-basic:{token}".encode()).decode()
310 return f"http.https://{hostname}/.extraheader=Authorization: Basic {basic}"
311
312
313def validate_github_token(token: str) -> None:

Callers 6

clone_repoFunction · 0.90
create_git_commandFunction · 0.85
_resolve_ref_to_shaFunction · 0.85

Calls

no outgoing calls