Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
Signed-off-by: Bence Santha <git@santha.eu>
  • Loading branch information
bencurio committed Oct 2, 2024
1 parent a983e12 commit 8883fad
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 4 additions & 2 deletions routers/api/v1/repo/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,11 +623,12 @@ func (a ActionWorkflow) ListRepositoryWorkflows(ctx *context.APIContext) {

workflows, err := actions_service.ListActionWorkflows(ctx)
if err != nil {
ctx.Error(http.StatusInternalServerError, "ListActionWorkflows", err)
return
}

if len(workflows) == 0 {
ctx.JSON(http.StatusNotFound, nil)
ctx.Error(http.StatusNotFound, "ListActionWorkflows", err)
return
}

Expand Down Expand Up @@ -679,11 +680,12 @@ func (a ActionWorkflow) GetWorkflow(ctx *context.APIContext) {

workflow, err := actions_service.GetActionWorkflow(ctx, workflowID)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetActionWorkflow", err)
return
}

if workflow == nil {
ctx.JSON(http.StatusNotFound, nil)
ctx.Error(http.StatusNotFound, "GetActionWorkflow", err)
return
}

Expand Down
10 changes: 5 additions & 5 deletions services/actions/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func GetActionWorkflow(ctx *context.APIContext, workflowID string) (*api.ActionW
}
}

return nil, fmt.Errorf("workflow not found")
return nil, fmt.Errorf("workflow '%s' not found", workflowID)
}

func DisableActionWorkflow(ctx *context.APIContext, workflowID string) error {
Expand All @@ -150,7 +150,7 @@ func DispatchActionWorkflow(ctx *context.APIContext, workflowID string, opt *api
cfg := cfgUnit.ActionsConfig()

if cfg.IsWorkflowDisabled(workflowID) {
ctx.Error(http.StatusInternalServerError, "WorkflowDisabled", ctx.Tr("actions.workflow.disabled"))
ctx.Error(http.StatusInternalServerError, "WorkflowDisabled", fmt.Sprintf("workflow '%s' is disabled", workflowID))
return
}

Expand All @@ -164,12 +164,12 @@ func DispatchActionWorkflow(ctx *context.APIContext, workflowID string, opt *api
case refName.IsBranch():
runTargetCommit, err = ctx.Repo.GitRepo.GetBranchCommit(refName.BranchName())
default:
ctx.Error(http.StatusInternalServerError, "WorkflowRefNameError", ctx.Tr("form.git_ref_name_error", opt.Ref))
ctx.Error(http.StatusInternalServerError, "WorkflowRefNameError", fmt.Sprintf("%s must be a well-formed Git reference name.", opt.Ref))
return
}

if err != nil {
ctx.Error(http.StatusNotFound, "WorkflowRefNotFound", ctx.Tr("form.target_ref_not_exist", opt.Ref))
ctx.Error(http.StatusNotFound, "WorkflowRefNotFound", fmt.Sprintf("target ref does not exist %s", opt.Ref))
return
}

Expand Down Expand Up @@ -204,7 +204,7 @@ func DispatchActionWorkflow(ctx *context.APIContext, workflowID string, opt *api
}

if workflow == nil {
ctx.Error(http.StatusNotFound, "WorkflowNotFound", ctx.Tr("actions.workflow.not_found", workflowID))
ctx.Error(http.StatusNotFound, "WorkflowNotFound", fmt.Sprintf("workflow '%s' is not found", workflowID))
return
}

Expand Down

0 comments on commit 8883fad

Please sign in to comment.