Skip to content

Commit

Permalink
Merge pull request #227 from yutailang0119/fix/annotaiton-properties
Browse files Browse the repository at this point in the history
Use actions/core/AnnotationProperties
  • Loading branch information
yutailang0119 authored Oct 6, 2021
2 parents 6fa4f5e + 6a2fafc commit 9a6ac55
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 36 deletions.
16 changes: 10 additions & 6 deletions __tests__/annotation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ test('test Annotation.constructor with Warning', () => {
expect(annotation.message).toEqual(
'Useless parent layout: This `RelativeLayout` layout or its `FrameLayout` parent is useless; transfer the `background` attribute to the other view'
)
expect(annotation.file).toEqual('layout.xml')
expect(annotation.line).toEqual(11)
expect(annotation.column).toEqual(22)
expect(annotation.properties).toEqual({
file: 'layout.xml',
startLine: 11,
startColumn: 22
})
})

test('test Annotation.constructor with Error', () => {
Expand All @@ -29,9 +31,11 @@ test('test Annotation.constructor with Error', () => {
expect(annotation.message).toEqual(
'Ignoring results: The result of `subscribe` is not used'
)
expect(annotation.file).toEqual('Foo.kt')
expect(annotation.line).toEqual(33)
expect(annotation.column).toEqual(44)
expect(annotation.properties).toEqual({
file: 'Foo.kt',
startLine: 33,
startColumn: 44
})
})

test('test Annotation.constructor with Other', () => {
Expand Down
24 changes: 12 additions & 12 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions src/annotation.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import {AnnotationProperties} from '@actions/core'
import {AnnotationSeverityLevel} from './annotation-severity-level'

export class Annotation {
severityLevel: AnnotationSeverityLevel
properties: AnnotationProperties

constructor(
severity: string,
public message: string,
public file: string,
public line: number,
public column: number
file: string,
line: number,
column: number
) {
this.severityLevel = severity === 'Error' ? 'error' : 'warning'
this.properties = {
file,
startLine: line,
startColumn: column
}
}
}
20 changes: 6 additions & 14 deletions src/command.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
import * as command from '@actions/core/lib/command'
import * as core from '@actions/core'
import {Annotation} from './annotation'

const commandProperties = (annotation: Annotation): {[key: string]: string} => {
return {
file: annotation.file,
line: `${annotation.line}`,
col: `${annotation.column}`
}
}

export const echoMessages = (annotations: Annotation[]): void => {
for (const annotation of annotations) {
command.issueCommand(
annotation.severityLevel,
commandProperties(annotation),
annotation.message
)
if (annotation.severityLevel === 'error') {
core.error(annotation.message, annotation.properties)
} else {
core.warning(annotation.message, annotation.properties)
}
}
}

0 comments on commit 9a6ac55

Please sign in to comment.