Skip to content

Commit 60145e4

Browse files
authored
Add file property to AnnotationProperties (#896)
1 parent ea81280 commit 60145e4

4 files changed

Lines changed: 48 additions & 2 deletions

File tree

packages/core/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ export interface AnnotationProperties {
142142
*/
143143
title?: string
144144

145+
/**
146+
* The name of the file for which the annotation should be created.
147+
*/
148+
file?: string
149+
145150
/**
146151
* The start line for the annotation.
147152
*/

packages/core/__tests__/core.test.ts

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,14 @@ describe('@actions/core', () => {
274274
const message = 'this is my error message'
275275
core.error(new Error(message), {
276276
title: 'A title',
277+
file: 'root/test.txt',
277278
startColumn: 1,
278279
endColumn: 2,
279280
startLine: 5,
280281
endLine: 5
281282
})
282283
assertWriteCalls([
283-
`::error title=A title,line=5,endLine=5,col=1,endColumn=2::Error: ${message}${os.EOL}`
284+
`::error title=A title,file=root/test.txt,line=5,endLine=5,col=1,endColumn=2::Error: ${message}${os.EOL}`
284285
])
285286
})
286287

@@ -304,25 +305,59 @@ describe('@actions/core', () => {
304305
const message = 'this is my error message'
305306
core.warning(new Error(message), {
306307
title: 'A title',
308+
file: 'root/test.txt',
307309
startColumn: 1,
308310
endColumn: 2,
309311
startLine: 5,
310312
endLine: 5
311313
})
312314
assertWriteCalls([
313-
`::warning title=A title,line=5,endLine=5,col=1,endColumn=2::Error: ${message}${os.EOL}`
315+
`::warning title=A title,file=root/test.txt,line=5,endLine=5,col=1,endColumn=2::Error: ${message}${os.EOL}`
316+
])
317+
})
318+
319+
it('notice sets the correct message', () => {
320+
core.notice('Notice')
321+
assertWriteCalls([`::notice::Notice${os.EOL}`])
322+
})
323+
324+
it('notice escapes the message', () => {
325+
core.notice('\r\nnotice\n')
326+
assertWriteCalls([`::notice::%0D%0Anotice%0A${os.EOL}`])
327+
})
328+
329+
it('notice handles an error object', () => {
330+
const message = 'this is my error message'
331+
core.notice(new Error(message))
332+
assertWriteCalls([`::notice::Error: ${message}${os.EOL}`])
333+
})
334+
335+
it('notice handles parameters correctly', () => {
336+
const message = 'this is my error message'
337+
core.notice(new Error(message), {
338+
title: 'A title',
339+
file: 'root/test.txt',
340+
startColumn: 1,
341+
endColumn: 2,
342+
startLine: 5,
343+
endLine: 5
344+
})
345+
assertWriteCalls([
346+
`::notice title=A title,file=root/test.txt,line=5,endLine=5,col=1,endColumn=2::Error: ${message}${os.EOL}`
314347
])
315348
})
316349

317350
it('annotations map field names correctly', () => {
318351
const commandProperties = toCommandProperties({
319352
title: 'A title',
353+
file: 'root/test.txt',
320354
startColumn: 1,
321355
endColumn: 2,
322356
startLine: 5,
323357
endLine: 5
324358
})
325359
expect(commandProperties.title).toBe('A title')
360+
expect(commandProperties.file).toBe('root/test.txt')
326361
expect(commandProperties.col).toBe(1)
327362
expect(commandProperties.endColumn).toBe(2)
328363
expect(commandProperties.line).toBe(5)

packages/core/src/core.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ export interface AnnotationProperties {
4141
*/
4242
title?: string
4343

44+
/**
45+
* The path of the file for which the annotation should be created.
46+
*/
47+
file?: string
48+
4449
/**
4550
* The start line for the annotation.
4651
*/

packages/core/src/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export function toCommandProperties(
3232

3333
return {
3434
title: annotationProperties.title,
35+
file: annotationProperties.file,
3536
line: annotationProperties.startLine,
3637
endLine: annotationProperties.endLine,
3738
col: annotationProperties.startColumn,

0 commit comments

Comments
 (0)