Add GitHub followers and repo stargazers (#518)

fix #511
This commit is contained in:
Henry Wang 2018-08-28 13:43:11 +01:00 committed by DIYgod
parent 7669d31af4
commit 976b5e3856
6 changed files with 143 additions and 5 deletions

View File

@ -159,11 +159,13 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇
- GitHub
- 用户仓库
- Trending
- Issue
- 仓库 Issues
- 用户 Followers
- 仓库 Stars
- Konachan.com Anime Wallpapers
- Popular Recent Posts
- Recent Popular Posts
- yande.re
- Popular Recent Posts
- Recent Popular Posts
- 纽约时报
- 新闻早报
- 3DMGame

View File

@ -1500,14 +1500,35 @@ since时间跨度可在 [Trending 页](https://github.com/trending/javascr
language语言可在 [Trending 页](https://github.com/trending/javascript?since=monthly) URL 中找到
### Issue <Author uid="HenryQW"/>
### 仓库 Issue <Author uid="HenryQW"/>
举例: [https://rsshub.app/github/issue/DIYgod/RSSHub](https://rsshub.app/github/issue/DIYgod/RSSHub)
路由: `/github/issue/:user/:repo`
参数:
user用户名
repo仓库名
### 用户 Followers <Author uid="HenryQW"/>
举例: [https://rsshub.app/github/user/followers/HenryQW](https://rsshub.app/github/user/followers/HenryQW)
路由: `/github/user/followers/:user`
参数: user用户名
参数: repo仓库名
### 仓库 Stars <Author uid="HenryQW"/>
举例: [https://rsshub.app/github/stars/DIYgod/RSSHub](https://rsshub.app/github/stars/DIYgod/RSSHub)
路由: `/github/stars/:user/:repo`
参数:
user用户名
repo仓库名
## 3DMGame

View File

@ -366,6 +366,28 @@ Parameters:
- repo, repo name
### Follower <Author uid="HenryQW"/>
Eg: [https://rsshub.app/github/user/followers/HenryQW](https://rsshub.app/github/user/followers/HenryQW)
Route: `/github/user/follower/:user`
Parameters:
- user, username
### Star <Author uid="HenryQW"/>
Eg: [https://rsshub.app/github/stars/DIYGod/RSSHub](https://rsshub.app/github/stars/DIYGod/RSSHub)
Route: `/github/stars/:user/:repo`
Parameters:
- user, username
- repo, repo name
## EZTV
::: tip

View File

@ -276,6 +276,8 @@ if (config.github && config.github.access_token) {
}
router.get('/github/trending/:since/:language?', require('./routes/github/trending'));
router.get('/github/issue/:user/:repo', require('./routes/github/issue'));
router.get('/github/user/followers/:user', require('./routes/github/follower'));
router.get('/github/stars/:user/:repo', require('./routes/github/star'));
// konachan
router.get('/konachan/post/popular_recent', require('./routes/konachan/post_popular_recent'));

45
routes/github/follower.js Normal file
View File

@ -0,0 +1,45 @@
const axios = require('../../utils/axios');
const config = require('../../config');
module.exports = async (ctx) => {
const user = ctx.params.user;
const host = `https://github.com/${user}`;
const url = 'https://api.github.com/graphql';
const response = await axios({
method: 'post',
url,
headers: {
Authorization: `bearer ${config.github.access_token}`,
},
data: {
query: `
{
user(login: "${user}") {
followers(last: 10) {
edges {
node {
login
avatarUrl
}
}
}
}
}
`,
},
});
const data = response.data.data.user.followers.edges.reverse();
ctx.state.data = {
title: `${user}'s followers`,
link: host,
item: data.map((follower) => ({
title: `${follower.node.login} started following ${user}`,
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}`,
})),
};
};

46
routes/github/star.js Normal file
View File

@ -0,0 +1,46 @@
const axios = require('../../utils/axios');
const config = require('../../config');
module.exports = async (ctx) => {
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 axios({
method: 'post',
url,
headers: {
Authorization: `bearer ${config.github.access_token}`,
},
data: {
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 = {
title: `${user}/${repo}s stargazers`,
link: host,
item: data.map((follower) => ({
title: `${follower.node.login} starred ${user}/${repo}`,
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}`,
})),
};
};