/
commits.ts
64 lines (61 loc) 路 1.96 KB
/
commits.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { Route } from '@/types';
import got from '@/utils/got';
import { config } from '@/config';
import queryString from 'query-string';
import { parseDate } from '@/utils/parse-date';
export const route: Route = {
path: '/commits/:workspace/:repo_slug',
categories: ['programming'],
example: '/bitbucket/commits/blaze-lib/blaze',
parameters: { workspace: 'Workspace', repo_slug: 'Repository' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['bitbucket.com/commits/:workspace/:repo_slug'],
},
],
name: 'Commits',
maintainers: ['AuroraDysis'],
handler,
};
async function handler(ctx) {
const workspace = ctx.req.param('workspace');
const repo_slug = ctx.req.param('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;
return {
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,
})),
};
}