mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-11 07:40:26 +08:00
Merge commit '026f9dce3aa2902531fcf4b682315fec3b06e6b7'
This commit is contained in:
@@ -227,6 +227,12 @@
|
|||||||
source: '/:user',
|
source: '/:user',
|
||||||
target: '/github/starred_repos/: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': {
|
'zhihu.com': {
|
||||||
|
|||||||
@@ -77,6 +77,10 @@ GitHub provides some official RSS feeds:
|
|||||||
|
|
||||||
<RouteEn author="LanceZhu" example="/github/starred_repos/DIYgod" path="/github/starred_repos/:user" :paramsDesc="['User name']" radar="1"/>
|
<RouteEn author="LanceZhu" example="/github/starred_repos/DIYgod" path="/github/starred_repos/:user" :paramsDesc="['User name']" radar="1"/>
|
||||||
|
|
||||||
|
### Repo Contributors
|
||||||
|
|
||||||
|
<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"/>
|
||||||
|
|
||||||
## GitLab
|
## GitLab
|
||||||
|
|
||||||
### Explore
|
### Explore
|
||||||
@@ -195,8 +199,7 @@ Website: https://news.ycombinator.com/
|
|||||||
|
|
||||||
### Scala Blog
|
### Scala Blog
|
||||||
|
|
||||||
<RouteEn author="fengkx" example="/scala/blog/posts" path="/scala/blog/:part?" :paramsDesc="['part']" >
|
<RouteEn author="fengkx" example="/scala/blog/posts" path="/scala/blog/:part?" :paramsDesc="['part parmater can be found in the url of blog']" >
|
||||||
part parmater can be found in the url of blog
|
|
||||||
</RouteEn>
|
</RouteEn>
|
||||||
|
|
||||||
## Visual Studio Code Marketplace
|
## Visual Studio Code Marketplace
|
||||||
|
|||||||
@@ -127,6 +127,10 @@ GitHub 官方也提供了一些 RSS:
|
|||||||
|
|
||||||
<Route author="LanceZhu" example="/github/starred_repos/DIYgod" path="/github/starred_repos/:user" :paramsDesc="['用户名']" radar="1"/>
|
<Route author="LanceZhu" example="/github/starred_repos/DIYgod" path="/github/starred_repos/:user" :paramsDesc="['用户名']" radar="1"/>
|
||||||
|
|
||||||
|
### 仓库 Contirbutors
|
||||||
|
|
||||||
|
<Route author="zoenglinghou" example="/github/contributors/DIYgod/RSSHub" path="/github/contributors/:user/:repo/:order?/:anon?" :paramsDesc="['用户名', '仓库名', 'Commit 数量排序顺序,desc和asc(默认desc降序)', '是否包括匿名用户,默认不包含,任意值包含匿名用户']" radar="1"/>
|
||||||
|
|
||||||
## GitLab
|
## GitLab
|
||||||
|
|
||||||
### Explore
|
### Explore
|
||||||
|
|||||||
@@ -274,6 +274,8 @@ router.get('/github/search/:query/:sort?/:order?', require('./routes/github/sear
|
|||||||
router.get('/github/branches/:user/:repo', require('./routes/github/branches'));
|
router.get('/github/branches/:user/:repo', require('./routes/github/branches'));
|
||||||
router.get('/github/file/:user/:repo/:branch/:filepath+', require('./routes/github/file'));
|
router.get('/github/file/:user/:repo/:branch/:filepath+', require('./routes/github/file'));
|
||||||
router.get('/github/starred_repos/:user', require('./routes/github/starred_repos'));
|
router.get('/github/starred_repos/:user', require('./routes/github/starred_repos'));
|
||||||
|
router.get('/github/contributors/:user/:repo/:order?/:anon?', require('./routes/github/contributors'));
|
||||||
|
|
||||||
// f-droid
|
// f-droid
|
||||||
router.get('/fdroid/apprelease/:app', require('./routes/fdroid/apprelease'));
|
router.get('/fdroid/apprelease/:app', require('./routes/fdroid/apprelease'));
|
||||||
|
|
||||||
|
|||||||
98
lib/routes/github/contributors.js
Normal file
98
lib/routes/github/contributors.js
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
const got = require('@/utils/got');
|
||||||
|
const config = require('@/config').value;
|
||||||
|
|
||||||
|
module.exports = async (ctx) => {
|
||||||
|
const { user, repo, order, anon } = ctx.params;
|
||||||
|
|
||||||
|
const host = `https://github.com/${user}/${repo}`;
|
||||||
|
const url = `https://api.github.com/repos/${user}/${repo}/contributors?` + (anon ? 'anon=1' : '');
|
||||||
|
|
||||||
|
// Use token if available
|
||||||
|
const headers = {};
|
||||||
|
if (config.github && config.github.access_token) {
|
||||||
|
headers.Authorization = `token ${config.github.access_token}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// First page
|
||||||
|
const response = await got({
|
||||||
|
method: 'get',
|
||||||
|
url,
|
||||||
|
headers,
|
||||||
|
});
|
||||||
|
let data = response.data;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Get total page number
|
||||||
|
const last_page_link = response.headers.link.split(',').find(function(elem) {
|
||||||
|
return elem.includes('"last"');
|
||||||
|
});
|
||||||
|
const url_base = last_page_link.match(/<(.*)page=\d*/)[1];
|
||||||
|
const page_count = Number(last_page_link.match(/page=(\d*)/)[1]);
|
||||||
|
|
||||||
|
const generate_array = (n) => [...Array(n - 1)].map((_, index) => index + 2);
|
||||||
|
const page_array = generate_array(page_count);
|
||||||
|
|
||||||
|
// Get everypage
|
||||||
|
const tasks = page_array.map(async (page) => {
|
||||||
|
const response = await got({
|
||||||
|
method: 'get',
|
||||||
|
url: `${url_base}page=${page}`,
|
||||||
|
headers,
|
||||||
|
});
|
||||||
|
data = data.concat(response.data);
|
||||||
|
});
|
||||||
|
await Promise.all(tasks);
|
||||||
|
} catch (err) {
|
||||||
|
// If only one page
|
||||||
|
|
||||||
|
// Other errors
|
||||||
|
if (!(err instanceof TypeError)) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort by commits
|
||||||
|
data.sort((a, b) => a.contributions - b.contributions);
|
||||||
|
if (order !== 'asc') {
|
||||||
|
data.reverse();
|
||||||
|
}
|
||||||
|
|
||||||
|
let title, description, link, guid;
|
||||||
|
|
||||||
|
const items = [];
|
||||||
|
let index = 0;
|
||||||
|
|
||||||
|
// Generate RSS
|
||||||
|
data.forEach(function(item) {
|
||||||
|
const time = new Date();
|
||||||
|
time.setMinutes(time.getMinutes() - index);
|
||||||
|
index++;
|
||||||
|
|
||||||
|
// Distiguished between acounts
|
||||||
|
if (item.type === 'Anonymous') {
|
||||||
|
title = `Contributor: ${item.name}`;
|
||||||
|
description = `<p>Anonymous contributor</p><p>Name: ${item.name}</p><p>E-mail: ${item.email}</p><p>Contributions: ${item.contributions}</p>`;
|
||||||
|
link = '';
|
||||||
|
guid = `anon-${item.name}`;
|
||||||
|
} else {
|
||||||
|
title = `Contributor: ${item.login}`;
|
||||||
|
description = `<img src="${item.avatar_url}"></img><p><a href="${item.html_url}">${item.login}</a></p><p>Contributions: ${item.contributions}</p>`;
|
||||||
|
link = item.html_url;
|
||||||
|
guid = item.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
items.push({
|
||||||
|
title: title,
|
||||||
|
description: description,
|
||||||
|
guid: guid,
|
||||||
|
link: link,
|
||||||
|
pubDate: time,
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
(ctx.state.data = {
|
||||||
|
title: `${user}/${repo} Contributors`,
|
||||||
|
link: `${host}/graphs/contributors`,
|
||||||
|
description: `New contributors for ${user}/${repo}`,
|
||||||
|
item: items,
|
||||||
|
});
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user