mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-02 18:18:06 +08:00
feat(route): add github issues/pull comments (#8128)
This commit is contained in:
@@ -113,6 +113,10 @@ For instance, the `/github/topics/framework/l=php&o=desc&s=stars` route will gen
|
||||
|
||||
<RouteEn author="zoenglinghou" example="/github/contributors/DIYgod/RSSHub" path="/github/contributors/:user/:repo/:order?/:anon?" :paramsDesc="['User name','Repo name','Sort order by commit numbers, desc and asc (descending by default)','Show anonymous users. Defaults to no, use any values for yes.']" radar="1" rssbud="1"/>
|
||||
|
||||
### Issues / Pull Requests comments
|
||||
|
||||
<RouteEn author="TonyRL" example="/github/comments/DIYgod/RSSHub/issues/8116" path="/github/comments/:user/:repo/:type/:number" :paramsDesc="['User / Org name', 'Repo name', 'Type, `issues` or `pull`', 'Number']"/>
|
||||
|
||||
## GitLab
|
||||
|
||||
### Explore
|
||||
|
||||
@@ -191,6 +191,10 @@ GitHub 官方也提供了一些 RSS:
|
||||
|
||||
<Route author="zoenglinghou" example="/github/contributors/DIYgod/RSSHub" path="/github/contributors/:user/:repo/:order?/:anon?" :paramsDesc="['用户名', '仓库名', 'Commit 数量排序顺序,desc和asc(默认desc降序)', '是否包括匿名用户,默认不包含,任意值包含匿名用户']" radar="1" rssbud="1"/>
|
||||
|
||||
### Issues / Pull Requests 评论
|
||||
|
||||
<Route author="TonyRL" example="/github/comments/DIYgod/RSSHub/issues/8116" path="/github/comments/:user/:repo/:type/:number" :paramsDesc="['用户名', '仓库', '类型,`issues`或`pull`', '编号']"/>
|
||||
|
||||
## GitLab
|
||||
|
||||
### Explore
|
||||
|
||||
64
lib/v2/github/comments.js
Normal file
64
lib/v2/github/comments.js
Normal file
@@ -0,0 +1,64 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const { art } = require('@/utils/render');
|
||||
const path = require('path');
|
||||
|
||||
const typeDict = {
|
||||
issues: {
|
||||
typeRootUrl: '/issues',
|
||||
},
|
||||
pull: {
|
||||
typeRootUrl: '/pulls',
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const user = ctx.params.user;
|
||||
const repo = ctx.params.repo;
|
||||
const type = ctx.params.type ?? 'issues';
|
||||
const number = ctx.params.number ?? '1';
|
||||
|
||||
const rootUrl = 'https://github.com';
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: `${rootUrl}/${user}/${repo}/${type}/${number}`,
|
||||
header: {
|
||||
Referer: `${rootUrl}/${user}/${repo}${typeDict[type].typeRootUrl}`,
|
||||
},
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const list = $('div.timeline-comment-group.js-minimizable-comment-group.js-targetable-element.TimelineItem-body.my-0')
|
||||
.map((_, item) => {
|
||||
item = $(item);
|
||||
return {
|
||||
title: item.find('div.edit-comment-hide').text().trim(),
|
||||
description: art(path.join(__dirname, 'templates/comments-description.art'), {
|
||||
desc: item.find('div.edit-comment-hide').html(),
|
||||
}),
|
||||
author: item.find('strong.css-truncate').text().trim(),
|
||||
pubDate: parseDate(item.find('relative-time.no-wrap').attr('datetime')),
|
||||
link: `${rootUrl}/${user}/${repo}/${type}/${number}` + item.find('a.Link--secondary.js-timestamp').attr('href'),
|
||||
};
|
||||
})
|
||||
.get();
|
||||
|
||||
const items = await Promise.all(list && list.map((item) => ctx.cache.tryGet(item.link, () => item)));
|
||||
|
||||
ctx.state.data = {
|
||||
title: $('span.author.flex-self-stretch').text().trim() + '/' + $('strong.mr-2.flex-self-stretch').text().trim() + `: ${type} #${number}`,
|
||||
description: $('span.author.flex-self-stretch').text().trim() + '/' + $('strong.mr-2.flex-self-stretch').text().trim() + ': ' + $('h1.gh-header-title.mb-2.lh-condensed.f1.mr-0.flex-auto.break-word').text().trim(),
|
||||
link: `${rootUrl}/${user}/${repo}/${type}/${number}`,
|
||||
item: items,
|
||||
};
|
||||
|
||||
ctx.state.json = {
|
||||
title: $('span.author.flex-self-stretch').text().trim() + '/' + $('strong.mr-2.flex-self-stretch').text().trim() + `: ${type} #${number}`,
|
||||
description: $('span.author.flex-self-stretch').text().trim() + '/' + $('strong.mr-2.flex-self-stretch').text().trim() + ': ' + $('h1.gh-header-title.mb-2.lh-condensed.f1.mr-0.flex-auto.break-word').text().trim(),
|
||||
link: `${rootUrl}/${user}/${repo}/${type}/${number}`,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
3
lib/v2/github/maintainer.js
Normal file
3
lib/v2/github/maintainer.js
Normal file
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
'/comments/:user/:repo/:type/:number': ['TonyRL'],
|
||||
};
|
||||
13
lib/v2/github/radar.js
Normal file
13
lib/v2/github/radar.js
Normal file
@@ -0,0 +1,13 @@
|
||||
module.exports = {
|
||||
'github.com': {
|
||||
_name: 'GitHub',
|
||||
'.': [
|
||||
{
|
||||
title: 'Issues / Pull Requests 评论',
|
||||
docs: 'https://docs.rsshub.app/programming.html#github',
|
||||
source: ['/:user/:repo/:type/:number'],
|
||||
target: '/github/comments/:user/:repo/:type/:number',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
3
lib/v2/github/router.js
Normal file
3
lib/v2/github/router.js
Normal file
@@ -0,0 +1,3 @@
|
||||
module.exports = function (router) {
|
||||
router.get('/comments/:user/:repo/:type/:number', require('./comments'));
|
||||
};
|
||||
1
lib/v2/github/templates/comments-description.art
Normal file
1
lib/v2/github/templates/comments-description.art
Normal file
@@ -0,0 +1 @@
|
||||
{{@ desc }}
|
||||
Reference in New Issue
Block a user