Skip to content

Commit

Permalink
feat: Adds a link to the workflow run in the report (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
davelosert committed Jun 17, 2023
1 parent 27ac8fe commit 78069b4
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { generateSummaryTableHtml } from './generateSummaryTableHtml.js';
import { parseVitestJsonFinal, parseVitestJsonSummary } from './parseJsonReports.js';
import { writeSummaryToPR } from './writeSummaryToPR.js';
import * as core from '@actions/core';
import * as github from '@actions/github';
import { RequestError } from '@octokit/request-error'
import { generateFileCoverageHtml } from './generateFileCoverageHtml.js';
import { getPullChanges } from './getPullChanges.js';
Expand Down Expand Up @@ -35,8 +36,11 @@ const run = async () => {
summary.addDetails('File Coverage', fileTable)
}

summary
.addRaw(`<em>Generated in workflow <a href=${getWorkflowSummaryURL()}>#${github.context.runNumber}</a></em>`)

try {
await writeSummaryToPR({
await writeSummaryToPR({
summary,
markerPostfix: getMarkerPostfix({ name, workingDirectory })
});
Expand All @@ -47,7 +51,7 @@ const run = async () => {
Original Error was: [${error.name}] - ${error.message}
`
)

} else {
// Rethrow to handle it in the catch block of the run()-call.
throw error;
Expand All @@ -58,11 +62,17 @@ const run = async () => {
};

function getMarkerPostfix({ name, workingDirectory }: { name: string, workingDirectory: string }) {
if(name) return name;
if(workingDirectory !== './') return workingDirectory;
if (name) return name;
if (workingDirectory !== './') return workingDirectory;
return 'root'
}

function getWorkflowSummaryURL() {
const { owner, repo } = github.context.repo;
const { runId } = github.context;
return `${github.context.serverUrl}/${owner}/${repo}/actions/runs/${runId}`
}


run().then(() => {
core.info('Report generated successfully.');
Expand Down

0 comments on commit 78069b4

Please sign in to comment.