feat(route): Add GitHub Notification (#12197)

* Add GitHub notification

* add docs and radar.

* add parseDate.

* Apply suggestions from code review

* Update router.js

* Update maintainer.js

---------
This commit is contained in:
Zhiyuan Zheng
2023-03-30 21:07:34 +08:00
committed by GitHub
parent 715abc7c3d
commit 14199e1a31
6 changed files with 63 additions and 0 deletions

View File

@@ -219,6 +219,10 @@ For instance, the `/github/topics/framework/l=php&o=desc&s=stars` route will gen
<RouteEn author="TonyRL" example="/github/wiki/flutter/flutter/Roadmap" path="/github/wiki/:user/:repo/:page?" :paramsDesc="['User / Org name', 'Repo name', 'Page slug, can be found in URL, empty means Home']" radar="1" rssbud="1"/> <RouteEn author="TonyRL" example="/github/wiki/flutter/flutter/Roadmap" path="/github/wiki/:user/:repo/:page?" :paramsDesc="['User / Org name', 'Repo name', 'Page slug, can be found in URL, empty means Home']" radar="1" rssbud="1"/>
### Notifications
<RouteEn author="zhzy0077" example="/github/notifications" path="/github/notifications" radar="1" rssbud="1" selfhost="1"/>
## GitLab ## GitLab
### Explore ### Explore

View File

@@ -314,6 +314,10 @@ GitHub 官方也提供了一些 RSS:
<Route author="TonyRL" example="/github/wiki/flutter/flutter/Roadmap" path="/github/wiki/:user/:repo/:page?" :paramsDesc="['用户名', '仓库名', '页面 Slug可在 URL 中找到,留空表示主页']" radar="1" rssbud="1"/> <Route author="TonyRL" example="/github/wiki/flutter/flutter/Roadmap" path="/github/wiki/:user/:repo/:page?" :paramsDesc="['用户名', '仓库名', '页面 Slug可在 URL 中找到,留空表示主页']" radar="1" rssbud="1"/>
### 通知
<Route author="zhzy0077" example="/github/notifications" path="/github/notifications" radar="1" rssbud="1" selfhost="1"/>
## GitLab ## GitLab
### Explore ### Explore

View File

@@ -4,6 +4,7 @@ module.exports = {
'/contributors/:user/:repo/:order?/:anon?': ['zoenglinghou'], '/contributors/:user/:repo/:order?/:anon?': ['zoenglinghou'],
'/file/:user/:repo/:branch/:filepath+': ['zengxs'], '/file/:user/:repo/:branch/:filepath+': ['zengxs'],
'/issue/:user/:repo/:state?/:labels?': ['HenryQW', 'AndreyMZ'], '/issue/:user/:repo/:state?/:labels?': ['HenryQW', 'AndreyMZ'],
'/notifications': ['zhzy0077'],
'/pull/:user/:repo/:state?': ['hashman', 'TonyRL'], '/pull/:user/:repo/:state?': ['hashman', 'TonyRL'],
'/repos/:user': ['DIYgod'], '/repos/:user': ['DIYgod'],
'/search/:query/:sort?/:order?': ['LogicJake'], '/search/:query/:sort?/:order?': ['LogicJake'],

View File

@@ -0,0 +1,47 @@
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
const apiUrl = 'https://api.github.com';
const config = require('@/config').value;
module.exports = async (ctx) => {
if (!config.github || !config.github.access_token) {
throw Error('GitHub trending RSS is disabled due to the lack of <a href="https://docs.rsshub.app/install/#pei-zhi-bu-fen-rss-mo-kuai-pei-zhi">relevant config</a>');
}
const headers = {
Accept: 'application/vnd.github.v3+json',
Authorization: `Bearer ${config.github.access_token}`,
'X-GitHub-Api-Version': '2022-11-28',
};
const response = await got(`${apiUrl}/notifications`, {
headers,
});
const notifications = response.data;
const items = notifications.map((item) => ({
title: item.subject.title,
description: item.subject.title,
pubDate: parseDate(item.updated_at), // item.updated_at follows ISO 8601.
guid: item.id,
link: item.subject.url,
}));
ctx.state.data = {
title: 'Github Notifications',
link: 'https://github.com/notifications',
item: items,
};
ctx.state.json = {
title: 'Github Notifications',
item: notifications,
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']),
},
};
};

View File

@@ -80,6 +80,12 @@ module.exports = {
source: ['/:user/:repo/wiki/:page/_history', '/:user/:repo/wiki/:page', '/:user/:repo/wiki/_history', '/:user/:repo/wiki'], source: ['/:user/:repo/wiki/:page/_history', '/:user/:repo/wiki/:page', '/:user/:repo/wiki/_history', '/:user/:repo/wiki'],
target: '/github/wiki/:user/:repo/:page', target: '/github/wiki/:user/:repo/:page',
}, },
{
title: 'Notifications 通知',
docs: 'https://docs.rsshub.app/programming.html#github',
source: ['/notifications'],
target: '/github/notifications',
},
], ],
}, },
}; };

View File

@@ -5,6 +5,7 @@ module.exports = function (router) {
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('/issue/:user/:repo/:state?/:labels?', require('./issue')); router.get('/issue/:user/:repo/:state?/:labels?', require('./issue'));
router.get('/notifications', require('./notifications'));
router.get('/pull/:user/:repo/:state?/:labels?', require('./pulls')); router.get('/pull/:user/:repo/:state?/:labels?', require('./pulls'));
router.get('/repos/:user', require('./repos')); router.get('/repos/:user', require('./repos'));
router.get('/search/:query/:sort?/:order?', require('./search')); router.get('/search/:query/:sort?/:order?', require('./search'));