Skip to content

Commit 8883fad

Browse files
committed
refactor
Signed-off-by: Bence Santha <[email protected]>
1 parent a983e12 commit 8883fad

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

routers/api/v1/repo/action.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,11 +623,12 @@ func (a ActionWorkflow) ListRepositoryWorkflows(ctx *context.APIContext) {
623623

624624
workflows, err := actions_service.ListActionWorkflows(ctx)
625625
if err != nil {
626+
ctx.Error(http.StatusInternalServerError, "ListActionWorkflows", err)
626627
return
627628
}
628629

629630
if len(workflows) == 0 {
630-
ctx.JSON(http.StatusNotFound, nil)
631+
ctx.Error(http.StatusNotFound, "ListActionWorkflows", err)
631632
return
632633
}
633634

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

680681
workflow, err := actions_service.GetActionWorkflow(ctx, workflowID)
681682
if err != nil {
683+
ctx.Error(http.StatusInternalServerError, "GetActionWorkflow", err)
682684
return
683685
}
684686

685687
if workflow == nil {
686-
ctx.JSON(http.StatusNotFound, nil)
688+
ctx.Error(http.StatusNotFound, "GetActionWorkflow", err)
687689
return
688690
}
689691

services/actions/workflow.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func GetActionWorkflow(ctx *context.APIContext, workflowID string) (*api.ActionW
138138
}
139139
}
140140

141-
return nil, fmt.Errorf("workflow not found")
141+
return nil, fmt.Errorf("workflow '%s' not found", workflowID)
142142
}
143143

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

152152
if cfg.IsWorkflowDisabled(workflowID) {
153-
ctx.Error(http.StatusInternalServerError, "WorkflowDisabled", ctx.Tr("actions.workflow.disabled"))
153+
ctx.Error(http.StatusInternalServerError, "WorkflowDisabled", fmt.Sprintf("workflow '%s' is disabled", workflowID))
154154
return
155155
}
156156

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

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

@@ -204,7 +204,7 @@ func DispatchActionWorkflow(ctx *context.APIContext, workflowID string, opt *api
204204
}
205205

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

0 commit comments

Comments
 (0)