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

CLI: remove step logs #3458

Merged
merged 14 commits into from
Apr 22, 2024
18 changes: 16 additions & 2 deletions cli/log/log_purge.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
var logPurgeCmd = &cli.Command{
Name: "purge",
Usage: "purge a log",
ArgsUsage: "<repo-id|repo-full-name> <pipeline>",
ArgsUsage: "<repo-id|repo-full-name> <pipeline> [step]",
Action: logPurge,
}

Expand All @@ -45,7 +45,21 @@ func logPurge(c *cli.Context) (err error) {
return err
}

err = client.LogsPurge(repoID, number)
stepArg := c.Args().Get(2) //nolint: gomnd
// 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)
if err != nil {
return err
}
}

if stepID > 0 {
err = client.StepLogsPurge(repoID, number, stepID)
} else {
err = client.LogsPurge(repoID, number)
}
if err != nil {
return err
}
Expand Down
29 changes: 18 additions & 11 deletions woodpecker-go/woodpecker/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ const (
pathRepair = "%s/api/repos/%d/repair"
pathPipelines = "%s/api/repos/%d/pipelines"
pathPipeline = "%s/api/repos/%d/pipelines/%v"
pathLogs = "%s/api/repos/%d/logs/%d/%d"
pathPipelineLogs = "%s/api/repos/%d/logs/%d"
pathStepLogs = "%s/api/repos/%d/logs/%d/%d"
pathApprove = "%s/api/repos/%d/pipelines/%d/approve"
pathDecline = "%s/api/repos/%d/pipelines/%d/decline"
pathStop = "%s/api/repos/%d/pipelines/%d/cancel"
pathLogPurge = "%s/api/repos/%d/logs/%d"
pathRepoSecrets = "%s/api/repos/%d/secrets"
pathRepoSecret = "%s/api/repos/%d/secrets/%s"
pathRepoRegistries = "%s/api/repos/%d/registry"
Expand Down Expand Up @@ -297,14 +297,28 @@ func (c *client) PipelineKill(repoID, pipeline int64) error {
return err
}

// PipelineLogs returns the pipeline logs for the specified step.
// LogsPurge purges the pipeline all steps logs for the specified pipeline.
func (c *client) LogsPurge(repoID, pipeline int64) error {
uri := fmt.Sprintf(pathPipelineLogs, c.addr, repoID, pipeline)
err := c.delete(uri)
return err
}

// StepLogEntries returns the pipeline logs for the specified step.
func (c *client) StepLogEntries(repoID, num, step int64) ([]*LogEntry, error) {
uri := fmt.Sprintf(pathLogs, c.addr, repoID, num, step)
uri := fmt.Sprintf(pathStepLogs, c.addr, repoID, num, step)
var out []*LogEntry
err := c.get(uri, &out)
return out, err
}

// StepLogsPurge purges the pipeline logs for the specified step.
func (c *client) StepLogsPurge(repoID, pipelineNumber, stepID int64) error {
uri := fmt.Sprintf(pathStepLogs, c.addr, repoID, pipelineNumber, stepID)
err := c.delete(uri)
return err
}

// Deploy triggers a deployment for an existing pipeline using the
// specified target environment.
func (c *client) Deploy(repoID, pipeline int64, env string, params map[string]string) (*Pipeline, error) {
Expand All @@ -317,13 +331,6 @@ func (c *client) Deploy(repoID, pipeline int64, env string, params map[string]st
return out, err
}

// LogsPurge purges the pipeline logs for the specified pipeline.
func (c *client) LogsPurge(repoID, pipeline int64) error {
uri := fmt.Sprintf(pathLogPurge, c.addr, repoID, pipeline)
err := c.delete(uri)
return err
}

// Registry returns a registry by hostname.
func (c *client) Registry(repoID int64, hostname string) (*Registry, error) {
out := new(Registry)
Expand Down
3 changes: 3 additions & 0 deletions woodpecker-go/woodpecker/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ type Client interface {
// LogsPurge purges the pipeline logs for the specified pipeline.
LogsPurge(repoID, pipeline int64) error

// StepLogsPurge purges the pipeline logs for the specified step.
StepLogsPurge(repoID, pipelineNumber, stepID int64) error

// Registry returns a registry by hostname.
Registry(repoID int64, hostname string) (*Registry, error)

Expand Down