Files
zhuiguang-ai/scripts/test-github.mjs
T

40 lines
1.0 KiB
JavaScript

import { Octokit } from "octokit";
const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN || undefined,
});
(async () => {
console.log("🔍 搜索热门 AI 项目...");
const q = "ai agent stars:>1000 pushed:>2024-01-01";
const { data } = await octokit.rest.search.repos({
q,
sort: "stars",
order: "desc",
per_page: 3,
});
const repos = data.items;
console.log(`找到 ${repos.length} 个仓库:\n`);
for (const repo of repos) {
console.log(`- ${repo.full_name} (⭐ ${repo.stargazers_count})`);
}
if (repos.length > 0) {
const [owner, name] = repos[0].full_name.split("/");
try {
const { data: readmeData } = await octokit.rest.repos.getReadme({
owner,
repo: name,
});
const readme = Buffer.from(readmeData.content, "base64").toString("utf-8");
console.log(
`\n📖 ${repos[0].full_name} README 前200字符:\n${readme.substring(0, 200)}`
);
} catch {
console.log("\n📖 README 获取失败");
}
}
})();