feat(route): gist commits (#12470)

This commit is contained in:
Tony
2023-05-07 20:51:53 -06:00
committed by GitHub
parent 64948e00d2
commit 61a303a1de
6 changed files with 53 additions and 0 deletions

View File

@@ -223,6 +223,10 @@ For instance, the `/github/topics/framework/l=php&o=desc&s=stars` route will gen
<RouteEn author="zhzy0077" example="/github/notifications" path="/github/notifications" radar="1" rssbud="1" selfhost="1"/>
### Gist Commits
<RouteEn author="TonyRL" example="/github/gist/d2c152bb7179d07015f336b1a0582679" path="/github/gist/:gistId" :paramsDesc="['Gist ID']" radar="1" rssbud="1"/>
## GitLab
### Explore

View File

@@ -318,6 +318,10 @@ GitHub 官方也提供了一些 RSS:
<Route author="zhzy0077" example="/github/notifications" path="/github/notifications" radar="1" rssbud="1" selfhost="1"/>
### Gist Commits
<Route author="TonyRL" example="/github/gist/d2c152bb7179d07015f336b1a0582679" path="/github/gist/:gistId" :paramsDesc="['Gist ID']" radar="1" rssbud="1"/>
## GitLab
### Explore

35
lib/v2/github/gist.js Normal file
View File

@@ -0,0 +1,35 @@
const got = require('@/utils/got');
const config = require('@/config').value;
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const { gistId } = ctx.params;
const headers = { Accept: 'application/vnd.github.v3+json' };
if (config.github && config.github.access_token) {
headers.Authorization = `Bearer ${config.github.access_token}`;
}
const host = 'https://gist.github.com';
const apiUrl = `https://api.github.com/gists/${gistId}`;
const { data: response } = await got(apiUrl, {
headers,
});
const items = response.history.map((item, index) => ({
title: `${item.user.login} ${index === response.history.length - 1 ? 'created' : 'revised'} this gist`,
description: item.change_status.total ? `${item.change_status.additions} additions and ${item.change_status.deletions} deletions` : null,
link: `${host}/${gistId}/${item.version}`,
pubDate: parseDate(item.committed_at), // e.g. 2022-09-02T11:09:56Z
}));
ctx.state.data = {
allowEmpty: true,
title: `${response.owner.login} / ${Object.values(response.files)[0].filename}`,
description: response.description,
image: response.owner.avatar_url,
link: `${response.html_url}/revisions`,
item: items,
};
};

View File

@@ -3,6 +3,7 @@ module.exports = {
'/comments/:user/:repo/:number': ['TonyRL'],
'/contributors/:user/:repo/:order?/:anon?': ['zoenglinghou'],
'/file/:user/:repo/:branch/:filepath+': ['zengxs'],
'/gist/:gistId': ['TonyRL'],
'/issue/:user/:repo/:state?/:labels?': ['HenryQW', 'AndreyMZ'],
'/notifications': ['zhzy0077'],
'/pull/:user/:repo/:state?': ['hashman', 'TonyRL'],

View File

@@ -87,5 +87,13 @@ module.exports = {
target: '/github/notifications',
},
],
gist: [
{
title: 'Gist Commits',
docs: 'https://docs.rsshub.app/programming.html#github',
source: ['/:owner/:gistId/revisions', '/:owner/:gistId/stargazers', '/:owner/:gistId/forks', '/:owner/:gistId'],
target: '/github/gist/:gistId',
},
],
},
};

View File

@@ -4,6 +4,7 @@ module.exports = function (router) {
router.get('/comments/:user/:repo/:number', require('./comments'));
router.get('/contributors/:user/:repo/:order?/:anon?', require('./contributors'));
router.get('/file/:user/:repo/:branch/:filepath+', require('./file'));
router.get('/gist/:gistId', require('./gist'));
router.get('/issue/:user/:repo/:state?/:labels?', require('./issue'));
router.get('/notifications', require('./notifications'));
router.get('/pull/:user/:repo/:state?/:labels?', require('./pulls'));