mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-04 02:58:08 +08:00
feat(route): add github all issue/pull comments (#12899)
This commit is contained in:
@@ -213,7 +213,7 @@ For instance, the `/github/topics/framework/l=php&o=desc&s=stars` route will gen
|
|||||||
|
|
||||||
### Issue / Pull Request comments
|
### Issue / Pull Request comments
|
||||||
|
|
||||||
<RouteEn author="TonyRL" example="/github/comments/DIYgod/RSSHub/8116" path="/github/comments/:user/:repo/:number" :paramsDesc="['User / Org name', 'Repo name', 'Issue or pull number']" radar="1" rssbud="1"/>
|
<RouteEn author="TonyRL FliegendeWurst" example="/github/comments/DIYgod/RSSHub/8116" path="/github/comments/:user/:repo/:number?" :paramsDesc="['User / Org name', 'Repo name', 'Issue or pull number (if omitted: all)']" radar="1" rssbud="1"/>
|
||||||
|
|
||||||
### Wiki History
|
### Wiki History
|
||||||
|
|
||||||
|
|||||||
@@ -308,7 +308,7 @@ GitHub 官方也提供了一些 RSS:
|
|||||||
|
|
||||||
### Issue / Pull Request 评论
|
### Issue / Pull Request 评论
|
||||||
|
|
||||||
<Route author="TonyRL" example="/github/comments/DIYgod/RSSHub/8116" path="/github/comments/:user/:repo/:number" :paramsDesc="['用户名', '仓库名', 'Issue 或 pull 编号']" radar="1" rssbud="1"/>
|
<Route author="TonyRL FliegendeWurst" example="/github/comments/DIYgod/RSSHub/8116" path="/github/comments/:user/:repo/:number?" :paramsDesc="['用户名', '仓库名', 'Issue 或 pull 编号']" radar="1" rssbud="1"/>
|
||||||
|
|
||||||
### Wiki 历史
|
### Wiki 历史
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,16 @@ const { parseDate } = require('@/utils/parse-date');
|
|||||||
const md = require('markdown-it')({
|
const md = require('markdown-it')({
|
||||||
html: true,
|
html: true,
|
||||||
});
|
});
|
||||||
|
const rootUrl = 'https://github.com';
|
||||||
const apiUrl = 'https://api.github.com';
|
const apiUrl = 'https://api.github.com';
|
||||||
const config = require('@/config').value;
|
const config = require('@/config').value;
|
||||||
const typeDict = {
|
const typeDict = {
|
||||||
issue: {
|
issue: {
|
||||||
title: 'Issue',
|
title: 'Issue',
|
||||||
},
|
},
|
||||||
|
issues: {
|
||||||
|
title: 'Issue',
|
||||||
|
},
|
||||||
pull: {
|
pull: {
|
||||||
title: 'Pull request',
|
title: 'Pull request',
|
||||||
},
|
},
|
||||||
@@ -17,8 +21,8 @@ const typeDict = {
|
|||||||
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 number = isNaN(parseInt(ctx.params.number)) ? 1 : parseInt(ctx.params.number);
|
const number = ctx.params.number && isNaN(parseInt(ctx.params.number)) ? 1 : parseInt(ctx.params.number);
|
||||||
const limit = ctx.query.limit ? parseInt(ctx.params.limit) : 100;
|
const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 100;
|
||||||
const headers =
|
const headers =
|
||||||
config.github && config.github.access_token
|
config.github && config.github.access_token
|
||||||
? {
|
? {
|
||||||
@@ -29,6 +33,64 @@ module.exports = async (ctx) => {
|
|||||||
Accept: 'application/vnd.github.v3+json',
|
Accept: 'application/vnd.github.v3+json',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (isNaN(number)) {
|
||||||
|
await allIssues(ctx, user, repo, limit, headers);
|
||||||
|
} else {
|
||||||
|
await singleIssue(ctx, user, repo, number, limit, headers);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
async function allIssues(ctx, user, repo, limit, headers) {
|
||||||
|
const response = await got(`${apiUrl}/repos/${user}/${repo}/issues/comments`, {
|
||||||
|
headers,
|
||||||
|
searchParams: {
|
||||||
|
sort: "updated",
|
||||||
|
direction: "desc",
|
||||||
|
per_page: limit,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const timeline = response.data;
|
||||||
|
|
||||||
|
const items = timeline.map((item) => {
|
||||||
|
const actor = item.actor?.login ?? item.user?.login ?? 'ghost';
|
||||||
|
const issueUrlParts = item.issue_url.split("/");
|
||||||
|
const issue = issueUrlParts[issueUrlParts.length - 1];
|
||||||
|
const urlParts = item.html_url.split("/");
|
||||||
|
const issueType = typeDict[urlParts[urlParts.length - 2]].title;
|
||||||
|
|
||||||
|
return {
|
||||||
|
title: `${actor} commented on ${user}/${repo}: ${issueType} #${issue}`,
|
||||||
|
author: actor,
|
||||||
|
pubDate: parseDate(item.created_at),
|
||||||
|
link: item.html_url,
|
||||||
|
description: item.body ? md.render(item.body) : null,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const rateLimit = {
|
||||||
|
limit: parseInt(response.headers['x-ratelimit-limit']),
|
||||||
|
remaining: parseInt(response.headers['x-ratelimit-remaining']),
|
||||||
|
reset: parseDate(parseInt(response.headers['x-ratelimit-reset']) * 1000),
|
||||||
|
resoure: response.headers['x-ratelimit-resource'],
|
||||||
|
used: parseInt(response.headers['x-ratelimit-used']),
|
||||||
|
};
|
||||||
|
|
||||||
|
ctx.state.data = {
|
||||||
|
title: `${user}/${repo}: Issue & Pull request comments`,
|
||||||
|
link: `${rootUrl}/${user}/${repo}`,
|
||||||
|
item: items,
|
||||||
|
};
|
||||||
|
|
||||||
|
ctx.state.json = {
|
||||||
|
title: `${user}/${repo}: Issue & Pull request comments`,
|
||||||
|
link: `${rootUrl}/${user}/${repo}`,
|
||||||
|
item: items,
|
||||||
|
rateLimit,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async function singleIssue(ctx, user, repo, number, limit, headers) {
|
||||||
const response = await got(`${apiUrl}/repos/${user}/${repo}/issues/${number}`, {
|
const response = await got(`${apiUrl}/repos/${user}/${repo}/issues/${number}`, {
|
||||||
headers,
|
headers,
|
||||||
});
|
});
|
||||||
@@ -124,4 +186,4 @@ module.exports = async (ctx) => {
|
|||||||
used: parseInt(response.headers['x-ratelimit-used']),
|
used: parseInt(response.headers['x-ratelimit-used']),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
'/branches/:user/:repo': ['max-arnold'],
|
'/branches/:user/:repo': ['max-arnold'],
|
||||||
'/comments/:user/:repo/:number': ['TonyRL'],
|
'/comments/:user/:repo/:number?': ['TonyRL', 'FliegendeWurst'],
|
||||||
'/contributors/:user/:repo/:order?/:anon?': ['zoenglinghou'],
|
'/contributors/:user/:repo/:order?/:anon?': ['zoenglinghou'],
|
||||||
'/file/:user/:repo/:branch/:filepath+': ['zengxs'],
|
'/file/:user/:repo/:branch/:filepath+': ['zengxs'],
|
||||||
'/gist/:gistId': ['TonyRL'],
|
'/gist/:gistId': ['TonyRL'],
|
||||||
|
|||||||
@@ -14,6 +14,12 @@ module.exports = {
|
|||||||
source: ['/:user/:repo/:type/:number'],
|
source: ['/:user/:repo/:type/:number'],
|
||||||
target: '/github/comments/:user/:repo/:number',
|
target: '/github/comments/:user/:repo/:number',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: 'Issue & Pull Request comments',
|
||||||
|
docs: 'https://docs.rsshub.app/programming.html#github',
|
||||||
|
source: ['/:user/:repo/:type'],
|
||||||
|
target: '/github/comments/:user/:repo',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: '仓库 Contributors',
|
title: '仓库 Contributors',
|
||||||
docs: 'https://docs.rsshub.app/programming.html#github',
|
docs: 'https://docs.rsshub.app/programming.html#github',
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
module.exports = function (router) {
|
module.exports = function (router) {
|
||||||
router.get('/branches/:user/:repo', require('./branches'));
|
router.get('/branches/:user/:repo', require('./branches'));
|
||||||
router.get('/comments/:user/:repo/:type/:number', require('./comments')); // deprecated
|
router.get('/comments/:user/:repo/:type/:number', require('./comments')); // deprecated
|
||||||
router.get('/comments/:user/:repo/:number', require('./comments'));
|
router.get('/comments/:user/:repo/:number?', require('./comments'));
|
||||||
router.get('/contributors/:user/:repo/:order?/:anon?', require('./contributors'));
|
router.get('/contributors/:user/:repo/:order?/:anon?', require('./contributors'));
|
||||||
router.get('/file/:user/:repo/:branch/:filepath+', require('./file'));
|
router.get('/file/:user/:repo/:branch/:filepath+', require('./file'));
|
||||||
router.get('/gist/:gistId', require('./gist'));
|
router.get('/gist/:gistId', require('./gist'));
|
||||||
|
|||||||
Reference in New Issue
Block a user