Skip to content

Commit 68c3070

Browse files
committed
fix jest exit code issue
1 parent 82ee1b4 commit 68c3070

File tree

4 files changed

+28
-25
lines changed

4 files changed

+28
-25
lines changed

__test__/command-helper.unit.test.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ describe('command-helper tests', () => {
153153
dispatch_type: 'repository'
154154
}
155155
]
156-
expect(configIsValid(config)).toBeTruthy()
156+
expect(configIsValid(config)).toEqual(null)
157157
})
158158

159159
test('invalid permission level in config', async () => {
@@ -169,7 +169,9 @@ describe('command-helper tests', () => {
169169
dispatch_type: 'repository'
170170
}
171171
]
172-
expect(configIsValid(config)).toBeFalsy()
172+
expect(configIsValid(config)).toEqual(
173+
`'test-case-invalid-permission' is not a valid 'permission'.`
174+
)
173175
})
174176

175177
test('invalid issue type in config', async () => {
@@ -185,23 +187,27 @@ describe('command-helper tests', () => {
185187
dispatch_type: 'repository'
186188
}
187189
]
188-
expect(configIsValid(config)).toBeFalsy()
190+
expect(configIsValid(config)).toEqual(
191+
`'test-case-invalid-issue-type' is not a valid 'issue-type'.`
192+
)
189193
})
190194

191195
test('invalid dispatch type in config', async () => {
192196
const config: Command[] = [
193197
{
194198
command: 'test',
195199
permission: 'write',
196-
issue_type: 'test-case-invalid-issue-type',
200+
issue_type: 'both',
197201
allow_edits: false,
198202
repository: 'peter-evans/slash-command-dispatch',
199203
event_type_suffix: '-command',
200204
static_args: [],
201205
dispatch_type: 'test-case-invalid-dispatch-type'
202206
}
203207
]
204-
expect(configIsValid(config)).toBeFalsy()
208+
expect(configIsValid(config)).toEqual(
209+
`'test-case-invalid-dispatch-type' is not a valid 'dispatch-type'.`
210+
)
205211
})
206212

207213
test('actor does not have permission', async () => {

dist/index.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,19 +147,16 @@ exports.getCommandsConfigFromJson = getCommandsConfigFromJson;
147147
function configIsValid(config) {
148148
for (const command of config) {
149149
if (!['none', 'read', 'triage', 'write', 'maintain', 'admin'].includes(command.permission)) {
150-
core.setFailed(`'${command.permission}' is not a valid 'permission'.`);
151-
return false;
150+
return `'${command.permission}' is not a valid 'permission'.`;
152151
}
153152
if (!['issue', 'pull-request', 'both'].includes(command.issue_type)) {
154-
core.setFailed(`'${command.issue_type}' is not a valid 'issue-type'.`);
155-
return false;
153+
return `'${command.issue_type}' is not a valid 'issue-type'.`;
156154
}
157155
if (!['repository', 'workflow'].includes(command.dispatch_type)) {
158-
core.setFailed(`'${command.dispatch_type}' is not a valid 'dispatch-type'.`);
159-
return false;
156+
return `'${command.dispatch_type}' is not a valid 'dispatch-type'.`;
160157
}
161158
}
162-
return true;
159+
return null;
163160
}
164161
exports.configIsValid = configIsValid;
165162
function actorHasPermission(actorPermission, commandPermission) {
@@ -454,8 +451,10 @@ function run() {
454451
const config = (0, command_helper_1.getCommandsConfig)(inputs);
455452
core.debug(`Commands config: ${(0, util_1.inspect)(config)}`);
456453
// Check the config is valid
457-
if (!(0, command_helper_1.configIsValid)(config))
458-
return;
454+
const configError = (0, command_helper_1.configIsValid)(config);
455+
if (configError) {
456+
throw new Error(configError);
457+
}
459458
// Get the comment body and id
460459
const commentBody = github.context.payload.comment.body;
461460
const commentId = github.context.payload.comment.id;

src/command-helper.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,28 +155,23 @@ export function getCommandsConfigFromJson(json: string): Command[] {
155155
return config
156156
}
157157

158-
export function configIsValid(config: Command[]): boolean {
158+
export function configIsValid(config: Command[]): string | null {
159159
for (const command of config) {
160160
if (
161161
!['none', 'read', 'triage', 'write', 'maintain', 'admin'].includes(
162162
command.permission
163163
)
164164
) {
165-
core.setFailed(`'${command.permission}' is not a valid 'permission'.`)
166-
return false
165+
return `'${command.permission}' is not a valid 'permission'.`
167166
}
168167
if (!['issue', 'pull-request', 'both'].includes(command.issue_type)) {
169-
core.setFailed(`'${command.issue_type}' is not a valid 'issue-type'.`)
170-
return false
168+
return `'${command.issue_type}' is not a valid 'issue-type'.`
171169
}
172170
if (!['repository', 'workflow'].includes(command.dispatch_type)) {
173-
core.setFailed(
174-
`'${command.dispatch_type}' is not a valid 'dispatch-type'.`
175-
)
176-
return false
171+
return `'${command.dispatch_type}' is not a valid 'dispatch-type'.`
177172
}
178173
}
179-
return true
174+
return null
180175
}
181176

182177
export function actorHasPermission(

src/main.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ async function run(): Promise<void> {
4545
core.debug(`Commands config: ${inspect(config)}`)
4646

4747
// Check the config is valid
48-
if (!configIsValid(config)) return
48+
const configError = configIsValid(config)
49+
if (configError) {
50+
throw new Error(configError)
51+
}
4952

5053
// Get the comment body and id
5154
const commentBody: string = github.context.payload.comment.body

0 commit comments

Comments
 (0)