-
Notifications
You must be signed in to change notification settings - Fork 10
/
generateContent.js
68 lines (52 loc) · 2.19 KB
/
generateContent.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
class GenerateContent {
generateRepositorySection(repositories, owner, getStatisticsContent) {
let content = '';
repositories.sort((repoA, repoB) => repoB.stargazers_count - repoA.stargazers_count);
content += '## Repositories\n\n';
content += '| Repository | Owner | Description | Topics | Stars | Forks | Open Issues | Watchers |\n';
content += '| --- | --- | --- | --- | --- | --- | --- | --- |\n';
for (const repo of repositories) {
const repoName = repo.name;
const repoDescription = repo.description || '';
const repoTopics = repo.topics ? repo.topics.join(', ') : '';
const statistics = getStatisticsContent(owner, repoName);
content += `| [${repoName}](https://github.com/${owner}/${repoName}) `;
content += `| ${owner} `;
content += `| ${repoDescription} `;
content += `| ${repoTopics} `;
content += `| ${statistics.Stars} `;
content += `| ${statistics.Forks} `;
content += `| ${statistics['Open Issues']} `;
content += `| ${statistics.Watchers} |\n`;
}
return content;
}
generateLanguageSection(languageCount) {
let content = '';
if (Object.keys(languageCount).length > 0) {
content += '## Most Used Languages\n\n';
const sortedLanguages = Object.keys(languageCount).sort(
(a, b) => languageCount[b] - languageCount[a]
);
for (const language of sortedLanguages) {
content += `- ${language}: ${languageCount[language]}\n`;
}
content += '---\n\n';
}
return content;
}
generateReadmeContent(repositories, owner, getStatisticsContent, languageCount) {
let content = '';
let tableOfContents = '';
for (const repo of repositories) {
tableOfContents += `- [${repo.name}](#${repo.name.toLowerCase().replace(/ /g, '-')})\n`;
}
content += '# GitHub Repository Statistics\n\n';
content += tableOfContents + '\n';
content += '---\n\n';
content += this.generateLanguageSection(languageCount);
content += this.generateRepositorySection(repositories, owner, getStatisticsContent);
return content;
}
}
module.exports = GenerateContent;