fix(route): github recent issues (#9473)

This commit is contained in:
Tony
2022-04-05 08:38:18 -07:00
committed by GitHub
parent 521862793e
commit 5ee16451dc
2 changed files with 7 additions and 3 deletions

View File

@@ -5,17 +5,19 @@ 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; const state = ctx.params.state;
const labels = ctx.params.labels; 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 host = `https://github.com/${user}/${repo}/issues`;
const url = `https://api.github.com/repos/${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) { if (config.github && config.github.access_token) {
headers.Authorization = `token ${config.github.access_token}`; headers.Authorization = `token ${config.github.access_token}`;
} }
@@ -26,6 +28,8 @@ module.exports = async (ctx) => {
state, state,
labels, labels,
sort: 'created', sort: 'created',
direction: 'desc',
per_page: limit,
}), }),
headers, headers,
}); });
@@ -40,7 +44,7 @@ module.exports = async (ctx) => {
.map((item) => ({ .map((item) => ({
title: item.title, title: item.title,
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),
author: item.user.login, author: item.user.login,
link: `${host}/${item.number}`, link: `${host}/${item.number}`,
})), })),

View File

@@ -15,7 +15,7 @@ module.exports = async (ctx) => {
const host = `https://github.com/${user}/${repo}/pulls`; const host = `https://github.com/${user}/${repo}/pulls`;
const url = `https://api.github.com/repos/${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) { if (config.github && config.github.access_token) {
headers.Authorization = `token ${config.github.access_token}`; headers.Authorization = `token ${config.github.access_token}`;
} }