2020-09-23 15:19:20 +00:00
|
|
|
// We use any as a valid input type
|
|
|
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
|
|
|
2021-07-28 21:34:31 +00:00
|
|
|
import {AnnotationProperties} from './core'
|
|
|
|
import {CommandProperties} from './command'
|
|
|
|
|
2020-09-23 15:19:20 +00:00
|
|
|
/**
|
|
|
|
* Sanitizes an input into a string so it can be passed into issueCommand safely
|
|
|
|
* @param input input to sanitize into a string
|
|
|
|
*/
|
|
|
|
export function toCommandValue(input: any): string {
|
|
|
|
if (input === null || input === undefined) {
|
|
|
|
return ''
|
|
|
|
} else if (typeof input === 'string' || input instanceof String) {
|
|
|
|
return input as string
|
|
|
|
}
|
|
|
|
return JSON.stringify(input)
|
|
|
|
}
|
2021-07-28 21:34:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param annotationProperties
|
|
|
|
* @returns The command properties to send with the actual annotation command
|
|
|
|
* See IssueCommandProperties: https://github.com/actions/runner/blob/main/src/Runner.Worker/ActionCommandManager.cs#L646
|
|
|
|
*/
|
|
|
|
export function toCommandProperties(
|
|
|
|
annotationProperties: AnnotationProperties
|
|
|
|
): CommandProperties {
|
|
|
|
if (!Object.keys(annotationProperties).length) {
|
|
|
|
return {}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
title: annotationProperties.title,
|
2021-09-28 13:47:06 +00:00
|
|
|
file: annotationProperties.file,
|
2021-07-28 21:34:31 +00:00
|
|
|
line: annotationProperties.startLine,
|
|
|
|
endLine: annotationProperties.endLine,
|
|
|
|
col: annotationProperties.startColumn,
|
|
|
|
endColumn: annotationProperties.endColumn
|
|
|
|
}
|
|
|
|
}
|