Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pkg/api/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ func CIGetRunStatus(ctx context.Context, token, orgID, runID string) (*civ1.GetR
return resp.Msg, nil
}

// CIGetWorkflow returns curated run/workflow/execution/job/attempt metadata for a single workflow.
func CIGetWorkflow(ctx context.Context, token, orgID, workflowID string) (*civ1.GetWorkflowResponse, error) {
client := newCIServiceClient()
resp, err := client.GetWorkflow(ctx, WithAuthenticationAndOrg(connect.NewRequest(&civ1.GetWorkflowRequest{WorkflowId: workflowID}), token, orgID))
if err != nil {
return nil, err
}
return resp.Msg, nil
}

// CIGetRun returns a flat CI run record.
func CIGetRun(ctx context.Context, token, orgID, runID string) (*civ1.GetRunResponse, error) {
client := newCIServiceClient()
Expand Down
20 changes: 20 additions & 0 deletions pkg/api/ci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ func (h ciServiceTestHandler) GetRunStatus(context.Context, *connect.Request[civ
return nil, connect.NewError(connect.CodeUnimplemented, nil)
}

func (h ciServiceTestHandler) GetWorkflow(_ context.Context, req *connect.Request[civ1.GetWorkflowRequest]) (*connect.Response[civ1.GetWorkflowResponse], error) {
assertAuthAndOrg(h.t, req.Header())
if req.Msg.WorkflowId != "workflow-123" {
h.t.Fatalf("WorkflowId = %q, want workflow-123", req.Msg.WorkflowId)
}
return connect.NewResponse(&civ1.GetWorkflowResponse{WorkflowId: req.Msg.WorkflowId, OrgId: "org-123"}), nil
}

func (h ciServiceTestHandler) GetJobAttemptLogs(context.Context, *connect.Request[civ1.GetJobAttemptLogsRequest]) (*connect.Response[civ1.GetJobAttemptLogsResponse], error) {
return nil, connect.NewError(connect.CodeUnimplemented, nil)
}
Expand Down Expand Up @@ -103,6 +111,18 @@ func TestCICancelRunWrapper(t *testing.T) {
})
}

func TestCIGetWorkflowWrapper(t *testing.T) {
withTestCIService(t, func() {
resp, err := CIGetWorkflow(context.Background(), "token-123", "org-123", "workflow-123")
if err != nil {
t.Fatalf("CIGetWorkflow returned error: %v", err)
}
if resp.WorkflowId != "workflow-123" || resp.OrgId != "org-123" {
t.Fatalf("unexpected response: %+v", resp)
}
})
}

func withTestCIService(t *testing.T, fn func()) {
t.Helper()

Expand Down
Loading
Loading