Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use actions/core/AnnotationProperties #227

Merged
merged 8 commits into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}
}