Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Profile: User Vansh codes #240 #276

Merged
merged 4 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/update-categories.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
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);
}
Binary file modified screenshots/Kratik1093.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/vansh-codes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading