feat(route): Add gitlab releases & tags(#7873)

add options for different gitlab instances
This commit is contained in:
zoenglinghou
2021-07-17 02:25:38 -07:00
committed by GitHub
parent 96331588d5
commit 53472e7ae6
6 changed files with 88 additions and 7 deletions
+10 -1
View File
@@ -111,7 +111,7 @@ For instance, the `/github/topics/framework/l=php&o=desc&s=stars` route will gen
### Explore
<RouteEn author="imlonghao" example="/gitlab/explore/trending" path="/gitlab/explore/:type" :paramsDesc="['type']">
<RouteEn author="imlonghao zoenglinghou" example="/gitlab/explore/trending" path="/gitlab/explore/:type/:host?" :paramsDesc="['type', 'Gitlab instance hostname, default to gitlab.com']">
| Trending | Most stars | All |
| -------- | ---------- | --- |
@@ -119,6 +119,15 @@ For instance, the `/github/topics/framework/l=php&o=desc&s=stars` route will gen
</RouteEn>
### Releases
<RouteEn author="zoenglinghou" example="/gitlab/release/pleroma/pleroma/git.pleroma.social" path="/gitlab/release/:namespace/:project/:host?" :paramsDesc="['owner or namespace. `/` needs to be replaced with `%2F`', 'project name', 'Gitlab instance hostname, default to gitlab.com']" />
### Tags
<RouteEn author="zoenglinghou" example="/gitlab/tag/rluna-open-source%2Ffile-management%2Fowncloud/core/gitlab.com" path="/gitlab/tag/:namespace/:project/:host?" :paramsDesc="['owner or namespace. `/` needs to be replaced with `%2F`', 'project name', 'Gitlab instance hostname, default to gitlab.com']" />
## Hacker News
### Section
+9 -1
View File
@@ -177,7 +177,7 @@ GitHub 官方也提供了一些 RSS:
### Explore
<Route author="imlonghao" example="/gitlab/explore/trending" path="/gitlab/explore/:type" :paramsDesc="['分类']">
<Route author="imlonghao zoenglinghou" example="/gitlab/explore/trending" path="/gitlab/explore/:type/:host?" :paramsDesc="['分类', '服务器地址,缺省为 gitlab.com']">
| Trending | Most stars | All |
| -------- | ---------- | --- |
@@ -185,6 +185,14 @@ GitHub 官方也提供了一些 RSS:
</Route>
### Releases
<Route author="zoenglinghou" example="/gitlab/release/pleroma/pleroma/git.pleroma.social" path="/gitlab/release/:namespace/:project/:host?" :paramsDesc="['项目所有者或命名空间。斜杠`/`需要替代为`%2F`', '项目名称', '服务器地址,缺省为 gitlab.com']" />
### Tags
<Route author="zoenglinghou" example="/gitlab/tag/rluna-open-source%2Ffile-management%2Fowncloud/core/gitlab.com" path="/gitlab/tag/:namespace/:project/:host?" :paramsDesc="['项目所有者或命名空间。斜杠`/`需要替代为`%2F`', '项目名称', '服务器地址,缺省为 gitlab.com']" />
## Go 语言中文网
### 周刊
+3 -1
View File
@@ -597,7 +597,9 @@ router.get('/novel/zhaishuyuan/:id', require('./routes/novel/zhaishuyuan'));
router.get('/weatheralarm/:province?', require('./routes/weatheralarm'));
// Gitlab
router.get('/gitlab/explore/:type', require('./routes/gitlab/explore'));
router.get('/gitlab/explore/:type/:host?', require('./routes/gitlab/explore'));
router.get('/gitlab/release/:namespace/:project/:host?', require('./routes/gitlab/release'));
router.get('/gitlab/tag/:namespace/:project/:host?', require('./routes/gitlab/tag'));
// 忧郁的loli
router.get('/mygalgame', require('./routes/galgame/hhgal')); // 废弃
+6 -4
View File
@@ -2,7 +2,9 @@ const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const type = ctx.params.type === 'all' ? '' : ctx.params.type;
let { type, host } = ctx.params;
type = type === 'all' ? '' : type;
host = host ? host : 'gitlab.com';
const typename = {
trending: 'Trending',
starred: 'Most stars',
@@ -11,14 +13,14 @@ module.exports = async (ctx) => {
const res = await got({
method: 'get',
url: `https://gitlab.com/explore/projects/${type}`,
url: `https://${host}/explore/projects/${type}`,
});
const $ = cheerio.load(res.data);
const list = $('ul.projects-list').find('li');
ctx.state.data = {
title: `${typename[ctx.params.type]} - Explore - Gitlab`,
link: `https://gitlab.com/explore/projects/${type}`,
link: `https://${host}/explore/projects/${type}`,
item:
list &&
list
@@ -28,7 +30,7 @@ module.exports = async (ctx) => {
title: item.find('.project-full-name').text(),
author: item.find('.namespace-name').text().slice(0, -1).split('\n').join('').trim(),
description: item.find('.description').text(),
link: `https://gitlab.com${item.find('a.text-plain').attr('href')}`,
link: `https://${host}${item.find('a.text-plain').attr('href')}`,
};
})
.get(),
+30
View File
@@ -0,0 +1,30 @@
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const { namespace, project, host } = ctx.params;
const host_ = host ? host : 'gitlab.com';
const namespace_ = encodeURIComponent(namespace);
const api_url = `https://${host_}/api/v4/projects/${namespace_}%2F${project}/releases`;
const response = await got({
method: 'get',
url: api_url,
});
const data = response.data;
ctx.state.data = {
title: `${project} - Releases - Gitlab`,
link: `https://${host_}/${namespace}/${project}/-/releases`,
description: `${namespace}/${project} Releases`,
item: data.map((item) => ({
title: item.name,
author: item.author.name,
description: item.description_html,
pubDate: parseDate(item.released_at),
link: item._links.self,
})),
};
};
+30
View File
@@ -0,0 +1,30 @@
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const { namespace, project, host } = ctx.params;
const host_ = host ? host : 'gitlab.com';
const namespace_ = encodeURIComponent(namespace);
const api_url = `https://${host_}/api/v4/projects/${namespace_}%2F${project}/repository/tags`;
const response = await got({
method: 'get',
url: api_url,
});
const data = response.data;
ctx.state.data = {
title: `${project} - Tags - Gitlab`,
link: `https://${host_}/${namespace}/${project}/-/tags`,
description: `${namespace}/${project} Tags`,
item: data.map((item) => ({
title: item.name,
author: item.commit.author_name,
description: item.message,
pubDate: parseDate(item.commit.created_at),
link: item.commit.web_url,
})),
};
};