From 46755694793bddc509fcd87e104372ed26963a3d Mon Sep 17 00:00:00 2001 From: TheDanniCraft Date: Mon, 2 Sep 2024 20:35:02 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=91=20Fixed=20bug=20when=20github=20Pu?= =?UTF-8?q?shEvent=20had=20no=20commits?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/index.js | 12 ++++++------ src/index.js | 3 ++- src/utils/eventDescriptions.js | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/dist/index.js b/dist/index.js index 6be14c3..ed0f1fc 100644 --- a/dist/index.js +++ b/dist/index.js @@ -29248,7 +29248,8 @@ module.exports = { const eventDescriptions = { 'PushEvent': ({ repo, isPrivate, payload }) => { - const commitSha = payload.commits[0].sha; + console.log(payload) + const commitSha = payload.commits[0]?.sha; return isPrivate ? '📝 Committed to a private repo' : `📝 Committed to [${repo.name}](https://github.com/${repo.name}/commit/${commitSha})`; @@ -29545,10 +29546,6 @@ async function updateReadme(activity) { return; } - // Write updated content to README.md - fs.writeFileSync(readmePath, updatedContent, 'utf-8'); - core.notice('✅ README.md updated successfully!'); - if (process.env.ACT) { core.debug('🚧 Act-Debug mode enabled)') console.log(activity); @@ -29591,6 +29588,8 @@ async function updateReadme(activity) { }] }); + core.notice('✅ README.md updated successfully!'); + // Create a new commit with the author set to github-actions[bot] const { data: newCommit } = await octokit.rest.git.createCommit({ owner, @@ -31702,7 +31701,8 @@ async function main() { const activity = await fetchAndFilterEvents({ username, token, eventLimit, ignoreEvents }); await updateReadme(activity, readmePath); } catch (error) { - core.setFailed('❌ Error in the update process:', error); + core.setFailed(`❌ Error in the update process: ${error.message}`); + console.error(error) process.exit(1); } } diff --git a/src/index.js b/src/index.js index 1481afc..e42e1d0 100644 --- a/src/index.js +++ b/src/index.js @@ -9,7 +9,8 @@ async function main() { const activity = await fetchAndFilterEvents({ username, token, eventLimit, ignoreEvents }); await updateReadme(activity, readmePath); } catch (error) { - core.setFailed('❌ Error in the update process:', error); + core.setFailed(`❌ Error in the update process: ${error.message}`); + console.error(error) process.exit(1); } } diff --git a/src/utils/eventDescriptions.js b/src/utils/eventDescriptions.js index f0837d2..ca5b151 100644 --- a/src/utils/eventDescriptions.js +++ b/src/utils/eventDescriptions.js @@ -1,6 +1,6 @@ const eventDescriptions = { 'PushEvent': ({ repo, isPrivate, payload }) => { - const commitSha = payload.commits[0].sha; + const commitSha = payload.commits[0]?.sha; return isPrivate ? '📝 Committed to a private repo' : `📝 Committed to [${repo.name}](https://github.com/${repo.name}/commit/${commitSha})`;