Skip to content

Commit 7f05f6a

Browse files
committed
Leverage highlighting of actions
1 parent e9fdfc2 commit 7f05f6a

File tree

4 files changed

+49
-28
lines changed

4 files changed

+49
-28
lines changed

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
"never"
7575
],
7676
"@typescript-eslint/type-annotation-spacing": "error",
77-
"@typescript-eslint/unbound-method": "off"
77+
"@typescript-eslint/unbound-method": "error"
7878
},
7979
"env": {
8080
"node": true,

__tests__/main.test.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe('nexusphp/no-merge-commits main', () => {
4040
process.env['INPUT_TOKEN'] = ''
4141

4242
await expect(runner()).rejects.toThrowError('Input required and not supplied: token')
43-
assertWritten(['\x1B[37m[NOTICE] Collecting token from input...\x1B[0m'])
43+
assertWritten(['::notice::\x1B[37m[NOTICE] Collecting token from input...\x1B[0m'])
4444
})
4545

4646
it('fails when status code is not HTTP 200', async () => {
@@ -64,14 +64,14 @@ describe('nexusphp/no-merge-commits main', () => {
6464
await expect(runner()).rejects.toThrowError('Retrieving the commits of the pull request failed with HTTP 422 status code.')
6565

6666
assertWritten([
67-
'\x1B[37m[NOTICE] Collecting token from input...\x1B[0m',
67+
'::notice::\x1B[37m[NOTICE] Collecting token from input...\x1B[0m',
6868
'\x1B[32m[INFO] Token collected.\x1B[0m',
69-
'\x1B[37m[NOTICE] Instantiating an Octokit client using token...\x1B[0m',
69+
'::notice::\x1B[37m[NOTICE] Instantiating an Octokit client using token...\x1B[0m',
7070
'\x1B[32m[INFO] Octokit client is ready.\x1B[0m',
71-
'\x1B[37m[NOTICE] Looking up owner: me\x1B[0m',
72-
'\x1B[37m[NOTICE] Looking up repository: awesome\x1B[0m',
73-
'\x1B[37m[NOTICE] Looking up pull request number: 1\x1B[0m',
74-
'\x1B[37m[NOTICE] Retrieving commits of PR #1...\x1B[0m',
71+
'::debug::\x1B[37m[DEBUG] Looking up owner: me\x1B[0m',
72+
'::debug::\x1B[37m[DEBUG] Looking up repository: awesome\x1B[0m',
73+
'::debug::\x1B[37m[DEBUG] Looking up pull request number: 1\x1B[0m',
74+
'::notice::\x1B[37m[NOTICE] Retrieving commits of PR #1...\x1B[0m',
7575
])
7676
})
7777

@@ -108,16 +108,16 @@ describe('nexusphp/no-merge-commits main', () => {
108108
await expect(runner()).resolves.toBeUndefined()
109109

110110
assertWritten([
111-
'\x1B[37m[NOTICE] Collecting token from input...\x1B[0m',
111+
'::notice::\x1B[37m[NOTICE] Collecting token from input...\x1B[0m',
112112
'\x1B[32m[INFO] Token collected.\x1B[0m',
113-
'\x1B[37m[NOTICE] Instantiating an Octokit client using token...\x1B[0m',
113+
'::notice::\x1B[37m[NOTICE] Instantiating an Octokit client using token...\x1B[0m',
114114
'\x1B[32m[INFO] Octokit client is ready.\x1B[0m',
115-
'\x1B[37m[NOTICE] Looking up owner: me\x1B[0m',
116-
'\x1B[37m[NOTICE] Looking up repository: awesome\x1B[0m',
117-
'\x1B[37m[NOTICE] Looking up pull request number: 1\x1B[0m',
118-
'\x1B[37m[NOTICE] Retrieving commits of PR #1...\x1B[0m',
115+
'::debug::\x1B[37m[DEBUG] Looking up owner: me\x1B[0m',
116+
'::debug::\x1B[37m[DEBUG] Looking up repository: awesome\x1B[0m',
117+
'::debug::\x1B[37m[DEBUG] Looking up pull request number: 1\x1B[0m',
118+
'::notice::\x1B[37m[NOTICE] Retrieving commits of PR #1...\x1B[0m',
119119
'\x1B[32m[INFO] PR #1 contains 1 commit.\x1B[0m',
120-
'\x1B[37m[NOTICE] Inspecting commit SHA: 819a33b\x1B[0m',
120+
'::notice::\x1B[37m[NOTICE] Inspecting commit SHA: 819a33b\x1B[0m',
121121
'\x1B[32m[INFO] No merge commits found in this pull request.\x1B[0m',
122122
])
123123
})
@@ -160,17 +160,17 @@ describe('nexusphp/no-merge-commits main', () => {
160160
await expect(runner()).rejects.toThrowError('Merge commits were found in this pull request.')
161161

162162
assertWritten([
163-
'\x1B[37m[NOTICE] Collecting token from input...\x1B[0m',
163+
'::notice::\x1B[37m[NOTICE] Collecting token from input...\x1B[0m',
164164
'\x1B[32m[INFO] Token collected.\x1B[0m',
165-
'\x1B[37m[NOTICE] Instantiating an Octokit client using token...\x1B[0m',
165+
'::notice::\x1B[37m[NOTICE] Instantiating an Octokit client using token...\x1B[0m',
166166
'\x1B[32m[INFO] Octokit client is ready.\x1B[0m',
167-
'\x1B[37m[NOTICE] Looking up owner: me\x1B[0m',
168-
'\x1B[37m[NOTICE] Looking up repository: awesome\x1B[0m',
169-
'\x1B[37m[NOTICE] Looking up pull request number: 1\x1B[0m',
170-
'\x1B[37m[NOTICE] Retrieving commits of PR #1...\x1B[0m',
167+
'::debug::\x1B[37m[DEBUG] Looking up owner: me\x1B[0m',
168+
'::debug::\x1B[37m[DEBUG] Looking up repository: awesome\x1B[0m',
169+
'::debug::\x1B[37m[DEBUG] Looking up pull request number: 1\x1B[0m',
170+
'::notice::\x1B[37m[NOTICE] Retrieving commits of PR #1...\x1B[0m',
171171
'\x1B[32m[INFO] PR #1 contains 1 commit.\x1B[0m',
172-
'\x1B[37m[NOTICE] Inspecting commit SHA: 819a33b\x1B[0m',
173-
'\x1B[31m[ERROR] Commit SHA 819a33b is a merge commit!\x1B[0m',
172+
'::notice::\x1B[37m[NOTICE] Inspecting commit SHA: 819a33b\x1B[0m',
173+
'::error::\x1B[31m[ERROR] Commit SHA 819a33b is a merge commit!\x1B[0m',
174174
])
175175
})
176176
})

src/runner.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ export async function runner(): Promise<void> {
1212
log('Octokit client is ready.', 'info')
1313

1414
const { owner, repo, number } = context.issue
15-
log(`Looking up owner: ${owner}`, 'notice')
16-
log(`Looking up repository: ${repo}`, 'notice')
17-
log(`Looking up pull request number: ${number}`, 'notice')
15+
log(`Looking up owner: ${owner}`, 'debug')
16+
log(`Looking up repository: ${repo}`, 'debug')
17+
log(`Looking up pull request number: ${number}`, 'debug')
1818

1919
log(`Retrieving commits of PR #${number}...`, 'notice')
2020

src/util.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { info } from '@actions/core'
1+
import * as core from '@actions/core'
22

33
export async function color(type: string): Promise<string> {
44
switch (type) {
@@ -8,6 +8,7 @@ export async function color(type: string): Promise<string> {
88
case 'warning':
99
return '\x1B[33m'
1010

11+
case 'debug':
1112
case 'notice':
1213
return '\x1B[37m'
1314

@@ -21,7 +22,27 @@ export async function color(type: string): Promise<string> {
2122
}
2223

2324
export async function log(message: string, type: string): Promise<void> {
24-
info(`${await color(type)}[${type.toUpperCase()}] ${message}${await color('reset')}`)
25+
let callable
26+
27+
switch (type) {
28+
case 'debug':
29+
callable = core.debug
30+
break
31+
32+
case 'notice':
33+
callable = core.notice
34+
break
35+
36+
case 'error':
37+
callable = core.error
38+
break
39+
40+
case 'info':
41+
default:
42+
callable = core.info
43+
}
44+
45+
callable(`${await color(type)}[${type.toUpperCase()}] ${message}${await color('reset')}`)
2546
}
2647

2748
export async function inflect(iterable: any[], singular: string, plural: string): Promise<string> {

0 commit comments

Comments
 (0)