Files
RSSHub/lib/v2/github/star.js
Fatpandac 03481653fa fix(route): fix GitHub route parameter conflict at trending.js and refactor to V2 (#8923)
* Fix(route): fix route parameter conflict at trending.js and change to V2

* Fix(route): modify the judgment condition of language parameter

* Fix(docs): Update docs/programming.md

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Fix(docs): Update docs/en/programming.md

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* fix(docs/route): add author and sort routes

* Fix(route): Update docs/en/programming.md

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Fix(route): sort routes

Co-authored-by: Tony <TonyRL@users.noreply.github.com>
2022-02-03 00:37:01 +08:00

52 lines
1.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const got = require('@/utils/got');
const config = require('@/config').value;
module.exports = async (ctx) => {
if (!config.github || !config.github.access_token) {
throw 'GitHub star RSS is disabled due to the lack of <a href="https://docs.rsshub.app/install/#%E9%83%A8%E5%88%86-rss-%E6%A8%A1%E5%9D%97%E9%85%8D%E7%BD%AE">relevant config</a>';
}
const user = ctx.params.user;
const repo = ctx.params.repo;
const host = `https://github.com/${user}/${repo}/stargazers`;
const url = 'https://api.github.com/graphql';
const response = await got({
method: 'post',
url,
headers: {
Authorization: `bearer ${config.github.access_token}`,
},
json: {
query: `
{
repository(owner: "${user}", name: "${repo}") {
stargazers(last: 10) {
edges {
node {
login
avatarUrl
}
}
}
}
}
`,
},
});
const data = response.data.data.repository.stargazers.edges.reverse();
ctx.state.data = {
allowEmpty: true,
title: `${user}/${repo}s stargazers`,
link: host,
item: data.map((follower) => ({
title: `${follower.node.login} starred ${user}/${repo}`,
author: follower.node.login,
description: `<a href="https://github.com/${follower.node.login}">${follower.node.login}</a> <br> <img sytle="width:50px;" src='${follower.node.avatarUrl}'>`,
link: `https://github.com/${follower.node.login}`,
})),
};
};