// Code generated by seatgen from the seat definitions; DO NOT EDIT. // Package git is the contract of the seat "git", defined whole (seats/git/seat.json): The forge: every read and act a delivery part makes of the mesh's git repositories, and what the forge says happened (design 47 *The seat git*, ADR 0596 §1, §2). A failed read answers an error, never an empty answer. The act verbs are the forge bridge's alone. package git import ( "bytes" "encoding/json" "errors" "strings" "time" ) // Seat is the seat's name. const Seat = "git" const ( VerbPull = "pull" VerbBranch = "branch" VerbOpenPulls = "open-pulls" VerbTags = "tags" VerbTrees = "trees" VerbFile = "file" VerbContains = "contains" VerbStatuses = "statuses" VerbStatus = "status" VerbComment = "comment" VerbView = "view" VerbNote = "note" VerbMergePull = "merge-pull" VerbTag = "tag" ) const ( EventPullUpdated = "pull-updated" EventPullMerged = "pull-merged" EventPullClosed = "pull-closed" EventForgePull = "forge-pull" EventForgeStatus = "forge-status" EventForgeDelete = "forge-delete" EventRepoWritable = "repo-writable" EventBranchMoved = "branch-moved" ) // Verbs is every verb the seat serves, in its definition's order: a new copy each call. func Verbs() []string { return []string{VerbPull, VerbBranch, VerbOpenPulls, VerbTags, VerbTrees, VerbFile, VerbContains, VerbStatuses, VerbStatus, VerbComment, VerbView, VerbNote, VerbMergePull, VerbTag} } // Events is every event published on the seat's subject: a new copy each call. func Events() []string { return []string{EventPullUpdated, EventPullMerged, EventPullClosed, EventForgePull, EventForgeStatus, EventForgeDelete, EventRepoWritable, EventBranchMoved} } // Family is where the seat's events are kept: the shared events stream, filtered to the seat's subjects. const ( Family = "git.events" FamilyMaxAgeDays = 7 ) // SubjectPullUpdated is where pull-updated is published. const SubjectPullUpdated = "mesh.seat.git.event.pull-updated" // SubjectPullMerged is where pull-merged is published. const SubjectPullMerged = "mesh.seat.git.event.pull-merged" // SubjectPullClosed is where pull-closed is published. const SubjectPullClosed = "mesh.seat.git.event.pull-closed" // SubjectForgePull is where forge-pull is published. const SubjectForgePull = "mesh.seat.git.event.forge-pull" // SubjectForgeStatus is where forge-status is published. const SubjectForgeStatus = "mesh.seat.git.event.forge-status" // SubjectForgeDelete is where forge-delete is published. const SubjectForgeDelete = "mesh.seat.git.event.forge-delete" // SubjectRepoWritable is where repo-writable is published. const SubjectRepoWritable = "mesh.seat.git.event.repo-writable" // StreamBranchMoved is the stream branch-moved is kept in. const StreamBranchMoved = "SEAT_git_branch-moved" // SubjectBranchMoved is where branch-moved is published. const SubjectBranchMoved = "mesh.seat.git.event.branch-moved" const ( StateFailedSteps = "failed-steps" ) // FailedStepsByModuleFingerprintStepKey is the key of one value of the state failed-steps under the form "..". func FailedStepsByModuleFingerprintStepKey(module, fingerprint, step string) string { return module + "." + fingerprint + "." + step } // ParseFailedStepsByModuleFingerprintStepKey reads the parts of a key of the form "..", in the order of the form; the last result is false for a key of another form. func ParseFailedStepsByModuleFingerprintStepKey(key string) (string, string, string, bool) { rest := key v0, after0, found0 := strings.Cut(rest, ".") if !found0 || v0 == "" { return "", "", "", false } rest = after0 v2, after2, found2 := strings.Cut(rest, ".") if !found2 || v2 == "" { return "", "", "", false } rest = after2 if rest == "" { return "", "", "", false } v4 := rest rest = "" if rest != "" { return "", "", "", false } return v0, v2, v4, true } // DecodeFailedStepsByModuleFingerprintStepValue reads one value of the state failed-steps under the form "..", refusing a field FailedStepsByModuleFingerprintStepValue does not know and any text after the value. func DecodeFailedStepsByModuleFingerprintStepValue(raw []byte) (FailedStepsByModuleFingerprintStepValue, error) { var v FailedStepsByModuleFingerprintStepValue dec := json.NewDecoder(bytes.NewReader(raw)) dec.DisallowUnknownFields() if err := dec.Decode(&v); err != nil { return v, err } if dec.More() { return v, errors.New("text after the value") } return v, nil } // Change is what a pull request changed. type Change struct { // the changed directories that hold a module at its head; absent when they could not be read ModuleDirs []string `json:"module-dirs,omitempty"` // the paths it changed Paths []string `json:"paths"` // the forge cut the list PathsTruncated bool `json:"paths-truncated,omitempty"` // which of them it deleted Removed []string `json:"removed,omitempty"` } // ErrorKind is which kind of error, set with error alone: refused, the forge or the holder refused and error says why in the forge's own words; not-found, the forge said that what was asked about (a repository, a commit, a pull request, a branch or a tag) does not exist, so a caller never reads it out of error's words; failed, the forge failed or could not be reached, so the act or read could not be performed. type ErrorKind = string // The values of ErrorKind. const ( ErrorKindRefused = "refused" ErrorKindNotFound = "not-found" ErrorKindFailed = "failed" ) // FailedStep is a failed required step at a build-input fingerprint, with the commits it was seen at and the run that failed it (design 47 *Judged from its own state, never by a call*); cleared by a later passing rerun of that step whose proved caller is the operator or a healer. type FailedStep struct { // the artifact reference, : Artifact string `json:"artifact,omitempty"` At *time.Time `json:"at,omitempty"` // every commit it was seen at Commits []string `json:"commits"` // the build-input fingerprint the step failed at Fingerprint string `json:"fingerprint"` Module string `json:"module"` // the run that failed it: the runner's pipeline key Run string `json:"run"` // why it failed, as the runner's step-ended said Said string `json:"said,omitempty"` Step string `json:"step"` // the layout version V int64 `json:"v,omitempty"` } // Merging is what the forge would merge now, for an open pull request (issues 1275, 1945; ADR 0441 §1): answered whole or not at all, and a read the forge could not make answers the verb's error, never a guess; absent for a merged or closed one. type Merging struct { // the forge's own word on whether it merges into its base now: false while it is in conflict with its base, or while the forge works that out after the base moved Mergeable bool `json:"mergeable"` // whether a protection rule guards its base branch Protected bool `json:"protected"` // the status contexts the base branch's protection requires; none when it requires none Required []string `json:"required"` // whether the forge's merging account may write the repository: false, its statuses and its merge are refused Writes bool `json:"writes"` } // OpenPull is an open pull request, with the statuses its base requires and those its head has. type OpenPull struct { // the head's statuses by context, the newest of each Checks map[string]Status `json:"checks"` Pull Pull `json:"pull"` // the contexts the base branch's protection requires; none when it requires none Required []string `json:"required"` } // Pull is one pull request as the forge holds it; never its description (ADR 0659 §1). type Pull struct { // who opened it, the forge's login Author string `json:"author,omitempty"` // the branch it merges into Base string `json:"base"` // its head branch: what a delivery group is named by Branch string `json:"branch"` // a commit, its full 40-hex sha Head string `json:"head"` // the merge commit, once merged MergeCommit string `json:"merge-commit,omitempty"` // when it merged MergedAt *time.Time `json:"merged-at,omitempty"` // the pull request's number Number int64 `json:"number"` // the repository, / Repository string `json:"repository"` // open, merged or closed State string `json:"state"` // its title Title string `json:"title,omitempty"` // its page on the forge URL string `json:"url,omitempty"` } // The values of Pull's state. const ( PullStateOpen = "open" PullStateMerged = "merged" PullStateClosed = "closed" ) // Status is the newest status of one context on a commit. type Status struct { // when it was set At *time.Time `json:"at,omitempty"` // who set it By string `json:"by,omitempty"` // the status's context, such as mesh/check Context string `json:"context"` // what it says Description string `json:"description,omitempty"` // pending, success, failure, error or warning State string `json:"state"` // the page it links to Target string `json:"target,omitempty"` } // PullInput is what pull takes. type PullInput struct { // instead of the number: the merge commit it made MergeCommit string `json:"merge-commit,omitempty"` // its number Number int64 `json:"number,omitempty"` // the repository, / Repository string `json:"repository"` } // PullAnswer is what pull answers. type PullAnswer struct { // why the forge could not answer, or refused: set alone with error-kind, and a caller reads it as a failure, never as none Error string `json:"error,omitempty"` ErrorKind ErrorKind `json:"error-kind,omitempty"` Merging *Merging `json:"merging,omitempty"` Pull *Pull `json:"pull,omitempty"` } // BranchInput is what branch takes. type BranchInput struct { Branch string `json:"branch"` // the repository, / Repository string `json:"repository"` } // BranchAnswer is what branch answers. type BranchAnswer struct { Branch string `json:"branch,omitempty"` // why the forge could not answer, or refused: set alone with error-kind, and a caller reads it as a failure, never as none Error string `json:"error,omitempty"` ErrorKind ErrorKind `json:"error-kind,omitempty"` // a commit, its full 40-hex sha Head string `json:"head,omitempty"` // a protection rule refuses a direct push and admits only merges Protected bool `json:"protected,omitempty"` Repository string `json:"repository,omitempty"` } // OpenPullsInput is what open-pulls takes. type OpenPullsInput struct { } // OpenPullsAnswer is what open-pulls answers. type OpenPullsAnswer struct { // why the forge could not answer, or refused: set alone with error-kind, and a caller reads it as a failure, never as none Error string `json:"error,omitempty"` ErrorKind ErrorKind `json:"error-kind,omitempty"` // every open pull request; said empty when none is open, so an answer that lacks it is never read as none Pulls []OpenPull `json:"pulls"` } // TagsInput is what tags takes. type TagsInput struct { // the page, from 1 Page int64 `json:"page,omitempty"` // only tags starting with it Prefix string `json:"prefix,omitempty"` // the repository, / Repository string `json:"repository"` } // TagsAnswer is what tags answers. type TagsAnswer struct { // how many tags a page holds Bound int64 `json:"bound,omitempty"` // why the forge could not answer, or refused: set alone with error-kind, and a caller reads it as a failure, never as none Error string `json:"error,omitempty"` ErrorKind ErrorKind `json:"error-kind,omitempty"` // another page exists More bool `json:"more,omitempty"` // the page Page int64 `json:"page,omitempty"` // the repository, / Repository string `json:"repository,omitempty"` // the tags of this page Tags []string `json:"tags,omitempty"` } // TreesInput is what trees takes. type TreesInput struct { // a commit, its full 40-hex sha Commit string `json:"commit"` // directories whose every blob is answered; the root is the empty name Files []string `json:"files,omitempty"` // {directory: [path relative to it]}; the root is the empty name Paths map[string][]string `json:"paths,omitempty"` // the repository, / Repository string `json:"repository"` } // TreesAnswer is what trees answers. type TreesAnswer struct { // a commit, its full 40-hex sha Commit string `json:"commit,omitempty"` // why the forge could not answer, or refused: set alone with error-kind, and a caller reads it as a failure, never as none Error string `json:"error,omitempty"` ErrorKind ErrorKind `json:"error-kind,omitempty"` // directory to {path: blob id} Files map[string]map[string]string `json:"files,omitempty"` // directory to {path: object id} Paths map[string]map[string]string `json:"paths,omitempty"` // the root tree's hash Root string `json:"root,omitempty"` // directory to its tree's hash, the root as the empty name Trees map[string]string `json:"trees,omitempty"` } // FileInput is what file takes. type FileInput struct { // the file's path from the repository's root Path string `json:"path"` // a commit, branch or tag; the default branch when absent Ref string `json:"ref,omitempty"` // the repository, / Repository string `json:"repository"` } // FileAnswer is what file answers. type FileAnswer struct { // the forge holds no such file there Absent bool `json:"absent,omitempty"` // the file's git blob id Blob string `json:"blob,omitempty"` // its content Content string `json:"content,omitempty"` // why the forge could not answer, or refused: set alone with error-kind, and a caller reads it as a failure, never as none Error string `json:"error,omitempty"` ErrorKind ErrorKind `json:"error-kind,omitempty"` // the path Path string `json:"path,omitempty"` // what was read Ref string `json:"ref,omitempty"` // its size in bytes Size int64 `json:"size,omitempty"` } // ContainsInput is what contains takes. type ContainsInput struct { // the commit asked about Commit string `json:"commit"` // the commit it may be contained in In string `json:"in"` // the repository, / Repository string `json:"repository"` } // ContainsAnswer is what contains answers. type ContainsAnswer struct { // how many commits commit is ahead of in Ahead int64 `json:"ahead,omitempty"` // the commit Commit string `json:"commit,omitempty"` // in contains commit Contains bool `json:"contains,omitempty"` // why the forge could not answer, or refused: set alone with error-kind, and a caller reads it as a failure, never as none Error string `json:"error,omitempty"` ErrorKind ErrorKind `json:"error-kind,omitempty"` // the other In string `json:"in,omitempty"` } // StatusesInput is what statuses takes. type StatusesInput struct { // a commit, its full 40-hex sha Commit string `json:"commit"` // the repository, / Repository string `json:"repository"` } // StatusesAnswer is what statuses answers. type StatusesAnswer struct { // the forge's combined state Combined string `json:"combined,omitempty"` // a commit, its full 40-hex sha Commit string `json:"commit,omitempty"` // why the forge could not answer, or refused: set alone with error-kind, and a caller reads it as a failure, never as none Error string `json:"error,omitempty"` ErrorKind ErrorKind `json:"error-kind,omitempty"` // the newest of each context Statuses []Status `json:"statuses,omitempty"` } // StatusInput is what status takes. type StatusInput struct { // a commit, its full 40-hex sha Commit string `json:"commit"` // the context, such as mesh/check Context string `json:"context"` // what it says Description string `json:"description,omitempty"` // the act's id ID string `json:"id"` // the repository, / Repository string `json:"repository"` // the state State string `json:"state"` // the page it links to Target string `json:"target,omitempty"` } // The values of StatusInput's state. const ( StatusInputStatePending = "pending" StatusInputStateSuccess = "success" StatusInputStateFailure = "failure" StatusInputStateError = "error" StatusInputStateWarning = "warning" ) // StatusAnswer is what status answers. type StatusAnswer struct { // why the forge could not answer, or refused: set alone with error-kind, and a caller reads it as a failure, never as none Error string `json:"error,omitempty"` ErrorKind ErrorKind `json:"error-kind,omitempty"` // the id was already held on the pull request or the note, so nothing was done again Held bool `json:"held,omitempty"` // the act's id, as the caller gave it ID string `json:"id,omitempty"` // the forge holds the act now Performed bool `json:"performed,omitempty"` } // CommentInput is what comment takes. type CommentInput struct { // the act's id ID string `json:"id"` // the pull request's number Number int64 `json:"number"` // the repository, / Repository string `json:"repository"` // the comment, markdown Text string `json:"text"` } // CommentAnswer is what comment answers. type CommentAnswer struct { // why the forge could not answer, or refused: set alone with error-kind, and a caller reads it as a failure, never as none Error string `json:"error,omitempty"` ErrorKind ErrorKind `json:"error-kind,omitempty"` // the id was already held on the pull request or the note, so nothing was done again Held bool `json:"held,omitempty"` // the act's id, as the caller gave it ID string `json:"id,omitempty"` // the forge holds the act now Performed bool `json:"performed,omitempty"` } // ViewInput is what view takes. type ViewInput struct { // the act's id ID string `json:"id"` // the pull request's number Number int64 `json:"number"` // the repository, / Repository string `json:"repository"` // the view, markdown Text string `json:"text"` } // ViewAnswer is what view answers. type ViewAnswer struct { // why the forge could not answer, or refused: set alone with error-kind, and a caller reads it as a failure, never as none Error string `json:"error,omitempty"` ErrorKind ErrorKind `json:"error-kind,omitempty"` // the id was already held on the pull request or the note, so nothing was done again Held bool `json:"held,omitempty"` // the act's id, as the caller gave it ID string `json:"id,omitempty"` // the forge holds the act now Performed bool `json:"performed,omitempty"` } // NoteInput is what note takes. type NoteInput struct { // a commit, its full 40-hex sha Commit string `json:"commit"` // the act's id ID string `json:"id"` // the line, one line Line string `json:"line"` // the repository, / Repository string `json:"repository"` } // NoteAnswer is what note answers. type NoteAnswer struct { // why the forge could not answer, or refused: set alone with error-kind, and a caller reads it as a failure, never as none Error string `json:"error,omitempty"` ErrorKind ErrorKind `json:"error-kind,omitempty"` // the id was already held on the pull request or the note, so nothing was done again Held bool `json:"held,omitempty"` // the act's id, as the caller gave it ID string `json:"id,omitempty"` // the forge holds the act now Performed bool `json:"performed,omitempty"` } // MergePullInput is what merge-pull takes. type MergePullInput struct { // the head the caller names Head string `json:"head"` // the act's id ID string `json:"id"` // the pull request's number Number int64 `json:"number"` // the repository, / Repository string `json:"repository"` } // MergePullAnswer is what merge-pull answers. type MergePullAnswer struct { // why the forge could not answer, or refused: set alone with error-kind, and a caller reads it as a failure, never as none Error string `json:"error,omitempty"` ErrorKind ErrorKind `json:"error-kind,omitempty"` // the id was already held on the pull request or the note, so nothing was done again Held bool `json:"held,omitempty"` // the act's id, as the caller gave it ID string `json:"id,omitempty"` // the merge commit MergeCommit string `json:"merge-commit,omitempty"` // for policy-failed, the module Module string `json:"module,omitempty"` // the forge holds the act now Performed bool `json:"performed,omitempty"` // why the forge or the holder refused the merge; the act is not performed Refused string `json:"refused,omitempty"` // which refusal, set with refused: head-moved, the pull request's head is not the one named; unprotected, the base branch's protection does not refuse a direct push; policy-failed, a run at the head's fingerprint failed a required step (run, module and step name it); no-registrations, no registration-changed heard yet (ADR 0667 section 10); git-refused, git refused the merge RefusedKind string `json:"refused-kind,omitempty"` // for policy-failed, the run that failed the step: the runner's pipeline key Run string `json:"run,omitempty"` // for policy-failed, the step Step string `json:"step,omitempty"` } // The values of MergePullAnswer's refused-kind. const ( MergePullAnswerRefusedKindHeadMoved = "head-moved" MergePullAnswerRefusedKindUnprotected = "unprotected" MergePullAnswerRefusedKindPolicyFailed = "policy-failed" MergePullAnswerRefusedKindNoRegistrations = "no-registrations" MergePullAnswerRefusedKindGitRefused = "git-refused" ) // TagInput is what tag takes. type TagInput struct { // the commit it is written at Commit string `json:"commit"` // the repository, / Repository string `json:"repository"` // the tag Tag string `json:"tag"` } // TagAnswer is what tag answers. type TagAnswer struct { // why the forge could not write it: set alone with error-kind Error string `json:"error,omitempty"` ErrorKind ErrorKind `json:"error-kind,omitempty"` // the forge holds the tag at that commit now Performed bool `json:"performed,omitempty"` // the tag, as asked Tag string `json:"tag,omitempty"` } // PullUpdatedEvent is the body of the event pull-updated. type PullUpdatedEvent struct { // who opened it Author string `json:"author,omitempty"` // the branch it merges into Base string `json:"base"` // the base branch's head as the head was announced; absent when it could not be read BaseHead string `json:"base-head,omitempty"` // its head branch Branch string `json:"branch"` Change *Change `json:"change,omitempty"` // a commit, its full 40-hex sha Head string `json:"head"` // the pull request's number Number int64 `json:"number"` // the repository, / Repository string `json:"repository"` // its title Title string `json:"title,omitempty"` // its page URL string `json:"url,omitempty"` } // PullMergedEvent is the body of the event pull-merged. type PullMergedEvent struct { // who opened it Author string `json:"author,omitempty"` // the branch it merges into Base string `json:"base"` // its head branch Branch string `json:"branch"` Change *Change `json:"change,omitempty"` // a commit, its full 40-hex sha Head string `json:"head"` // the head's statuses by context, their states; absent when they could not be read HeadChecks map[string]string `json:"head-checks,omitempty"` // a commit, its full 40-hex sha MergeCommit string `json:"merge-commit"` // when MergedAt *time.Time `json:"merged-at,omitempty"` // the pull request's number Number int64 `json:"number"` // the repository, / Repository string `json:"repository"` // its title Title string `json:"title,omitempty"` // its page URL string `json:"url,omitempty"` } // PullClosedEvent is the body of the event pull-closed. type PullClosedEvent struct { // who opened it Author string `json:"author,omitempty"` // the branch it merges into Base string `json:"base"` // its head branch Branch string `json:"branch"` // a commit, its full 40-hex sha Head string `json:"head"` // the pull request's number Number int64 `json:"number"` // the repository, / Repository string `json:"repository"` // its title Title string `json:"title,omitempty"` // its page URL string `json:"url,omitempty"` } // ForgePullEvent is the body of the event forge-pull. type ForgePullEvent struct { // what the forge said: opened, reopened, synchronized, edited, closed, merged Action string `json:"action"` // who opened it Author string `json:"author,omitempty"` // its base branch Base string `json:"base,omitempty"` // its head branch Branch string `json:"branch,omitempty"` // its head commit Head string `json:"head,omitempty"` // the merge commit MergeCommit string `json:"merge-commit,omitempty"` // merged Merged bool `json:"merged,omitempty"` // its number Number int64 `json:"number"` // the repository, / Repository string `json:"repository"` // who acted Sender string `json:"sender,omitempty"` } // ForgeStatusEvent is the body of the event forge-status. type ForgeStatusEvent struct { // the commit Commit string `json:"commit"` // the context Context string `json:"context"` // what it says Description string `json:"description,omitempty"` // the repository, / Repository string `json:"repository"` // who set it Sender string `json:"sender,omitempty"` // the state State string `json:"state"` } // ForgeDeleteEvent is the body of the event forge-delete. type ForgeDeleteEvent struct { // the deleted branch or tag Ref string `json:"ref"` // branch or tag RefType string `json:"ref-type,omitempty"` // the repository, / Repository string `json:"repository"` // who deleted it Sender string `json:"sender,omitempty"` } // RepoWritableEvent is the body of the event repo-writable. type RepoWritableEvent struct { // the account that writes it now Account string `json:"account"` // the repository, / Repository string `json:"repository"` } // BranchMovedEvent is the body of the event branch-moved. type BranchMovedEvent struct { At *time.Time `json:"at,omitempty"` Branch string `json:"branch"` // the head the webhook said, a commit's full 40-hex sha; read again by branch Head string `json:"head,omitempty"` // the repository, / Repository string `json:"repository"` } // FailedStepsByModuleFingerprintStepValue is one value of the state failed-steps under the key ... type FailedStepsByModuleFingerprintStepValue = FailedStep