fix(route): github pull requests (#9341)

* fix(route): github pull

* fix: typo
This commit is contained in:
Tony
2022-03-19 03:14:53 +08:00
committed by GitHub
parent 41910802f2
commit 96d392fec9
5 changed files with 11 additions and 7 deletions

View File

@@ -141,7 +141,7 @@ For instance, the `/github/topics/framework/l=php&o=desc&s=stars` route will gen
### Repo Pull Requests ### Repo Pull Requests
<RouteEn author="hashman" example="/github/pull/DIYgod/RSSHub" path="/github/pull/:user/:repo" :paramsDesc="['User name', 'Repo name']" radar="1" rssbud="1"/> <RouteEn author="hashman TonyRL" example="/github/pull/DIYgod/RSSHub" path="/github/pull/:user/:repo/:state?" :paramsDesc="['User name', 'Repo name', 'the state of pull requests. Can be either `open`, `closed`, or `all`. Default: `open`.']" radar="1" rssbud="1"/>
### User Followers ### User Followers

View File

@@ -219,7 +219,7 @@ GitHub 官方也提供了一些 RSS:
### 仓库 Pull Requests ### 仓库 Pull Requests
<Route author="hashman" example="/github/pull/DIYgod/RSSHub" path="/github/pull/:user/:repo" :paramsDesc="['用户名', '仓库名']" radar="1" rssbud="1"/> <Route author="hashman" example="/github/pull/DIYgod/RSSHub" path="/github/pull/:user/:repo/:state?" :paramsDesc="['用户名', '仓库名', 'pull request 状态,`open`,`closed``all`,默认为`open`']" radar="1" rssbud="1"/>
### 用户 Followers ### 用户 Followers

View File

@@ -4,7 +4,7 @@ module.exports = {
'/contributors/:user/:repo/:order?/:anon?': ['zoenglinghou'], '/contributors/:user/:repo/:order?/:anon?': ['zoenglinghou'],
'/file/:user/:repo/:branch/:filepath+': ['zengxs'], '/file/:user/:repo/:branch/:filepath+': ['zengxs'],
'/issue/:user/:repo/:state?/:labels?': ['HenryQW', 'AndreyMZ'], '/issue/:user/:repo/:state?/:labels?': ['HenryQW', 'AndreyMZ'],
'/pull/:user/:repo': ['hashman'], '/pull/:user/:repo/:state?': ['hashman', 'TonyRL'],
'/repos/:user': ['DIYgod'], '/repos/:user': ['DIYgod'],
'/search/:query/:sort?/:order?': ['LogicJake'], '/search/:query/:sort?/:order?': ['LogicJake'],
'/starred_repos/:user': ['LanceZhu'], '/starred_repos/:user': ['LanceZhu'],

View File

@@ -5,13 +5,14 @@ const md = require('markdown-it')({
linkify: true, linkify: true,
}); });
const queryString = require('query-string'); const queryString = require('query-string');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => { module.exports = async (ctx) => {
const user = ctx.params.user; const user = ctx.params.user;
const repo = ctx.params.repo; const repo = ctx.params.repo;
const state = ctx.params.state ?? 'open';
const host = `https://github.com/${user}/${repo}/pulls`; const host = `https://github.com/${user}/${repo}/pulls`;
const link = `https://github.com/${user}/${repo}/pull`;
const url = `https://api.github.com/repos/${user}/${repo}/pulls`; const url = `https://api.github.com/repos/${user}/${repo}/pulls`;
const headers = {}; const headers = {};
@@ -22,7 +23,10 @@ module.exports = async (ctx) => {
method: 'get', method: 'get',
url, url,
searchParams: queryString.stringify({ searchParams: queryString.stringify({
state,
sort: 'created', sort: 'created',
direction: 'desc',
per_page: ctx.query.limit ? (parseInt(ctx.query.limit) <= 100 ? parseInt(ctx.query.limit) : 100) : 100,
}), }),
headers, headers,
}); });
@@ -36,8 +40,8 @@ module.exports = async (ctx) => {
title: item.title, title: item.title,
author: item.user.login, author: item.user.login,
description: item.body ? md.render(item.body) : 'No description', description: item.body ? md.render(item.body) : 'No description',
pubDate: new Date(item.created_at).toUTCString(), pubDate: parseDate(item.created_at),
link: `${link}/${item.number}`, link: item.html_url,
})), })),
}; };
}; };

View File

@@ -4,7 +4,7 @@ module.exports = function (router) {
router.get('/contributors/:user/:repo/:order?/:anon?', require('./contributors')); router.get('/contributors/:user/:repo/:order?/:anon?', require('./contributors'));
router.get('/file/:user/:repo/:branch/:filepath+', require('./file')); router.get('/file/:user/:repo/:branch/:filepath+', require('./file'));
router.get('/issue/:user/:repo/:state?/:labels?', require('./issue')); router.get('/issue/:user/:repo/:state?/:labels?', require('./issue'));
router.get('/pull/:user/:repo', require('./pulls')); router.get('/pull/:user/:repo/:state?', require('./pulls'));
router.get('/repos/:user', require('./repos')); router.get('/repos/:user', require('./repos'));
router.get('/search/:query/:sort?/:order?', require('./search')); router.get('/search/:query/:sort?/:order?', require('./search'));
router.get('/starred_repos/:user', require('./starred_repos')); router.get('/starred_repos/:user', require('./starred_repos'));