Skip to content

Commit

Permalink
Update update-contributors.js
Browse files Browse the repository at this point in the history
  • Loading branch information
MrSunshyne authored Aug 7, 2023
1 parent 74a8f26 commit 8e3510c
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions update-contributors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand All @@ -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 "[email protected]"');
// Configure Git user and email for the commit
execSync('git config --global user.name "GitHub Action"');
execSync('git config --global user.email "[email protected]"');

// 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);
}
Expand Down

0 comments on commit 8e3510c

Please sign in to comment.