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

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

View File

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