-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
170 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// For internal use, subject to change. | ||
|
||
// We use any as a valid input type | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
|
||
import * as fs from 'fs' | ||
import * as os from 'os' | ||
import {toCommandValue} from './utils' | ||
|
||
export function issueCommand(command: string, message: any): void { | ||
let filePath = process.env[`GITHUB_${command}`] | ||
if (!filePath) { | ||
throw new Error( | ||
`Unable to find environment variable for file command ${command}` | ||
) | ||
} | ||
if (!fs.existsSync(filePath)) { | ||
throw new Error(`Missing file at path: ${filePath}`) | ||
} | ||
|
||
fs.appendFileSync(filePath, `${toCommandValue(message)}${os.EOL}`, { | ||
encoding: 'utf8' | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* 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) | ||
} |