mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-02-08 15:42:36 +00: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:
parent
e51f804ad6
commit
b02f2df89e
3 changed files with 37 additions and 13 deletions
|
@ -26,7 +26,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>",
|
ArgsUsage: "<repo-id|repo-full-name> <pipeline> [step]",
|
||||||
Action: logPurge,
|
Action: logPurge,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +45,21 @@ func logPurge(c *cli.Context) (err error) {
|
||||||
return err
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,11 +36,11 @@ const (
|
||||||
pathRepair = "%s/api/repos/%d/repair"
|
pathRepair = "%s/api/repos/%d/repair"
|
||||||
pathPipelines = "%s/api/repos/%d/pipelines"
|
pathPipelines = "%s/api/repos/%d/pipelines"
|
||||||
pathPipeline = "%s/api/repos/%d/pipelines/%v"
|
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"
|
pathApprove = "%s/api/repos/%d/pipelines/%d/approve"
|
||||||
pathDecline = "%s/api/repos/%d/pipelines/%d/decline"
|
pathDecline = "%s/api/repos/%d/pipelines/%d/decline"
|
||||||
pathStop = "%s/api/repos/%d/pipelines/%d/cancel"
|
pathStop = "%s/api/repos/%d/pipelines/%d/cancel"
|
||||||
pathLogPurge = "%s/api/repos/%d/logs/%d"
|
|
||||||
pathRepoSecrets = "%s/api/repos/%d/secrets"
|
pathRepoSecrets = "%s/api/repos/%d/secrets"
|
||||||
pathRepoSecret = "%s/api/repos/%d/secrets/%s"
|
pathRepoSecret = "%s/api/repos/%d/secrets/%s"
|
||||||
pathRepoRegistries = "%s/api/repos/%d/registry"
|
pathRepoRegistries = "%s/api/repos/%d/registry"
|
||||||
|
@ -297,14 +297,28 @@ func (c *client) PipelineKill(repoID, pipeline int64) error {
|
||||||
return err
|
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) {
|
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
|
var out []*LogEntry
|
||||||
err := c.get(uri, &out)
|
err := c.get(uri, &out)
|
||||||
return out, err
|
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
|
// Deploy triggers a deployment for an existing pipeline using the
|
||||||
// specified target environment.
|
// specified target environment.
|
||||||
func (c *client) Deploy(repoID, pipeline int64, env string, params map[string]string) (*Pipeline, error) {
|
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
|
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.
|
// Registry returns a registry by hostname.
|
||||||
func (c *client) Registry(repoID int64, hostname string) (*Registry, error) {
|
func (c *client) Registry(repoID int64, hostname string) (*Registry, error) {
|
||||||
out := new(Registry)
|
out := new(Registry)
|
||||||
|
|
|
@ -118,6 +118,9 @@ type Client interface {
|
||||||
// LogsPurge purges the pipeline logs for the specified pipeline.
|
// LogsPurge purges the pipeline logs for the specified pipeline.
|
||||||
LogsPurge(repoID, pipeline int64) error
|
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 returns a registry by hostname.
|
||||||
Registry(repoID int64, hostname string) (*Registry, error)
|
Registry(repoID int64, hostname string) (*Registry, error)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue