Fix pipeline cancel API endpoint and update Web and CLI clients (#1372)

Fixes #1369 

Co-authored-by: Anbraten <anton@ju60.de>
This commit is contained in:
Divya Jain 2022-10-30 19:09:01 +05:30 committed by GitHub
parent a5e1714039
commit 280d27d723
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 15 additions and 19 deletions

View file

@ -27,7 +27,7 @@ import (
var pipelineStopCmd = &cli.Command{
Name: "stop",
Usage: "stop a pipeline",
ArgsUsage: "<repo/name> [pipeline] [step]",
ArgsUsage: "<repo/name> [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
}

View file

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

View file

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

View file

@ -80,8 +80,8 @@ export default class WoodpeckerClient extends ApiClient {
return this._get(`/api/user/feed?${query}`) as Promise<PipelineFeed[]>;
}
cancelPipeline(owner: string, repo: string, number: number, ppid: number): Promise<unknown> {
return this._delete(`/api/repos/${owner}/${repo}/pipelines/${number}/${ppid}`);
cancelPipeline(owner: string, repo: string, number: number): Promise<unknown> {
return this._post(`/api/repos/${owner}/${repo}/pipelines/${number}/cancel`);
}
approvePipeline(owner: string, repo: string, pipeline: string): Promise<unknown> {

View file

@ -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' });
});

View file

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

View file

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