mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 06:56:24 +00:00
refactor(platform): Fix lint warnings (#7113)
This commit is contained in:
parent
60b101d22c
commit
28d16d17bc
6 changed files with 89 additions and 43 deletions
|
@ -16,6 +16,7 @@ function repoMock(
|
||||||
projectKey: string,
|
projectKey: string,
|
||||||
repositorySlug: string
|
repositorySlug: string
|
||||||
) {
|
) {
|
||||||
|
const endpointStr = endpoint.toString();
|
||||||
const projectKeyLower = projectKey.toLowerCase();
|
const projectKeyLower = projectKey.toLowerCase();
|
||||||
return {
|
return {
|
||||||
slug: repositorySlug,
|
slug: repositorySlug,
|
||||||
|
@ -41,7 +42,7 @@ function repoMock(
|
||||||
links: {
|
links: {
|
||||||
clone: [
|
clone: [
|
||||||
{
|
{
|
||||||
href: `${endpoint}/scm/${projectKeyLower}/${repositorySlug}.git`,
|
href: `${endpointStr}/scm/${projectKeyLower}/${repositorySlug}.git`,
|
||||||
name: 'http',
|
name: 'http',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -51,14 +52,19 @@ function repoMock(
|
||||||
],
|
],
|
||||||
self: [
|
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 {
|
return {
|
||||||
id: 5,
|
id: 5,
|
||||||
version: 1,
|
version: 1,
|
||||||
|
@ -94,7 +100,7 @@ function prMock(endpoint, projectKey, repositorySlug) {
|
||||||
slug: 'userName1',
|
slug: 'userName1',
|
||||||
type: 'NORMAL',
|
type: 'NORMAL',
|
||||||
links: {
|
links: {
|
||||||
self: [{ href: `${endpoint}/users/userName1` }],
|
self: [{ href: `${endpointStr}/users/userName1` }],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
role: 'AUTHOR',
|
role: 'AUTHOR',
|
||||||
|
@ -112,7 +118,7 @@ function prMock(endpoint, projectKey, repositorySlug) {
|
||||||
slug: 'userName2',
|
slug: 'userName2',
|
||||||
type: 'NORMAL',
|
type: 'NORMAL',
|
||||||
links: {
|
links: {
|
||||||
self: [{ href: `${endpoint}/users/userName2` }],
|
self: [{ href: `${endpointStr}/users/userName2` }],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
role: 'REVIEWER',
|
role: 'REVIEWER',
|
||||||
|
@ -124,7 +130,7 @@ function prMock(endpoint, projectKey, repositorySlug) {
|
||||||
links: {
|
links: {
|
||||||
self: [
|
self: [
|
||||||
{
|
{
|
||||||
href: `${endpoint}/projects/${projectKey}/repos/${repositorySlug}/pull-requests/5`,
|
href: `${endpointStr}/projects/${projectKey}/repos/${repositorySlug}/pull-requests/5`,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// SEE for the reference https://github.com/renovatebot/renovate/blob/c3e9e572b225085448d94aa121c7ec81c14d3955/lib/platform/bitbucket/utils.js
|
// SEE for the reference https://github.com/renovatebot/renovate/blob/c3e9e572b225085448d94aa121c7ec81c14d3955/lib/platform/bitbucket/utils.js
|
||||||
import url from 'url';
|
import url from 'url';
|
||||||
import { PrState } from '../../types';
|
import { PrState } from '../../types';
|
||||||
import { HttpResponse } from '../../util/http';
|
import { HttpOptions, HttpPostOptions, HttpResponse } from '../../util/http';
|
||||||
import { BitbucketServerHttp } from '../../util/http/bitbucket-server';
|
import { BitbucketServerHttp } from '../../util/http/bitbucket-server';
|
||||||
import { BbbsRestPr, BbsPr } from './types';
|
import { BbbsRestPr, BbsPr } from './types';
|
||||||
|
|
||||||
|
@ -39,20 +39,29 @@ const addMaxLength = (inputUrl: string, limit = 100): string => {
|
||||||
function callApi<T>(
|
function callApi<T>(
|
||||||
apiUrl: string,
|
apiUrl: string,
|
||||||
method: string,
|
method: string,
|
||||||
options?: any
|
options?: HttpOptions | HttpPostOptions
|
||||||
): Promise<HttpResponse<T>> {
|
): Promise<HttpResponse<T>> {
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
switch (method.toLowerCase()) {
|
switch (method.toLowerCase()) {
|
||||||
case 'post':
|
case 'post':
|
||||||
return bitbucketServerHttp.postJson<T>(apiUrl, options);
|
return bitbucketServerHttp.postJson<T>(
|
||||||
|
apiUrl,
|
||||||
|
options as HttpPostOptions
|
||||||
|
);
|
||||||
case 'put':
|
case 'put':
|
||||||
return bitbucketServerHttp.putJson<T>(apiUrl, options);
|
return bitbucketServerHttp.putJson<T>(apiUrl, options as HttpPostOptions);
|
||||||
case 'patch':
|
case 'patch':
|
||||||
return bitbucketServerHttp.patchJson<T>(apiUrl, options);
|
return bitbucketServerHttp.patchJson<T>(
|
||||||
|
apiUrl,
|
||||||
|
options as HttpPostOptions
|
||||||
|
);
|
||||||
case 'head':
|
case 'head':
|
||||||
return bitbucketServerHttp.headJson<T>(apiUrl, options);
|
return bitbucketServerHttp.headJson<T>(apiUrl, options);
|
||||||
case 'delete':
|
case 'delete':
|
||||||
return bitbucketServerHttp.deleteJson<T>(apiUrl, options);
|
return bitbucketServerHttp.deleteJson<T>(
|
||||||
|
apiUrl,
|
||||||
|
options as HttpPostOptions
|
||||||
|
);
|
||||||
case 'get':
|
case 'get':
|
||||||
default:
|
default:
|
||||||
return bitbucketServerHttp.getJson<T>(apiUrl, options);
|
return bitbucketServerHttp.getJson<T>(apiUrl, options);
|
||||||
|
@ -62,7 +71,7 @@ function callApi<T>(
|
||||||
export async function accumulateValues<T = any>(
|
export async function accumulateValues<T = any>(
|
||||||
reqUrl: string,
|
reqUrl: string,
|
||||||
method = 'get',
|
method = 'get',
|
||||||
options?: any,
|
options?: HttpOptions | HttpPostOptions,
|
||||||
limit?: number
|
limit?: number
|
||||||
): Promise<T[]> {
|
): Promise<T[]> {
|
||||||
let accumulator: T[] = [];
|
let accumulator: T[] = [];
|
||||||
|
|
|
@ -33,6 +33,7 @@ import { smartTruncate } from '../utils/pr-body';
|
||||||
import { readOnlyIssueBody } from '../utils/read-only-issue-body';
|
import { readOnlyIssueBody } from '../utils/read-only-issue-body';
|
||||||
import * as comments from './comments';
|
import * as comments from './comments';
|
||||||
import * as utils from './utils';
|
import * as utils from './utils';
|
||||||
|
import { PrResponse, RepoInfoBody } from './utils';
|
||||||
|
|
||||||
const bitbucketHttp = new BitbucketHttp();
|
const bitbucketHttp = new BitbucketHttp();
|
||||||
|
|
||||||
|
@ -100,7 +101,11 @@ export async function initRepo({
|
||||||
let info: utils.RepoInfo;
|
let info: utils.RepoInfo;
|
||||||
try {
|
try {
|
||||||
info = utils.repoInfoTransformer(
|
info = utils.repoInfoTransformer(
|
||||||
(await bitbucketHttp.getJson(`/2.0/repositories/${repository}`)).body
|
(
|
||||||
|
await bitbucketHttp.getJson<RepoInfoBody>(
|
||||||
|
`/2.0/repositories/${repository}`
|
||||||
|
)
|
||||||
|
).body
|
||||||
);
|
);
|
||||||
|
|
||||||
if (optimizeForDisabled) {
|
if (optimizeForDisabled) {
|
||||||
|
@ -230,22 +235,6 @@ async function isPrConflicted(prNo: number): Promise<boolean> {
|
||||||
return utils.isConflicted(parseDiff(diff));
|
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
|
// Gets details for a PR
|
||||||
export async function getPr(prNo: number): Promise<Pr | null> {
|
export async function getPr(prNo: number): Promise<Pr | null> {
|
||||||
const pr = (
|
const pr = (
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import url from 'url';
|
import url from 'url';
|
||||||
import { BranchStatus, PrState } from '../../types';
|
import { BranchStatus, PrState } from '../../types';
|
||||||
import { HttpResponse } from '../../util/http';
|
import { HttpOptions, HttpPostOptions, HttpResponse } from '../../util/http';
|
||||||
import { BitbucketHttp } from '../../util/http/bitbucket';
|
import { BitbucketHttp } from '../../util/http/bitbucket';
|
||||||
import { Pr } from '../common';
|
import { Pr } from '../common';
|
||||||
|
|
||||||
|
@ -39,7 +39,14 @@ export interface BitbucketStatus {
|
||||||
state: BitbucketBranchState;
|
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 {
|
return {
|
||||||
isFork: !!repoInfoBody.parent,
|
isFork: !!repoInfoBody.parent,
|
||||||
owner: repoInfoBody.owner.username,
|
owner: repoInfoBody.owner.username,
|
||||||
|
@ -75,20 +82,20 @@ const addMaxLength = (inputUrl: string, pagelen = 100): string => {
|
||||||
function callApi<T>(
|
function callApi<T>(
|
||||||
apiUrl: string,
|
apiUrl: string,
|
||||||
method: string,
|
method: string,
|
||||||
options?: any
|
options?: HttpOptions | HttpPostOptions
|
||||||
): Promise<HttpResponse<T>> {
|
): Promise<HttpResponse<T>> {
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
switch (method.toLowerCase()) {
|
switch (method.toLowerCase()) {
|
||||||
case 'post':
|
case 'post':
|
||||||
return bitbucketHttp.postJson<T>(apiUrl, options);
|
return bitbucketHttp.postJson<T>(apiUrl, options as HttpPostOptions);
|
||||||
case 'put':
|
case 'put':
|
||||||
return bitbucketHttp.putJson<T>(apiUrl, options);
|
return bitbucketHttp.putJson<T>(apiUrl, options as HttpPostOptions);
|
||||||
case 'patch':
|
case 'patch':
|
||||||
return bitbucketHttp.patchJson<T>(apiUrl, options);
|
return bitbucketHttp.patchJson<T>(apiUrl, options as HttpPostOptions);
|
||||||
case 'head':
|
case 'head':
|
||||||
return bitbucketHttp.headJson<T>(apiUrl, options);
|
return bitbucketHttp.headJson<T>(apiUrl, options);
|
||||||
case 'delete':
|
case 'delete':
|
||||||
return bitbucketHttp.deleteJson<T>(apiUrl, options);
|
return bitbucketHttp.deleteJson<T>(apiUrl, options as HttpPostOptions);
|
||||||
case 'get':
|
case 'get':
|
||||||
default:
|
default:
|
||||||
return bitbucketHttp.getJson<T>(apiUrl, options);
|
return bitbucketHttp.getJson<T>(apiUrl, options);
|
||||||
|
@ -98,7 +105,7 @@ function callApi<T>(
|
||||||
export async function accumulateValues<T = any>(
|
export async function accumulateValues<T = any>(
|
||||||
reqUrl: string,
|
reqUrl: string,
|
||||||
method = 'get',
|
method = 'get',
|
||||||
options?: any,
|
options?: HttpOptions | HttpPostOptions,
|
||||||
pagelen?: number
|
pagelen?: number
|
||||||
): Promise<T[]> {
|
): Promise<T[]> {
|
||||||
let accumulator: T[] = [];
|
let accumulator: T[] = [];
|
||||||
|
@ -117,7 +124,17 @@ export async function accumulateValues<T = any>(
|
||||||
return accumulator;
|
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 file of files) {
|
||||||
for (const chunk of file.chunks) {
|
for (const chunk of file.chunks) {
|
||||||
for (const change of chunk.changes) {
|
for (const change of chunk.changes) {
|
||||||
|
@ -130,7 +147,31 @@ export /* istanbul ignore next */ function isConflicted(files: any): boolean {
|
||||||
return false;
|
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 {
|
return {
|
||||||
number: pr.id,
|
number: pr.id,
|
||||||
body: pr.summary ? pr.summary.raw : /* istanbul ignore next */ undefined,
|
body: pr.summary ? pr.summary.raw : /* istanbul ignore next */ undefined,
|
||||||
|
|
|
@ -677,12 +677,13 @@ describe('platform/gitea/gitea-helper', () => {
|
||||||
{ ...mockCommitStatus, status: 'unknown' },
|
{ ...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
|
// Add current status ot list of commit statuses, then mock the API to return the whole list
|
||||||
commitStatuses.push({
|
commitStatuses.push({
|
||||||
...mockCommitStatus,
|
...mockCommitStatus,
|
||||||
status,
|
status,
|
||||||
created_at,
|
created_at: statusElem.created_at,
|
||||||
});
|
});
|
||||||
httpMock
|
httpMock
|
||||||
.scope(baseUrl)
|
.scope(baseUrl)
|
||||||
|
|
|
@ -98,7 +98,7 @@ export async function initPlatform(
|
||||||
);
|
);
|
||||||
gitAuthor = 'Renovate Bot <renovate@whitesourcesoftware.com>';
|
gitAuthor = 'Renovate Bot <renovate@whitesourcesoftware.com>';
|
||||||
} /* istanbul ignore next */ else {
|
} /* istanbul ignore next */ else {
|
||||||
logger.debug('Using platform gitAuthor: ' + platformInfo.gitAuthor);
|
logger.debug(`Using platform gitAuthor: ${String(platformInfo.gitAuthor)}`);
|
||||||
gitAuthor = platformInfo.gitAuthor;
|
gitAuthor = platformInfo.gitAuthor;
|
||||||
}
|
}
|
||||||
const gitAuthorParsed = parseGitAuthor(gitAuthor);
|
const gitAuthorParsed = parseGitAuthor(gitAuthor);
|
||||||
|
|
Loading…
Reference in a new issue