From 280d27d7234e0c4863902f5ec6c41a6fcf7b400d Mon Sep 17 00:00:00 2001 From: Divya Jain Date: Sun, 30 Oct 2022 19:09:01 +0530 Subject: [PATCH] Fix pipeline cancel API endpoint and update Web and CLI clients (#1372) Fixes #1369 Co-authored-by: Anbraten --- cli/pipeline/stop.go | 10 +++------- server/api/pipeline.go | 4 ++-- server/router/api.go | 2 +- web/src/lib/api/index.ts | 4 ++-- web/src/views/repo/pipeline/PipelineWrapper.vue | 2 +- woodpecker-go/woodpecker/client.go | 8 ++++---- woodpecker-go/woodpecker/interface.go | 4 ++-- 7 files changed, 15 insertions(+), 19 deletions(-) diff --git a/cli/pipeline/stop.go b/cli/pipeline/stop.go index ca80298d4..c71d4cad5 100644 --- a/cli/pipeline/stop.go +++ b/cli/pipeline/stop.go @@ -27,7 +27,7 @@ import ( var pipelineStopCmd = &cli.Command{ Name: "stop", Usage: "stop a pipeline", - ArgsUsage: " [pipeline] [step]", + ArgsUsage: " [pipeline]", Flags: common.GlobalFlags, Action: pipelineStop, } @@ -42,21 +42,17 @@ func pipelineStop(c *cli.Context) (err error) { if err != nil { return err } - step, _ := strconv.Atoi(c.Args().Get(2)) - if step == 0 { - step = 1 - } client, err := internal.NewClient(c) if err != nil { return err } - err = client.PipelineStop(owner, name, number, step) + err = client.PipelineStop(owner, name, number) if err != nil { return err } - fmt.Printf("Stopping pipeline %s/%s#%d.%d\n", owner, name, number, step) + fmt.Printf("Stopping pipeline %s/%s#%d\n", owner, name, number) return nil } diff --git a/server/api/pipeline.go b/server/api/pipeline.go index c17347386..06b95ab0a 100644 --- a/server/api/pipeline.go +++ b/server/api/pipeline.go @@ -255,8 +255,8 @@ func GetPipelineConfig(c *gin.Context) { c.JSON(http.StatusOK, configs) } -// DeletePipeline cancels a pipeline -func DeletePipeline(c *gin.Context) { +// CancelPipeline cancels a pipeline +func CancelPipeline(c *gin.Context) { _store := store.FromContext(c) repo := session.Repo(c) num, _ := strconv.ParseInt(c.Params.ByName("number"), 10, 64) diff --git a/server/router/api.go b/server/router/api.go index 5dc314193..fe3dbdb3b 100644 --- a/server/router/api.go +++ b/server/router/api.go @@ -82,7 +82,7 @@ func apiRoutes(e *gin.Engine) { // requires push permissions repo.POST("/pipelines/:number", session.MustPush, api.PostPipeline) - repo.DELETE("/pipelines/:number", session.MustPush, api.DeletePipeline) + repo.POST("/pipelines/:number/cancel", session.MustPush, api.CancelPipeline) repo.POST("/pipelines/:number/approve", session.MustPush, api.PostApproval) repo.POST("/pipelines/:number/decline", session.MustPush, api.PostDecline) diff --git a/web/src/lib/api/index.ts b/web/src/lib/api/index.ts index 036446f3e..5ace212f1 100644 --- a/web/src/lib/api/index.ts +++ b/web/src/lib/api/index.ts @@ -80,8 +80,8 @@ export default class WoodpeckerClient extends ApiClient { return this._get(`/api/user/feed?${query}`) as Promise; } - cancelPipeline(owner: string, repo: string, number: number, ppid: number): Promise { - return this._delete(`/api/repos/${owner}/${repo}/pipelines/${number}/${ppid}`); + cancelPipeline(owner: string, repo: string, number: number): Promise { + return this._post(`/api/repos/${owner}/${repo}/pipelines/${number}/cancel`); } approvePipeline(owner: string, repo: string, pipeline: string): Promise { diff --git a/web/src/views/repo/pipeline/PipelineWrapper.vue b/web/src/views/repo/pipeline/PipelineWrapper.vue index 47fe3e98d..b460671dc 100644 --- a/web/src/views/repo/pipeline/PipelineWrapper.vue +++ b/web/src/views/repo/pipeline/PipelineWrapper.vue @@ -156,7 +156,7 @@ export default defineComponent({ // throw new Error('Unexpected: Step not found'); // } - await apiClient.cancelPipeline(repo.value.owner, repo.value.name, parseInt(pipelineId.value, 10), 0); + await apiClient.cancelPipeline(repo.value.owner, repo.value.name, parseInt(pipelineId.value, 10)); notifications.notify({ title: i18n.t('repo.pipeline.actions.cancel_success'), type: 'success' }); }); diff --git a/woodpecker-go/woodpecker/client.go b/woodpecker-go/woodpecker/client.go index 86139c0f8..1acca4569 100644 --- a/woodpecker-go/woodpecker/client.go +++ b/woodpecker-go/woodpecker/client.go @@ -37,7 +37,7 @@ const ( pathLogs = "%s/api/repos/%s/%s/logs/%d/%d" pathApprove = "%s/api/repos/%s/%s/pipelines/%d/approve" pathDecline = "%s/api/repos/%s/%s/pipelines/%d/decline" - pathStep = "%s/api/repos/%s/%s/pipelines/%d/%d" + pathStop = "%s/api/repos/%s/%s/pipelines/%d/cancel" pathLogPurge = "%s/api/repos/%s/%s/logs/%d" pathRepoSecrets = "%s/api/repos/%s/%s/secrets" pathRepoSecret = "%s/api/repos/%s/%s/secrets/%s" @@ -253,9 +253,9 @@ func (c *client) PipelineStart(owner, name string, num int, params map[string]st } // PipelineStop cancels the running step. -func (c *client) PipelineStop(owner, name string, num, step int) error { - uri := fmt.Sprintf(pathStep, c.addr, owner, name, num, step) - err := c.delete(uri) +func (c *client) PipelineStop(owner, name string, pipeline int) error { + uri := fmt.Sprintf(pathStop, c.addr, owner, name, pipeline) + err := c.post(uri, nil, nil) return err } diff --git a/woodpecker-go/woodpecker/interface.go b/woodpecker-go/woodpecker/interface.go index fb62a6d51..a75206c7a 100644 --- a/woodpecker-go/woodpecker/interface.go +++ b/woodpecker-go/woodpecker/interface.go @@ -93,8 +93,8 @@ type Client interface { // PipelineStart re-starts a stopped pipeline. PipelineStart(string, string, int, map[string]string) (*Pipeline, error) - // PipelineStop stops the specified running step for given pipeline. - PipelineStop(string, string, int, int) error + // PipelineStop stops the given pipeline. + PipelineStop(string, string, int) error // PipelineApprove approves a blocked pipeline. PipelineApprove(string, string, int) (*Pipeline, error)