-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-topics-report.js
More file actions
158 lines (129 loc) Β· 5.54 KB
/
generate-topics-report.js
File metadata and controls
158 lines (129 loc) Β· 5.54 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/env node
/**
* Generate a report of suggested topics for all DecisionsDev repositories
* Creates a markdown table showing what topics would be added to each repo
*/
const https = require('https');
const fs = require('fs');
const { analyzeRepository } = require('./topic-analyzer');
const ORG_NAME = 'DecisionsDev';
function fetchRepositories() {
return new Promise((resolve, reject) => {
const headers = {
'User-Agent': 'DecisionsDev-Topic-Manager',
'Accept': 'application/vnd.github.v3+json'
};
const options = {
hostname: 'api.github.com',
path: `/orgs/${ORG_NAME}/repos?per_page=100`,
method: 'GET',
headers: headers
};
const req = https.request(options, (res) => {
let data = '';
res.on('data', (chunk) => { data += chunk; });
res.on('end', () => {
if (res.statusCode === 200) {
resolve(JSON.parse(data));
} else {
reject(new Error(`Failed to fetch repos: ${res.statusCode}`));
}
});
});
req.on('error', reject);
req.end();
});
}
async function generateReport() {
console.log('π Fetching repositories from DecisionsDev organization...\n');
try {
const repos = await fetchRepositories();
console.log(`π¦ Found ${repos.length} repositories\n`);
console.log('π Analyzing and generating report...\n');
let report = '# DecisionsDev Repository Topics Report\n\n';
report += `Generated: ${new Date().toISOString()}\n\n`;
report += `Total Repositories: ${repos.length}\n\n`;
// Summary statistics
let reposWithSuggestions = 0;
let totalSuggestions = 0;
const productCounts = {};
const componentCounts = {};
const typeCounts = {};
// Analyze all repos first for statistics
const analyses = repos.map(repo => {
const suggestions = analyzeRepository(repo);
const allSuggestions = [
...suggestions.products,
...suggestions.components,
...suggestions.types
];
if (allSuggestions.length > 0) {
reposWithSuggestions++;
totalSuggestions += allSuggestions.length;
}
suggestions.products.forEach(p => productCounts[p] = (productCounts[p] || 0) + 1);
suggestions.components.forEach(c => componentCounts[c] = (componentCounts[c] || 0) + 1);
suggestions.types.forEach(t => typeCounts[t] = (typeCounts[t] || 0) + 1);
return { repo, suggestions, allSuggestions };
});
// Summary section
report += '## Summary\n\n';
report += `- Repositories with suggested topics: ${reposWithSuggestions} / ${repos.length}\n`;
report += `- Total topic suggestions: ${totalSuggestions}\n`;
report += `- Average suggestions per repo: ${(totalSuggestions / reposWithSuggestions).toFixed(1)}\n\n`;
// Top topics
report += '### Most Common Suggested Topics\n\n';
report += '**Products:**\n';
Object.entries(productCounts).sort((a, b) => b[1] - a[1]).forEach(([topic, count]) => {
report += `- ${topic}: ${count} repositories\n`;
});
report += '\n**Components:**\n';
Object.entries(componentCounts).sort((a, b) => b[1] - a[1]).forEach(([topic, count]) => {
report += `- ${topic}: ${count} repositories\n`;
});
report += '\n**Types:**\n';
Object.entries(typeCounts).sort((a, b) => b[1] - a[1]).forEach(([topic, count]) => {
report += `- ${topic}: ${count} repositories\n`;
});
report += '\n';
// Detailed table
report += '## Detailed Repository Analysis\n\n';
report += '| Repository | Current Topics | Suggested Topics | Status |\n';
report += '|------------|----------------|------------------|--------|\n';
analyses.sort((a, b) => a.repo.name.localeCompare(b.repo.name)).forEach(({ repo, suggestions, allSuggestions }) => {
const currentTopics = repo.topics || [];
const structuredPrefixes = ['product-', 'comp-', 'type-'];
const hasStructured = currentTopics.some(t => structuredPrefixes.some(p => t.startsWith(p)));
const currentDisplay = currentTopics.length > 0
? currentTopics.slice(0, 3).join(', ') + (currentTopics.length > 3 ? '...' : '')
: '(none)';
const suggestedDisplay = allSuggestions.length > 0
? allSuggestions.join(', ')
: '(none)';
const status = allSuggestions.length === 0
? 'β No changes'
: hasStructured
? 'β οΈ Has some'
: 'β New topics';
report += `| [${repo.name}](${repo.html_url}) | ${currentDisplay} | ${suggestedDisplay} | ${status} |\n`;
});
report += '\n## Legend\n\n';
report += '- β No changes: No structured topics suggested\n';
report += '- β οΈ Has some: Repository already has some structured topics\n';
report += '- β New topics: New structured topics will be added\n';
// Write to file
fs.writeFileSync('topics-report.md', report);
console.log('β
Report generated: topics-report.md\n');
// Also print summary to console
console.log('π Summary:');
console.log(` Repositories analyzed: ${repos.length}`);
console.log(` Repositories with suggestions: ${reposWithSuggestions}`);
console.log(` Total topic suggestions: ${totalSuggestions}`);
console.log('\nπ‘ Open topics-report.md to see the full report');
} catch (error) {
console.error('β Error:', error.message);
process.exit(1);
}
}
generateReport();
// Made with Bob