1
0
Fork 0

feedback: add summary write options

pull/1014/head
Rob Herley 2022-03-08 16:37:20 -05:00
parent 6295f5d25b
commit edee7cde32
No known key found for this signature in database
GPG Key ID: D1602042C3543B06
2 changed files with 13 additions and 4 deletions

View File

@ -111,7 +111,7 @@ describe('@actions/core/src/markdown-summary', () => {
it('overwrites text to summary file', async () => {
await fs.promises.writeFile(testFilePath, 'overwrite', {encoding: 'utf8'})
await markdownSummary.addRaw(fixtures.text).write(true)
await markdownSummary.addRaw(fixtures.text).write({overwrite: true})
await assertSummary(fixtures.text)
})

View File

@ -45,6 +45,14 @@ export interface SummaryImageOptions {
height?: string
}
export interface SummaryWriteOptions {
/**
* Replace all existing content in summary file with buffer contents
* (optional) default: false
*/
overwrite?: boolean
}
class MarkdownSummary {
private _buffer: string
private _filePath?: string
@ -134,11 +142,12 @@ class MarkdownSummary {
* Writes text in the buffer to the summary buffer file and empties buffer. Will append by default.
* Checks if resulting file size > SUMMARY_LIMIT_BYTES, will throw and empty buffer
*
* @param {boolean} [overwrite=false] (optional) replace existing content in summary file with buffer contents, default: false
* @param {SummaryWriteOptions | undefined} options (optional) options for write operation
*
* @returns {Promise<MarkdownSummary>} markdown summary instance
*/
async write(overwrite = false): Promise<MarkdownSummary> {
async write(options?: SummaryWriteOptions): Promise<MarkdownSummary> {
const overwrite = !!options?.overwrite
const filePath = await this.filePath()
if (await this.willExceedLimit(overwrite)) {
@ -160,7 +169,7 @@ class MarkdownSummary {
* @returns {MarkdownSummary} markdown summary instance
*/
async clear(): Promise<MarkdownSummary> {
return this.emptyBuffer().write(true)
return this.emptyBuffer().write({overwrite: true})
}
/**