-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateCatalog.js
61 lines (50 loc) · 1.61 KB
/
updateCatalog.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
const { Octokit } = require("@octokit/rest");
const fs = require("fs");
const path = require("path");
require('dotenv').config();
const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN,
});
async function getRepoTopics() {
try {
const owner = "epiverse";
const repo = "catalog";
const { data } = await octokit.repos.getAllTopics({
owner,
repo,
});
console.log("Repository Topics:", data.names);
for (const topic of data.names) {
const repositories = await getRepositoriesByTopic(topic);
const jsonData = JSON.stringify(repositories);
fs.writeFile('./catalog/index.json', jsonData, (err) => {
if (err) {
console.error('Error writing to file', err);
} else {
console.log('JSON file has been saved.');
}
});
}
} catch (error) {
console.error("Error fetching repository topics:", error.message);
}
}
async function getRepositoriesByTopic(topic) {
try {
const response = await octokit.rest.search.repos({
q: `topic:${topic}`,
sort: "stars", // Optionally sort by stars
order: "desc",
});
return response.data.items.map(repo => ({
name: repo.name,
full_name: repo.full_name,
url: repo.html_url,
description: repo.description,
stars: repo.stargazers_count,
}));
} catch (error) {
console.error("Error fetching repositories:", error);
}
}
getRepoTopics();