Skip to content

Commit 39f7ac7

Browse files
authored
Merge pull request #89 from dorny/fix-suite-links
Use full URL to link test suites
2 parents f486461 + 4c2f9f3 commit 39f7ac7

File tree

4 files changed

+47
-21
lines changed

4 files changed

+47
-21
lines changed

dist/index.js

+22-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

+17-5
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,22 @@ class TestReporter {
146146
results.push(tr)
147147
}
148148

149+
core.info(`Creating check run ${name}`)
150+
const createResp = await this.octokit.checks.create({
151+
head_sha: this.context.sha,
152+
name,
153+
status: 'in_progress',
154+
output: {
155+
title: name,
156+
summary: ''
157+
},
158+
...github.context.repo
159+
})
160+
149161
core.info('Creating report summary')
150162
const {listSuites, listTests} = this
151-
const summary = getReport(results, {listSuites, listTests})
163+
const baseUrl = createResp.data.html_url
164+
const summary = getReport(results, {listSuites, listTests, baseUrl})
152165

153166
core.info('Creating annotations')
154167
const annotations = getAnnotations(results, this.maxAnnotations)
@@ -157,10 +170,9 @@ class TestReporter {
157170
const conclusion = isFailed ? 'failure' : 'success'
158171
const icon = isFailed ? Icon.fail : Icon.success
159172

160-
core.info(`Creating check run with conclusion ${conclusion}`)
161-
const resp = await this.octokit.checks.create({
162-
head_sha: this.context.sha,
163-
name,
173+
core.info(`Updating check run conclusion (${conclusion}) and output`)
174+
const resp = await this.octokit.checks.update({
175+
check_run_id: createResp.data.id,
164176
conclusion,
165177
status: 'completed',
166178
output: {

src/report/get-report.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ const MAX_REPORT_LENGTH = 65535
99
export interface ReportOptions {
1010
listSuites: 'all' | 'failed'
1111
listTests: 'all' | 'failed' | 'none'
12+
baseUrl: string
1213
}
1314

1415
const defaultOptions: ReportOptions = {
1516
listSuites: 'all',
16-
listTests: 'all'
17+
listTests: 'all',
18+
baseUrl: ''
1719
}
1820

1921
export function getReport(results: TestRunResult[], options: ReportOptions = defaultOptions): string {
@@ -134,7 +136,7 @@ function getTestRunsReport(testRuns: TestRunResult[], options: ReportOptions): s
134136
const tableData = testRuns.map((tr, runIndex) => {
135137
const time = formatTime(tr.time)
136138
const name = tr.path
137-
const addr = makeRunSlug(runIndex).link
139+
const addr = options.baseUrl + makeRunSlug(runIndex).link
138140
const nameLink = link(name, addr)
139141
const passed = tr.passed > 0 ? `${tr.passed}${Icon.success}` : ''
140142
const failed = tr.failed > 0 ? `${tr.failed}${Icon.fail}` : ''
@@ -159,7 +161,7 @@ function getSuitesReport(tr: TestRunResult, runIndex: number, options: ReportOpt
159161
const sections: string[] = []
160162

161163
const trSlug = makeRunSlug(runIndex)
162-
const nameLink = `<a id="${trSlug.id}" href="${trSlug.link}">${tr.path}</a>`
164+
const nameLink = `<a id="${trSlug.id}" href="${options.baseUrl + trSlug.link}">${tr.path}</a>`
163165
const icon = getResultIcon(tr.result)
164166
sections.push(`## ${icon}\xa0${nameLink}`)
165167

@@ -179,7 +181,7 @@ function getSuitesReport(tr: TestRunResult, runIndex: number, options: ReportOpt
179181
const tsTime = formatTime(s.time)
180182
const tsName = s.name
181183
const skipLink = options.listTests === 'none' || (options.listTests === 'failed' && s.result !== 'failed')
182-
const tsAddr = makeSuiteSlug(runIndex, suiteIndex).link
184+
const tsAddr = options.baseUrl + makeSuiteSlug(runIndex, suiteIndex).link
183185
const tsNameLink = skipLink ? tsName : link(tsName, tsAddr)
184186
const passed = s.passed > 0 ? `${s.passed}${Icon.success}` : ''
185187
const failed = s.failed > 0 ? `${s.failed}${Icon.fail}` : ''
@@ -214,7 +216,7 @@ function getTestsReport(ts: TestSuiteResult, runIndex: number, suiteIndex: numbe
214216

215217
const tsName = ts.name
216218
const tsSlug = makeSuiteSlug(runIndex, suiteIndex)
217-
const tsNameLink = `<a id="${tsSlug.id}" href="${tsSlug.link}">${tsName}</a>`
219+
const tsNameLink = `<a id="${tsSlug.id}" href="${options.baseUrl + tsSlug.link}">${tsName}</a>`
218220
const icon = getResultIcon(ts.result)
219221
sections.push(`### ${icon}\xa0${tsNameLink}`)
220222

0 commit comments

Comments
 (0)