Skip to content

Commit

Permalink
🚑 Fixed bug when github PushEvent had no commits
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDanniCraft committed Sep 2, 2024
1 parent ae899cc commit 4675569
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
12 changes: 6 additions & 6 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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})`;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/eventDescriptions.js
Original file line number Diff line number Diff line change
@@ -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})`;
Expand Down

0 comments on commit 4675569

Please sign in to comment.