Make cli plugin log purge recognize steps by name (#3953)

This commit is contained in:
smainz 2024-07-21 11:36:01 +02:00 committed by GitHub
parent 0c98f49b1e
commit c7b64e24ab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -27,7 +27,7 @@ import (
var logPurgeCmd = &cli.Command{ var logPurgeCmd = &cli.Command{
Name: "purge", Name: "purge",
Usage: "purge a log", 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, Action: logPurge,
} }
@ -37,34 +37,42 @@ func logPurge(ctx context.Context, c *cli.Command) (err error) {
return err return err
} }
repoIDOrFullName := c.Args().First() repoIDOrFullName := c.Args().First()
if len(repoIDOrFullName) == 0 {
return fmt.Errorf("missing required argument repo-id / repo-full-name")
}
repoID, err := internal.ParseRepo(client, repoIDOrFullName) repoID, err := internal.ParseRepo(client, repoIDOrFullName)
if err != nil { if err != nil {
return err return fmt.Errorf("invalid repo '%s': %w", repoIDOrFullName, err)
} }
number, err := strconv.ParseInt(c.Args().Get(1), 10, 64)
pipelineArg := c.Args().Get(1)
if len(pipelineArg) == 0 {
return fmt.Errorf("missing required argument pipeline")
}
number, err := strconv.ParseInt(pipelineArg, 10, 64)
if err != nil { if err != nil {
return err return err
} }
stepArg := c.Args().Get(2) //nolint:mnd stepArg := c.Args().Get(2) //nolint:mnd
// TODO: Add lookup by name: stepID, err := internal.ParseStep(client, repoID, stepIDOrName)
var stepID int64 var stepID int64
if len(stepArg) != 0 { if len(stepArg) != 0 {
stepID, err = strconv.ParseInt(stepArg, 10, 64) stepID, err = internal.ParseStep(client, repoID, number, stepArg)
if err != nil { if err != nil {
return err return err
} }
} }
if stepID > 0 { if stepID > 0 {
fmt.Printf("Purging logs for pipeline %s#%d step %d\n", repoIDOrFullName, number, stepID)
err = client.StepLogsPurge(repoID, number, stepID) err = client.StepLogsPurge(repoID, number, stepID)
} else { } else {
fmt.Printf("Purging logs for pipeline %s#%d\n", repoIDOrFullName, number)
err = client.LogsPurge(repoID, number) err = client.LogsPurge(repoID, number)
} }
if err != nil { if err != nil {
return err return err
} }
fmt.Printf("Purging logs for pipeline %s#%d\n", repoIDOrFullName, number)
return nil return nil
} }