mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-02 18:18:06 +08:00
* add bitbucket commits and tags * add english doc * fix bitbucket radar.js * fix bitbucket docs * docs: add bitbucket cn docs * fix: use parseDate utils
41 lines
1.4 KiB
JavaScript
41 lines
1.4 KiB
JavaScript
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,
|
|
})),
|
|
};
|
|
};
|