diff --git a/modules/actions/workflows.go b/modules/actions/workflows.go index 0d2b0dd919..ae78d0abf8 100644 --- a/modules/actions/workflows.go +++ b/modules/actions/workflows.go @@ -66,6 +66,7 @@ func ListWorkflows(commit *git.Commit) (git.Entries, error) { ret = append(ret, entry) } } + return ret, nil } diff --git a/modules/git/tree_entry.go b/modules/git/tree_entry.go index 9513121487..0d22ff9053 100644 --- a/modules/git/tree_entry.go +++ b/modules/git/tree_entry.go @@ -179,3 +179,24 @@ func (tes Entries) Sort() { func (tes Entries) CustomSort(cmp func(s1, s2 string) bool) { sort.Sort(customSortableEntries{cmp, tes}) } + +// GetPathInRepo returns the relative path in the tree to this entry +func (te *TreeEntry) GetPathInRepo() string { + if te == nil { + return "" + } + + path := te.name + current := te.ptree + + for current != nil && current.ptree != nil { + for _, entry := range current.ptree.entries { + if entry.ID == current.ID { + path = entry.name + "/" + path + } + } + current = current.ptree + } + + return path +} diff --git a/routers/web/repo/actions/view.go b/routers/web/repo/actions/view.go index 11199d69eb..0ea18b5fba 100644 --- a/routers/web/repo/actions/view.go +++ b/routers/web/repo/actions/view.go @@ -85,6 +85,7 @@ type ViewResponse struct { CanRerun bool `json:"canRerun"` CanDeleteArtifact bool `json:"canDeleteArtifact"` Done bool `json:"done"` + WorkflowFileLink string `json:"workflowFileLink"` WorkflowID string `json:"workflowID"` WorkflowLink string `json:"workflowLink"` IsSchedule bool `json:"isSchedule"` @@ -170,6 +171,7 @@ func ViewPost(ctx *context_module.Context) { resp.State.Run.CanRerun = run.Status.IsDone() && ctx.Repo.CanWrite(unit.TypeActions) resp.State.Run.CanDeleteArtifact = run.Status.IsDone() && ctx.Repo.CanWrite(unit.TypeActions) resp.State.Run.Done = run.Status.IsDone() + resp.State.Run.WorkflowFileLink = getWorkflowFileLink(ctx, run) resp.State.Run.WorkflowID = run.WorkflowID resp.State.Run.WorkflowLink = run.WorkflowLink() resp.State.Run.IsSchedule = run.IsSchedule() @@ -304,6 +306,37 @@ func ViewPost(ctx *context_module.Context) { ctx.JSON(http.StatusOK, resp) } +// getWorkflowFileLink return url for the source of the workflow file that was run +func getWorkflowFileLink(ctx *context_module.Context, run *actions_model.ActionRun) string { + if run.Repo == nil || run.CommitSHA == "" { + return "" + } + + commit, err := ctx.Repo.GitRepo.GetCommit(run.CommitSHA) + if err != nil { + return "" + } + entries, err := actions.ListWorkflows(commit) + if err != nil { + return "" + } + var workflowEntry *git.TreeEntry + for _, entry := range entries { + if entry.Name() == run.WorkflowID { + workflowEntry = entry + } + } + var workflowFilePath string + if workflowEntry != nil { + workflowFilePath = workflowEntry.GetPathInRepo() + } + if workflowFilePath == "" { + return "" + } + + return fmt.Sprintf("%s/src/commit/%s/%s", run.Repo.Link(), run.CommitSHA, workflowFilePath) +} + // Rerun will rerun jobs in the given run // If jobIndexStr is a blank string, it means rerun all jobs func Rerun(ctx *context_module.Context) { diff --git a/web_src/js/components/RepoActionView.vue b/web_src/js/components/RepoActionView.vue index 7adc29ad41..48c3504022 100644 --- a/web_src/js/components/RepoActionView.vue +++ b/web_src/js/components/RepoActionView.vue @@ -46,6 +46,7 @@ const sfc = { done: false, workflowID: '', workflowLink: '', + workflowFileLink: '', isSchedule: false, jobs: [ // { @@ -421,17 +422,29 @@ export function initRepositoryActionView() { -