feat(route): add bitbucket commits and tags (#9316)

* add bitbucket commits and tags

* add english doc

* fix bitbucket radar.js

* fix bitbucket docs

* docs: add bitbucket cn docs

* fix: use parseDate utils
This commit is contained in:
Zhen Zhong
2022-03-14 12:57:54 +00:00
committed by GitHub
parent fddd2719a4
commit 3baeb0aa8c
10 changed files with 141 additions and 0 deletions

View File

@@ -508,6 +508,11 @@ See docs of the specified route and `lib/config.js` for detailed information.
:::
- Bitbucket: [Basic auth with App passwords](https://developer.atlassian.com/cloud/bitbucket/rest/intro/#basic-auth)
- `BITBUCKET_USERNAME`: Your Bitbucket username
- `BITBUCKET_PASSWORD`: Your Bitbucket app password
- Discuz cookie
- `DISCUZ_COOKIE_{cid}`: Cookie of a forum powered by Discuz, cid can be anything from 00 to 99. When visiting a Discuz route, use cid to specify this cookie.

View File

@@ -205,6 +205,16 @@ For instance, the `/github/topics/framework/l=php&o=desc&s=stars` route will gen
<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']" />
## Bitbucket
### Commits
<RouteEn author="AuroraDysis" example="/bitbucket/commits/blaze-lib/blaze" path="/bitbucket/commits/:workspace/:repo_slug" :paramsDesc="['Workspace', 'Repository']" rssbud="1" rssbud="1"/>
### Tags
<RouteEn author="AuroraDysis" example="/bitbucket/tags/blaze-lib/blaze" path="/bitbucket/tags/:workspace/:repo_slug" :paramsDesc="['Workspace', 'Repository']" rssbud="1" rssbud="1"/>
## Gitpod
### Blog

View File

@@ -525,6 +525,11 @@ RSSHub 支持使用访问密钥 / 码,白名单和黑名单三种方式进行
3. 点击 dynamic_new 请求,找到 Cookie
4. 视频和专栏只要求 `SESSDATA` 字段,动态需复制整段 Cookie
- Bitbucket: [Basic auth with App passwords](https://developer.atlassian.com/cloud/bitbucket/rest/intro/#basic-auth)
- `BITBUCKET_USERNAME`: 你的 Bitbucket 用户名
- `BITBUCKET_PASSWORD`: 你的 Bitbucket 密码
- BTBYR
- `BTBYR_HOST`: 支持 ipv4 访问的 BTBYR 镜像,默认为原站 `https://bt.byr.cn/`

View File

@@ -283,6 +283,16 @@ GitHub 官方也提供了一些 RSS:
<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']" />
## Bitbucket
### Commits
<Route author="AuroraDysis" example="/bitbucket/commits/blaze-lib/blaze" path="/bitbucket/commits/:workspace/:repo_slug" :paramsDesc="['Workspace', 'Repository']" rssbud="1" rssbud="1"/>
### Tags
<Route author="AuroraDysis" example="/bitbucket/tags/blaze-lib/blaze" path="/bitbucket/tags/:workspace/:repo_slug" :paramsDesc="['Workspace', 'Repository']" rssbud="1" rssbud="1"/>
## Gitpod
### 博客

View File

@@ -91,6 +91,10 @@ const calculateValue = () => {
bilibili: {
cookies: bilibili_cookies,
},
bitbucket: {
username: envs.BITBUCKET_USERNAME,
password: envs.BITBUCKET_PASSWORD,
},
btbyr: {
host: envs.BTBYR_HOST,
cookies: envs.BTBYR_COOKIE,

View File

@@ -0,0 +1,40 @@
const got = require('@/utils/got');
const config = require('@/config').value;
const queryString = require('query-string');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const workspace = ctx.params.workspace;
const repo_slug = ctx.params.repo_slug;
const headers = {
Accept: 'application/json',
};
let auth = '';
if (config.bitbucket && config.bitbucket.username && config.bitbucket.password) {
auth = config.bitbucket.username + ':' + config.bitbucket.password + '@';
}
const response = await got({
method: 'get',
url: `https://${auth}api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/commits/`,
searchParams: queryString.stringify({
sort: '-target.date',
}),
headers,
});
const data = response.data.values;
ctx.state.data = {
allowEmpty: true,
title: `Recent Commits to ${workspace}/${repo_slug}`,
link: `https://bitbucket.org/${workspace}/${repo_slug}`,
item:
data &&
data.map((item) => ({
title: item.message,
author: item.author.raw,
description: item.rendered.message.html || 'No description',
pubDate: parseDate(item.date),
link: item.links.html.href,
})),
};
};

View File

@@ -0,0 +1,4 @@
module.exports = {
'/commits/:workspace/:repo_slug': ['AuroraDysis'],
'/tags/:workspace/:repo_slug': ['AuroraDysis'],
};

19
lib/v2/bitbucket/radar.js Normal file
View File

@@ -0,0 +1,19 @@
module.exports = {
'bitbucket.com': {
_name: 'Bitbucket',
'.': [
{
title: 'Commits',
docs: 'https://docs.rsshub.app/programming.html#bitbucket',
source: ['/commits/:workspace/:repo_slug'],
target: '/bitbucket/commits/:workspace/:repo_slug',
},
{
title: 'Tags',
docs: 'https://docs.rsshub.app/programming.html#bitbucket',
source: ['/tags/:workspace/:repo_slug'],
target: '/bitbcuket/tags/:workspace/:repo_slug',
},
],
},
};

View File

@@ -0,0 +1,4 @@
module.exports = (router) => {
router.get('/commits/:workspace/:repo_slug', require('./commits'));
router.get('/tags/:workspace/:repo_slug', require('./tags'));
};

40
lib/v2/bitbucket/tags.js Normal file
View File

@@ -0,0 +1,40 @@
const got = require('@/utils/got');
const config = require('@/config').value;
const queryString = require('query-string');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const workspace = ctx.params.workspace;
const repo_slug = ctx.params.repo_slug;
const headers = {
Accept: 'application/json',
};
let auth = '';
if (config.bitbucket && config.bitbucket.username && config.bitbucket.password) {
auth = config.bitbucket.username + ':' + config.bitbucket.password + '@';
}
const response = await got({
method: 'get',
url: `https://${auth}api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/refs/tags/`,
searchParams: queryString.stringify({
sort: '-target.date',
}),
headers,
});
const data = response.data.values;
ctx.state.data = {
allowEmpty: true,
title: `Recent Tags in ${workspace}/${repo_slug}`,
link: `https://bitbucket.org/${workspace}/${repo_slug}`,
item:
data &&
data.map((item) => ({
title: item.name,
author: item.tagger.raw,
description: item.message || 'No description',
pubDate: parseDate(item.date),
link: item.links.html.href,
})),
};
};