-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathget_repos.js
More file actions
77 lines (70 loc) · 2.12 KB
/
get_repos.js
File metadata and controls
77 lines (70 loc) · 2.12 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
import { Octokit } from "@octokit/rest";
import fs from "fs";
import "dotenv/config";
/*
ENV NEEDED:
~~~~~~~~~~~
API_KEY
API_BASE
API_MODEL
GITHUB_TOKEN
*/
async function getResponse(messages) {
const apiKey = process.env.API_KEY;
const apiBase = process.env.API_BASE;
const apiUrl = apiBase + "/chat/completions";
const data = await fetch(apiUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${apiKey}`,
},
body: JSON.stringify({
model: process.env.API_MODEL,
messages,
}),
}).then((r) => r.json());
const answer = data.choices[0].message.content;
return answer;
}
async function run() {
const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN,
});
let repos = await octokit
.paginate(octokit.repos.listForUser, {
username: "Explosion-Scratch",
per_page: 100,
})
.then((repos) => repos.filter((repo) => repo.stargazers_count >= 12));
for (let i in repos) {
repos[i].emoji = await getResponse([
{
role: "system",
content: `Generate a single emoji for a repo with the following title and description. Output only the emoji and nothing else`,
},
{
role: "user",
content: `Title: ${repos[i].name}\nDescription: ${repos[i].description}`,
},
]);
console.log("Generated emoji for", repos[i].name, repos[i].emoji);
await new Promise((r) => setTimeout(r, 100));
}
const md = repos
.map(
// n## [${repo.name}](${repo.html_url})\n${repo.description || "No description"}\n
(repo) =>
`<li><a href=${JSON.stringify(repo.html_url)}>${repo.emoji} <b>${repo.name}</b></a>${repo.description?.trim()?.length ? `: <i>${repo.description || ""}</i>` : ""}</li>`,
)
.join("\n");
const startContent = fs.readFileSync("start.md", "utf-8");
const START_DELIM = "<!-- START -->";
const END_DELIM = "<!-- END -->";
const newContent =
startContent.split(START_DELIM)[0] +
`${START_DELIM}\n${md}\n${END_DELIM}`.split("\n").join("\t\n") +
startContent.split(END_DELIM)[1];
fs.writeFileSync("README.md", newContent);
}
run();