From 5ee16451dcd9abd2a1d5a9c7c8a3b905fc62e50c Mon Sep 17 00:00:00 2001 From: Tony Date: Tue, 5 Apr 2022 08:38:18 -0700 Subject: [PATCH] fix(route): github recent issues (#9473) --- lib/v2/github/issue.js | 8 ++++++-- lib/v2/github/pulls.js | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/v2/github/issue.js b/lib/v2/github/issue.js index 8ca937394..d3009f6c5 100644 --- a/lib/v2/github/issue.js +++ b/lib/v2/github/issue.js @@ -5,17 +5,19 @@ 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; const labels = ctx.params.labels; + const limit = ctx.query.limit ? (parseInt(ctx.query.limit) > 100 ? 100 : parseInt(ctx.query.limit)) : 100; const host = `https://github.com/${user}/${repo}/issues`; const url = `https://api.github.com/repos/${user}/${repo}/issues`; - const headers = {}; + const headers = { Accept: 'application/vnd.github.v3+json' }; if (config.github && config.github.access_token) { headers.Authorization = `token ${config.github.access_token}`; } @@ -26,6 +28,8 @@ module.exports = async (ctx) => { state, labels, sort: 'created', + direction: 'desc', + per_page: limit, }), headers, }); @@ -40,7 +44,7 @@ module.exports = async (ctx) => { .map((item) => ({ title: item.title, description: item.body ? md.render(item.body) : 'No description', - pubDate: new Date(item.created_at).toUTCString(), + pubDate: parseDate(item.created_at), author: item.user.login, link: `${host}/${item.number}`, })), diff --git a/lib/v2/github/pulls.js b/lib/v2/github/pulls.js index ceac91e6a..0184b09f5 100644 --- a/lib/v2/github/pulls.js +++ b/lib/v2/github/pulls.js @@ -15,7 +15,7 @@ module.exports = async (ctx) => { const host = `https://github.com/${user}/${repo}/pulls`; const url = `https://api.github.com/repos/${user}/${repo}/pulls`; - const headers = {}; + const headers = { Accept: 'application/vnd.github.v3+json' }; if (config.github && config.github.access_token) { headers.Authorization = `token ${config.github.access_token}`; }