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")
| 280 | |
| 281 | |
| 282 | def 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 | |
| 313 | def validate_github_token(token: str) -> None: |
no outgoing calls