Skip to content

Commit 953ed0b

Browse files
authored
Merge pull request #276 from nishant0708/main
Fix Profile: User Vansh codes #240
2 parents f4ad3a5 + 492d574 commit 953ed0b

File tree

4 files changed

+30
-13
lines changed

4 files changed

+30
-13
lines changed

.github/workflows/update-categories.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ jobs:
2121
run: npm install
2222

2323
- name: Update Contributors File
24-
run: node .github/workflows/update-contributors.js ${{ github.event.pull_request.user.login }} "${{ github.event.pull_request.body }}"
24+
run: |
25+
node .github/workflows/update-contributors.js "${{ github.event.pull_request.user.login }}" "${{ github.event.pull_request.body }}"
26+
env:
27+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2528

2629
- name: Commit and Push Changes
2730
run: |

.github/workflows/update-contributors.js

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,42 @@ const prBody = process.argv[3];
66
const screenshotUrl = `https://raw.githubusercontent.com/nishant0708/awesome-github-profiles/main/screenshots/${username}.png`;
77

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

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

14-
// Check if the user already exists in the contributors data
15-
const existingContributor = contributorsData.contributors.find(contributor => contributor.login === username);
14+
// Read the existing contributors file
15+
let contributorsData;
16+
try {
17+
contributorsData = JSON.parse(fs.readFileSync(contributorsFilePath, 'utf8'));
18+
} catch (error) {
19+
console.error(`Failed to read .all-contributorsrc: ${error.message}`);
20+
process.exit(1);
21+
}
22+
23+
// Find existing contributor or create a new one
24+
let contributor = contributorsData.contributors.find(contributor => contributor.login === username);
1625

17-
if (existingContributor) {
18-
// Update existing contributor's categories
19-
existingContributor.contributions = categories;
26+
if (contributor) {
27+
contributor.contributions = categories;
2028
} else {
21-
// Add a new contributor
22-
contributorsData.contributors.push({
29+
contributor = {
2330
login: username,
2431
name: username, // Customize as needed
2532
avatar_url: `https://avatars.githubusercontent.com/${username}`,
2633
ScreenShot: screenshotUrl,
2734
profile: `https://github.com/${username}`,
2835
contributions: categories
29-
});
36+
};
37+
contributorsData.contributors.push(contributor);
3038
}
3139

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

screenshots/Kratik1093.png

174 KB
Loading

screenshots/vansh-codes.png

691 KB
Loading

0 commit comments

Comments
 (0)