tangled.go
1// Package lex holds Go types for the lexicons this project reads and emits:
2// the vendored Tangled ones (lexicons/tangled) and our own run.rtw.ci.*
3// (lexicons/ci). Types are hand-written; lex_test.go checks each against its
4// lexicon so the two cannot drift.
5package lex
6
7import "encoding/json"
8
9const (
10 GitRefUpdateNSID = "sh.tangled.git.refUpdate"
11 PipelineNSID = "sh.tangled.pipeline"
12 PipelineStatusNSID = "sh.tangled.pipeline.status"
13)
14
15// Event is the envelope of a Tangled /events stream (upstream
16// eventstream.Event). Created is a monotonic local clock value and is the
17// cursor: a subscriber resumes with ?cursor=<last Created>.
18type Event struct {
19 Rkey string `json:"rkey"`
20 Nsid string `json:"nsid"`
21 Event json.RawMessage `json:"event"`
22 Created int64 `json:"created"`
23}
24
25// GitRefUpdate is sh.tangled.git.refUpdate, emitted by a knot (here: the
26// bridge) for every pushed ref.
27type GitRefUpdate struct {
28 LexiconTypeID string `json:"$type"`
29 Ref string `json:"ref"`
30 CommitterDid string `json:"committerDid"`
31 OwnerDid *string `json:"ownerDid,omitempty"`
32 Repo string `json:"repo"`
33 OldSha string `json:"oldSha"`
34 NewSha string `json:"newSha"`
35 ChangedFiles []string `json:"changedFiles,omitempty"`
36 PushOptions []string `json:"pushOptions,omitempty"`
37 Meta *GitRefUpdateMeta `json:"meta"`
38}
39
40type GitRefUpdateMeta struct {
41 IsDefaultRef bool `json:"isDefaultRef"`
42 LangBreakdown *GitRefUpdateLangBreakdown `json:"langBreakdown,omitempty"`
43 CommitCount *GitRefUpdateCommitCount `json:"commitCount"`
44}
45
46type GitRefUpdateLangBreakdown struct {
47 Inputs []GitRefUpdateLanguageSize `json:"inputs,omitempty"`
48}
49
50type GitRefUpdateLanguageSize struct {
51 Lang string `json:"lang"`
52 Size int64 `json:"size"`
53}
54
55type GitRefUpdateCommitCount struct {
56 ByEmail []GitRefUpdateEmailCommitCount `json:"byEmail,omitempty"`
57}
58
59type GitRefUpdateEmailCommitCount struct {
60 Email string `json:"email"`
61 Count int64 `json:"count"`
62}
63
64// Pipeline is sh.tangled.pipeline. Upstream marks the record deprecated in
65// favour of sh.tangled.ci.pipeline, but the spindle still emits it on
66// /events and the appview still consumes it.
67type Pipeline struct {
68 LexiconTypeID string `json:"$type"`
69 TriggerMetadata *PipelineTriggerMetadata `json:"triggerMetadata"`
70 Workflows []*PipelineWorkflow `json:"workflows"`
71}
72
73type PipelineTriggerMetadata struct {
74 Kind string `json:"kind"`
75 Repo *PipelineTriggerRepo `json:"repo"`
76 Push *PipelinePushTriggerData `json:"push,omitempty"`
77 PullRequest *PipelinePullRequestTrigger `json:"pullRequest,omitempty"`
78 Manual *PipelineManualTriggerData `json:"manual,omitempty"`
79 Schedule *PipelineScheduleTrigger `json:"schedule,omitempty"`
80 SourceRepo *string `json:"sourceRepo,omitempty"`
81}
82
83type PipelineTriggerRepo struct {
84 Knot string `json:"knot"`
85 Did string `json:"did"`
86 RepoDid *string `json:"repoDid,omitempty"`
87 Repo *string `json:"repo,omitempty"`
88 DefaultBranch string `json:"defaultBranch"`
89}
90
91type PipelinePushTriggerData struct {
92 Ref string `json:"ref"`
93 NewSha string `json:"newSha"`
94 OldSha string `json:"oldSha"`
95}
96
97type PipelinePullRequestTrigger struct {
98 Action *string `json:"action,omitempty"`
99 SourceBranch string `json:"sourceBranch"`
100 TargetBranch string `json:"targetBranch"`
101 SourceSha string `json:"sourceSha"`
102 Pull *string `json:"pull,omitempty"`
103}
104
105type PipelineManualTriggerData struct {
106 Sha string `json:"sha"`
107 Ref *string `json:"ref,omitempty"`
108 Inputs []*PipelinePair `json:"inputs,omitempty"`
109}
110
111type PipelineScheduleTrigger struct {
112 Sha string `json:"sha"`
113 Ref string `json:"ref"`
114 ScheduledAt string `json:"scheduledAt"`
115}
116
117type PipelineWorkflow struct {
118 Name string `json:"name"`
119 Engine string `json:"engine"`
120 RunsOn []string `json:"runsOn,omitempty"`
121 Clone *PipelineCloneOpts `json:"clone"`
122 Raw string `json:"raw"`
123}
124
125type PipelineCloneOpts struct {
126 Skip bool `json:"skip"`
127 Depth int64 `json:"depth"`
128 Submodules bool `json:"submodules"`
129 Tags bool `json:"tags"`
130}
131
132type PipelinePair struct {
133 Key string `json:"key"`
134 Value string `json:"value"`
135}
136
137// Workflow statuses shared by sh.tangled.pipeline.status and
138// sh.tangled.ci.pipeline#workflow.
139const (
140 StatusPending = "pending"
141 StatusRunning = "running"
142 StatusFailed = "failed"
143 StatusTimeout = "timeout"
144 StatusCancelled = "cancelled"
145 StatusSuccess = "success"
146)
147
148// PipelineStatus is sh.tangled.pipeline.status: one workflow's status change.
149type PipelineStatus struct {
150 LexiconTypeID string `json:"$type"`
151 Pipeline string `json:"pipeline"`
152 Workflow string `json:"workflow"`
153 Status string `json:"status"`
154 CreatedAt string `json:"createdAt"`
155 Error *string `json:"error,omitempty"`
156 ExitCode *int64 `json:"exitCode,omitempty"`
157}
158
159// LogLine is one message of a spindle's legacy /logs/{knot}/{rkey}/{name}
160// websocket, as upstream's spindle/models.LogLine (not a lexicon). Data lines
161// carry output; control lines mark a step's start and end.
162type LogLine struct {
163 Kind string `json:"kind"` // data | control
164 Content string `json:"content"`
165 Time string `json:"time"` // RFC 3339
166 StepId int `json:"step_id"`
167 Stream string `json:"stream,omitempty"` // data: stdout | stderr
168 StepStatus string `json:"step_status,omitempty"` // control: start | end
169 StepKind string `json:"step_kind,omitempty"` // control: system | user
170 StepCommand string `json:"step_command,omitempty"` // control
171}
172
173// TriggerPipelineInput is the input of sh.tangled.ci.triggerPipeline, with
174// the manual trigger (the only kind accepted here) inlined.
175type TriggerPipelineInput struct {
176 Repo string `json:"repo"`
177 Trigger *ManualTrigger `json:"trigger"`
178 Workflows []string `json:"workflows,omitempty"`
179}
180
181// ManualTrigger is sh.tangled.ci.trigger#manual.
182type ManualTrigger struct {
183 LexiconTypeID string `json:"$type"`
184 Sha string `json:"sha"`
185 Ref *string `json:"ref,omitempty"`
186 SourceRepo *string `json:"sourceRepo,omitempty"`
187 Inputs []*PipelinePair `json:"inputs,omitempty"`
188}
189
190type TriggerPipelineOutput struct {
191 Pipeline string `json:"pipeline"`
192}