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

@@ -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,
})),
};
};