0
0
mirror of https://github.com/go-gitea/gitea.git synced 2025-06-07 01:03:03 +02:00

Merge branch 'main' into fix-file-view-css

This commit is contained in:
wxiaoguang 2025-05-28 21:41:31 +08:00 committed by GitHub
commit 3374c48221
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 47 additions and 28 deletions

View File

@ -43,21 +43,23 @@ func IsWorkflow(path string) bool {
return strings.HasPrefix(path, ".gitea/workflows") || strings.HasPrefix(path, ".github/workflows") return strings.HasPrefix(path, ".gitea/workflows") || strings.HasPrefix(path, ".github/workflows")
} }
func ListWorkflows(commit *git.Commit) (git.Entries, error) { func ListWorkflows(commit *git.Commit) (string, git.Entries, error) {
tree, err := commit.SubTree(".gitea/workflows") rpath := ".gitea/workflows"
tree, err := commit.SubTree(rpath)
if _, ok := err.(git.ErrNotExist); ok { if _, ok := err.(git.ErrNotExist); ok {
tree, err = commit.SubTree(".github/workflows") rpath = ".github/workflows"
tree, err = commit.SubTree(rpath)
} }
if _, ok := err.(git.ErrNotExist); ok { if _, ok := err.(git.ErrNotExist); ok {
return nil, nil return "", nil, nil
} }
if err != nil { if err != nil {
return nil, err return "", nil, err
} }
entries, err := tree.ListEntriesRecursiveFast() entries, err := tree.ListEntriesRecursiveFast()
if err != nil { if err != nil {
return nil, err return "", nil, err
} }
ret := make(git.Entries, 0, len(entries)) ret := make(git.Entries, 0, len(entries))
@ -66,7 +68,7 @@ func ListWorkflows(commit *git.Commit) (git.Entries, error) {
ret = append(ret, entry) ret = append(ret, entry)
} }
} }
return ret, nil return rpath, ret, nil
} }
func GetContentFromEntry(entry *git.TreeEntry) ([]byte, error) { func GetContentFromEntry(entry *git.TreeEntry) ([]byte, error) {
@ -102,7 +104,7 @@ func DetectWorkflows(
payload api.Payloader, payload api.Payloader,
detectSchedule bool, detectSchedule bool,
) ([]*DetectedWorkflow, []*DetectedWorkflow, error) { ) ([]*DetectedWorkflow, []*DetectedWorkflow, error) {
entries, err := ListWorkflows(commit) _, entries, err := ListWorkflows(commit)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -147,7 +149,7 @@ func DetectWorkflows(
} }
func DetectScheduledWorkflows(gitRepo *git.Repository, commit *git.Commit) ([]*DetectedWorkflow, error) { func DetectScheduledWorkflows(gitRepo *git.Repository, commit *git.Commit) ([]*DetectedWorkflow, error) {
entries, err := ListWorkflows(commit) _, entries, err := ListWorkflows(commit)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -3815,6 +3815,7 @@ runs.expire_log_message = Logs have been purged because they were too old.
runs.delete = Delete workflow run runs.delete = Delete workflow run
runs.delete.description = Are you sure you want to permanently delete this workflow run? This action cannot be undone. runs.delete.description = Are you sure you want to permanently delete this workflow run? This action cannot be undone.
runs.not_done = This workflow run is not done. runs.not_done = This workflow run is not done.
runs.view_workflow_file = View workflow file
workflow.disable = Disable Workflow workflow.disable = Disable Workflow
workflow.disable_success = Workflow '%s' disabled successfully. workflow.disable_success = Workflow '%s' disabled successfully.

View File

@ -126,7 +126,7 @@ func prepareWorkflowDispatchTemplate(ctx *context.Context, commit *git.Commit) (
var curWorkflow *model.Workflow var curWorkflow *model.Workflow
entries, err := actions.ListWorkflows(commit) _, entries, err := actions.ListWorkflows(commit)
if err != nil { if err != nil {
ctx.ServerError("ListWorkflows", err) ctx.ServerError("ListWorkflows", err)
return nil return nil

View File

@ -64,6 +64,36 @@ func View(ctx *context_module.Context) {
ctx.HTML(http.StatusOK, tplViewActions) ctx.HTML(http.StatusOK, tplViewActions)
} }
func ViewWorkflowFile(ctx *context_module.Context) {
runIndex := getRunIndex(ctx)
run, err := actions_model.GetRunByIndex(ctx, ctx.Repo.Repository.ID, runIndex)
if err != nil {
ctx.NotFoundOrServerError("GetRunByIndex", func(err error) bool {
return errors.Is(err, util.ErrNotExist)
}, err)
return
}
commit, err := ctx.Repo.GitRepo.GetCommit(run.CommitSHA)
if err != nil {
ctx.NotFoundOrServerError("GetCommit", func(err error) bool {
return errors.Is(err, util.ErrNotExist)
}, err)
return
}
rpath, entries, err := actions.ListWorkflows(commit)
if err != nil {
ctx.ServerError("ListWorkflows", err)
return
}
for _, entry := range entries {
if entry.Name() == run.WorkflowID {
ctx.Redirect(fmt.Sprintf("%s/src/commit/%s/%s/%s", ctx.Repo.RepoLink, url.PathEscape(run.CommitSHA), util.PathEscapeSegments(rpath), util.PathEscapeSegments(run.WorkflowID)))
return
}
}
ctx.NotFound(nil)
}
type LogCursor struct { type LogCursor struct {
Step int `json:"step"` Step int `json:"step"`
Cursor int64 `json:"cursor"` Cursor int64 `json:"cursor"`

View File

@ -1445,6 +1445,7 @@ func registerWebRoutes(m *web.Router) {
m.Post("/rerun", reqRepoActionsWriter, actions.Rerun) m.Post("/rerun", reqRepoActionsWriter, actions.Rerun)
m.Get("/logs", actions.Logs) m.Get("/logs", actions.Logs)
}) })
m.Get("/workflow", actions.ViewWorkflowFile)
m.Post("/cancel", reqRepoActionsWriter, actions.Cancel) m.Post("/cancel", reqRepoActionsWriter, actions.Cancel)
m.Post("/approve", reqRepoActionsWriter, actions.Approve) m.Post("/approve", reqRepoActionsWriter, actions.Approve)
m.Post("/delete", reqRepoActionsWriter, actions.Delete) m.Post("/delete", reqRepoActionsWriter, actions.Delete)

View File

@ -31,16 +31,6 @@ import (
"github.com/nektos/act/pkg/model" "github.com/nektos/act/pkg/model"
) )
func getActionWorkflowPath(commit *git.Commit) string {
paths := []string{".gitea/workflows", ".github/workflows"}
for _, treePath := range paths {
if _, err := commit.SubTree(treePath); err == nil {
return treePath
}
}
return ""
}
func getActionWorkflowEntry(ctx *context.APIContext, commit *git.Commit, folder string, entry *git.TreeEntry) *api.ActionWorkflow { func getActionWorkflowEntry(ctx *context.APIContext, commit *git.Commit, folder string, entry *git.TreeEntry) *api.ActionWorkflow {
cfgUnit := ctx.Repo.Repository.MustGetUnit(ctx, unit.TypeActions) cfgUnit := ctx.Repo.Repository.MustGetUnit(ctx, unit.TypeActions)
cfg := cfgUnit.ActionsConfig() cfg := cfgUnit.ActionsConfig()
@ -109,14 +99,12 @@ func ListActionWorkflows(ctx *context.APIContext) ([]*api.ActionWorkflow, error)
return nil, err return nil, err
} }
entries, err := actions.ListWorkflows(defaultBranchCommit) folder, entries, err := actions.ListWorkflows(defaultBranchCommit)
if err != nil { if err != nil {
ctx.APIError(http.StatusNotFound, err.Error()) ctx.APIError(http.StatusNotFound, err.Error())
return nil, err return nil, err
} }
folder := getActionWorkflowPath(defaultBranchCommit)
workflows := make([]*api.ActionWorkflow, len(entries)) workflows := make([]*api.ActionWorkflow, len(entries))
for i, entry := range entries { for i, entry := range entries {
workflows[i] = getActionWorkflowEntry(ctx, defaultBranchCommit, folder, entry) workflows[i] = getActionWorkflowEntry(ctx, defaultBranchCommit, folder, entry)
@ -185,7 +173,7 @@ func DispatchActionWorkflow(ctx reqctx.RequestContext, doer *user_model.User, re
} }
// get workflow entry from runTargetCommit // get workflow entry from runTargetCommit
entries, err := actions.ListWorkflows(runTargetCommit) _, entries, err := actions.ListWorkflows(runTargetCommit)
if err != nil { if err != nil {
return err return err
} }

View File

@ -39,10 +39,7 @@
<div class="ui dropdown jump tw-p-2"> <div class="ui dropdown jump tw-p-2">
{{svg "octicon-kebab-horizontal"}} {{svg "octicon-kebab-horizontal"}}
<div class="menu flex-items-menu"> <div class="menu flex-items-menu">
<!-- TODO: This redundant link should be replaced by something else in future, <a class="item" href="{{$run.Link}}/workflow">{{svg "octicon-play"}}{{ctx.Locale.Tr "actions.runs.view_workflow_file"}}</a>
because have not figured out how to add "View Workflow" or anything similar to GitHub.
Related: https://github.com/go-gitea/gitea/pull/34530 -->
<a class="item" href="{{$run.Link}}">{{svg "octicon-play"}}{{ctx.Locale.Tr "view"}}</a>
{{if and $.AllowDeleteWorkflowRuns $run.Status.IsDone}} {{if and $.AllowDeleteWorkflowRuns $run.Status.IsDone}}
<a class="item link-action" <a class="item link-action"
data-url="{{$run.Link}}/delete" data-url="{{$run.Link}}/delete"