Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions __tests__/github/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ describe('createStatusCheck', () => {
const report: Report = {
results: {
summary: {
failed: 0
passed: 5,
skipped: 2
}
}
} as Report
Expand All @@ -139,7 +140,7 @@ describe('createStatusCheck', () => {
'Test Status',
'completed',
'success',
'Test Results',
'5 passed, 2 skipped',
'Test summary'
)
})
Expand Down Expand Up @@ -167,7 +168,7 @@ describe('createStatusCheck', () => {
'Test Status',
'completed',
'failure',
'Test Results',
'1 failed',
'Test summary'
)
})
Expand All @@ -184,6 +185,7 @@ describe('createStatusCheck', () => {
const report: Report = {
results: {
summary: {
passed: 10,
failed: 0
}
}
Expand All @@ -201,7 +203,7 @@ describe('createStatusCheck', () => {
'Test Status',
'completed',
'success',
'Test Results',
'10 passed',
expect.stringMatching(/^a{65000}$/)
)
})
Expand Down
40 changes: 39 additions & 1 deletion src/github/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,42 @@ async function postOrUpdateIssueComment(
}
}

/**
* Formats the test summary into a string like "10 passed, 1 failed, 2 skipped".
* @param summary - The test summary object
* @returns Formatted summary string
*/
function formatTestSummary(summary: { passed: number; failed: number; skipped: number; pending: number; other: number }): string {
const parts: string[] = []

if (summary.passed > 0) {
parts.push(`${summary.passed} passed`)
}

if (summary.failed > 0) {
parts.push(`${summary.failed} failed`)
}

if (summary.skipped > 0) {
parts.push(`${summary.skipped} skipped`)
}

if (summary.pending > 0) {
parts.push(`${summary.pending} pending`)
}

if (summary.other > 0) {
parts.push(`${summary.other} other`)
}

if (parts.length === 0) {
return 'No tests'
}

return parts.join(', ')
}


/**
* Creates a status check for a action.
*
Expand All @@ -285,14 +321,16 @@ export async function createStatusCheck(
}

try {
const formattedSummary = formatTestSummary(report.results.summary)

await createCheckRun(
context.repo.owner,
context.repo.repo,
context.sha,
inputs.statusCheckName,
'completed',
report.results.summary.failed > 0 ? 'failure' : 'success',
'Test Results',
formattedSummary,
summary
)
} catch (error) {
Expand Down
Loading