Skip to content

Commit ad47d82

Browse files
Support for Workflow Summary (#143)
* Write to workflow summary * Write to workflow summary - only body * Add choice type * Print comment-type * Run build * Adding commentType validation * Code cleanup * Adapt tests * Adding more tests * Adding tests for validation * Support for workflow summary (#89) * Add summary_mode * Token is not necessary for workflow summary * Add summary_mode in action.ts * Update description for comment-type field --------- Co-authored-by: thsaravana <[email protected]> --------- Co-authored-by: YiJhen Lin <[email protected]>
1 parent 62da025 commit ad47d82

19 files changed

+559
-109
lines changed

__tests__/action.test.ts

Lines changed: 67 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable @typescript-eslint/ban-ts-comment */
2+
// @ts-nocheck
13
import * as action from '../src/action'
24
import * as core from '@actions/core'
35
import * as github from '@actions/github'
@@ -6,6 +8,19 @@ jest.mock('@actions/core')
68
jest.mock('@actions/github')
79

810
describe('Input validation', function () {
11+
const eventName = 'pull_request'
12+
const payload = {
13+
pull_request: {
14+
number: '45',
15+
base: {
16+
sha: 'guasft7asdtf78asfd87as6df7y2u3',
17+
},
18+
head: {
19+
sha: 'aahsdflais76dfa78wrglghjkaghkj',
20+
},
21+
},
22+
}
23+
924
function getInput(key: string): string | undefined {
1025
switch (key) {
1126
case 'paths':
@@ -19,47 +34,44 @@ describe('Input validation', function () {
1934
const listComments = jest.fn()
2035
const updateComment = jest.fn()
2136

22-
/* eslint-disable @typescript-eslint/ban-ts-comment */
23-
// @ts-ignore
2437
core.getInput = jest.fn(getInput)
25-
// @ts-ignore
2638
github.getOctokit = jest.fn(() => {
2739
return {
28-
repos: {
29-
compareCommits: jest.fn(() => {
30-
return {
31-
data: {
32-
files: [
33-
{
34-
filename: 'src/main/kotlin/com/madrapps/jacoco/Math.kt',
35-
blob_url:
36-
'https://github.com/thsaravana/jacoco-playground/blob/77b14eb61efcd211ee93a7d8bac80cf292d207cc/src/main/kotlin/com/madrapps/jacoco/Math.kt',
37-
},
38-
{
39-
filename:
40-
'src/main/java/com/madrapps/jacoco/operation/StringOp.java',
41-
blob_url:
42-
'https://github.com/thsaravana/jacoco-playground/blob/77b14eb61efcd211ee93a7d8bac80cf292d207cc/src/main/java/com/madrapps/jacoco/operation/StringOp.java',
43-
},
44-
],
45-
},
46-
}
47-
}),
48-
},
49-
issues: {
50-
createComment,
51-
listComments,
52-
updateComment,
40+
rest: {
41+
repos: {
42+
compareCommits: jest.fn(() => {
43+
return {
44+
data: {
45+
files: [
46+
{
47+
filename: 'src/main/kotlin/com/madrapps/jacoco/Math.kt',
48+
blob_url:
49+
'https://github.com/thsaravana/jacoco-playground/blob/77b14eb61efcd211ee93a7d8bac80cf292d207cc/src/main/kotlin/com/madrapps/jacoco/Math.kt',
50+
},
51+
{
52+
filename:
53+
'src/main/java/com/madrapps/jacoco/operation/StringOp.java',
54+
blob_url:
55+
'https://github.com/thsaravana/jacoco-playground/blob/77b14eb61efcd211ee93a7d8bac80cf292d207cc/src/main/java/com/madrapps/jacoco/operation/StringOp.java',
56+
},
57+
],
58+
},
59+
}
60+
}),
61+
},
62+
issues: {
63+
createComment,
64+
listComments,
65+
updateComment,
66+
},
5367
},
5468
}
5569
})
56-
// @ts-ignore
5770
core.setFailed = jest.fn(c => {
5871
fail(c)
5972
})
6073

6174
it('Fail if paths is not present', async () => {
62-
// @ts-ignore
6375
core.getInput = jest.fn(c => {
6476
switch (c) {
6577
case 'paths':
@@ -70,15 +82,13 @@ describe('Input validation', function () {
7082
})
7183
github.context.eventName = 'pull_request'
7284

73-
// @ts-ignore
7485
core.setFailed = jest.fn(c => {
7586
expect(c).toEqual("'paths' is missing")
7687
})
7788
await action.action()
7889
})
7990

8091
it('Fail if token is not present', async () => {
81-
// @ts-ignore
8292
core.getInput = jest.fn(c => {
8393
switch (c) {
8494
case 'token':
@@ -88,10 +98,34 @@ describe('Input validation', function () {
8898
}
8999
})
90100
github.context.eventName = 'pull_request'
91-
// @ts-ignore
92101
core.setFailed = jest.fn(c => {
93102
expect(c).toEqual("'token' is missing")
94103
})
95104
await action.action()
96105
})
106+
107+
it('Fail if comment-type is invalid', async () => {
108+
core.getInput = jest.fn(c => {
109+
switch (c) {
110+
case 'comment-type':
111+
return 'invalid'
112+
default:
113+
return getInput(c)
114+
}
115+
})
116+
core.setFailed = jest.fn(c => {
117+
expect(c).toEqual("'comment-type' invalid is invalid")
118+
})
119+
initContext(eventName, payload)
120+
121+
await action.action()
122+
})
97123
})
124+
125+
function initContext(eventName, payload): void {
126+
const context = github.context
127+
context.eventName = eventName
128+
context.payload = payload
129+
context.repo = 'jacoco-playground'
130+
context.owner = 'madrapps'
131+
}

__tests__/action_aggregate.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ describe('Aggregate report', function () {
2020
return './__tests__/__fixtures__/aggregate-report.xml'
2121
case 'token':
2222
return 'SMPLEHDjasdf876a987'
23+
case 'comment-type':
24+
return 'pr_comment'
2325
case 'min-coverage-overall':
2426
return 45
2527
case 'min-coverage-changed-files':

__tests__/action_empty_aggregate.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ describe('Aggregate Empty report', function () {
2020
return './__tests__/__fixtures__/empty-aggregate-report.xml'
2121
case 'token':
2222
return 'SMPLEHDjasdf876a987'
23+
case 'comment-type':
24+
return 'pr_comment'
2325
case 'min-coverage-overall':
2426
return 45
2527
case 'min-coverage-changed-files':

__tests__/action_empty_multiple.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ describe('Multiple Empty reports', function () {
5757
return './__tests__/__fixtures__/empty_multi_module/empty-appCoverage.xml,./__tests__/__fixtures__/multi_module/mathCoverage.xml,./__tests__/__fixtures__/empty_multi_module/empty-textCoverage.xml'
5858
case 'token':
5959
return 'SMPLEHDjasdf876a987'
60+
case 'comment-type':
61+
return 'pr_comment'
6062
case 'min-coverage-overall':
6163
return 45
6264
case 'min-coverage-changed-files':

__tests__/action_empty_report.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ describe('Single Empty report', function () {
2020
return './__tests__/__fixtures__/empty-report.xml'
2121
case 'token':
2222
return 'SMPLEHDjasdf876a987'
23+
case 'comment-type':
24+
return 'pr_comment'
2325
case 'min-coverage-overall':
2426
return 45
2527
case 'min-coverage-changed-files':

__tests__/action_multiple.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ describe('Multiple reports', function () {
5757
return './__tests__/__fixtures__/multi_module/appCoverage.xml,./__tests__/__fixtures__/multi_module/mathCoverage.xml,./__tests__/__fixtures__/multi_module/textCoverage.xml'
5858
case 'token':
5959
return 'SMPLEHDjasdf876a987'
60+
case 'comment-type':
61+
return 'pr_comment'
6062
case 'min-coverage-overall':
6163
return 45
6264
case 'min-coverage-changed-files':

0 commit comments

Comments
 (0)