Add a link to show which workflow file was run

This commit is contained in:
william-allspice 2024-08-22 15:27:34 -05:00
parent e0c27e5996
commit a1b9f26dc4
4 changed files with 80 additions and 12 deletions

View File

@ -66,6 +66,7 @@ func ListWorkflows(commit *git.Commit) (git.Entries, error) {
ret = append(ret, entry)
}
}
return ret, nil
}

View File

@ -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
}

View File

@ -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) {

View File

@ -46,6 +46,7 @@ const sfc = {
done: false,
workflowID: '',
workflowLink: '',
workflowFileLink: '',
isSchedule: false,
jobs: [
// {
@ -421,17 +422,29 @@ export function initRepositoryActionView() {
</a>
</div>
</div>
<div class="job-artifacts" v-if="artifacts.length > 0">
<div class="job-artifacts-title">
<div class="left-side-section">
<div class="left-side-section-title">
Run details
</div>
<ul class="left-side-section-list">
<li class="left-side-section-item" v-for="artifact in artifacts" :key="artifact.name">
<a class="left-side-section-link" target="_blank" :href="run.workflowFileLink">
<SvgIcon name="octicon-file" class="ui text black left-side-section-icon"/>{{ run.workflowID }}
</a>
</li>
</ul>
</div>
<div class="left-side-section" v-if="artifacts.length > 0">
<div class="left-side-section-title">
{{ locale.artifactsTitle }}
</div>
<ul class="job-artifacts-list">
<li class="job-artifacts-item" v-for="artifact in artifacts" :key="artifact.name">
<a class="job-artifacts-link" target="_blank" :href="run.link+'/artifacts/'+artifact.name">
<SvgIcon name="octicon-file" class="ui text black job-artifacts-icon"/>{{ artifact.name }}
<ul class="left-side-section-list">
<li class="left-side-section-item" v-for="artifact in artifacts" :key="artifact.name">
<a class="left-side-section-link" target="_blank" :href="run.link+'/artifacts/'+artifact.name">
<SvgIcon name="octicon-file" class="ui text black left-side-section-icon"/>{{ artifact.name }}
</a>
<a v-if="run.canDeleteArtifact" @click="deleteArtifact(artifact.name)" class="job-artifacts-delete">
<SvgIcon name="octicon-trash" class="ui text black job-artifacts-icon"/>
<a v-if="run.canDeleteArtifact" @click="deleteArtifact(artifact.name)" class="left-side-section-delete">
<SvgIcon name="octicon-trash" class="ui text black left-side-section-icon"/>
</a>
</li>
</ul>
@ -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;
}