1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-12-24 10:07:21 +02:00

CLI: remove step logs (#3458)

On top of #3451, addresses [PR
note](https://github.com/woodpecker-ci/woodpecker/pull/3451#discussion_r1505438144)

related to #1100

Not tested.

---------

Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: qwerty287 <80460567+qwerty287@users.noreply.github.com>
Co-authored-by: qwerty287 <qwerty287@posteo.de>
This commit is contained in:
Thomas Anderson 2024-04-22 20:11:59 +03:00 committed by GitHub
parent e51f804ad6
commit b02f2df89e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 37 additions and 13 deletions

View File

@ -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,
}
@ -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
}

View File

@ -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"
@ -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) {
@ -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)

View File

@ -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)