Monorepo for Tangled
0

Configure Feed

Select the types of activity you want to include in your feed.

knotserver/internal: emit CI SSH command conditionally

it was being emitted unconditionally, but now it only emits the command
if there are a non-zero number of compiled workflows.

Signed-off-by: oppiliappan <me@oppi.li>

authored by

oppiliappan and committed by
Tangled
(Jul 13, 2026, 5:42 PM +0300) f855dc67 707d3291

+34 -25
+34 -25
knotserver/internal.go
··· 267 267 268 268 if !git.HasSkipCIPushOption(pushOptions) { 269 269 verbose := hasVerboseCIPushOption(pushOptions) 270 - if err := h.emitCiDiagnostics(&resp.Messages, line, ownerDid, repoName, repoDid, repoPath, verbose); err != nil { 271 - l.Error("failed to emit ci diagnostics", "err", err, "line", line, "did", gitUserDid, "repo", gitRelativeDir) 272 - } 273 - } 274 - 275 - // emit pipeline logs link 276 - if h.c.LogsAddr != "" { 277 - host, port, err := net.SplitHostPort(h.c.LogsAddr) 278 - if err == nil { 279 - resp.Messages = append(resp.Messages, "→ Browse CI logs in your terminal:") 280 - resp.Messages = append(resp.Messages, fmt.Sprintf(" ssh -t -p %s %s %s %s", port, host, repoDid, line.NewSha)) 270 + compiler, compiled, err := h.compileCiPipeline(line, ownerDid, repoName, repoDid, repoPath) 271 + if err != nil { 272 + l.Error("failed to compile ci pipeline", "err", err, "line", line, "did", gitUserDid, "repo", gitRelativeDir) 273 + } else { 274 + h.emitCiDiagnostics(&resp.Messages, compiler, compiled, verbose) 275 + h.emitCiSshCommand(&resp.Messages, compiled, repoDid, line) 281 276 } 282 277 } 283 278 } ··· 343 338 return false 344 339 } 345 340 346 - func (h *InternalHandle) emitCiDiagnostics( 347 - clientMsgs *[]string, 341 + func (h *InternalHandle) compileCiPipeline( 348 342 line git.PostReceiveLine, 349 343 ownerDid string, 350 344 repoName string, 351 345 repoDid string, 352 346 repoPath string, 353 - verbose bool, 354 - ) error { 347 + ) (workflow.Compiler, tangled.Pipeline, error) { 355 348 if line.NewSha.IsZero() { 356 - return nil 349 + return workflow.Compiler{}, tangled.Pipeline{}, nil 357 350 } 358 351 359 352 gr, err := git.Open(repoPath, line.Ref) 360 353 if err != nil { 361 - return fmt.Errorf("failed to open git repo at ref %s: %w", line.Ref, err) 354 + return workflow.Compiler{}, tangled.Pipeline{}, fmt.Errorf("failed to open git repo at ref %s: %w", line.Ref, err) 362 355 } 363 356 364 357 workflowDir, err := gr.FileTree(context.Background(), workflow.WorkflowDir) 365 358 if err != nil { 366 - return nil 359 + return workflow.Compiler{}, tangled.Pipeline{}, nil 367 360 } 368 361 369 - var pipeline workflow.RawPipeline 362 + var rawPipeline workflow.RawPipeline 370 363 for _, e := range workflowDir { 371 364 if !e.IsFile() { 372 365 continue 373 366 } 374 - 375 367 fpath := filepath.Join(workflow.WorkflowDir, e.Name) 376 368 contents, err := gr.RawContent(fpath) 377 369 if err != nil { 378 370 continue 379 371 } 380 - 381 - pipeline = append(pipeline, workflow.RawWorkflow{ 372 + rawPipeline = append(rawPipeline, workflow.RawWorkflow{ 382 373 Name: e.Name, 383 374 Contents: contents, 384 375 }) ··· 402 393 403 394 changedFiles, err := gr.ChangedFilesBetween(line.OldSha.String(), line.NewSha.String()) 404 395 if err != nil { 405 - return fmt.Errorf("getting changed files: %w", err) 396 + return workflow.Compiler{}, tangled.Pipeline{}, fmt.Errorf("getting changed files: %w", err) 406 397 } 407 398 408 399 compiler := workflow.Compiler{ ··· 414 405 ChangedFiles: changedFiles, 415 406 } 416 407 417 - compiler.Compile(compiler.Parse(pipeline)) 408 + compiled := compiler.Compile(compiler.Parse(rawPipeline)) 409 + return compiler, compiled, nil 410 + } 418 411 412 + func (h *InternalHandle) emitCiDiagnostics(clientMsgs *[]string, compiler workflow.Compiler, compiled tangled.Pipeline, verbose bool) { 419 413 for _, e := range compiler.Diagnostics.Errors { 420 414 *clientMsgs = append(*clientMsgs, e.String()) 421 415 } 422 416 if verbose { 417 + if len(compiled.Workflows) == 0 { 418 + *clientMsgs = append(*clientMsgs, "info: no pipelines to compile") 419 + return 420 + } 423 421 if compiler.Diagnostics.IsEmpty() { 424 422 *clientMsgs = append(*clientMsgs, "success: pipeline compiled with no diagnostics") 423 + return 425 424 } 426 425 for _, w := range compiler.Diagnostics.Warnings { 427 426 *clientMsgs = append(*clientMsgs, w.String()) 428 427 } 429 428 } 429 + } 430 430 431 - return nil 431 + func (h *InternalHandle) emitCiSshCommand(clientMsgs *[]string, compiled tangled.Pipeline, repoDid string, line git.PostReceiveLine) { 432 + if len(compiled.Workflows) == 0 || h.c.LogsAddr == "" { 433 + return 434 + } 435 + host, port, err := net.SplitHostPort(h.c.LogsAddr) 436 + if err != nil { 437 + return 438 + } 439 + *clientMsgs = append(*clientMsgs, "→ Browse CI logs in your terminal:") 440 + *clientMsgs = append(*clientMsgs, fmt.Sprintf(" ssh -t -p %s %s %s %s", port, host, repoDid, line.NewSha)) 432 441 } 433 442 434 443 func (h *InternalHandle) emitPullRequestLink(