diff --git a/.github/workflows/update-categories.yml b/.github/workflows/update-categories.yml index a224e0ad..f057a212 100644 --- a/.github/workflows/update-categories.yml +++ b/.github/workflows/update-categories.yml @@ -21,7 +21,10 @@ jobs: run: npm install - name: Update Contributors File - run: node .github/workflows/update-contributors.js ${{ github.event.pull_request.user.login }} "${{ github.event.pull_request.body }}" + run: | + node .github/workflows/update-contributors.js "${{ github.event.pull_request.user.login }}" "${{ github.event.pull_request.body }}" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Commit and Push Changes run: | diff --git a/.github/workflows/update-contributors.js b/.github/workflows/update-contributors.js index 40ae307c..e091f969 100644 --- a/.github/workflows/update-contributors.js +++ b/.github/workflows/update-contributors.js @@ -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>/g) || []).map(tag => tag.replace(/\[x\] (.+?)<\/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); +} diff --git a/screenshots/Kratik1093.png b/screenshots/Kratik1093.png index 9d1c3a75..dbca3e36 100644 Binary files a/screenshots/Kratik1093.png and b/screenshots/Kratik1093.png differ diff --git a/screenshots/vansh-codes.png b/screenshots/vansh-codes.png new file mode 100644 index 00000000..acfc0043 Binary files /dev/null and b/screenshots/vansh-codes.png differ