From 6410c2f8765b416558a7f21d3fc8f4241f7a3868 Mon Sep 17 00:00:00 2001 From: Hash Lin Date: Tue, 19 Feb 2019 11:30:13 +0800 Subject: [PATCH] add Github Pull requests rss feed (#1549) add Github pull requests rss feed with `github/pull/{user}/{repo}` this pattern --- docs/README.md | 2 ++ lib/router.js | 1 + lib/routes/github/pulls.js | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 lib/routes/github/pulls.js diff --git a/docs/README.md b/docs/README.md index c15f5b7b47..3c17f58639 100644 --- a/docs/README.md +++ b/docs/README.md @@ -682,6 +682,8 @@ GitHub 官方也提供了一些 RSS: + + diff --git a/lib/router.js b/lib/router.js index 4e857ea003..87561abb56 100644 --- a/lib/router.js +++ b/lib/router.js @@ -321,6 +321,7 @@ if (config.github && config.github.access_token) { } router.get('/github/trending/:since/:language?', require('./routes/github/trending')); router.get('/github/issue/:user/:repo', require('./routes/github/issue')); +router.get('/github/pull/:user/:repo', require('./routes/github/pulls')); router.get('/github/user/followers/:user', require('./routes/github/follower')); router.get('/github/stars/:user/:repo', require('./routes/github/star')); router.get('/github/search/:query/:sort?/:order?', require('./routes/github/search')); diff --git a/lib/routes/github/pulls.js b/lib/routes/github/pulls.js new file mode 100644 index 0000000000..d615b2bc1a --- /dev/null +++ b/lib/routes/github/pulls.js @@ -0,0 +1,34 @@ +const axios = require('../../utils/axios'); +const config = require('../../config'); +const md = require('markdown-it')({ + html: true, +}); + +module.exports = async (ctx) => { + const user = ctx.params.user; + const repo = ctx.params.repo; + + const host = `https://github.com/${user}/${repo}/pull`; + const url = `https://api.github.com/repos/${user}/${repo}/pulls`; + + const response = await axios({ + method: 'get', + url, + params: { + sort: 'created', + access_token: config.github.access_token, + }, + }); + const data = response.data; + + ctx.state.data = { + title: `${user}/${repo} Pull requests`, + link: host, + item: data.map((item) => ({ + title: item.title, + description: md.render(item.body) || 'No description', + pubDate: new Date(item.created_at).toUTCString(), + link: `${host}/${item.number}`, + })), + }; +};