Skip to content

Commit 51097fd

Browse files
committed
Some improvements
1 parent aede29b commit 51097fd

File tree

3 files changed

+39
-37
lines changed

3 files changed

+39
-37
lines changed

routers/api/v1/api.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -917,17 +917,16 @@ func Routes() *web.Router {
917917

918918
addActionsWorkflowRoutes := func(
919919
m *web.Router,
920-
reqChecker func(ctx *context.APIContext),
921920
actw actions.WorkflowAPI,
922921
) {
923922
m.Group("/actions", func() {
924923
m.Group("/workflows", func() {
925-
m.Get("", reqToken(), reqChecker, actw.ListRepositoryWorkflows)
926-
m.Get("/{workflow_id}", reqToken(), reqChecker, actw.GetWorkflow)
927-
m.Put("/{workflow_id}/disable", reqToken(), reqChecker, actw.DisableWorkflow)
928-
m.Post("/{workflow_id}/dispatches", reqToken(), reqChecker, bind(api.CreateActionWorkflowDispatch{}), actw.DispatchWorkflow)
929-
m.Put("/{workflow_id}/enable", reqToken(), reqChecker, actw.EnableWorkflow)
930-
}, context.ReferencesGitRepo(), reqRepoWriter(unit.TypeActions))
924+
m.Get("", reqToken(), actw.ListRepositoryWorkflows)
925+
m.Get("/{workflow_id}", reqToken(), actw.GetWorkflow)
926+
m.Put("/{workflow_id}/disable", reqToken(), reqRepoWriter(unit.TypeActions), actw.DisableWorkflow)
927+
m.Post("/{workflow_id}/dispatches", reqToken(), reqRepoWriter(unit.TypeActions), bind(api.CreateActionWorkflowDispatch{}), actw.DispatchWorkflow)
928+
m.Put("/{workflow_id}/enable", reqToken(), reqRepoWriter(unit.TypeActions), actw.EnableWorkflow)
929+
}, context.ReferencesGitRepo(), reqRepoReader(unit.TypeActions))
931930
})
932931
}
933932

@@ -1178,7 +1177,6 @@ func Routes() *web.Router {
11781177
)
11791178
addActionsWorkflowRoutes(
11801179
m,
1181-
reqRepoWriter(unit.TypeActions),
11821180
repo.NewActionWorkflow(),
11831181
)
11841182
m.Group("/hooks/git", func() {

routers/web/repo/actions/view.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -831,19 +831,21 @@ func Run(ctx *context_module.Context) {
831831
// find workflow from commit
832832
var workflows []*jobparser.SingleWorkflow
833833
for _, entry := range entries {
834-
if entry.Name() == workflowID {
835-
content, err := actions.GetContentFromEntry(entry)
836-
if err != nil {
837-
ctx.Error(http.StatusInternalServerError, err.Error())
838-
return
839-
}
840-
workflows, err = jobparser.Parse(content)
841-
if err != nil {
842-
ctx.ServerError("workflow", err)
843-
return
844-
}
845-
break
834+
if entry.Name() != workflowID {
835+
continue
836+
}
837+
838+
content, err := actions.GetContentFromEntry(entry)
839+
if err != nil {
840+
ctx.Error(http.StatusInternalServerError, err.Error())
841+
return
842+
}
843+
workflows, err = jobparser.Parse(content)
844+
if err != nil {
845+
ctx.ServerError("workflow", err)
846+
return
846847
}
848+
break
847849
}
848850

849851
if len(workflows) == 0 {

services/actions/workflow.go

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -187,24 +187,26 @@ func DispatchActionWorkflow(ctx *context.APIContext, workflowID string, opt *api
187187

188188
var workflow *jobparser.SingleWorkflow
189189
for _, entry := range entries {
190-
if entry.Name() == workflowID {
191-
content, err := actions.GetContentFromEntry(entry)
192-
if err != nil {
193-
ctx.Error(http.StatusInternalServerError, "WorkflowGetContentError", err.Error())
194-
return
195-
}
196-
workflows, err := jobparser.Parse(content)
197-
if err != nil {
198-
ctx.Error(http.StatusInternalServerError, "WorkflowParseError", err.Error())
199-
return
200-
}
201-
if len(workflows) == 0 {
202-
ctx.Error(http.StatusNotFound, "WorkflowNotFound", fmt.Sprintf("workflow '%s' is not found", workflowID))
203-
return
204-
}
205-
workflow = workflows[0]
206-
break
190+
if entry.Name() != workflowID {
191+
continue
192+
}
193+
194+
content, err := actions.GetContentFromEntry(entry)
195+
if err != nil {
196+
ctx.Error(http.StatusInternalServerError, "WorkflowGetContentError", err.Error())
197+
return
198+
}
199+
workflows, err := jobparser.Parse(content)
200+
if err != nil {
201+
ctx.Error(http.StatusInternalServerError, "WorkflowParseError", err.Error())
202+
return
203+
}
204+
if len(workflows) == 0 {
205+
ctx.Error(http.StatusNotFound, "WorkflowNotFound", fmt.Sprintf("workflow '%s' is not found", workflowID))
206+
return
207207
}
208+
workflow = workflows[0]
209+
break
208210
}
209211

210212
// Process workflow inputs

0 commit comments

Comments
 (0)