-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Actions support workflow dispatch event #28163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 40 commits
fbadf6f
8eb79f3
d973fc1
e18bbcc
d0a70d3
2d2f921
660cf18
2829a88
f4a55d1
5afedfd
1b7864d
0e67591
300f068
a7c0016
36c47f1
78d636f
44615a5
c24dede
65b0313
faf3b08
1f64b24
5e0a0bc
5ddf23a
a6db416
ab84156
c9aeacc
b3203b4
5b51dfb
d1f8cef
e78a88d
82e27b8
9fc0e0d
4a34fc8
ce55bd5
57653ac
28350dc
50694f2
b261c3c
0027bc9
85ec450
1d20af3
7c9eba6
c0b87a5
b2092d2
6d3c634
8e70046
8d23757
8312260
2d882b0
65de06e
4097052
43e0e3d
eb71452
cf5fe7f
83fb4b0
ea31b78
c159998
d2588fd
4683d81
899abcf
91358ac
052acfe
283d475
20896ed
ef3a18a
ecb0f41
d682687
ddd8b37
791e790
94029b6
2ea6fa2
b88ae0f
e3e321b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,17 +7,21 @@ import ( | |
"bytes" | ||
"fmt" | ||
"net/http" | ||
"slices" | ||
"strings" | ||
|
||
actions_model "code.gitea.io/gitea/models/actions" | ||
"code.gitea.io/gitea/models/db" | ||
git_model "code.gitea.io/gitea/models/git" | ||
repo_model "code.gitea.io/gitea/models/repo" | ||
"code.gitea.io/gitea/models/unit" | ||
"code.gitea.io/gitea/modules/actions" | ||
"code.gitea.io/gitea/modules/base" | ||
"code.gitea.io/gitea/modules/container" | ||
"code.gitea.io/gitea/modules/git" | ||
"code.gitea.io/gitea/modules/optional" | ||
"code.gitea.io/gitea/modules/setting" | ||
"code.gitea.io/gitea/modules/util" | ||
"code.gitea.io/gitea/routers/web/repo" | ||
"code.gitea.io/gitea/services/context" | ||
"code.gitea.io/gitea/services/convert" | ||
|
@@ -58,8 +62,13 @@ func MustEnableActions(ctx *context.Context) { | |
func List(ctx *context.Context) { | ||
ctx.Data["Title"] = ctx.Tr("actions.actions") | ||
ctx.Data["PageIsActions"] = true | ||
workflowID := ctx.FormString("workflow") | ||
actorID := ctx.FormInt64("actor") | ||
status := ctx.FormInt("status") | ||
ctx.Data["CurWorkflow"] = workflowID | ||
|
||
var workflows []Workflow | ||
var curWorkflow *model.Workflow | ||
if empty, err := ctx.Repo.GitRepo.IsEmpty(); err != nil { | ||
ctx.ServerError("IsEmpty", err) | ||
return | ||
|
@@ -124,6 +133,11 @@ func List(ctx *context.Context) { | |
} | ||
} | ||
workflows = append(workflows, workflow) | ||
|
||
if workflow.Entry.Name() == workflowID { | ||
curWorkflow = wf | ||
} | ||
|
||
} | ||
} | ||
ctx.Data["workflows"] = workflows | ||
|
@@ -134,17 +148,44 @@ func List(ctx *context.Context) { | |
page = 1 | ||
} | ||
|
||
workflow := ctx.FormString("workflow") | ||
actorID := ctx.FormInt64("actor") | ||
status := ctx.FormInt("status") | ||
ctx.Data["CurWorkflow"] = workflow | ||
|
||
actionsConfig := ctx.Repo.Repository.MustGetUnit(ctx, unit.TypeActions).ActionsConfig() | ||
ctx.Data["ActionsConfig"] = actionsConfig | ||
|
||
if len(workflow) > 0 && ctx.Repo.IsAdmin() { | ||
if len(workflowID) > 0 && ctx.Repo.IsAdmin() { | ||
ctx.Data["AllowDisableOrEnableWorkflow"] = true | ||
ctx.Data["CurWorkflowDisabled"] = actionsConfig.IsWorkflowDisabled(workflow) | ||
isWorkflowDisabled := actionsConfig.IsWorkflowDisabled(workflowID) | ||
ctx.Data["CurWorkflowDisabled"] = isWorkflowDisabled | ||
|
||
if !isWorkflowDisabled && curWorkflow != nil { | ||
workflowDispatchConfig := curWorkflow.WorkflowDispatchConfig() | ||
if workflowDispatchConfig != nil { | ||
ctx.Data["WorkflowDispatchConfig"] = workflowDispatchConfig | ||
|
||
branchOpts := git_model.FindBranchOptions{ | ||
RepoID: ctx.Repo.Repository.ID, | ||
IsDeletedBranch: optional.Some(false), | ||
ListOptions: db.ListOptions{ | ||
ListAll: true, | ||
}, | ||
} | ||
branches, err := git_model.FindBranchNames(ctx, branchOpts) | ||
if err != nil { | ||
ctx.JSON(http.StatusInternalServerError, err) | ||
return | ||
} | ||
// always put default branch on the top if it exists | ||
if slices.Contains(branches, ctx.Repo.Repository.DefaultBranch) { | ||
branches = util.SliceRemoveAll(branches, ctx.Repo.Repository.DefaultBranch) | ||
branches = append([]string{ctx.Repo.Repository.DefaultBranch}, branches...) | ||
} | ||
ctx.Data["Branches"] = branches | ||
|
||
tags, err := repo_model.GetTagNamesByRepoID(ctx, ctx.Repo.Repository.ID) | ||
if err == nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. err == nil means the function returned correctly. Then set tags to ctx. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
So, if the tags are optional, then There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I can not understand why tags are optional. 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My previous thought was that if there was an error in the get tag, just use the branch and it would not be blocked. |
||
ctx.Data["Tags"] = tags | ||
} | ||
} | ||
} | ||
} | ||
|
||
// if status or actor query param is not given to frontend href, (href="/<repoLink>/actions") | ||
|
@@ -161,7 +202,7 @@ func List(ctx *context.Context) { | |
PageSize: convert.ToCorrectPageSize(ctx.FormInt("limit")), | ||
}, | ||
RepoID: ctx.Repo.Repository.ID, | ||
WorkflowID: workflow, | ||
WorkflowID: workflowID, | ||
TriggerUserID: actorID, | ||
} | ||
|
||
|
@@ -198,7 +239,7 @@ func List(ctx *context.Context) { | |
|
||
pager := context.NewPagination(int(total), opts.PageSize, opts.Page, 5) | ||
pager.SetDefaultParams(ctx) | ||
pager.AddParamString("workflow", workflow) | ||
pager.AddParamString("workflow", workflowID) | ||
pager.AddParamString("actor", fmt.Sprint(actorID)) | ||
pager.AddParamString("status", fmt.Sprint(status)) | ||
ctx.Data["Page"] = pager | ||
|
Uh oh!
There was an error while loading. Please reload this page.