Skip to content

Commit febc40d

Browse files
authored
Merge pull request #437 from depot/luke/jj-myyymplnmkvr
feat: add --org flag to depot ci run, run list, status, and logs
2 parents 927b769 + d01322f commit febc40d

File tree

4 files changed

+45
-14
lines changed

4 files changed

+45
-14
lines changed

pkg/api/ci.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,24 @@ func newCIServiceClient() civ1connect.CIServiceClient {
1717
}
1818

1919
// CIGetRunStatus returns the current status of a CI run including its workflows, jobs, and attempts.
20-
func CIGetRunStatus(ctx context.Context, token, runID string) (*civ1.GetRunStatusResponse, error) {
20+
func CIGetRunStatus(ctx context.Context, token, orgID, runID string) (*civ1.GetRunStatusResponse, error) {
2121
client := newCIServiceClient()
22-
resp, err := client.GetRunStatus(ctx, WithAuthentication(connect.NewRequest(&civ1.GetRunStatusRequest{RunId: runID}), token))
22+
resp, err := client.GetRunStatus(ctx, WithAuthenticationAndOrg(connect.NewRequest(&civ1.GetRunStatusRequest{RunId: runID}), token, orgID))
2323
if err != nil {
2424
return nil, err
2525
}
2626
return resp.Msg, nil
2727
}
2828

2929
// CIGetJobAttemptLogs returns all log lines for a job attempt, paginating through all pages.
30-
func CIGetJobAttemptLogs(ctx context.Context, token, attemptID string) ([]*civ1.LogLine, error) {
30+
func CIGetJobAttemptLogs(ctx context.Context, token, orgID, attemptID string) ([]*civ1.LogLine, error) {
3131
client := newCIServiceClient()
3232
var allLines []*civ1.LogLine
3333
var pageToken string
3434

3535
for {
3636
req := &civ1.GetJobAttemptLogsRequest{AttemptId: attemptID, PageToken: pageToken}
37-
resp, err := client.GetJobAttemptLogs(ctx, WithAuthentication(connect.NewRequest(req), token))
37+
resp, err := client.GetJobAttemptLogs(ctx, WithAuthenticationAndOrg(connect.NewRequest(req), token, orgID))
3838
if err != nil {
3939
return nil, err
4040
}
@@ -49,9 +49,9 @@ func CIGetJobAttemptLogs(ctx context.Context, token, attemptID string) ([]*civ1.
4949
}
5050

5151
// CIRun triggers a CI run.
52-
func CIRun(ctx context.Context, token string, req *civ1.RunRequest) (*civ1.RunResponse, error) {
52+
func CIRun(ctx context.Context, token, orgID string, req *civ1.RunRequest) (*civ1.RunResponse, error) {
5353
client := newCIServiceClient()
54-
resp, err := client.Run(ctx, WithAuthentication(connect.NewRequest(req), token))
54+
resp, err := client.Run(ctx, WithAuthenticationAndOrg(connect.NewRequest(req), token, orgID))
5555
if err != nil {
5656
return nil, err
5757
}
@@ -60,7 +60,7 @@ func CIRun(ctx context.Context, token string, req *civ1.RunRequest) (*civ1.RunRe
6060

6161
// CIListRuns returns CI runs, paginating as needed to collect up to `limit` results.
6262
// If limit is 0, all results are returned.
63-
func CIListRuns(ctx context.Context, token string, statuses []civ1.CIRunStatus, limit int32) ([]*civ1.ListRunsResponseRun, error) {
63+
func CIListRuns(ctx context.Context, token, orgID string, statuses []civ1.CIRunStatus, limit int32) ([]*civ1.ListRunsResponseRun, error) {
6464
client := newCIServiceClient()
6565
var allRuns []*civ1.ListRunsResponseRun
6666
var pageToken string
@@ -80,7 +80,7 @@ func CIListRuns(ctx context.Context, token string, statuses []civ1.CIRunStatus,
8080
PageSize: pageSize,
8181
PageToken: pageToken,
8282
}
83-
resp, err := client.ListRuns(ctx, WithAuthentication(connect.NewRequest(req), token))
83+
resp, err := client.ListRuns(ctx, WithAuthenticationAndOrg(connect.NewRequest(req), token, orgID))
8484
if err != nil {
8585
return nil, err
8686
}

pkg/cmd/ci/logs.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@ import (
44
"fmt"
55

66
"github.com/depot/cli/pkg/api"
7+
"github.com/depot/cli/pkg/config"
78
"github.com/depot/cli/pkg/helpers"
89
"github.com/spf13/cobra"
910
)
1011

1112
func NewCmdLogs() *cobra.Command {
12-
var token string
13+
var (
14+
orgID string
15+
token string
16+
)
1317

1418
cmd := &cobra.Command{
1519
Use: "logs <attempt-id>",
@@ -23,6 +27,10 @@ func NewCmdLogs() *cobra.Command {
2327
ctx := cmd.Context()
2428
attemptID := args[0]
2529

30+
if orgID == "" {
31+
orgID = config.GetCurrentOrganization()
32+
}
33+
2634
tokenVal, err := helpers.ResolveOrgAuth(ctx, token)
2735
if err != nil {
2836
return err
@@ -31,7 +39,7 @@ func NewCmdLogs() *cobra.Command {
3139
return fmt.Errorf("missing API token, please run `depot login`")
3240
}
3341

34-
lines, err := api.CIGetJobAttemptLogs(ctx, tokenVal, attemptID)
42+
lines, err := api.CIGetJobAttemptLogs(ctx, tokenVal, orgID, attemptID)
3543
if err != nil {
3644
return fmt.Errorf("failed to get job attempt logs: %w", err)
3745
}
@@ -44,6 +52,7 @@ func NewCmdLogs() *cobra.Command {
4452
},
4553
}
4654

55+
cmd.Flags().StringVar(&orgID, "org", "", "Organization ID (required when user is a member of multiple organizations)")
4756
cmd.Flags().StringVar(&token, "token", "", "Depot API token")
4857

4958
return cmd

pkg/cmd/ci/run.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"strings"
1212

1313
"github.com/depot/cli/pkg/api"
14+
"github.com/depot/cli/pkg/config"
1415
"github.com/depot/cli/pkg/helpers"
1516
civ1 "github.com/depot/cli/pkg/proto/depot/ci/v1"
1617
"github.com/spf13/cobra"
@@ -21,6 +22,7 @@ const cacheBaseURL = "https://cache.depot.dev"
2122

2223
func NewCmdRun() *cobra.Command {
2324
var (
25+
orgID string
2426
token string
2527
workflowPath string
2628
jobNames []string
@@ -55,6 +57,10 @@ This command is in beta and subject to change.`,
5557
return fmt.Errorf("--ssh-after-step requires exactly one --job")
5658
}
5759

60+
if orgID == "" {
61+
orgID = config.GetCurrentOrganization()
62+
}
63+
5864
tokenVal, err := helpers.ResolveOrgAuth(ctx, token)
5965
if err != nil {
6066
return err
@@ -185,7 +191,7 @@ This command is in beta and subject to change.`,
185191
req.Job = &job
186192
}
187193

188-
resp, err := api.CIRun(ctx, tokenVal, req)
194+
resp, err := api.CIRun(ctx, tokenVal, orgID, req)
189195
if err != nil {
190196
return fmt.Errorf("failed to start CI run: %w", err)
191197
}
@@ -197,6 +203,7 @@ This command is in beta and subject to change.`,
197203
},
198204
}
199205

206+
cmd.Flags().StringVar(&orgID, "org", "", "Organization ID (required when user is a member of multiple organizations)")
200207
cmd.Flags().StringVar(&token, "token", "", "Depot API token")
201208
cmd.Flags().StringVar(&workflowPath, "workflow", "", "Path to workflow YAML file")
202209
cmd.Flags().StringSliceVar(&jobNames, "job", nil, "Job name(s) to run (repeatable; omit to run all)")
@@ -442,6 +449,7 @@ func formatStatus(s civ1.CIRunStatus) string {
442449

443450
func NewCmdRunList() *cobra.Command {
444451
var (
452+
orgID string
445453
token string
446454
statuses []string
447455
n int32
@@ -474,6 +482,10 @@ func NewCmdRunList() *cobra.Command {
474482

475483
ctx := cmd.Context()
476484

485+
if orgID == "" {
486+
orgID = config.GetCurrentOrganization()
487+
}
488+
477489
tokenVal, err := helpers.ResolveOrgAuth(ctx, token)
478490
if err != nil {
479491
return err
@@ -491,7 +503,7 @@ func NewCmdRunList() *cobra.Command {
491503
protoStatuses = append(protoStatuses, ps)
492504
}
493505

494-
runs, err := api.CIListRuns(ctx, tokenVal, protoStatuses, n)
506+
runs, err := api.CIListRuns(ctx, tokenVal, orgID, protoStatuses, n)
495507
if err != nil {
496508
return fmt.Errorf("failed to list runs: %w", err)
497509
}
@@ -547,6 +559,7 @@ func NewCmdRunList() *cobra.Command {
547559
},
548560
}
549561

562+
cmd.Flags().StringVar(&orgID, "org", "", "Organization ID (required when user is a member of multiple organizations)")
550563
cmd.Flags().StringVar(&token, "token", "", "Depot API token")
551564
cmd.Flags().StringSliceVar(&statuses, "status", nil, "Filter by status (repeatable: queued, running, finished, failed, cancelled)")
552565
cmd.Flags().Int32VarP(&n, "n", "n", 50, "Number of runs to return")

pkg/cmd/ci/status.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@ import (
44
"fmt"
55

66
"github.com/depot/cli/pkg/api"
7+
"github.com/depot/cli/pkg/config"
78
"github.com/depot/cli/pkg/helpers"
89
"github.com/spf13/cobra"
910
)
1011

1112
func NewCmdStatus() *cobra.Command {
12-
var token string
13+
var (
14+
orgID string
15+
token string
16+
)
1317

1418
cmd := &cobra.Command{
1519
Use: "status <run-id>",
@@ -23,6 +27,10 @@ func NewCmdStatus() *cobra.Command {
2327
ctx := cmd.Context()
2428
runID := args[0]
2529

30+
if orgID == "" {
31+
orgID = config.GetCurrentOrganization()
32+
}
33+
2634
tokenVal, err := helpers.ResolveOrgAuth(ctx, token)
2735
if err != nil {
2836
return err
@@ -31,7 +39,7 @@ func NewCmdStatus() *cobra.Command {
3139
return fmt.Errorf("missing API token, please run `depot login`")
3240
}
3341

34-
resp, err := api.CIGetRunStatus(ctx, tokenVal, runID)
42+
resp, err := api.CIGetRunStatus(ctx, tokenVal, orgID, runID)
3543
if err != nil {
3644
return fmt.Errorf("failed to get run status: %w", err)
3745
}
@@ -59,6 +67,7 @@ func NewCmdStatus() *cobra.Command {
5967
},
6068
}
6169

70+
cmd.Flags().StringVar(&orgID, "org", "", "Organization ID (required when user is a member of multiple organizations)")
6271
cmd.Flags().StringVar(&token, "token", "", "Depot API token")
6372

6473
return cmd

0 commit comments

Comments
 (0)