chore: rename platform types

This commit is contained in:
Rhys Arkins 2020-07-24 17:57:45 +02:00
parent bcdd97cb61
commit b11e5cb761
9 changed files with 42 additions and 42 deletions

View file

@ -26,10 +26,10 @@ import {
EnsureIssueResult, EnsureIssueResult,
FindPRConfig, FindPRConfig,
Issue, Issue,
PlatformConfig, PlatformResult,
Pr, Pr,
RepoConfig,
RepoParams, RepoParams,
RepoResult,
VulnerabilityAlert, VulnerabilityAlert,
} from '../common'; } from '../common';
import { smartTruncate } from '../utils/pr-body'; import { smartTruncate } from '../utils/pr-body';
@ -65,7 +65,7 @@ export function initPlatform({
token, token,
username, username,
password, password,
}: RenovateConfig): Promise<PlatformConfig> { }: RenovateConfig): Promise<PlatformResult> {
if (!endpoint) { if (!endpoint) {
throw new Error('Init: You must configure an Azure DevOps endpoint'); throw new Error('Init: You must configure an Azure DevOps endpoint');
} }
@ -80,7 +80,7 @@ export function initPlatform({
}; };
defaults.endpoint = res.endpoint; defaults.endpoint = res.endpoint;
azureApi.setEndpoint(res.endpoint); azureApi.setEndpoint(res.endpoint);
const platformConfig: PlatformConfig = { const platformConfig: PlatformResult = {
endpoint: defaults.endpoint, endpoint: defaults.endpoint,
}; };
return Promise.resolve(platformConfig); return Promise.resolve(platformConfig);
@ -98,7 +98,7 @@ export async function initRepo({
localDir, localDir,
azureWorkItemId, azureWorkItemId,
optimizeForDisabled, optimizeForDisabled,
}: RepoParams): Promise<RepoConfig> { }: RepoParams): Promise<RepoResult> {
logger.debug(`initRepo("${repository}")`); logger.debug(`initRepo("${repository}")`);
config = { repository, azureWorkItemId } as any; config = { repository, azureWorkItemId } as any;
const azureApiGit = await azureApi.gitApi(); const azureApiGit = await azureApi.gitApi();
@ -157,7 +157,7 @@ export async function initRepo({
gitAuthorName: global.gitAuthor?.name, gitAuthorName: global.gitAuthor?.name,
gitAuthorEmail: global.gitAuthor?.email, gitAuthorEmail: global.gitAuthor?.email,
}); });
const repoConfig: RepoConfig = { const repoConfig: RepoResult = {
defaultBranch, defaultBranch,
isFork: false, isFork: false,
}; };

View file

