From 03481653fa66d111f8121bf5372d26fbe491d1f7 Mon Sep 17 00:00:00 2001 From: Fatpandac <1779196284@qq.com> Date: Thu, 3 Feb 2022 00:37:01 +0800 Subject: [PATCH] fix(route): fix GitHub route parameter conflict at trending.js and refactor to V2 (#8923) * Fix(route): fix route parameter conflict at trending.js and change to V2 * Fix(route): modify the judgment condition of language parameter * Fix(docs): Update docs/programming.md Co-authored-by: Tony * Fix(docs): Update docs/en/programming.md Co-authored-by: Tony * fix(docs/route): add author and sort routes * Fix(route): Update docs/en/programming.md Co-authored-by: Tony * Fix(route): sort routes Co-authored-by: Tony --- docs/en/programming.md | 2 +- docs/programming.md | 2 +- lib/radar-rules.js | 71 ---------------------- lib/router.js | 14 ----- lib/{routes => v2}/github/branches.js | 0 lib/{routes => v2}/github/contributors.js | 0 lib/{routes => v2}/github/file.js | 0 lib/{routes => v2}/github/follower.js | 0 lib/{routes => v2}/github/issue.js | 0 lib/v2/github/maintainer.js | 12 ++++ lib/{routes => v2}/github/pulls.js | 0 lib/v2/github/radar.js | 66 ++++++++++++++++++++ lib/{routes => v2}/github/repos.js | 0 lib/v2/github/router.js | 12 ++++ lib/{routes => v2}/github/search.js | 0 lib/{routes => v2}/github/star.js | 0 lib/{routes => v2}/github/starred_repos.js | 0 lib/{routes => v2}/github/topic.js | 0 lib/{routes => v2}/github/trending.js | 6 +- 19 files changed, 95 insertions(+), 90 deletions(-) rename lib/{routes => v2}/github/branches.js (100%) rename lib/{routes => v2}/github/contributors.js (100%) rename lib/{routes => v2}/github/file.js (100%) rename lib/{routes => v2}/github/follower.js (100%) rename lib/{routes => v2}/github/issue.js (100%) rename lib/{routes => v2}/github/pulls.js (100%) rename lib/{routes => v2}/github/repos.js (100%) rename lib/{routes => v2}/github/search.js (100%) rename lib/{routes => v2}/github/star.js (100%) rename lib/{routes => v2}/github/starred_repos.js (100%) rename lib/{routes => v2}/github/topic.js (100%) rename lib/{routes => v2}/github/trending.js (87%) diff --git a/docs/en/programming.md b/docs/en/programming.md index c33970da1c..e15a9d5247 100644 --- a/docs/en/programming.md +++ b/docs/en/programming.md @@ -98,7 +98,7 @@ GitHub provides some official RSS feeds: ### Trending - + ### Topics diff --git a/docs/programming.md b/docs/programming.md index fee085f240..9fbcfd8824 100644 --- a/docs/programming.md +++ b/docs/programming.md @@ -175,7 +175,7 @@ GitHub 官方也提供了一些 RSS: ### Trending - + ### Topics diff --git a/lib/radar-rules.js b/lib/radar-rules.js index d139a277f4..c4df9c87b1 100644 --- a/lib/radar-rules.js +++ b/lib/radar-rules.js @@ -243,77 +243,6 @@ module.exports = { }, ], }, - 'github.com': { - _name: 'GitHub', - '.': [ - { - title: '用户仓库', - docs: 'https://docs.rsshub.app/programming.html#github', - source: '/:user', - target: '/github/repos/:user', - }, - { - title: '用户 Followers', - docs: 'https://docs.rsshub.app/programming.html#github', - source: '/:user', - target: '/github/user/followers/:user', - }, - { - title: 'Trending', - docs: 'https://docs.rsshub.app/programming.html#github', - source: '/trending', - target: '/github/trending/:since', - }, - { - title: 'Trending', - docs: 'https://docs.rsshub.app/programming.html#github', - source: '/topics', - target: '/github/topics/:name/:qs?', - }, - { - title: '仓库 Issue', - docs: 'https://docs.rsshub.app/programming.html#github', - source: ['/:user/:repo/issues', '/:user/:repo/issues/:id', '/:user/:repo'], - target: '/github/issue/:user/:repo', - }, - { - title: '仓库 Pull Requests', - docs: 'https://docs.rsshub.app/programming.html#github', - source: ['/:user/:repo/pulls', '/:user/:repo/pulls/:id', '/:user/:repo'], - target: '/github/pull/:user/:repo', - }, - { - title: '仓库 Stars', - docs: 'https://docs.rsshub.app/programming.html#github', - source: ['/:user/:repo/stargazers', '/:user/:repo'], - target: '/github/stars/:user/:repo', - }, - { - title: '仓库 Branches', - docs: 'https://docs.rsshub.app/programming.html#github', - source: ['/:user/:repo/branches', '/:user/:repo'], - target: '/github/branches/:user/:repo', - }, - { - title: '文件 Commits', - docs: 'https://docs.rsshub.app/programming.html#github', - source: '/:user/:repo/blob/:branch/*filepath', - target: '/github/file/:user/:repo/:branch/:filepath', - }, - { - title: '用户 Starred Repositories', - docs: 'https://docs.rsshub.app/programming.html#github', - source: '/:user', - target: '/github/starred_repos/:user', - }, - { - title: '仓库 Contributors', - docs: 'https://docs.rsshub.app/programming.html#github', - source: ['/:user/:repo/graphs/contributors', '/:user/:repo'], - target: '/github/contributors/:user/:repo', - }, - ], - }, 'zhihu.com': { _name: '知乎', www: [ diff --git a/lib/router.js b/lib/router.js index 0da6266b4c..923fe3e958 100644 --- a/lib/router.js +++ b/lib/router.js @@ -245,20 +245,6 @@ router.get('/v2ex/tab/:tabid', lazyloadRouteHandler('./routes/v2ex/tab')); // readhub router.get('/readhub/category/:category', lazyloadRouteHandler('./routes/readhub/category')); -// GitHub -router.get('/github/repos/:user', lazyloadRouteHandler('./routes/github/repos')); -router.get('/github/trending/:since/:language?/:spoken_language?', lazyloadRouteHandler('./routes/github/trending')); -router.get('/github/issue/:user/:repo/:state?/:labels?', lazyloadRouteHandler('./routes/github/issue')); -router.get('/github/pull/:user/:repo', lazyloadRouteHandler('./routes/github/pulls')); -router.get('/github/user/followers/:user', lazyloadRouteHandler('./routes/github/follower')); -router.get('/github/stars/:user/:repo', lazyloadRouteHandler('./routes/github/star')); -router.get('/github/search/:query/:sort?/:order?', lazyloadRouteHandler('./routes/github/search')); -router.get('/github/branches/:user/:repo', lazyloadRouteHandler('./routes/github/branches')); -router.get('/github/file/:user/:repo/:branch/:filepath+', lazyloadRouteHandler('./routes/github/file')); -router.get('/github/starred_repos/:user', lazyloadRouteHandler('./routes/github/starred_repos')); -router.get('/github/contributors/:user/:repo/:order?/:anon?', lazyloadRouteHandler('./routes/github/contributors')); -router.get('/github/topics/:name/:qs?', lazyloadRouteHandler('./routes/github/topic')); - // f-droid router.get('/fdroid/apprelease/:app', lazyloadRouteHandler('./routes/fdroid/apprelease')); diff --git a/lib/routes/github/branches.js b/lib/v2/github/branches.js similarity index 100% rename from lib/routes/github/branches.js rename to lib/v2/github/branches.js diff --git a/lib/routes/github/contributors.js b/lib/v2/github/contributors.js similarity index 100% rename from lib/routes/github/contributors.js rename to lib/v2/github/contributors.js diff --git a/lib/routes/github/file.js b/lib/v2/github/file.js similarity index 100% rename from lib/routes/github/file.js rename to lib/v2/github/file.js diff --git a/lib/routes/github/follower.js b/lib/v2/github/follower.js similarity index 100% rename from lib/routes/github/follower.js rename to lib/v2/github/follower.js diff --git a/lib/routes/github/issue.js b/lib/v2/github/issue.js similarity index 100% rename from lib/routes/github/issue.js rename to lib/v2/github/issue.js diff --git a/lib/v2/github/maintainer.js b/lib/v2/github/maintainer.js index 318341638a..87e1db702e 100644 --- a/lib/v2/github/maintainer.js +++ b/lib/v2/github/maintainer.js @@ -1,3 +1,15 @@ module.exports = { + '/branches/:user/:repo': ['max-arnold'], '/comments/:user/:repo/:type/:number': ['TonyRL'], + '/contributors/:user/:repo/:order?/:anon?': ['zoenglinghou'], + '/file/:user/:repo/:branch/:filepath+': ['zengxs'], + '/issue/:user/:repo/:state?/:labels?': ['HenryQW', 'AndreyMZ'], + '/pull/:user/:repo': ['hashman'], + '/repos/:user': ['DIYgod'], + '/search/:query/:sort?/:order?': ['LogicJake'], + '/starred_repos/:user': ['LanceZhu'], + '/stars/:user/:repo': ['HenryQW'], + '/topics/:name/:qs?': ['queensferryme'], + '/trending/:since/:language?/:spoken_language?': ['DIYgod'], + '/user/followers/:user': ['HenryQW'], }; diff --git a/lib/routes/github/pulls.js b/lib/v2/github/pulls.js similarity index 100% rename from lib/routes/github/pulls.js rename to lib/v2/github/pulls.js diff --git a/lib/v2/github/radar.js b/lib/v2/github/radar.js index 12d3ec05ce..2adcf8bb79 100644 --- a/lib/v2/github/radar.js +++ b/lib/v2/github/radar.js @@ -8,6 +8,72 @@ module.exports = { source: ['/:user/:repo/:type/:number'], target: '/github/comments/:user/:repo/:type/:number', }, + { + title: '用户仓库', + docs: 'https://docs.rsshub.app/programming.html#github', + source: '/:user', + target: '/github/repos/:user', + }, + { + title: '用户 Followers', + docs: 'https://docs.rsshub.app/programming.html#github', + source: '/:user', + target: '/github/user/followers/:user', + }, + { + title: 'Trending', + docs: 'https://docs.rsshub.app/programming.html#github', + source: '/trending', + target: '/github/trending/:since', + }, + { + title: 'Trending', + docs: 'https://docs.rsshub.app/programming.html#github', + source: '/topics', + target: '/github/topics/:name/:qs?', + }, + { + title: '仓库 Issue', + docs: 'https://docs.rsshub.app/programming.html#github', + source: ['/:user/:repo/issues', '/:user/:repo/issues/:id', '/:user/:repo'], + target: '/github/issue/:user/:repo', + }, + { + title: '仓库 Pull Requests', + docs: 'https://docs.rsshub.app/programming.html#github', + source: ['/:user/:repo/pulls', '/:user/:repo/pulls/:id', '/:user/:repo'], + target: '/github/pull/:user/:repo', + }, + { + title: '仓库 Stars', + docs: 'https://docs.rsshub.app/programming.html#github', + source: ['/:user/:repo/stargazers', '/:user/:repo'], + target: '/github/stars/:user/:repo', + }, + { + title: '仓库 Branches', + docs: 'https://docs.rsshub.app/programming.html#github', + source: ['/:user/:repo/branches', '/:user/:repo'], + target: '/github/branches/:user/:repo', + }, + { + title: '文件 Commits', + docs: 'https://docs.rsshub.app/programming.html#github', + source: '/:user/:repo/blob/:branch/*filepath', + target: '/github/file/:user/:repo/:branch/:filepath', + }, + { + title: '用户 Starred Repositories', + docs: 'https://docs.rsshub.app/programming.html#github', + source: '/:user', + target: '/github/starred_repos/:user', + }, + { + title: '仓库 Contributors', + docs: 'https://docs.rsshub.app/programming.html#github', + source: ['/:user/:repo/graphs/contributors', '/:user/:repo'], + target: '/github/contributors/:user/:repo', + }, ], }, }; diff --git a/lib/routes/github/repos.js b/lib/v2/github/repos.js similarity index 100% rename from lib/routes/github/repos.js rename to lib/v2/github/repos.js diff --git a/lib/v2/github/router.js b/lib/v2/github/router.js index dad53ce628..1dda4be8c3 100644 --- a/lib/v2/github/router.js +++ b/lib/v2/github/router.js @@ -1,3 +1,15 @@ module.exports = function (router) { + router.get('/branches/:user/:repo', require('./branches')); router.get('/comments/:user/:repo/:type/:number', require('./comments')); + router.get('/contributors/:user/:repo/:order?/:anon?', require('./contributors')); + router.get('/file/:user/:repo/:branch/:filepath+', require('./file')); + router.get('/issue/:user/:repo/:state?/:labels?', require('./issue')); + router.get('/pull/:user/:repo', require('./pulls')); + router.get('/repos/:user', require('./repos')); + router.get('/search/:query/:sort?/:order?', require('./search')); + router.get('/starred_repos/:user', require('./starred_repos')); + router.get('/stars/:user/:repo', require('./star')); + router.get('/topics/:name/:qs?', require('./topic')); + router.get('/trending/:since/:language/:spoken_language?', require('./trending')); + router.get('/user/followers/:user', require('./follower')); }; diff --git a/lib/routes/github/search.js b/lib/v2/github/search.js similarity index 100% rename from lib/routes/github/search.js rename to lib/v2/github/search.js diff --git a/lib/routes/github/star.js b/lib/v2/github/star.js similarity index 100% rename from lib/routes/github/star.js rename to lib/v2/github/star.js diff --git a/lib/routes/github/starred_repos.js b/lib/v2/github/starred_repos.js similarity index 100% rename from lib/routes/github/starred_repos.js rename to lib/v2/github/starred_repos.js diff --git a/lib/routes/github/topic.js b/lib/v2/github/topic.js similarity index 100% rename from lib/routes/github/topic.js rename to lib/v2/github/topic.js diff --git a/lib/routes/github/trending.js b/lib/v2/github/trending.js similarity index 87% rename from lib/routes/github/trending.js rename to lib/v2/github/trending.js index 9efc474cb9..9c0a6caed5 100644 --- a/lib/routes/github/trending.js +++ b/lib/v2/github/trending.js @@ -3,8 +3,8 @@ const cheerio = require('cheerio'); module.exports = async (ctx) => { const since = ctx.params.since; - const language = ctx.params.language || ''; - const spoken_language = ctx.params.spoken_language || ''; + const language = ctx.params.language === 'any' ? '' : ctx.params.language; + const spoken_language = ctx.params.spoken_language ?? ''; const url = `https://github.com/trending/${encodeURIComponent(language)}?since=${since}&spoken_language_code=${spoken_language}`; const response = await got({ @@ -32,7 +32,7 @@ module.exports = async (ctx) => { title: item.find('h1').text(), author: item.find('h1').text().split('/')[0].trim(), description: `${item.find('.pr-4').text()}
-
Language: ${item.find('span[itemprop="programmingLanguage"]').text() || 'unknown'} +
Language: ${item.find('span[itemprop="programmingLanguage"]').text() ?? 'unknown'}
Star: ${item.find('.Link--muted').eq(0).text().trim()}
Fork: ${item.find('.Link--muted').eq(1).text().trim()}`, link: `https://github.com${item.find('h1 a').attr('href')}`,