diff --git a/lib/platform/bitbucket-server/index.spec.ts b/lib/platform/bitbucket-server/index.spec.ts index 24343d44a639b8c65e8423a481fa116a7fd52330..77c8871a2d1962000e46749af1100632c82f1e04 100644 --- a/lib/platform/bitbucket-server/index.spec.ts +++ b/lib/platform/bitbucket-server/index.spec.ts @@ -16,6 +16,7 @@ function repoMock( projectKey: string, repositorySlug: string ) { + const endpointStr = endpoint.toString(); const projectKeyLower = projectKey.toLowerCase(); return { slug: repositorySlug, @@ -41,7 +42,7 @@ function repoMock( links: { clone: [ { - href: `${endpoint}/scm/${projectKeyLower}/${repositorySlug}.git`, + href: `${endpointStr}/scm/${projectKeyLower}/${repositorySlug}.git`, name: 'http', }, { @@ -51,14 +52,19 @@ function repoMock( ], self: [ { - href: `${endpoint}/projects/${projectKey}/repos/${repositorySlug}/browse`, + href: `${endpointStr}/projects/${projectKey}/repos/${repositorySlug}/browse`, }, ], }, }; } -function prMock(endpoint, projectKey, repositorySlug) { +function prMock( + endpoint: URL | string, + projectKey: string, + repositorySlug: string +) { + const endpointStr = endpoint.toString(); return { id: 5, version: 1, @@ -94,7 +100,7 @@ function prMock(endpoint, projectKey, repositorySlug) { slug: 'userName1', type: 'NORMAL', links: { - self: [{ href: `${endpoint}/users/userName1` }], + self: [{ href: `${endpointStr}/users/userName1` }], }, }, role: 'AUTHOR', @@ -112,7 +118,7 @@ function prMock(endpoint, projectKey, repositorySlug) { slug: 'userName2', type: 'NORMAL', links: { - self: [{ href: `${endpoint}/users/userName2` }], + self: [{ href: `${endpointStr}/users/userName2` }], }, }, role: 'REVIEWER', @@ -124,7 +130,7 @@ function prMock(endpoint, projectKey, repositorySlug) { links: { self: [ { - href: `${endpoint}/projects/${projectKey}/repos/${repositorySlug}/pull-requests/5`, + href: `${endpointStr}/projects/${projectKey}/repos/${repositorySlug}/pull-requests/5`, }, ], }, diff --git a/lib/platform/bitbucket-server/utils.ts b/lib/platform/bitbucket-server/utils.ts index b236d67970a9cb7ba65c51f2e21a44f76eb4ca08..5fa338bab8c44c3970a866da30d2ff2499d48c6b 100644 --- a/lib/platform/bitbucket-server/utils.ts +++ b/lib/platform/bitbucket-server/utils.ts @@ -1,7 +1,7 @@ // SEE for the reference https://github.com/renovatebot/renovate/blob/c3e9e572b225085448d94aa121c7ec81c14d3955/lib/platform/bitbucket/utils.js import url from 'url'; import { PrState } from '../../types'; -import { HttpResponse } from '../../util/http'; +import { HttpOptions, HttpPostOptions, HttpResponse } from '../../util/http'; import { BitbucketServerHttp } from '../../util/http/bitbucket-server'; import { BbbsRestPr, BbsPr } from './types'; @@ -39,20 +39,29 @@ const addMaxLength = (inputUrl: string, limit = 100): string => { function callApi<T>( apiUrl: string, method: string, - options?: any + options?: HttpOptions | HttpPostOptions ): Promise<HttpResponse<T>> { /* istanbul ignore next */ switch (method.toLowerCase()) { case 'post': - return bitbucketServerHttp.postJson<T>(apiUrl, options); + return bitbucketServerHttp.postJson<T>( + apiUrl, + options as HttpPostOptions + ); case 'put': - return bitbucketServerHttp.putJson<T>(apiUrl, options); + return bitbucketServerHttp.putJson<T>(apiUrl, options as HttpPostOptions); case 'patch': - return bitbucketServerHttp.patchJson<T>(apiUrl, options); + return bitbucketServerHttp.patchJson<T>( + apiUrl, + options as HttpPostOptions + ); case 'head': return bitbucketServerHttp.headJson<T>(apiUrl, options); case 'delete': - return bitbucketServerHttp.deleteJson<T>(apiUrl, options); + return bitbucketServerHttp.deleteJson<T>( + apiUrl, + options as HttpPostOptions + ); case 'get': default: return bitbucketServerHttp.getJson<T>(apiUrl, options); @@ -62,7 +71,7 @@ function callApi<T>( export async function accumulateValues<T = any>( reqUrl: string, method = 'get', - options?: any, + options?: HttpOptions | HttpPostOptions, limit?: number ): Promise<T[]> { let accumulator: T[] = []; diff --git a/lib/platform/bitbucket/index.ts b/lib/platform/bitbucket/index.ts index 40c4d3beb971c1e7eda73bbbdb5378f959811ede..b5c6603f8ed45f0eb47c388a606e5fcf8894ac8b 100644 --- a/lib/platform/bitbucket/index.ts +++ b/lib/platform/bitbucket/index.ts @@ -33,6 +33,7 @@ import { smartTruncate } from '../utils/pr-body'; import { readOnlyIssueBody } from '../utils/read-only-issue-body'; import * as comments from './comments'; import * as utils from './utils'; +import { PrResponse, RepoInfoBody } from './utils'; const bitbucketHttp = new BitbucketHttp(); @@ -100,7 +101,11 @@ export async function initRepo({ let info: utils.RepoInfo; try { info = utils.repoInfoTransformer( - (await bitbucketHttp.getJson(`/2.0/repositories/${repository}`)).body + ( + await bitbucketHttp.getJson<RepoInfoBody>( + `/2.0/repositories/${repository}` + ) + ).body ); if (optimizeForDisabled) { @@ -230,22 +235,6 @@ async function isPrConflicted(prNo: number): Promise<boolean> { return utils.isConflicted(parseDiff(diff)); } -interface PrResponse { - id: string; - state: string; - links: { - commits: { - href: string; - }; - }; - source: { - branch: { - name: string; - }; - }; - reviewers: Array<any>; -} - // Gets details for a PR export async function getPr(prNo: number): Promise<Pr | null> { const pr = ( diff --git a/lib/platform/bitbucket/utils.ts b/lib/platform/bitbucket/utils.ts index 818389e3c47ec37550dd7f8f54d0db619c1b9577..6504b98045d12b5d21307d3db35fa3d16b103cfa 100644 --- a/lib/platform/bitbucket/utils.ts +++ b/lib/platform/bitbucket/utils.ts @@ -1,6 +1,6 @@ import url from 'url'; import { BranchStatus, PrState } from '../../types'; -import { HttpResponse } from '../../util/http'; +import { HttpOptions, HttpPostOptions, HttpResponse } from '../../util/http'; import { BitbucketHttp } from '../../util/http/bitbucket'; import { Pr } from '../common'; @@ -39,7 +39,14 @@ export interface BitbucketStatus { state: BitbucketBranchState; } -export function repoInfoTransformer(repoInfoBody: any): RepoInfo { +export interface RepoInfoBody { + parent?: any; + owner: { username: string }; + mainbranch: { name: string }; + has_issues: boolean; +} + +export function repoInfoTransformer(repoInfoBody: RepoInfoBody): RepoInfo { return { isFork: !!repoInfoBody.parent, owner: repoInfoBody.owner.username, @@ -75,20 +82,20 @@ const addMaxLength = (inputUrl: string, pagelen = 100): string => { function callApi<T>( apiUrl: string, method: string, - options?: any + options?: HttpOptions | HttpPostOptions ): Promise<HttpResponse<T>> { /* istanbul ignore next */ switch (method.toLowerCase()) { case 'post': - return bitbucketHttp.postJson<T>(apiUrl, options); + return bitbucketHttp.postJson<T>(apiUrl, options as HttpPostOptions); case 'put': - return bitbucketHttp.putJson<T>(apiUrl, options); + return bitbucketHttp.putJson<T>(apiUrl, options as HttpPostOptions); case 'patch': - return bitbucketHttp.patchJson<T>(apiUrl, options); + return bitbucketHttp.patchJson<T>(apiUrl, options as HttpPostOptions); case 'head': return bitbucketHttp.headJson<T>(apiUrl, options); case 'delete': - return bitbucketHttp.deleteJson<T>(apiUrl, options); + return bitbucketHttp.deleteJson<T>(apiUrl, options as HttpPostOptions); case 'get': default: return bitbucketHttp.getJson<T>(apiUrl, options); @@ -98,7 +105,7 @@ function callApi<T>( export async function accumulateValues<T = any>( reqUrl: string, method = 'get', - options?: any, + options?: HttpOptions | HttpPostOptions, pagelen?: number ): Promise<T[]> { let accumulator: T[] = []; @@ -117,7 +124,17 @@ export async function accumulateValues<T = any>( return accumulator; } -export /* istanbul ignore next */ function isConflicted(files: any): boolean { +interface Files { + chunks: { + changes: { + content: string; + }[]; + }[]; +} + +export /* istanbul ignore next */ function isConflicted( + files: Files[] +): boolean { for (const file of files) { for (const chunk of file.chunks) { for (const change of chunk.changes) { @@ -130,7 +147,31 @@ export /* istanbul ignore next */ function isConflicted(files: any): boolean { return false; } -export function prInfo(pr: any): Pr { +export interface PrResponse { + id: number; + title: string; + state: string; + links: { + commits: { + href: string; + }; + }; + summary?: { raw: string }; + source: { + branch: { + name: string; + }; + }; + destination: { + branch: { + name: string; + }; + }; + reviewers: Array<any>; + created_on: string; +} + +export function prInfo(pr: PrResponse): Pr { return { number: pr.id, body: pr.summary ? pr.summary.raw : /* istanbul ignore next */ undefined, diff --git a/lib/platform/gitea/gitea-helper.spec.ts b/lib/platform/gitea/gitea-helper.spec.ts index edf77fc755d19ecc132f2a90661b9344c43297f1..741171d6f6f0afe3c30530d595da6f36b8946368 100644 --- a/lib/platform/gitea/gitea-helper.spec.ts +++ b/lib/platform/gitea/gitea-helper.spec.ts @@ -677,12 +677,13 @@ describe('platform/gitea/gitea-helper', () => { { ...mockCommitStatus, status: 'unknown' }, ]; - for (const { status, created_at, expected } of statuses) { + for (const statusElem of statuses) { + const { status, expected } = statusElem; // Add current status ot list of commit statuses, then mock the API to return the whole list commitStatuses.push({ ...mockCommitStatus, status, - created_at, + created_at: statusElem.created_at, }); httpMock .scope(baseUrl) diff --git a/lib/platform/index.ts b/lib/platform/index.ts index 247d5c48daa14404e25f967335433170e8330f32..d417cee8c1836c38b581274d3fea9d9347e09bcb 100644 --- a/lib/platform/index.ts +++ b/lib/platform/index.ts @@ -98,7 +98,7 @@ export async function initPlatform( ); gitAuthor = 'Renovate Bot <renovate@whitesourcesoftware.com>'; } /* istanbul ignore next */ else { - logger.debug('Using platform gitAuthor: ' + platformInfo.gitAuthor); + logger.debug(`Using platform gitAuthor: ${String(platformInfo.gitAuthor)}`); gitAuthor = platformInfo.gitAuthor; } const gitAuthorParsed = parseGitAuthor(gitAuthor);