mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-08 05:59:00 +08:00
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:
40
lib/v2/bitbucket/commits.js
Normal file
40
lib/v2/bitbucket/commits.js
Normal 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,
|
||||
})),
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user