mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-04 19:59:54 +08:00
feat: add GitHub user starred repositories (#2999)
This commit is contained in:
@@ -197,6 +197,12 @@
|
||||
source: '/:user/:repo/blob/:branch/*filepath',
|
||||
target: '/github/file/:user/:repo/:branch/:filepath',
|
||||
},
|
||||
{
|
||||
title: '用户 Starred Repositories',
|
||||
docs: 'https://docs.rsshub.app/programming.html#github',
|
||||
source: '/:user',
|
||||
target: '/github/starred_repos/:user',
|
||||
},
|
||||
],
|
||||
},
|
||||
'zhihu.com': {
|
||||
|
||||
@@ -111,6 +111,10 @@ GitHub 官方也提供了一些 RSS:
|
||||
| 根据 fork 数量排序 | forks |
|
||||
| 根据更新时间排序 | updated |
|
||||
|
||||
### 用户 Starred Repositories
|
||||
|
||||
<Route author="LanceZhu" example="/github/starred_repos/DIYgod" path="/github/starred_repos/:user" :paramsDesc="['用户名']" radar="1"/>
|
||||
|
||||
## GitLab
|
||||
|
||||
### Explore
|
||||
|
||||
@@ -232,6 +232,7 @@ router.get('/github/stars/:user/:repo', require('./routes/github/star'));
|
||||
router.get('/github/search/:query/:sort?/:order?', require('./routes/github/search'));
|
||||
router.get('/github/branches/:user/:repo', require('./routes/github/branches'));
|
||||
router.get('/github/file/:user/:repo/:branch/:filepath+', require('./routes/github/file'));
|
||||
router.get('/github/starred_repos/:user', require('./routes/github/starred_repos'));
|
||||
|
||||
// f-droid
|
||||
router.get('/fdroid/apprelease/:app', require('./routes/fdroid/apprelease'));
|
||||
|
||||
60
lib/routes/github/starred_repos.js
Normal file
60
lib/routes/github/starred_repos.js
Normal file
@@ -0,0 +1,60 @@
|
||||
const got = require('@/utils/got');
|
||||
const config = require('@/config');
|
||||
|
||||
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: true,
|
||||
data: {
|
||||
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 = {
|
||||
title: `${user}’s starred repositories`,
|
||||
link: host,
|
||||
description: `${user}’s starred repositories`,
|
||||
item: data.map((repo) => ({
|
||||
title: `${user} starred ${repo.node.name}`,
|
||||
description: `${repo.node.description} <br> 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}`).toUTCString(),
|
||||
link: `${repo.node.url}`,
|
||||
})),
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user