{"modulePath":"github.com/giantswarm/gitops-commit","version":"v0.3.0","isLatest":false,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package commit\n\nPackage commit lands rendered files in GitOps repositories as the person: a branch, one commit per repository, the pull request carrying the caller's text, and the merge once the caller says approved and the checks are green.\n\nThe module holds no token. A Remote is built from the token the caller supplies (for the managers: the person's user token of the manager's App), and a token GitHub refuses surfaces as ErrAuth carrying the HTTP status; the callers turn it into their sign-in answer. Nothing is retried with another token, nothing is logged, and no error carries file content.\n\n## Constants\n\n```go\nconst (\n\tReviewNone             ReviewState = \"none\"\n\tReviewApproved         ReviewState = \"approved\"\n\tReviewChangesRequested ReviewState = \"changes_requested\"\n\n\t// ChecksNone: the head carries no statuses and no check runs; nothing to wait for.\n\tChecksNone    CheckState = \"none\"\n\tChecksPending CheckState = \"pending\"\n\tChecksSuccess CheckState = \"success\"\n\tChecksFailure CheckState = \"failure\"\n)\n```\n\n```go\nconst (\n\tOpCreateBranch    = \"create branch\"\n\tOpCommit          = \"commit\"\n\tOpOpenPullRequest = \"open pull request\"\n\tOpStatus          = \"pull request status\"\n\tOpMerge           = \"merge\"\n)\n```\nOperation names of the remote calls, carried by AuthError and by Fake.Fail.\n\n## Variables\n\n```go\nvar (\n\t// ErrAuth: the remote refused the caller's token (401 or 403). The callers\n\t// answer with their sign-in flow; the module neither retries nor substitutes.\n\tErrAuth = errors.New(\"token refused\")\n\t// ErrInvalidRequest: the request lacks a branch or a title.\n\tErrInvalidRequest = errors.New(\"request needs a branch and a title\")\n\t// ErrNoFiles: a change carries no files.\n\tErrNoFiles = errors.New(\"no files to commit\")\n\t// ErrConflictingBase: two changes for one repository name different branches.\n\tErrConflictingBase = errors.New(\"one repository, two base branches\")\n\t// ErrDuplicatePath: two changes for one repository write the same path.\n\tErrDuplicatePath = errors.New(\"one path in two changes\")\n\t// ErrNotApproved: the caller has not said approved.\n\tErrNotApproved = errors.New(\"merge refused: not approved\")\n\t// ErrChecksPending: a status or check run on the head has not finished.\n\tErrChecksPending = errors.New(\"merge refused: checks pending\")\n\t// ErrChecksFailed: a status or check run on the head failed.\n\tErrChecksFailed = errors.New(\"merge refused: checks failed\")\n\t// ErrHeadMoved: the head is no longer the commit the caller saw.\n\tErrHeadMoved = errors.New(\"merge refused: the head moved since the pull request was seen\")\n)\n```\n\n## Functions\n\n```go\nfunc Merge(ctx context.Context, remote Remote, pr PullRequest, approved bool) error\n```\nMerge merges the pull request as the person. It is refused before the caller says approved (ErrNotApproved, no remote call), before every check on the head is green (ErrChecksPending, ErrChecksFailed; a head without checks has nothing to wait for) and when the head is not the commit the caller saw (ErrHeadMoved). A merged pull request is left as it is. GitHub's own rules — the approving review that satisfies enforce\\_admins and rulesets — apply at the merge call; no administrative path exists.\n\n## Types\n\n```go\ntype AuthError struct {\n\tOp     string\n\tStatus int\n}\n```\nAuthError is ErrAuth with the status the remote answered and the operation it refused. errors.Is(err, ErrAuth) matches it.\n\n```go\nfunc (e *AuthError) Error() string\n```\n\n```go\nfunc (e *AuthError) Unwrap() error\n```\nUnwrap makes errors.Is(err, ErrAuth) true.\n\n```go\ntype Change struct {\n\tLocation provenance.Location\n\tFiles    map[string][]byte\n}\n```\nChange is the set of files for one location: the repository, the base branch and the repository-relative paths the files land at (the keys of what sopsenc.Encrypt returns). Changes for one repository become one commit.\n\n```go\ntype CheckState string\n```\nCheckState is the rollup of the commit statuses and check runs on the head.\n\n```go\ntype Fake struct {\n\t// Fail maps an operation name (OpCreateBranch, OpCommit, ...) to the error\n\t// that operation returns instead of acting.\n\tFail map[string]error\n\t// contains filtered or unexported fields\n}\n```\nFake is an in-process Remote for tests — the module's own and its callers': branches with commits, pull requests with review and check state, and a way to make any operation fail. It never touches the network.\n\n```go\nfunc NewFake() *Fake\n```\nNewFake returns an empty Fake; seed base branches with AddBranch.\n\n```go\nfunc (f *Fake) AddBranch(repo Repository, branch string, files map[string][]byte)\n```\nAddBranch seeds branch in repo with one commit holding files (nil for an empty tree).\n\n```go\nfunc (f *Fake) Commit(_ context.Context, repo Repository, branch, message string, files map[string][]byte) error\n```\nCommit implements Remote.\n\n```go\nfunc (f *Fake) Commits(repo Repository, branch string) []FakeCommit\n```\nCommits returns the commits made on branch after its seed, oldest first.\n\n```go\nfunc (f *Fake) CreateBranch(_ context.Context, repo Repository, branch, base string) error\n```\nCreateBranch implements Remote.\n\n```go\nfunc (f *Fake) Files(repo Repository, branch string) map[string][]byte\n```\nFiles returns the tree at the head of branch.\n\n```go\nfunc (f *Fake) Merge(_ context.Context, pr PullRequest) error\n```\nMerge implements Remote: the base fast-forwards to the head.\n\n```go\nfunc (f *Fake) OpenPullRequest(_ context.Context, repo Repository, head, base, title, body string) (PullRequest, error)\n```\nOpenPullRequest implements Remote.\n\n```go\nfunc (f *Fake) PullRequests() []FakePullRequest\n```\nPullRequests returns every pull request the Fake holds, oldest first.\n\n```go\nfunc (f *Fake) SetChecks(pr PullRequest, state CheckState)\n```\nSetChecks sets the check rollup the Fake reports for pr.\n\n```go\nfunc (f *Fake) SetReview(pr PullRequest, state ReviewState)\n```\nSetReview sets the review rollup the Fake reports for pr.\n\n```go\nfunc (f *Fake) Status(_ context.Context, pr PullRequest) (Status, error)\n```\nStatus implements Remote.\n\n```go\ntype FakeCommit struct {\n\tRepository Repository\n\tBranch     string\n\tMessage    string\n\tParent     string\n\tSHA        string\n\tFiles      map[string][]byte\n}\n```\nFakeCommit is one commit the Fake holds; Files is the full tree at that commit.\n\n```go\ntype FakePullRequest struct {\n\tPullRequest\n\tTitle  string\n\tBody   string\n\tMerged bool\n\tReview ReviewState\n\tChecks CheckState\n}\n```\nFakePullRequest is a pull request the Fake holds, with what the remote knows about it.\n\n```go\ntype GitHub struct {\n\t// contains filtered or unexported fields\n}\n```\nGitHub is the Remote for github.com (or a GitHub Enterprise Server) acting with the token the caller supplies. It talks REST through google/go-github, never a git or sops binary.\n\n```go\nfunc NewGitHub(token string, opts ...GitHubOption) (*GitHub, error)\n```\nNewGitHub builds the Remote from the caller's token. The token is the person's; the module keeps none of its own.\n\n```go\nfunc (g *GitHub) Commit(ctx context.Context, repo Repository, branch, message string, files map[string][]byte) error\n```\nCommit writes one commit with files on top of branch: blobs, a tree on the head's tree, the commit, and a fast-forward of the branch.\n\n```go\nfunc (g *GitHub) CreateBranch(ctx context.Context, repo Repository, branch, base string) error\n```\nCreateBranch creates branch at base's head; an existing branch is kept.\n\n```go\nfunc (g *GitHub) Merge(ctx context.Context, pr PullRequest) error\n```\nMerge merges the pull request with the repository's merge method (squash where allowed, else merge commit, else rebase), only if the head is still pr.HeadSHA. GitHub applies its own protection rules to the call.\n\n```go\nfunc (g *GitHub) OpenPullRequest(ctx context.Context, repo Repository, head, base, title, body string) (PullRequest, error)\n```\nOpenPullRequest opens head against base with the caller's title and body. When head already has an open pull request, that one is returned.\n\n```go\nfunc (g *GitHub) Status(ctx context.Context, pr PullRequest) (Status, error)\n```\nStatus reads the pull request, its reviews, and the statuses and check runs of its head.\n\n```go\ntype GitHubOption = github.ClientOptionsFunc\n```\nGitHubOption configures NewGitHub.\n\n```go\nfunc WithBaseURL(baseURL string) GitHubOption\n```\nWithBaseURL points the client at another API root: a GitHub Enterprise Server, or a test server.\n\n```go\nfunc WithHTTPClient(c *http.Client) GitHubOption\n```\nWithHTTPClient sets the HTTP client the requests go through.\n\n```go\ntype PullRequest struct {\n\tRepository Repository\n\tNumber     int\n\tURL        string\n\tHead       string\n\tBase       string\n\tHeadSHA    string\n}\n```\nPullRequest identifies a pull request the module opened or found open. HeadSHA is the commit the caller saw; Merge refuses when the head has moved.\n\n```go\nfunc Open(ctx context.Context, remote Remote, req Request, changes []Change) ([]PullRequest, error)\n```\nOpen lands the changes: for every repository one branch from its base, one commit with all of that repository's files, one pull request with the caller's title and body. Repositories are handled in name order; on an error the pull requests opened so far are returned with it.\n\n```go\ntype Remote interface {\n\t// CreateBranch creates branch from base; a branch that exists is left as it is.\n\tCreateBranch(ctx context.Context, repo Repository, branch, base string) error\n\t// Commit adds one commit with files to branch.\n\tCommit(ctx context.Context, repo Repository, branch, message string, files map[string][]byte) error\n\t// OpenPullRequest opens head against base, or returns the open pull request head already has.\n\tOpenPullRequest(ctx context.Context, repo Repository, head, base, title, body string) (PullRequest, error)\n\t// Status reads the pull request's head, merged flag, review and check state.\n\tStatus(ctx context.Context, pr PullRequest) (Status, error)\n\t// Merge merges the pull request as the person, refusing when the head is not pr.HeadSHA.\n\tMerge(ctx context.Context, pr PullRequest) error\n}\n```\nRemote is the git hosting the package talks to: GitHub in production, Fake in tests. Every operation acts with the token the Remote was built from.\n\n```go\ntype Repository = provenance.Repository\n```\nRepository is the GitHub repository a change lands in.\n\n```go\ntype Request struct {\n\tBranch string\n\tTitle  string\n\tBody   string\n}\n```\nRequest names one run: its head branch, its commit message and pull request title, and the pull request body — the caller's text, carried verbatim.\n\n```go\ntype ReviewState string\n```\nReviewState is the pull request's review rollup: the latest stance of every reviewer, approved when at least one approves and none requests changes.\n\n```go\ntype Status struct {\n\tHeadSHA string\n\tMerged  bool\n\tReview  ReviewState\n\tChecks  CheckState\n}\n```\nStatus is the pull request's state as the remote reports it.\n\n","path":"github.com/giantswarm/gitops-commit/commit","name":"commit","synopsis":"Package commit lands rendered files in GitOps repositories as the person: a branch, one commit per repository, the pull request carrying the caller's text, and the merge once the caller says approved and the checks are green.","isRedistributable":true}
