From 07a81a1d4f8eb49ac7858c6b748c2a39971a3df0 Mon Sep 17 00:00:00 2001 From: william-allspice Date: Thu, 22 Aug 2024 15:27:34 -0500 Subject: [PATCH 01/13] Add a link to show which workflow file was run --- modules/actions/workflows.go | 1 + modules/git/tree_entry.go | 21 ++++++++++++++ routers/web/repo/actions/view.go | 33 +++++++++++++++++++++ web_src/js/components/RepoActionView.vue | 37 ++++++++++++++++-------- 4 files changed, 80 insertions(+), 12 deletions(-) diff --git a/modules/actions/workflows.go b/modules/actions/workflows.go index 0d2b0dd9194d9..ae78d0abf874e 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 95131214872e6..0d22ff9053101 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 11199d69eb3b2..0ea18b5fbae1e 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 7adc29ad4148b..48c3504022e95 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() { -
-
+
+
+ Run details +
+ +
+
+
{{ locale.artifactsTitle }}
-
    -
  • - - {{ artifact.name }} + @@ -565,26 +578,26 @@ export function initRepositoryActionView() { } } -.job-artifacts-title { +.left-side-section-title { font-size: 18px; margin-top: 16px; padding: 16px 10px 0 20px; border-top: 1px solid var(--color-secondary); } -.job-artifacts-item { +.left-side-section-item { margin: 5px 0; padding: 6px; display: flex; justify-content: space-between; } -.job-artifacts-list { +.left-side-section-list { padding-left: 12px; list-style: none; } -.job-artifacts-icon { +.left-side-section-icon { padding-right: 3px; } From 360b64a7cea2879d284018337b480a20c32ba170 Mon Sep 17 00:00:00 2001 From: william-allspice Date: Thu, 22 Aug 2024 15:45:15 -0500 Subject: [PATCH 02/13] clean up --- modules/actions/workflows.go | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/actions/workflows.go b/modules/actions/workflows.go index ae78d0abf874e..0d2b0dd9194d9 100644 --- a/modules/actions/workflows.go +++ b/modules/actions/workflows.go @@ -66,7 +66,6 @@ func ListWorkflows(commit *git.Commit) (git.Entries, error) { ret = append(ret, entry) } } - return ret, nil } From c91396d56808293c85be71114258de11c7203895 Mon Sep 17 00:00:00 2001 From: william-allspice Date: Thu, 22 Aug 2024 15:51:53 -0500 Subject: [PATCH 03/13] Break early when found --- modules/git/tree_entry.go | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/git/tree_entry.go b/modules/git/tree_entry.go index 0d22ff9053101..327b7f39f663e 100644 --- a/modules/git/tree_entry.go +++ b/modules/git/tree_entry.go @@ -193,6 +193,7 @@ func (te *TreeEntry) GetPathInRepo() string { for _, entry := range current.ptree.entries { if entry.ID == current.ID { path = entry.name + "/" + path + break } } current = current.ptree From 5dbaf6ec6e0d33739ffc5cb2cf7375e4faa15d8c Mon Sep 17 00:00:00 2001 From: william-allspice Date: Thu, 22 Aug 2024 15:55:37 -0500 Subject: [PATCH 04/13] minor clean up --- routers/web/repo/actions/view.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/routers/web/repo/actions/view.go b/routers/web/repo/actions/view.go index 0ea18b5fbae1e..cadfc7f56d4ad 100644 --- a/routers/web/repo/actions/view.go +++ b/routers/web/repo/actions/view.go @@ -316,20 +316,25 @@ func getWorkflowFileLink(ctx *context_module.Context, run *actions_model.ActionR 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 + break } } - var workflowFilePath string - if workflowEntry != nil { - workflowFilePath = workflowEntry.GetPathInRepo() + + if workflowEntry == nil { + return "" } + + workflowFilePath := workflowEntry.GetPathInRepo() if workflowFilePath == "" { return "" } From d096c970b30bcaaeceb6d8c964601ead6d547046 Mon Sep 17 00:00:00 2001 From: william-allspice Date: Thu, 22 Aug 2024 21:35:56 -0500 Subject: [PATCH 05/13] add translations --- options/locale/locale_en-US.ini | 2 ++ templates/repo/actions/view.tmpl | 2 ++ web_src/js/components/RepoActionView.vue | 10 ++++++---- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 8d51864d3d12d..eecb0ab2ac4a0 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -3697,6 +3697,7 @@ runs.no_workflows.documentation = For more information on Gitea Actions, see
diff --git a/web_src/js/components/RepoActionView.vue b/web_src/js/components/RepoActionView.vue index 48c3504022e95..12affddf83e7d 100644 --- a/web_src/js/components/RepoActionView.vue +++ b/web_src/js/components/RepoActionView.vue @@ -351,10 +351,12 @@ export function initRepositoryActionView() { artifactsTitle: el.getAttribute('data-locale-artifacts-title'), areYouSure: el.getAttribute('data-locale-are-you-sure'), confirmDeleteArtifact: el.getAttribute('data-locale-confirm-delete-artifact'), + runDetails: el.getAttribute('data-locale-runs-details'), showTimeStamps: el.getAttribute('data-locale-show-timestamps'), showLogSeconds: el.getAttribute('data-locale-show-log-seconds'), showFullScreen: el.getAttribute('data-locale-show-full-screen'), downloadLogs: el.getAttribute('data-locale-download-logs'), + workflowFile: el.getAttribute('data-locale-workflow-file'), status: { unknown: el.getAttribute('data-locale-status-unknown'), waiting: el.getAttribute('data-locale-status-waiting'), @@ -422,14 +424,14 @@ export function initRepositoryActionView() {
-
+
- Run details + {{ locale.runDetails }}
From a53ff725fd68adebcb7c18c8569114fdca458c1b Mon Sep 17 00:00:00 2001 From: william-allspice Date: Thu, 22 Aug 2024 21:48:22 -0500 Subject: [PATCH 06/13] swap places --- web_src/js/components/RepoActionView.vue | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/web_src/js/components/RepoActionView.vue b/web_src/js/components/RepoActionView.vue index 12affddf83e7d..56634e5fe4e63 100644 --- a/web_src/js/components/RepoActionView.vue +++ b/web_src/js/components/RepoActionView.vue @@ -424,18 +424,6 @@ export function initRepositoryActionView() {
-
-
- {{ locale.runDetails }} -
- -
{{ locale.artifactsTitle }} @@ -451,6 +439,18 @@ export function initRepositoryActionView() {
+
+
+ {{ locale.runDetails }} +
+ +
From 907176fad02cd10d89dbb39390f083ae243d9d66 Mon Sep 17 00:00:00 2001 From: william-allspice Date: Fri, 23 Aug 2024 10:09:26 -0500 Subject: [PATCH 07/13] User Name method not property --- modules/git/tree_entry.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/git/tree_entry.go b/modules/git/tree_entry.go index 327b7f39f663e..1c11d04e1b831 100644 --- a/modules/git/tree_entry.go +++ b/modules/git/tree_entry.go @@ -186,13 +186,13 @@ func (te *TreeEntry) GetPathInRepo() string { return "" } - path := te.name + 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 + path = entry.Name() + "/" + path break } } From fb57043abfcd6aafbee87c066bd25d456c959f24 Mon Sep 17 00:00:00 2001 From: william-allspice Date: Fri, 23 Aug 2024 15:05:07 -0500 Subject: [PATCH 08/13] Use ListEntries --- modules/git/tree_entry.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/git/tree_entry.go b/modules/git/tree_entry.go index 1c11d04e1b831..94c550396f124 100644 --- a/modules/git/tree_entry.go +++ b/modules/git/tree_entry.go @@ -8,6 +8,8 @@ import ( "io" "sort" "strings" + + "code.gitea.io/gitea/modules/log" ) // Type returns the type of the entry (commit, tree, blob) @@ -190,7 +192,12 @@ func (te *TreeEntry) GetPathInRepo() string { current := te.ptree for current != nil && current.ptree != nil { - for _, entry := range current.ptree.entries { + entries, err := current.ptree.ListEntries() + if err != nil { + log.Error("Failed to climb git tree %v", err) + return "" + } + for _, entry := range entries { if entry.ID == current.ID { path = entry.Name() + "/" + path break From 96fdaa322d278c0cf0def9fe93fa93d990f1e6a2 Mon Sep 17 00:00:00 2001 From: william-allspice Date: Thu, 29 Aug 2024 11:50:53 -0500 Subject: [PATCH 09/13] add unit test case --- modules/git/tree_entry_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/modules/git/tree_entry_test.go b/modules/git/tree_entry_test.go index 30eee13669e43..901f67e2d6ad1 100644 --- a/modules/git/tree_entry_test.go +++ b/modules/git/tree_entry_test.go @@ -100,3 +100,30 @@ func TestFollowLink(t *testing.T) { _, err = target.FollowLink() assert.EqualError(t, err, "link_short: broken link") } + +func TestGetPathInRepo(t *testing.T) { + r, err := openRepositoryWithDefaultContext("tests/repos/repo1_bare") + assert.NoError(t, err) + defer r.Close() + + commit, err := r.GetCommit("37991dec2c8e592043f47155ce4808d4580f9123") + assert.NoError(t, err) + + // nested entry + entry, err := commit.Tree.GetTreeEntryByPath("foo/bar/link_to_hello") + assert.NoError(t, err) + path := entry.GetPathInRepo() + assert.Equal(t, "foo/bar/link_to_hello", path) + + // folder + entry, err = commit.Tree.GetTreeEntryByPath("foo/bar") + assert.NoError(t, err) + path = entry.GetPathInRepo() + assert.Equal(t, "foo/bar", path) + + // top level file + entry, err = commit.Tree.GetTreeEntryByPath("file2.txt") + assert.NoError(t, err) + path = entry.GetPathInRepo() + assert.Equal(t, "file2.txt", path) +} From 0807b6fa85d292c261bf1f0d8f37f24a59172282 Mon Sep 17 00:00:00 2001 From: william-allspice Date: Thu, 29 Aug 2024 12:47:14 -0500 Subject: [PATCH 10/13] Refactor gogit test into its own file --- modules/git/tree_entry_gogit_test.go | 55 ++++++++++++++++++++++++++++ modules/git/tree_entry_test.go | 45 ----------------------- 2 files changed, 55 insertions(+), 45 deletions(-) create mode 100644 modules/git/tree_entry_gogit_test.go diff --git a/modules/git/tree_entry_gogit_test.go b/modules/git/tree_entry_gogit_test.go new file mode 100644 index 0000000000000..9ca82675e0797 --- /dev/null +++ b/modules/git/tree_entry_gogit_test.go @@ -0,0 +1,55 @@ +// Copyright 2017 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +//go:build gogit + +package git + +import ( + "testing" + + "github.com/go-git/go-git/v5/plumbing/filemode" + "github.com/go-git/go-git/v5/plumbing/object" + "github.com/stretchr/testify/assert" +) + +func getTestEntries() Entries { + return Entries{ + &TreeEntry{gogitTreeEntry: &object.TreeEntry{Name: "v1.0", Mode: filemode.Dir}}, + &TreeEntry{gogitTreeEntry: &object.TreeEntry{Name: "v2.0", Mode: filemode.Dir}}, + &TreeEntry{gogitTreeEntry: &object.TreeEntry{Name: "v2.1", Mode: filemode.Dir}}, + &TreeEntry{gogitTreeEntry: &object.TreeEntry{Name: "v2.12", Mode: filemode.Dir}}, + &TreeEntry{gogitTreeEntry: &object.TreeEntry{Name: "v2.2", Mode: filemode.Dir}}, + &TreeEntry{gogitTreeEntry: &object.TreeEntry{Name: "v12.0", Mode: filemode.Dir}}, + &TreeEntry{gogitTreeEntry: &object.TreeEntry{Name: "abc", Mode: filemode.Regular}}, + &TreeEntry{gogitTreeEntry: &object.TreeEntry{Name: "bcd", Mode: filemode.Regular}}, + } +} + +func TestEntriesSort(t *testing.T) { + entries := getTestEntries() + entries.Sort() + assert.Equal(t, "v1.0", entries[0].Name()) + assert.Equal(t, "v12.0", entries[1].Name()) + assert.Equal(t, "v2.0", entries[2].Name()) + assert.Equal(t, "v2.1", entries[3].Name()) + assert.Equal(t, "v2.12", entries[4].Name()) + assert.Equal(t, "v2.2", entries[5].Name()) + assert.Equal(t, "abc", entries[6].Name()) + assert.Equal(t, "bcd", entries[7].Name()) +} + +func TestEntriesCustomSort(t *testing.T) { + entries := getTestEntries() + entries.CustomSort(func(s1, s2 string) bool { + return s1 > s2 + }) + assert.Equal(t, "v2.2", entries[0].Name()) + assert.Equal(t, "v2.12", entries[1].Name()) + assert.Equal(t, "v2.1", entries[2].Name()) + assert.Equal(t, "v2.0", entries[3].Name()) + assert.Equal(t, "v12.0", entries[4].Name()) + assert.Equal(t, "v1.0", entries[5].Name()) + assert.Equal(t, "bcd", entries[6].Name()) + assert.Equal(t, "abc", entries[7].Name()) +} diff --git a/modules/git/tree_entry_test.go b/modules/git/tree_entry_test.go index 901f67e2d6ad1..61afea59a243a 100644 --- a/modules/git/tree_entry_test.go +++ b/modules/git/tree_entry_test.go @@ -1,59 +1,14 @@ // Copyright 2017 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT -//go:build gogit - package git import ( "testing" - "github.com/go-git/go-git/v5/plumbing/filemode" - "github.com/go-git/go-git/v5/plumbing/object" "github.com/stretchr/testify/assert" ) -func getTestEntries() Entries { - return Entries{ - &TreeEntry{gogitTreeEntry: &object.TreeEntry{Name: "v1.0", Mode: filemode.Dir}}, - &TreeEntry{gogitTreeEntry: &object.TreeEntry{Name: "v2.0", Mode: filemode.Dir}}, - &TreeEntry{gogitTreeEntry: &object.TreeEntry{Name: "v2.1", Mode: filemode.Dir}}, - &TreeEntry{gogitTreeEntry: &object.TreeEntry{Name: "v2.12", Mode: filemode.Dir}}, - &TreeEntry{gogitTreeEntry: &object.TreeEntry{Name: "v2.2", Mode: filemode.Dir}}, - &TreeEntry{gogitTreeEntry: &object.TreeEntry{Name: "v12.0", Mode: filemode.Dir}}, - &TreeEntry{gogitTreeEntry: &object.TreeEntry{Name: "abc", Mode: filemode.Regular}}, - &TreeEntry{gogitTreeEntry: &object.TreeEntry{Name: "bcd", Mode: filemode.Regular}}, - } -} - -func TestEntriesSort(t *testing.T) { - entries := getTestEntries() - entries.Sort() - assert.Equal(t, "v1.0", entries[0].Name()) - assert.Equal(t, "v12.0", entries[1].Name()) - assert.Equal(t, "v2.0", entries[2].Name()) - assert.Equal(t, "v2.1", entries[3].Name()) - assert.Equal(t, "v2.12", entries[4].Name()) - assert.Equal(t, "v2.2", entries[5].Name()) - assert.Equal(t, "abc", entries[6].Name()) - assert.Equal(t, "bcd", entries[7].Name()) -} - -func TestEntriesCustomSort(t *testing.T) { - entries := getTestEntries() - entries.CustomSort(func(s1, s2 string) bool { - return s1 > s2 - }) - assert.Equal(t, "v2.2", entries[0].Name()) - assert.Equal(t, "v2.12", entries[1].Name()) - assert.Equal(t, "v2.1", entries[2].Name()) - assert.Equal(t, "v2.0", entries[3].Name()) - assert.Equal(t, "v12.0", entries[4].Name()) - assert.Equal(t, "v1.0", entries[5].Name()) - assert.Equal(t, "bcd", entries[6].Name()) - assert.Equal(t, "abc", entries[7].Name()) -} - func TestFollowLink(t *testing.T) { r, err := openRepositoryWithDefaultContext("tests/repos/repo1_bare") assert.NoError(t, err) From b1eadac8053b1bd8b5c1285284cca1d048c92c25 Mon Sep 17 00:00:00 2001 From: william-allspice Date: Fri, 30 Aug 2024 10:06:38 -0500 Subject: [PATCH 11/13] use string comparison --- modules/git/tree_entry.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/git/tree_entry.go b/modules/git/tree_entry.go index 94c550396f124..eb992ba538cb7 100644 --- a/modules/git/tree_entry.go +++ b/modules/git/tree_entry.go @@ -198,7 +198,7 @@ func (te *TreeEntry) GetPathInRepo() string { return "" } for _, entry := range entries { - if entry.ID == current.ID { + if entry.ID.String() == current.ID.String() { path = entry.Name() + "/" + path break } From c18e6b973e03e46298c5d680b0daf0676068b35d Mon Sep 17 00:00:00 2001 From: william-allspice Date: Tue, 3 Sep 2024 14:47:03 -0500 Subject: [PATCH 12/13] Refactor link logic to live in workflows module --- models/actions/run.go | 1 + modules/actions/workflows.go | 38 ++++++++++++++++++++++++++++++++ routers/web/repo/actions/view.go | 38 +------------------------------- 3 files changed, 40 insertions(+), 37 deletions(-) diff --git a/models/actions/run.go b/models/actions/run.go index 37064520a213a..aa3861c475477 100644 --- a/models/actions/run.go +++ b/models/actions/run.go @@ -74,6 +74,7 @@ func (run *ActionRun) Link() string { return fmt.Sprintf("%s/actions/runs/%d", run.Repo.Link(), run.Index) } +// WorkflowLink return the url to the actions list filtered for this runs workflow func (run *ActionRun) WorkflowLink() string { if run.Repo == nil { return "" diff --git a/modules/actions/workflows.go b/modules/actions/workflows.go index 0d2b0dd9194d9..ed8e60c6476dd 100644 --- a/modules/actions/workflows.go +++ b/modules/actions/workflows.go @@ -5,9 +5,11 @@ package actions import ( "bytes" + "fmt" "io" "strings" + actions_model "code.gitea.io/gitea/models/actions" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" api "code.gitea.io/gitea/modules/structs" @@ -69,6 +71,42 @@ func ListWorkflows(commit *git.Commit) (git.Entries, error) { return ret, nil } +// GetRunsWorkflowFileLink return url for the source of the workflow file for an ActionRun +func GetRunsWorkflowFileLink(run *actions_model.ActionRun, gitRepo *git.Repository) string { + if run.Repo == nil || run.CommitSHA == "" { + return "" + } + + commit, err := gitRepo.GetCommit(run.CommitSHA) + if err != nil { + return "" + } + + entries, err := ListWorkflows(commit) + if err != nil { + return "" + } + + var workflowEntry *git.TreeEntry + for _, entry := range entries { + if entry.Name() == run.WorkflowID { + workflowEntry = entry + break + } + } + + if workflowEntry == nil { + return "" + } + + workflowFilePath := workflowEntry.GetPathInRepo() + if workflowFilePath == "" { + return "" + } + + return fmt.Sprintf("%s/src/commit/%s/%s", run.Repo.Link(), run.CommitSHA, workflowFilePath) +} + func GetContentFromEntry(entry *git.TreeEntry) ([]byte, error) { f, err := entry.Blob().DataAsync() if err != nil { diff --git a/routers/web/repo/actions/view.go b/routers/web/repo/actions/view.go index cadfc7f56d4ad..c01648dd2d2e6 100644 --- a/routers/web/repo/actions/view.go +++ b/routers/web/repo/actions/view.go @@ -171,7 +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.WorkflowFileLink = actions.GetRunsWorkflowFileLink(run, ctx.Repo.GitRepo) resp.State.Run.WorkflowID = run.WorkflowID resp.State.Run.WorkflowLink = run.WorkflowLink() resp.State.Run.IsSchedule = run.IsSchedule() @@ -306,42 +306,6 @@ 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 - break - } - } - - if workflowEntry == nil { - return "" - } - - 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) { From 9ded4a77dcd898ddcd1c58d7719fe84ed4980f17 Mon Sep 17 00:00:00 2001 From: william-allspice Date: Wed, 4 Sep 2024 09:05:28 -0500 Subject: [PATCH 13/13] copy right year --- modules/git/tree_entry_gogit_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/git/tree_entry_gogit_test.go b/modules/git/tree_entry_gogit_test.go index 9ca82675e0797..b01a692b086e5 100644 --- a/modules/git/tree_entry_gogit_test.go +++ b/modules/git/tree_entry_gogit_test.go @@ -1,4 +1,4 @@ -// Copyright 2017 The Gitea Authors. All rights reserved. +// Copyright 2024 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT //go:build gogit