Skip to content

Commit

Permalink
feat(bitbucket-server): convert to typescript (#3756)
Browse files Browse the repository at this point in the history
  • Loading branch information
viceice authored and rarkins committed May 20, 2019
1 parent 154f776 commit cc52c20
Show file tree
Hide file tree
Showing 13 changed files with 386 additions and 297 deletions.
7 changes: 7 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ module.exports = {
'promise/no-promise-in-callback': 'warn',
'promise/no-callback-in-promise': 'warn',
'promise/avoid-new': 'warn',

'@typescript-eslint/explicit-member-accessibility': 0,
'@typescript-eslint/explicit-function-return-type': 0,
'@typescript-eslint/interface-name-prefix': 0,
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/no-non-null-assertion': 0,
'no-underscore-dangle': 0,
},
settings: {
'import/resolver': {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
const got = require('got');
const URL = require('url');
const hostRules = require('../../util/host-rules');
import got from 'got';
import URL from 'url';
import * as hostRules from '../../util/host-rules';
import { IGotApiOptions, IGotApi } from '../common';

let cache = {};
let cache: Renovate.IDict<got.Response<any>> = {};

const platform = 'bitbucket-server';
let endpoint;
let endpoint: string;

async function get(path, options) {
async function get(path: string, options: IGotApiOptions & got.GotJSONOptions) {
const host = URL.parse(path).host || URL.parse(endpoint).host;
const opts = {
const opts: IGotApiOptions &
hostRules.IPlatformConfig &
got.GotJSONOptions = {
// TODO: Move to configurable host rules, or use utils/got
timeout: 60 * 1000,
json: true,
Expand All @@ -18,7 +21,9 @@ async function get(path, options) {
...options,
};
const url = URL.resolve(endpoint, path);
const method = (opts.method || 'get').toLowerCase();
const method = (
opts.method || /* istanbul ignore next */ 'get'
).toLowerCase();
const useCache = opts.useCache;
if (method === 'get' && useCache !== false && cache[path]) {
logger.trace({ path }, 'Returning cached result');
Expand All @@ -27,7 +32,10 @@ async function get(path, options) {
opts.headers = {
'user-agent': 'https://github.com/renovatebot/renovate',
'X-Atlassian-Token': 'no-check',
authorization: opts.token ? `Basic ${opts.token}` : undefined,

authorization: opts.token
? /* istanbul ignore next */ `Basic ${opts.token}`
: undefined,
...opts.headers,
};

Expand All @@ -41,17 +49,19 @@ async function get(path, options) {

const helpers = ['get', 'post', 'put', 'patch', 'head', 'delete'];

export const api: IGotApi = {} as any;

for (const x of helpers) {
get[x] = (url, opts) =>
(api as any)[x] = (url: string, opts: any) =>
get(url, Object.assign({}, opts, { method: x.toUpperCase() }));
}

get.reset = function reset() {
api.reset = function reset() {
cache = {};
};

get.setEndpoint = e => {
api.setEndpoint = (e: string) => {
endpoint = e;
};

module.exports = get;
export default api;
Loading

0 comments on commit cc52c20

Please sign in to comment.