Files
RSSHub/lib/routes/github/starred_repos.js
T
Daniel Li (李丹阳)andSukka d77a039f05 style(eslint): add no-implicit-coercion rule (#8175)
* refactor: add no-implicit-coercion rule for ESLint

* fix: errors from deepscan

* fix: errors from deepscan

* fix: errors from deepscan

* fix: errors from deepscan

* fix: errors from deepscan

* Update docs/en/joinus/quick-start.md

Co-authored-by: Sukka <isukkaw@gmail.com>

* Update docs/joinus/quick-start.md

Co-authored-by: Sukka <isukkaw@gmail.com>

* Update lib/routes/av01/tag.js

Co-authored-by: Sukka <isukkaw@gmail.com>

* Update lib/routes/gov/taiwan/mnd.js

Co-authored-by: Sukka <isukkaw@gmail.com>

* Update lib/routes/ps/product.js

Co-authored-by: Sukka <isukkaw@gmail.com>

* refactor: minify html string

Co-authored-by: Sukka <isukkaw@gmail.com>
2021-09-15 21:22:11 +08:00

64 lines
2.2 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 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,
})),
};
};