From 8e3510ca85be7f64831bd3a438c84843a099bcf8 Mon Sep 17 00:00:00 2001 From: Sandeep Ramgolam Date: Mon, 7 Aug 2023 15:54:34 +0400 Subject: [PATCH] Update update-contributors.js --- update-contributors.js | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/update-contributors.js b/update-contributors.js index 7fcbbf6..d390e9e 100644 --- a/update-contributors.js +++ b/update-contributors.js @@ -10,10 +10,7 @@ const contributorsFile = 'contributors.json'; async function updateContributors() { try { const response = await axios.get(`https://api.github.com/repos/${owner}/${repo}/contributors`); - const contributors = response.data.map(contributor => { - console.log(contributor); - return contributor.login; - }); + const contributors = response.data.map(contributor => contributor.login); let existingContributors = []; @@ -23,26 +20,30 @@ async function updateContributors() { const updatedContributors = [...new Set(existingContributors.concat(contributors))]; - fs.writeFileSync(contributorsFile, JSON.stringify(updatedContributors, null, 2)); - console.log('Contributors file updated.'); + if (JSON.stringify(existingContributors) !== JSON.stringify(updatedContributors)) { + fs.writeFileSync(contributorsFile, JSON.stringify(updatedContributors, null, 2)); + console.log('Contributors file updated.'); - // Add the commit and push logic - const { execSync } = require('child_process'); + // Add the commit and push logic + const { execSync } = require('child_process'); - // Configure Git user and email for the commit - execSync('git config --global user.name "GitHub Action"'); - execSync('git config --global user.email "action@github.com"'); + // Configure Git user and email for the commit + execSync('git config --global user.name "GitHub Action"'); + execSync('git config --global user.email "action@github.com"'); - // Stage the changes - execSync('git add .'); + // Stage the changes + execSync('git add .'); - // Create the commit - execSync(`git commit -m "Update contributors.json [skip ci]"`); + // Create the commit + execSync(`git commit -m "Update contributors.json [skip ci]"`); - // Push the changes to the repository - execSync(`git push origin ${branch}`); + // Push the changes to the repository + execSync(`git push origin ${branch}`); - console.log('Changes committed and pushed to the repository.'); + console.log('Changes committed and pushed to the repository.'); + } else { + console.log('No changes detected in contributors. Skipping commit and push.'); + } } catch (error) { console.error('Error updating contributors:', error); }