Set sha only when defined

This commit is contained in:
lowlighter
2020-10-18 02:05:48 +02:00
parent 48426cd16f
commit 889bf6fa49
2 changed files with 4 additions and 3 deletions

File diff suppressed because one or more lines are too long

View File

@@ -91,7 +91,7 @@
console.log(`Committer REST API | ok`) console.log(`Committer REST API | ok`)
console.log(`Committer | ${(await rest.users.getAuthenticated()).data.login}`) console.log(`Committer | ${(await rest.users.getAuthenticated()).data.login}`)
//Retrieve previous render SHA to be able to update file content through API //Retrieve previous render SHA to be able to update file content through API
let sha = undefined let sha = null
try { try {
const {data} = await rest.repos.getContent({ const {data} = await rest.repos.getContent({
owner:user, owner:user,
@@ -103,8 +103,9 @@
console.log(`Previous render sha | ${sha || "none"}`) console.log(`Previous render sha | ${sha || "none"}`)
//Update file content through API //Update file content through API
await rest.repos.createOrUpdateFileContents({ await rest.repos.createOrUpdateFileContents({
owner:user, repo:user, path:filename, sha, message:`Update ${filename} - [Skip GitHub Action]`, owner:user, repo:user, path:filename, message:`Update ${filename} - [Skip GitHub Action]`,
content:Buffer.from(rendered).toString("base64"), content:Buffer.from(rendered).toString("base64"),
...(sha ? {sha} : {})
}) })
console.log(`Commit to repo | ok`) console.log(`Commit to repo | ok`)
} }