Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make cli plugin log purge recognize steps by name #3953

Merged
merged 1 commit into from
Jul 21, 2024
Merged
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
20 changes: 14 additions & 6 deletions cli/log/log_purge.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
var logPurgeCmd = &cli.Command{
Name: "purge",
Usage: "purge a log",
ArgsUsage: "<repo-id|repo-full-name> <pipeline> [step]",
ArgsUsage: "<repo-id|repo-full-name> <pipeline> [step-number|step-name]",
Action: logPurge,
}

Expand All @@ -37,34 +37,42 @@
return err
}
repoIDOrFullName := c.Args().First()
if len(repoIDOrFullName) == 0 {
return fmt.Errorf("missing required argument repo-id / repo-full-name")
}

Check warning on line 42 in cli/log/log_purge.go

View check run for this annotation

Codecov / codecov/patch

cli/log/log_purge.go#L40-L42

Added lines #L40 - L42 were not covered by tests
repoID, err := internal.ParseRepo(client, repoIDOrFullName)
if err != nil {
return err
return fmt.Errorf("invalid repo '%s': %w", repoIDOrFullName, err)
}

Check warning on line 46 in cli/log/log_purge.go

View check run for this annotation

Codecov / codecov/patch

cli/log/log_purge.go#L45-L46

Added lines #L45 - L46 were not covered by tests

pipelineArg := c.Args().Get(1)
if len(pipelineArg) == 0 {
return fmt.Errorf("missing required argument pipeline")

Check warning on line 50 in cli/log/log_purge.go

View check run for this annotation

Codecov / codecov/patch

cli/log/log_purge.go#L48-L50

Added lines #L48 - L50 were not covered by tests
}
number, err := strconv.ParseInt(c.Args().Get(1), 10, 64)
number, err := strconv.ParseInt(pipelineArg, 10, 64)

Check warning on line 52 in cli/log/log_purge.go

View check run for this annotation

Codecov / codecov/patch

cli/log/log_purge.go#L52

Added line #L52 was not covered by tests
if err != nil {
return err
}

stepArg := c.Args().Get(2) //nolint:mnd
// TODO: Add lookup by name: stepID, err := internal.ParseStep(client, repoID, stepIDOrName)
var stepID int64
if len(stepArg) != 0 {
stepID, err = strconv.ParseInt(stepArg, 10, 64)
stepID, err = internal.ParseStep(client, repoID, number, stepArg)

Check warning on line 60 in cli/log/log_purge.go

View check run for this annotation

Codecov / codecov/patch

cli/log/log_purge.go#L60

Added line #L60 was not covered by tests
if err != nil {
return err
}
}

if stepID > 0 {
fmt.Printf("Purging logs for pipeline %s#%d step %d\n", repoIDOrFullName, number, stepID)

Check warning on line 67 in cli/log/log_purge.go

View check run for this annotation

Codecov / codecov/patch

cli/log/log_purge.go#L67

Added line #L67 was not covered by tests
err = client.StepLogsPurge(repoID, number, stepID)
} else {
fmt.Printf("Purging logs for pipeline %s#%d\n", repoIDOrFullName, number)

Check warning on line 70 in cli/log/log_purge.go

View check run for this annotation

Codecov / codecov/patch

cli/log/log_purge.go#L70

Added line #L70 was not covered by tests
err = client.LogsPurge(repoID, number)
}
if err != nil {
return err
}

fmt.Printf("Purging logs for pipeline %s#%d\n", repoIDOrFullName, number)
return nil
}