Skip to content

Commit

Permalink
Update update-contributors.js
Browse files Browse the repository at this point in the history
  • Loading branch information
nishant0708 authored Aug 9, 2024
1 parent b1d57fd commit 492d574
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions .github/workflows/update-contributors.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,42 @@ const prBody = process.argv[3];
const screenshotUrl = `https://raw.githubusercontent.com/nishant0708/awesome-github-profiles/main/screenshots/${username}.png`;

// Extract selected categories from the PR body
const categories = (prBody.match(/\[(x| )\] (.+)/g) || []).map(line => line.replace(/^\[(x| )\] /, ''));
const categories = (prBody.match(/\[x\] <span class="tag">(.+?)<\/span>/g) || []).map(tag => tag.replace(/\[x\] <span class="tag">(.+?)<\/span>/, '$1'));

// Path to .all-contributorsrc file
const contributorsFilePath = path.join(process.cwd(), '.all-contributorsrc');
const contributorsData = JSON.parse(fs.readFileSync(contributorsFilePath, 'utf8'));

// Check if the user already exists in the contributors data
const existingContributor = contributorsData.contributors.find(contributor => contributor.login === username);
// Read the existing contributors file
let contributorsData;
try {
contributorsData = JSON.parse(fs.readFileSync(contributorsFilePath, 'utf8'));
} catch (error) {
console.error(`Failed to read .all-contributorsrc: ${error.message}`);
process.exit(1);
}

// Find existing contributor or create a new one
let contributor = contributorsData.contributors.find(contributor => contributor.login === username);

if (existingContributor) {
// Update existing contributor's categories
existingContributor.contributions = categories;
if (contributor) {
contributor.contributions = categories;
} else {
// Add a new contributor
contributorsData.contributors.push({
contributor = {
login: username,
name: username, // Customize as needed
avatar_url: `https://avatars.githubusercontent.com/${username}`,
ScreenShot: screenshotUrl,
profile: `https://github.com/${username}`,
contributions: categories
});
};
contributorsData.contributors.push(contributor);
}

fs.writeFileSync(contributorsFilePath, JSON.stringify(contributorsData, null, 2));
console.log('Contributors file updated successfully!');
// Write the updated data back to the file
try {
fs.writeFileSync(contributorsFilePath, JSON.stringify(contributorsData, null, 2));
console.log('Contributors file updated successfully!');
} catch (error) {
console.error(`Failed to write to .all-contributorsrc: ${error.message}`);
process.exit(1);
}

0 comments on commit 492d574

Please sign in to comment.