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

@@ -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,
})),
};
};