@ -29,10 +29,10 @@ import {
EnsureIssueResult, EnsureIssueResult,
FindPRConfig, FindPRConfig,
Issue, Issue,
PlatformConfig, PlatformResult,
Pr, Pr,
RepoConfig,
RepoParams, RepoParams,
RepoResult,
VulnerabilityAlert, VulnerabilityAlert,
} from '../common'; } from '../common';
import { smartTruncate } from '../utils/pr-body'; import { smartTruncate } from '../utils/pr-body';
@ -68,7 +68,7 @@ export function initPlatform({
endpoint, endpoint,
username, username,
password, password,
}: RenovateConfig): Promise<PlatformConfig> { }: RenovateConfig): Promise<PlatformResult> {
if (!endpoint) { if (!endpoint) {
throw new Error('Init: You must configure a Bitbucket Server endpoint'); throw new Error('Init: You must configure a Bitbucket Server endpoint');
} }
@ -80,7 +80,7 @@ export function initPlatform({
// TODO: Add a connection check that endpoint/username/password combination are valid // TODO: Add a connection check that endpoint/username/password combination are valid
defaults.endpoint = ensureTrailingSlash(endpoint); defaults.endpoint = ensureTrailingSlash(endpoint);
setBaseUrl(defaults.endpoint); setBaseUrl(defaults.endpoint);
const platformConfig: PlatformConfig = { const platformConfig: PlatformResult = {
endpoint: defaults.endpoint, endpoint: defaults.endpoint,
}; };
return Promise.resolve(platformConfig); return Promise.resolve(platformConfig);
@ -111,7 +111,7 @@ export async function initRepo({
localDir, localDir,
optimizeForDisabled, optimizeForDisabled,
bbUseDefaultReviewers, bbUseDefaultReviewers,
}: RepoParams): Promise<RepoConfig> { }: RepoParams): Promise<RepoResult> {
logger.debug( logger.debug(
`initRepo("${JSON.stringify({ repository, localDir }, null, 2)}")` `initRepo("${JSON.stringify({ repository, localDir }, null, 2)}")`
); );
@ -202,7 +202,7 @@ export async function initRepo({
) )
).body.displayId; ).body.displayId;
config.mergeMethod = 'merge'; config.mergeMethod = 'merge';
const repoConfig: RepoConfig = { const repoConfig: RepoResult = {
defaultBranch, defaultBranch,
isFork: !!info.parent, isFork: !!info.parent,
}; };

View file

@ -23,10 +23,10 @@ import {
EnsureIssueResult, EnsureIssueResult,
FindPRConfig, FindPRConfig,
Issue, Issue,
PlatformConfig, PlatformResult,
Pr, Pr,
RepoConfig,
RepoParams, RepoParams,
RepoResult,
VulnerabilityAlert, VulnerabilityAlert,
} from '../common'; } from '../common';
import { smartTruncate } from '../utils/pr-body'; import { smartTruncate } from '../utils/pr-body';
@ -46,7 +46,7 @@ export function initPlatform({
endpoint, endpoint,
username, username,
password, password,
}: RenovateConfig): Promise<PlatformConfig> { }: RenovateConfig): Promise<PlatformResult> {
if (!(username && password)) { if (!(username && password)) {
throw new Error( throw new Error(
'Init: You must configure a Bitbucket username and password' 'Init: You must configure a Bitbucket username and password'
@ -60,7 +60,7 @@ export function initPlatform({
} }
setBaseUrl(endpoint_); setBaseUrl(endpoint_);
// TODO: Add a connection check that endpoint/username/password combination are valid // TODO: Add a connection check that endpoint/username/password combination are valid
const platformConfig: PlatformConfig = { const platformConfig: PlatformResult = {
endpoint: endpoint || BITBUCKET_PROD_ENDPOINT, endpoint: endpoint || BITBUCKET_PROD_ENDPOINT,
}; };
return Promise.resolve(platformConfig); return Promise.resolve(platformConfig);
@ -86,7 +86,7 @@ export async function initRepo({
localDir, localDir,
optimizeForDisabled, optimizeForDisabled,
bbUseDefaultReviewers, bbUseDefaultReviewers,
}: RepoParams): Promise<RepoConfig> { }: RepoParams): Promise<RepoResult> {
logger.debug(`initRepo("${repository}")`); logger.debug(`initRepo("${repository}")`);
const opts = hostRules.find({ const opts = hostRules.find({
hostType: PLATFORM_TYPE_BITBUCKET, hostType: PLATFORM_TYPE_BITBUCKET,
@ -159,7 +159,7 @@ export async function initRepo({
gitAuthorName: global.gitAuthor?.name, gitAuthorName: global.gitAuthor?.name,
gitAuthorEmail: global.gitAuthor?.email, gitAuthorEmail: global.gitAuthor?.email,
}); });
const repoConfig: RepoConfig = { const repoConfig: RepoResult = {
defaultBranch: info.mainbranch, defaultBranch: info.mainbranch,
isFork: info.isFork, isFork: info.isFork,
}; };

View file

@ -6,13 +6,13 @@ import {
export type VulnerabilityAlert = _VulnerabilityAlert; export type VulnerabilityAlert = _VulnerabilityAlert;
export interface PlatformConfig { export interface PlatformResult {
endpoint: string; endpoint: string;
renovateUsername?: any; renovateUsername?: any;
gitAuthor?: any; gitAuthor?: any;
} }
export interface RepoConfig { export interface RepoResult {
defaultBranch: string; defaultBranch: string;
isFork: boolean; isFork: boolean;
} }
@ -122,7 +122,7 @@ export interface Platform {
findIssue(title: string): Promise<Issue | null>; findIssue(title: string): Promise<Issue | null>;
getIssueList(): Promise<Issue[]>; getIssueList(): Promise<Issue[]>;
getVulnerabilityAlerts(): Promise<VulnerabilityAlert[]>; getVulnerabilityAlerts(): Promise<VulnerabilityAlert[]>;
initRepo(config: RepoParams): Promise<RepoConfig>; initRepo(config: RepoParams): Promise<RepoResult>;
getPrList(): Promise<Pr[]>; getPrList(): Promise<Pr[]>;
ensureIssueClosing(title: string): Promise<void>; ensureIssueClosing(title: string): Promise<void>;
ensureIssue( ensureIssue(
@ -158,5 +158,5 @@ export interface Platform {
requiredStatusChecks?: string[] | null requiredStatusChecks?: string[] | null
): Promise<BranchStatus>; ): Promise<BranchStatus>;
getBranchPr(branchName: string): Promise<Pr | null>; getBranchPr(branchName: string): Promise<Pr | null>;
initPlatform(config: RenovateConfig): Promise<PlatformConfig>; initPlatform(config: RenovateConfig): Promise<PlatformResult>;
} }

View file

@ -1,4 +1,4 @@
import { BranchStatusConfig, Platform, RepoConfig, RepoParams } from '..'; import { BranchStatusConfig, Platform, RepoParams, RepoResult } from '..';
import { partial } from '../../../test/util'; import { partial } from '../../../test/util';
import { import {
REPOSITORY_ACCESS_FORBIDDEN, REPOSITORY_ACCESS_FORBIDDEN,
@ -168,7 +168,7 @@ describe('platform/gitea', () => {
function initFakeRepo( function initFakeRepo(
repo?: Partial<ght.Repo>, repo?: Partial<ght.Repo>,
config?: Partial<RepoParams> config?: Partial<RepoParams>
): Promise<RepoConfig> { ): Promise<RepoResult> {
helper.getRepo.mockResolvedValueOnce({ ...mockRepo, ...repo }); helper.getRepo.mockResolvedValueOnce({ ...mockRepo, ...repo });
return gitea.initRepo({ return gitea.initRepo({

View file

@ -29,10 +29,10 @@ import {
FindPRConfig, FindPRConfig,
Issue, Issue,
Platform, Platform,
PlatformConfig, PlatformResult,
Pr, Pr,
RepoConfig,
RepoParams, RepoParams,
RepoResult,
VulnerabilityAlert, VulnerabilityAlert,
} from '../common'; } from '../common';
import { smartTruncate } from '../utils/pr-body'; import { smartTruncate } from '../utils/pr-body';
@ -186,7 +186,7 @@ const platform: Platform = {
async initPlatform({ async initPlatform({
endpoint, endpoint,
token, token,
}: GiteaRenovateConfig): Promise<PlatformConfig> { }: GiteaRenovateConfig): Promise<PlatformResult> {
if (!token) { if (!token) {
throw new Error('Init: You must configure a Gitea personal access token'); throw new Error('Init: You must configure a Gitea personal access token');
} }
@ -221,7 +221,7 @@ const platform: Platform = {
repository, repository,
localDir, localDir,
optimizeForDisabled, optimizeForDisabled,
}: RepoParams): Promise<RepoConfig> { }: RepoParams): Promise<RepoResult> {
let renovateConfig: RenovateConfig; let renovateConfig: RenovateConfig;
let repo: helper.Repo; let repo: helper.Repo;

View file

@ -38,10 +38,10 @@ import {
EnsureIssueResult, EnsureIssueResult,
FindPRConfig, FindPRConfig,
Issue, Issue,
PlatformConfig, PlatformResult,
Pr, Pr,
RepoConfig,
RepoParams, RepoParams,
RepoResult,
VulnerabilityAlert, VulnerabilityAlert,
} from '../common'; } from '../common';
import { smartTruncate } from '../utils/pr-body'; import { smartTruncate } from '../utils/pr-body';
@ -76,7 +76,7 @@ export async function initPlatform({
}: { }: {
endpoint: string; endpoint: string;
token: string; token: string;
}): Promise<PlatformConfig> { }): Promise<PlatformResult> {
if (!token) { if (!token) {
throw new Error('Init: You must configure a GitHub personal access token'); throw new Error('Init: You must configure a GitHub personal access token');
} }
@ -126,7 +126,7 @@ export async function initPlatform({
gitAuthor = undefined; gitAuthor = undefined;
} }
logger.debug('Authenticated as GitHub user: ' + renovateUsername); logger.debug('Authenticated as GitHub user: ' + renovateUsername);
const platformConfig: PlatformConfig = { const platformConfig: PlatformResult = {
endpoint: defaults.endpoint, endpoint: defaults.endpoint,
gitAuthor, gitAuthor,
renovateUsername, renovateUsername,
@ -172,7 +172,7 @@ export async function initRepo({
includeForks, includeForks,
renovateUsername, renovateUsername,
optimizeForDisabled, optimizeForDisabled,
}: RepoParams): Promise<RepoConfig> { }: RepoParams): Promise<RepoResult> {
logger.debug(`initRepo("${repository}")`); logger.debug(`initRepo("${repository}")`);
// config is used by the platform api itself, not necessary for the app layer to know // config is used by the platform api itself, not necessary for the app layer to know
config = { localDir, repository } as any; config = { localDir, repository } as any;
@ -422,7 +422,7 @@ export async function initRepo({
gitAuthorName: global.gitAuthor?.name, gitAuthorName: global.gitAuthor?.name,
gitAuthorEmail: global.gitAuthor?.email, gitAuthorEmail: global.gitAuthor?.email,
}); });
const repoConfig: RepoConfig = { const repoConfig: RepoResult = {
defaultBranch: config.defaultBranch, defaultBranch: config.defaultBranch,
isFork: repo.isFork === true, isFork: repo.isFork === true,
}; };

View file

@ -32,10 +32,10 @@ import {
EnsureIssueConfig, EnsureIssueConfig,
FindPRConfig, FindPRConfig,
Issue, Issue,
PlatformConfig, PlatformResult,
Pr, Pr,
RepoConfig,
RepoParams, RepoParams,
RepoResult,
VulnerabilityAlert, VulnerabilityAlert,
} from '../common'; } from '../common';
import { smartTruncate } from '../utils/pr-body'; import { smartTruncate } from '../utils/pr-body';
@ -79,7 +79,7 @@ export async function initPlatform({
}: { }: {
token: string; token: string;
endpoint: string; endpoint: string;
}): Promise<PlatformConfig> { }): Promise<PlatformResult> {
if (!token) { if (!token) {
throw new Error('Init: You must configure a GitLab personal access token'); throw new Error('Init: You must configure a GitLab personal access token');
} }
@ -106,7 +106,7 @@ export async function initPlatform({
); );
throw new Error('Init: Authentication failure'); throw new Error('Init: Authentication failure');
} }
const platformConfig: PlatformConfig = { const platformConfig: PlatformResult = {
endpoint: defaults.endpoint, endpoint: defaults.endpoint,
gitAuthor, gitAuthor,
}; };
@ -140,7 +140,7 @@ export async function initRepo({
repository, repository,
localDir, localDir,
optimizeForDisabled, optimizeForDisabled,
}: RepoParams): Promise<RepoConfig> { }: RepoParams): Promise<RepoResult> {
config = {} as any; config = {} as any;
config.repository = urlEscape(repository); config.repository = urlEscape(repository);
config.localDir = localDir; config.localDir = localDir;
@ -252,7 +252,7 @@ export async function initRepo({
logger.debug({ err }, 'Unknown GitLab initRepo error'); logger.debug({ err }, 'Unknown GitLab initRepo error');
throw err; throw err;
} }
const repoConfig: RepoConfig = { const repoConfig: RepoResult = {
defaultBranch, defaultBranch,
isFork: !!res.body.forked_from_project, isFork: !!res.body.forked_from_project,
}; };

View file

@ -1,9 +1,9 @@
import { RenovateConfig } from '../../../config'; import { RenovateConfig } from '../../../config';
import * as npmApi from '../../../datasource/npm'; import * as npmApi from '../../../datasource/npm';
import { RepoConfig, RepoParams, platform } from '../../../platform'; import { RepoParams, RepoResult, platform } from '../../../platform';
// TODO: fix types // TODO: fix types
export type WorkerPlatformConfig = RepoConfig & export type WorkerPlatformConfig = RepoResult &
RenovateConfig & RenovateConfig &
Record<string, any>; Record<string, any>;