mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-23 13:06:27 +00:00
28 lines
730 B
TypeScript
28 lines
730 B
TypeScript
import { GotJSONOptions } from 'got';
|
|
import got from '../../util/got';
|
|
import { GotApi, GotApiOptions, GotResponse } from '../common';
|
|
|
|
async function get(
|
|
path: string,
|
|
options: GotApiOptions & GotJSONOptions
|
|
): Promise<GotResponse> {
|
|
const opts: GotApiOptions & GotJSONOptions = {
|
|
json: true,
|
|
hostType: 'bitbucket',
|
|
baseUrl: 'https://api.bitbucket.org/',
|
|
...options,
|
|
};
|
|
const res = await got(path, opts);
|
|
return res;
|
|
}
|
|
|
|
const helpers = ['get', 'post', 'put', 'patch', 'head', 'delete'];
|
|
|
|
export const api: GotApi = {} as any;
|
|
|
|
for (const x of helpers) {
|
|
(api as any)[x] = (url: string, opts: any): Promise<GotResponse> =>
|
|
get(url, { ...opts, method: x.toUpperCase() });
|
|
}
|
|
|
|
export default api;
|