Files
RSSHub/lib/v2/bitbucket/commits.js
Zhen Zhong 3baeb0aa8c 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
2022-03-14 20:57:54 +08:00

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