Encode the showFiletRef output as base64 out of the gate
This commit is contained in:
parent
65c46285dc
commit
4e9b4181aa
@ -22,7 +22,8 @@ export type Commit = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type ExecOpts = {
|
export type ExecOpts = {
|
||||||
allowAllExitCodes?: boolean,
|
allowAllExitCodes?: boolean
|
||||||
|
encoding?: 'utf8' | 'base64'
|
||||||
}
|
}
|
||||||
|
|
||||||
export class GitCommandManager {
|
export class GitCommandManager {
|
||||||
@ -282,9 +283,9 @@ export class GitCommandManager {
|
|||||||
return output.stdout.trim()
|
return output.stdout.trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
async showFileAtRef(ref: string, path: string): Promise<string> {
|
async showFileAtRefBase64(ref: string, path: string): Promise<string> {
|
||||||
const args = ['show', `${ref}:${path}`]
|
const args = ['show', `${ref}:${path}`]
|
||||||
const output = await this.exec(args)
|
const output = await this.exec(args, {encoding: 'base64'})
|
||||||
return output.stdout.trim()
|
return output.stdout.trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -376,10 +377,10 @@ export class GitCommandManager {
|
|||||||
ignoreReturnCode: opts.allowAllExitCodes ?? false,
|
ignoreReturnCode: opts.allowAllExitCodes ?? false,
|
||||||
listeners: {
|
listeners: {
|
||||||
stdout: (data: Buffer) => {
|
stdout: (data: Buffer) => {
|
||||||
stdout.push(data.toString())
|
stdout.push(data.toString(opts.encoding ?? 'utf8'))
|
||||||
},
|
},
|
||||||
stderr: (data: Buffer) => {
|
stderr: (data: Buffer) => {
|
||||||
stderr.push(data.toString())
|
stderr.push(data.toString(opts.encoding ?? 'utf8'))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -275,7 +275,7 @@ export class GitHubHelper {
|
|||||||
const {data: blob} = await blobCreationLimit(() =>
|
const {data: blob} = await blobCreationLimit(() =>
|
||||||
this.octokit.rest.git.createBlob({
|
this.octokit.rest.git.createBlob({
|
||||||
...repository,
|
...repository,
|
||||||
content: git.showFileAtRef(commit.sha, path),
|
content: await git.showFileAtRefBase64(commit.sha, path),
|
||||||
encoding: 'base64'
|
encoding: 'base64'
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|||||||
10
src/utils.ts
10
src/utils.ts
@ -126,16 +126,6 @@ export function readFile(path: string): string {
|
|||||||
return fs.readFileSync(path, 'utf-8')
|
return fs.readFileSync(path, 'utf-8')
|
||||||
}
|
}
|
||||||
|
|
||||||
export function readFileBase64(pathParts: string[]): string {
|
|
||||||
const resolvedPath = path.resolve(...pathParts)
|
|
||||||
if (fs.lstatSync(resolvedPath).isSymbolicLink()) {
|
|
||||||
return fs
|
|
||||||
.readlinkSync(resolvedPath, {encoding: 'buffer'})
|
|
||||||
.toString('base64')
|
|
||||||
}
|
|
||||||
return fs.readFileSync(resolvedPath).toString('base64')
|
|
||||||
}
|
|
||||||
|
|
||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
function hasErrorCode(error: any): error is {code: string} {
|
function hasErrorCode(error: any): error is {code: string} {
|
||||||
return typeof (error && error.code) === 'string'
|
return typeof (error && error.code) === 'string'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user