mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-02 01:58:11 +08:00
64 lines
2.2 KiB
JavaScript
64 lines
2.2 KiB
JavaScript
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/#pei-zhi-bu-fen-rss-mo-kuai-pei-zhi">relevant config</a>';
|
||
}
|
||
const user = ctx.params.user;
|
||
|
||
const host = `https://github.com/${user}?tab=stars`;
|
||
const url = 'https://api.github.com/graphql';
|
||
|
||
const response = await got({
|
||
method: 'post',
|
||
url,
|
||
headers: {
|
||
Authorization: `bearer ${config.github.access_token}`,
|
||
},
|
||
json: {
|
||
query: `
|
||
{
|
||
user(login: "${user}") {
|
||
starredRepositories(first: 10, orderBy: {direction: DESC, field: STARRED_AT}) {
|
||
edges {
|
||
starredAt
|
||
node {
|
||
name
|
||
description
|
||
url
|
||
openGraphImageUrl
|
||
primaryLanguage {
|
||
name
|
||
}
|
||
stargazers {
|
||
totalCount
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
`,
|
||
},
|
||
});
|
||
|
||
const data = response.data.data.user.starredRepositories.edges;
|
||
|
||
ctx.state.data = {
|
||
allowEmpty: true,
|
||
title: `${user}’s starred repositories`,
|
||
link: host,
|
||
description: `${user}’s starred repositories`,
|
||
item: data.map((repo) => ({
|
||
title: `${user} starred ${repo.node.name}`,
|
||
author: user,
|
||
description: `${repo.node.description === null ? 'no description' : repo.node.description} <br> primary language: ${
|
||
repo.node.primaryLanguage === null ? 'no primary language' : repo.node.primaryLanguage.name
|
||
} <br> stargazers: ${repo.node.stargazers.totalCount} <br> <img sytle="width:50px;" src='${repo.node.openGraphImageUrl}'>`,
|
||
pubDate: new Date(repo.starredAt),
|
||
link: repo.node.url,
|
||
})),
|
||
};
|
||
};
|