mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-01-04 22:58:43 +00:00
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:
parent
a5e1714039
commit
280d27d723
7 changed files with 15 additions and 19 deletions
|
@ -27,7 +27,7 @@ import (
|
||||||
var pipelineStopCmd = &cli.Command{
|
var pipelineStopCmd = &cli.Command{
|
||||||
Name: "stop",
|
Name: "stop",
|
||||||
Usage: "stop a pipeline",
|
Usage: "stop a pipeline",
|
||||||
ArgsUsage: "<repo/name> [pipeline] [step]",
|
ArgsUsage: "<repo/name> [pipeline]",
|
||||||
Flags: common.GlobalFlags,
|
Flags: common.GlobalFlags,
|
||||||
Action: pipelineStop,
|
Action: pipelineStop,
|
||||||
}
|
}
|
||||||
|
@ -42,21 +42,17 @@ func pipelineStop(c *cli.Context) (err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
step, _ := strconv.Atoi(c.Args().Get(2))
|
|
||||||
if step == 0 {
|
|
||||||
step = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
client, err := internal.NewClient(c)
|
client, err := internal.NewClient(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = client.PipelineStop(owner, name, number, step)
|
err = client.PipelineStop(owner, name, number)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -255,8 +255,8 @@ func GetPipelineConfig(c *gin.Context) {
|
||||||
c.JSON(http.StatusOK, configs)
|
c.JSON(http.StatusOK, configs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeletePipeline cancels a pipeline
|
// CancelPipeline cancels a pipeline
|
||||||
func DeletePipeline(c *gin.Context) {
|
func CancelPipeline(c *gin.Context) {
|
||||||
_store := store.FromContext(c)
|
_store := store.FromContext(c)
|
||||||
repo := session.Repo(c)
|
repo := session.Repo(c)
|
||||||
num, _ := strconv.ParseInt(c.Params.ByName("number"), 10, 64)
|
num, _ := strconv.ParseInt(c.Params.ByName("number"), 10, 64)
|
||||||
|
|
|
@ -82,7 +82,7 @@ func apiRoutes(e *gin.Engine) {
|
||||||
|
|
||||||
// requires push permissions
|
// requires push permissions
|
||||||
repo.POST("/pipelines/:number", session.MustPush, api.PostPipeline)
|
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/approve", session.MustPush, api.PostApproval)
|
||||||
repo.POST("/pipelines/:number/decline", session.MustPush, api.PostDecline)
|
repo.POST("/pipelines/:number/decline", session.MustPush, api.PostDecline)
|
||||||
|
|
||||||
|
|
|
@ -80,8 +80,8 @@ export default class WoodpeckerClient extends ApiClient {
|
||||||
return this._get(`/api/user/feed?${query}`) as Promise<PipelineFeed[]>;
|
return this._get(`/api/user/feed?${query}`) as Promise<PipelineFeed[]>;
|
||||||
}
|
}
|
||||||
|
|
||||||
cancelPipeline(owner: string, repo: string, number: number, ppid: number): Promise<unknown> {
|
cancelPipeline(owner: string, repo: string, number: number): Promise<unknown> {
|
||||||
return this._delete(`/api/repos/${owner}/${repo}/pipelines/${number}/${ppid}`);
|
return this._post(`/api/repos/${owner}/${repo}/pipelines/${number}/cancel`);
|
||||||
}
|
}
|
||||||
|
|
||||||
approvePipeline(owner: string, repo: string, pipeline: string): Promise<unknown> {
|
approvePipeline(owner: string, repo: string, pipeline: string): Promise<unknown> {
|
||||||
|
|
|
@ -156,7 +156,7 @@ export default defineComponent({
|
||||||
// throw new Error('Unexpected: Step not found');
|
// 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' });
|
notifications.notify({ title: i18n.t('repo.pipeline.actions.cancel_success'), type: 'success' });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ const (
|
||||||
pathLogs = "%s/api/repos/%s/%s/logs/%d/%d"
|
pathLogs = "%s/api/repos/%s/%s/logs/%d/%d"
|
||||||
pathApprove = "%s/api/repos/%s/%s/pipelines/%d/approve"
|
pathApprove = "%s/api/repos/%s/%s/pipelines/%d/approve"
|
||||||
pathDecline = "%s/api/repos/%s/%s/pipelines/%d/decline"
|
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"
|
pathLogPurge = "%s/api/repos/%s/%s/logs/%d"
|
||||||
pathRepoSecrets = "%s/api/repos/%s/%s/secrets"
|
pathRepoSecrets = "%s/api/repos/%s/%s/secrets"
|
||||||
pathRepoSecret = "%s/api/repos/%s/%s/secrets/%s"
|
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.
|
// PipelineStop cancels the running step.
|
||||||
func (c *client) PipelineStop(owner, name string, num, step int) error {
|
func (c *client) PipelineStop(owner, name string, pipeline int) error {
|
||||||
uri := fmt.Sprintf(pathStep, c.addr, owner, name, num, step)
|
uri := fmt.Sprintf(pathStop, c.addr, owner, name, pipeline)
|
||||||
err := c.delete(uri)
|
err := c.post(uri, nil, nil)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -93,8 +93,8 @@ type Client interface {
|
||||||
// PipelineStart re-starts a stopped pipeline.
|
// PipelineStart re-starts a stopped pipeline.
|
||||||
PipelineStart(string, string, int, map[string]string) (*Pipeline, error)
|
PipelineStart(string, string, int, map[string]string) (*Pipeline, error)
|
||||||
|
|
||||||
// PipelineStop stops the specified running step for given pipeline.
|
// PipelineStop stops the given pipeline.
|
||||||
PipelineStop(string, string, int, int) error
|
PipelineStop(string, string, int) error
|
||||||
|
|
||||||
// PipelineApprove approves a blocked pipeline.
|
// PipelineApprove approves a blocked pipeline.
|
||||||
PipelineApprove(string, string, int) (*Pipeline, error)
|
PipelineApprove(string, string, int) (*Pipeline, error)
|
||||||
|
|
Loading…
Reference in a new issue