···
11
+
securejoin "github.com/cyphar/filepath-securejoin"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"tangled.sh/tangled.sh/core/api/tangled"
···
"tangled.sh/tangled.sh/core/knotserver/git"
"tangled.sh/tangled.sh/core/knotserver/notifier"
"tangled.sh/tangled.sh/core/rbac"
20
+
"tangled.sh/tangled.sh/core/workflow"
type InternalHandle struct {
···
l.Error("failed to insert op", "err", err, "line", line, "did", gitUserDid, "repo", gitRelativeDir)
99
+
err = h.triggerPipeline(line, gitUserDid, repoDid, repoName)
101
+
l.Error("failed to trigger pipeline", "err", err, "line", line, "did", gitUserDid, "repo", gitRelativeDir)
···
Nsid: tangled.GitRefUpdateNSID,
124
+
EventJson: string(eventJson),
127
+
return h.db.InsertEvent(event, h.n)
130
+
func (h *InternalHandle) triggerPipeline(line git.PostReceiveLine, gitUserDid, repoDid, repoName string) error {
132
+
WorkflowDir = ".tangled/workflows"
135
+
didSlashRepo, err := securejoin.SecureJoin(repoDid, repoName)
140
+
repoPath, err := securejoin.SecureJoin(h.c.Repo.ScanPath, didSlashRepo)
145
+
gr, err := git.Open(repoPath, line.Ref)
150
+
workflowDir, err := gr.FileTree(context.Background(), WorkflowDir)
155
+
var pipeline workflow.Pipeline
156
+
for _, e := range workflowDir {
161
+
fpath := filepath.Join(WorkflowDir, e.Name)
162
+
contents, err := gr.RawContent(fpath)
167
+
wf, err := workflow.FromFile(e.Name, contents)
169
+
// TODO: log here, respond to client that is pushing
173
+
pipeline = append(pipeline, wf)
176
+
trigger := tangled.Pipeline_PushTriggerData{
178
+
OldSha: line.OldSha,
179
+
NewSha: line.NewSha,
182
+
compiler := workflow.Compiler{
183
+
Trigger: tangled.Pipeline_TriggerMetadata{
184
+
Kind: string(workflow.TriggerKindPush),
186
+
Repo: &tangled.Pipeline_TriggerRepo{
188
+
Knot: h.c.Server.Hostname,
194
+
// TODO: send the diagnostics back to the user here via stderr
195
+
cp := compiler.Compile(pipeline)
196
+
eventJson, err := json.Marshal(cp)
203
+
Nsid: tangled.PipelineNSID,
EventJson: string(eventJson),