A vibe coded tangled fork which supports pijul.
1package models
2
3import (
4 "fmt"
5 "slices"
6
7 "github.com/bluesky-social/indigo/atproto/syntax"
8 "tangled.org/core/api/tangled"
9)
10
11// `sh.tangled.ci.event`
12type Event struct {
13 SourceRepo syntax.ATURI // repository to find the workflow definition
14 SourceSha string // sha to find the workflow definition
15 TargetSha string // sha to run the workflow
16 // union type of:
17 // 1. PullRequestEvent
18 // 2. PushEvent
19 // 3. ManualEvent
20}
21
22func (e *Event) AsRecord() tangled.CiEvent {
23 // var meta tangled.CiEvent_Meta
24 // return tangled.CiEvent{
25 // Meta: &meta,
26 // }
27 panic("unimplemented")
28}
29
30// `sh.tangled.ci.pipeline`
31//
32// Pipeline is basically a group of workflows triggered by single event.
33type Pipeline2 struct {
34 Did syntax.DID
35 Rkey syntax.RecordKey
36
37 Event Event // event that triggered the pipeline
38 WorkflowRuns []WorkflowRun // workflow runs inside this pipeline
39}
40
41func (p *Pipeline2) AtUri() syntax.ATURI {
42 return syntax.ATURI(fmt.Sprintf("at://%s/%s/%s", p.Did, tangled.CiPipelineNSID, p.Rkey))
43}
44
45func (p *Pipeline2) AsRecord() tangled.CiPipeline {
46 event := p.Event.AsRecord()
47 runs := make([]string, len(p.WorkflowRuns))
48 for i, run := range p.WorkflowRuns {
49 runs[i] = run.AtUri().String()
50 }
51 return tangled.CiPipeline{
52 Event: &event,
53 WorkflowRuns: runs,
54 }
55}
56
57// `sh.tangled.ci.workflow.run`
58type WorkflowRun struct {
59 Did syntax.DID
60 Rkey syntax.RecordKey
61
62 AdapterId string // adapter id
63 Name string // name of workflow run (not workflow definition name!)
64 Status WorkflowStatus // workflow status
65 // TODO: can add some custom fields like adapter-specific log-id
66}
67
68func (r WorkflowRun) WithStatus(status WorkflowStatus) WorkflowRun {
69 return WorkflowRun{
70 Did: r.Did,
71 Rkey: r.Rkey,
72 AdapterId: r.AdapterId,
73 Name: r.Name,
74 Status: status,
75 }
76}
77
78func (r *WorkflowRun) AtUri() syntax.ATURI {
79 return syntax.ATURI(fmt.Sprintf("at://%s/%s/%s", r.Did, tangled.CiWorkflowRunNSID, r.Rkey))
80}
81
82func (r *WorkflowRun) AsRecord() tangled.CiWorkflowRun {
83 statusStr := string(r.Status)
84 return tangled.CiWorkflowRun{
85 Adapter: r.AdapterId,
86 Name: r.Name,
87 Status: &statusStr,
88 }
89}
90
91// `sh.tangled.ci.workflow.status`
92type WorkflowStatus string
93
94var (
95 WorkflowStatusPending WorkflowStatus = "pending"
96 WorkflowStatusRunning WorkflowStatus = "running"
97 WorkflowStatusFailed WorkflowStatus = "failed"
98 WorkflowStatusCancelled WorkflowStatus = "cancelled"
99 WorkflowStatusSuccess WorkflowStatus = "success"
100 WorkflowStatusTimeout WorkflowStatus = "timeout"
101
102 activeStatuses [2]WorkflowStatus = [2]WorkflowStatus{
103 WorkflowStatusPending,
104 WorkflowStatusRunning,
105 }
106)
107
108func (s WorkflowStatus) IsActive() bool {
109 return slices.Contains(activeStatuses[:], s)
110}
111
112func (s WorkflowStatus) IsFinish() bool {
113 return !s.IsActive()
114}
115
116// `sh.tangled.ci.workflow.def`
117//
118// Brief information of the workflow definition. A workflow can be defined in
119// any form. This is a common info struct for any workflow definitions
120type WorkflowDef struct {
121 AdapterId string // adapter id
122 Name string // name or the workflow (usually the yml file name)
123 When any // events the workflow is listening to
124}