package control import "encoding/json" // Named payloads for the commands other surfaces decode. A command used // to declare its output inline, so the web type-asserted map keys and // nothing tied what a command emits to what a client reads (#126). // Created is what issue create, issue comment and mr comment emit. type Created struct { Number int64 `json:"number"` } // MRCreated is what mr create emits. type MRCreated struct { Number int64 `json:"number"` HeadSHA string `json:"head_sha"` StackedOn *stackRef `json:"stacked_on,omitempty"` } // IssueShow is issue show's payload: the issue and its comments. type IssueShow struct { issueOut Comments []commentOut `json:"comments,omitempty"` } // MRShow is mr show's payload. type MRShow struct { mrOut Checks []CheckOut `json:"checks,omitempty"` Combined string `json:"checks_combined,omitempty"` UnresolvedThreads int `json:"unresolved_threads,omitempty"` Commits []CommitOut `json:"commits,omitempty"` Comments []commentOut `json:"comments,omitempty"` Reviews []ReviewOut `json:"reviews,omitempty"` // Gates is set while the merge request is open. Gates *GatesOut `json:"gates,omitempty"` } // OwnersOut is a set of changed files still waiting on an approval from // one of their CODEOWNERS. type OwnersOut struct { Files []string `json:"files"` Owners []string `json:"owners"` } // GatesOut is what a merge request has to pass to merge, and where it // stands: the same computation mr merge refuses on, so nothing is // learned at the refusal that mr show did not say (#199). type GatesOut struct { Draft bool `json:"draft,omitempty"` ApprovalsRequired int `json:"approvals_required"` Approvals []string `json:"approvals,omitempty"` // fresh, from reviewers who count ChangesRequested []string `json:"changes_requested,omitempty"` CodeownersRequired bool `json:"codeowners_required"` OwnersOutstanding []OwnersOut `json:"owners_outstanding,omitempty"` ResolvedRequired bool `json:"resolved_required"` OpenThreads int `json:"open_threads"` ChecksRequired bool `json:"checks_required"` Checks string `json:"checks,omitempty"` // combined status; "" when none reported FastForward bool `json:"fast_forward"` Unmet []string `json:"unmet,omitempty"` } // ReviewOut is one review on a merge request. type ReviewOut struct { Reviewer string `json:"reviewer"` Verdict string `json:"verdict"` Stale bool `json:"stale"` // Counts reports whether this verdict decides the merge gates. A // reader may review a public merge request; only someone who can // write to the repository decides whether it merges. Without this the // page would show an approval the gate ignores, and the difference // would be invisible until a merge was refused (#147). Counts bool `json:"counts"` CreatedAt string `json:"created_at"` } // CheckOut is one commit status on a merge request head. type CheckOut struct { Context string `json:"context"` State string `json:"state"` URL string `json:"url,omitempty"` UpdatedAt string `json:"updated_at"` Duration string `json:"duration,omitempty"` // CI checks only, once finished } // CommitOut is one commit a merge request carries. type CommitOut struct { SHA string `json:"sha"` Subject string `json:"subject"` } // jsonStrings renders a string slice as a JSON array, for the event data // the webhook payload carries. A nil slice is [], never null: a consumer // iterating the field should not have to special-case one of them. func jsonStrings(ss []string) string { if ss == nil { ss = []string{} } raw, err := json.Marshal(ss) if err != nil { return "[]" } return string(raw) }