Documentation
¶
Overview ¶
Package gitremote reads a git remote as the GitHub repository it names.
`cloop remote init` (Task 20417) creates a hub project from the checkout it is run in, and the first thing it needs from that checkout is which repository it is a clone of — the name the project's GitHub grant is then narrowed to. The answer is in the origin remote, written in whichever of git's spellings the developer cloned with: https, the scp form GitHub prints for ssh (git@github.com:owner/name.git), an ssh:// URL, the ssh-over-443 host. All of them name the same owner/name, and that is all this package returns.
Two things are refused rather than read, and both by name:
- A remote that is not on GitHub. The hub reaches repositories through a GitHub App installation or a GitHub token, so a GitLab or Bitbucket remote names nothing either could reach, and guessing an owner/name from its path would attach a GitHub repository of the same name — somebody else's.
- A remote that carries a credential: https://<token>@github.com/…, a password in an ssh URL, an access_token query. Nothing here would use it, and every place the remote would go next — a grant, an audit row, an error message — is somewhere a credential must not. Errors print the remote with its user information replaced (Redact).
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotGitHub: the remote names a repository somewhere other than // github.com, or a local path. ErrNotGitHub = errors.New("not a GitHub repository") // ErrCredential: the remote embeds a credential. ErrCredential = errors.New("embeds a credential") // ErrMalformed: the remote is not a repository URL at all. ErrMalformed = errors.New("not a repository URL") )
The three ways a remote can fail to name a GitHub repository. An *Error matches exactly one of them with errors.Is.
Functions ¶
Types ¶
type Error ¶
Error says why a remote names no GitHub repository. Remote is already redacted, so the error is safe to print.
type Repo ¶
Repo is a repository on github.com.
func ParseGitHub ¶
ParseGitHub reads a git remote — https, http, ssh, git+ssh, git://, or the scp form [user@]host:owner/name — as the GitHub repository it names.
func ParseRepo ¶
ParseRepo reads a repository named on a command line: owner/name, or any remote ParseGitHub accepts.