feat(api): return run info for dispatched workflows (#7193)
- When the API endpoint `/repos/{owner}/{repo}/actions/workflows/{workflowname}/dispatches` is used to launch a workflow, it currently returns no data; `/repos/{owner}/{repo}/actions/tasks` can be used to track the progress of a workflow, but you need at least that workflow's run_id and the quantity of its child jobs. Tracking workflow progress is especially important if you want to chain together multiple workflows that exist within different repositories, which is desired for https://codeberg.org/forgejo/forgejo/issues/6312. - Make it possible to track the progress of manually triggered workflows by modifying the `/repos/{owner}/{repo}/actions/workflows/{workflowname}/dispatches` to return a JSON object containing the triggered workflow's id and a list of its child job names. Co-authored-by: Andrii Chyrva <achyrva@amcbridge.com> Co-authored-by: Andrii Chyrva <andrii.s.chyrva@hotmail.com> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7193 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: markturney <markturney@gmail.com> Co-committed-by: markturney <markturney@gmail.com>
This commit is contained in:
parent
c7cb5f9978
commit
7a19d3c2be
7 changed files with 88 additions and 13 deletions
|
@ -670,7 +670,8 @@ func DispatchWorkflow(ctx *context.APIContext) {
|
|||
return opt.Inputs[key]
|
||||
}
|
||||
|
||||
if err := workflow.Dispatch(ctx, inputGetter, ctx.Repo.Repository, ctx.Doer); err != nil {
|
||||
run, jobs, err := workflow.Dispatch(ctx, inputGetter, ctx.Repo.Repository, ctx.Doer)
|
||||
if err != nil {
|
||||
if actions_service.IsInputRequiredErr(err) {
|
||||
ctx.Error(http.StatusBadRequest, "workflow.Dispatch", err)
|
||||
} else {
|
||||
|
@ -679,5 +680,14 @@ func DispatchWorkflow(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusNoContent, nil)
|
||||
workflowRun := &api.DispatchWorkflowRun{
|
||||
ID: run.ID,
|
||||
Jobs: jobs,
|
||||
}
|
||||
|
||||
if opt.ReturnRunInfo {
|
||||
ctx.JSON(http.StatusCreated, workflowRun)
|
||||
} else {
|
||||
ctx.JSON(http.StatusNoContent, nil)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,3 +39,10 @@ type swaggerRunJobList struct {
|
|||
// in:body
|
||||
Body []*api.ActionRunJob `json:"body"`
|
||||
}
|
||||
|
||||
// DispatchWorkflowRun is a Workflow Run after dispatching
|
||||
// swagger:response DispatchWorkflowRun
|
||||
type swaggerDispatchWorkflowRun struct {
|
||||
// in:body
|
||||
Body *api.DispatchWorkflowRun `json:"body"`
|
||||
}
|
||||
|
|
|
@ -46,7 +46,8 @@ func ManualRunWorkflow(ctx *context_module.Context) {
|
|||
return ctx.Req.PostFormValue(formKey)
|
||||
}
|
||||
|
||||
if err := workflow.Dispatch(ctx, formKeyGetter, ctx.Repo.Repository, ctx.Doer); err != nil {
|
||||
_, _, err = workflow.Dispatch(ctx, formKeyGetter, ctx.Repo.Repository, ctx.Doer)
|
||||
if err != nil {
|
||||
if actions_service.IsInputRequiredErr(err) {
|
||||
ctx.Flash.Error(ctx.Locale.Tr("actions.workflow.dispatch.input_required", err.(actions_service.InputRequiredErr).Name))
|
||||
ctx.Redirect(location)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue