-
Notifications
You must be signed in to change notification settings - Fork 29
/
generateContributors.js
45 lines (40 loc) · 1.53 KB
/
generateContributors.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const axios = require('axios');
const fs = require('fs');
const owner = 'arpittyagi102';
const repo = 'Humari-Dukan';
// Fetch the contributors from the GitHub API
axios.get(`https://api.github.com/repos/${owner}/${repo}/contributors`)
.then((response) => {
// Generate the contributors section in markdown format
let contributorsSection = '## Contributors\n\n';
response.data.forEach((contributor) => {
contributorsSection += `<a href="${contributor.html_url}">
<img src="https://images.weserv.nl/?url=${contributor.avatar_url}&h=300&w=300&fit=cover&mask=circle&maxage=7d" width="120px"/>
</a>
`;
});
// Read the existing README.md file
fs.readFile('README.md', 'utf8', (readError, data) => {
if (readError) {
console.error(`Error reading README.md: ${readError}`);
return;
}
// Update the contributors section in the README content
const regex = new RegExp('## Contributors[\\s\\S]*<br class="br"/>');
const updatedReadmeContent = data.replace(
regex,
`## Contributors\n\n${contributorsSection}\n<br class="br"/>`
);
// Write the updated content back to the README.md file
fs.writeFile('README.md', updatedReadmeContent, 'utf8', (writeError) => {
if (writeError) {
console.error(`Error writing to README.md: ${writeError}`);
return;
}
console.log('Contributors section updated in README.md');
});
});
})
.catch((error) => {
console.error(`Error fetching contributors: ${error}`);
});