2019-05-20 13:08:18 +00:00
|
|
|
import got from 'got';
|
2019-09-10 07:50:29 +00:00
|
|
|
import Git from 'simple-git/promise';
|
|
|
|
import { RenovateConfig } from '../config/common';
|
2020-05-07 08:23:45 +00:00
|
|
|
import {
|
|
|
|
BranchStatus,
|
|
|
|
VulnerabilityAlert as _VulnerabilityAlert,
|
|
|
|
} from '../types';
|
|
|
|
|
|
|
|
export type VulnerabilityAlert = _VulnerabilityAlert;
|
2019-05-20 13:08:18 +00:00
|
|
|
|
2020-04-09 05:43:47 +00:00
|
|
|
/**
|
|
|
|
* File to commit to branch
|
|
|
|
*/
|
|
|
|
export interface File {
|
|
|
|
/**
|
|
|
|
* Relative file path
|
|
|
|
*/
|
2019-10-18 12:30:51 +00:00
|
|
|
name: string;
|
2020-04-09 05:43:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* file contents
|
|
|
|
*/
|
2020-02-13 05:39:07 +00:00
|
|
|
contents: string | Buffer;
|
2019-10-18 12:30:51 +00:00
|
|
|
}
|
|
|
|
|
2020-04-09 05:43:47 +00:00
|
|
|
export type CommitFilesConfig = {
|
|
|
|
branchName: string;
|
|
|
|
files: File[];
|
|
|
|
message: string;
|
|
|
|
};
|
|
|
|
|
2019-07-10 08:41:12 +00:00
|
|
|
export interface GotApiOptions {
|
2019-05-20 13:08:18 +00:00
|
|
|
useCache?: boolean;
|
2019-05-26 09:25:24 +00:00
|
|
|
hostType?: string;
|
2019-05-20 13:08:18 +00:00
|
|
|
body?: any;
|
|
|
|
}
|
|
|
|
|
2019-07-17 14:52:09 +00:00
|
|
|
export type GotResponse<T extends object = any> = got.Response<T>;
|
|
|
|
|
2019-07-10 08:41:12 +00:00
|
|
|
export interface GotApi<TOptions extends object = any> {
|
2019-05-20 13:08:18 +00:00
|
|
|
get<T extends object = any>(
|
|
|
|
url: string,
|
2019-07-10 08:41:12 +00:00
|
|
|
options?: GotApiOptions & TOptions
|
2019-07-17 14:52:09 +00:00
|
|
|
): Promise<GotResponse<T>>;
|
2019-05-20 13:08:18 +00:00
|
|
|
post<T extends object = any>(
|
|
|
|
url: string,
|
2019-07-10 08:41:12 +00:00
|
|
|
options?: GotApiOptions & TOptions
|
2019-07-17 14:52:09 +00:00
|
|
|
): Promise<GotResponse<T>>;
|
2019-05-20 13:08:18 +00:00
|
|
|
put<T extends object = any>(
|
|
|
|
url: string,
|
2019-07-10 08:41:12 +00:00
|
|
|
options?: GotApiOptions & TOptions
|
2019-07-17 14:52:09 +00:00
|
|
|
): Promise<GotResponse<T>>;
|
2019-05-20 13:08:18 +00:00
|
|
|
patch<T extends object = any>(
|
|
|
|
url: string,
|
2019-07-10 08:41:12 +00:00
|
|
|
options?: GotApiOptions & TOptions
|
2019-07-17 14:52:09 +00:00
|
|
|
): Promise<GotResponse<T>>;
|
2019-05-20 13:08:18 +00:00
|
|
|
head<T extends object = any>(
|
|
|
|
url: string,
|
2019-07-10 08:41:12 +00:00
|
|
|
options?: GotApiOptions & TOptions
|
2019-07-17 14:52:09 +00:00
|
|
|
): Promise<GotResponse<T>>;
|
2019-05-20 13:08:18 +00:00
|
|
|
delete<T extends object = any>(
|
|
|
|
url: string,
|
2019-07-10 08:41:12 +00:00
|
|
|
options?: GotApiOptions & TOptions
|
2019-07-17 14:52:09 +00:00
|
|
|
): Promise<GotResponse<T>>;
|
2019-05-20 13:08:18 +00:00
|
|
|
|
|
|
|
reset(): void;
|
|
|
|
|
2019-05-26 18:51:27 +00:00
|
|
|
setBaseUrl(endpoint: string): void;
|
2019-05-20 13:08:18 +00:00
|
|
|
}
|
2019-05-29 12:00:56 +00:00
|
|
|
|
|
|
|
export interface PlatformConfig {
|
2019-08-14 04:04:09 +00:00
|
|
|
endpoint: string;
|
|
|
|
renovateUsername?: any;
|
|
|
|
gitAuthor?: any;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface RepoConfig {
|
2019-08-14 09:38:13 +00:00
|
|
|
baseBranch: string;
|
2019-08-07 07:19:45 +00:00
|
|
|
endpoint?: string;
|
|
|
|
renovateUsername?: any;
|
|
|
|
gitAuthor?: any;
|
2019-05-29 12:00:56 +00:00
|
|
|
isFork: boolean;
|
2019-07-22 05:16:16 +00:00
|
|
|
}
|
|
|
|
|
2019-08-14 04:04:09 +00:00
|
|
|
export interface RepoParams {
|
|
|
|
azureWorkItemId?: number; // shouldn't this be configurable within a renovate.json?
|
|
|
|
bbUseDefaultReviewers?: boolean; // shouldn't this be configurable within a renovate.json?
|
2019-07-22 05:16:16 +00:00
|
|
|
gitPrivateKey?: string;
|
|
|
|
localDir: string;
|
2019-08-14 04:04:09 +00:00
|
|
|
optimizeForDisabled: boolean;
|
2019-07-22 05:16:16 +00:00
|
|
|
repository: string;
|
2019-08-14 04:04:09 +00:00
|
|
|
endpoint?: string;
|
|
|
|
forkMode?: string;
|
|
|
|
forkToken?: string;
|
|
|
|
includeForks?: boolean;
|
|
|
|
renovateUsername?: string;
|
2019-05-29 12:00:56 +00:00
|
|
|
}
|
2019-09-10 07:50:29 +00:00
|
|
|
|
|
|
|
/**
|
2020-05-07 08:23:45 +00:00
|
|
|
*
|
2019-09-10 07:50:29 +00:00
|
|
|
*/
|
2020-05-07 08:23:45 +00:00
|
|
|
export interface Pr {
|
|
|
|
body?: string;
|
2019-12-09 11:42:55 +00:00
|
|
|
branchName: string;
|
2020-05-07 08:23:45 +00:00
|
|
|
canMerge?: boolean;
|
|
|
|
canMergeReason?: string;
|
|
|
|
createdAt?: string;
|
|
|
|
displayNumber?: string;
|
2019-12-09 11:42:55 +00:00
|
|
|
isConflicted?: boolean;
|
|
|
|
isModified?: boolean;
|
2020-05-07 08:23:45 +00:00
|
|
|
isStale?: boolean;
|
|
|
|
labels?: string[];
|
|
|
|
number?: number;
|
|
|
|
reviewers?: string[];
|
|
|
|
sha?: string;
|
|
|
|
sourceRepo?: string;
|
|
|
|
state: string;
|
|
|
|
targetBranch?: string;
|
|
|
|
title: string;
|
|
|
|
}
|
2019-09-10 07:50:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* TODO: Proper typing
|
|
|
|
*/
|
|
|
|
export interface Issue {
|
|
|
|
body?: string;
|
|
|
|
number?: number;
|
|
|
|
state?: string;
|
|
|
|
title?: string;
|
|
|
|
}
|
|
|
|
export type PlatformPrOptions = {
|
2020-01-07 15:33:19 +00:00
|
|
|
azureAutoComplete?: boolean;
|
|
|
|
statusCheckVerify?: boolean;
|
|
|
|
gitLabAutomerge?: boolean;
|
2019-09-10 07:50:29 +00:00
|
|
|
};
|
2020-01-07 15:33:19 +00:00
|
|
|
export interface CreatePRConfig {
|
|
|
|
branchName: string;
|
|
|
|
prTitle: string;
|
|
|
|
prBody: string;
|
|
|
|
labels?: string[] | null;
|
|
|
|
useDefaultBranch?: boolean;
|
|
|
|
platformOptions?: PlatformPrOptions;
|
|
|
|
}
|
2020-01-07 10:40:53 +00:00
|
|
|
export interface EnsureIssueConfig {
|
|
|
|
title: string;
|
|
|
|
body: string;
|
|
|
|
once?: boolean;
|
|
|
|
shouldReOpen?: boolean;
|
|
|
|
}
|
2020-01-07 09:59:14 +00:00
|
|
|
export interface BranchStatusConfig {
|
|
|
|
branchName: string;
|
|
|
|
context: string;
|
|
|
|
description: string;
|
2020-03-08 14:03:19 +00:00
|
|
|
state: BranchStatus;
|
2020-01-07 09:59:14 +00:00
|
|
|
url?: string;
|
|
|
|
}
|
2020-01-14 15:12:14 +00:00
|
|
|
export interface FindPRConfig {
|
|
|
|
branchName: string;
|
|
|
|
prTitle?: string | null;
|
|
|
|
state?: 'open' | 'closed' | '!open' | 'all';
|
|
|
|
refreshCache?: boolean;
|
|
|
|
}
|
2020-01-14 11:13:35 +00:00
|
|
|
export interface EnsureCommentConfig {
|
|
|
|
number: number;
|
|
|
|
topic: string;
|
|
|
|
content: string;
|
|
|
|
}
|
2020-05-12 21:21:58 +00:00
|
|
|
|
|
|
|
export interface EnsureCommentRemovalConfigByTopic {
|
|
|
|
number: number;
|
|
|
|
topic: string;
|
|
|
|
}
|
|
|
|
export interface EnsureCommentRemovalConfigByContent {
|
|
|
|
number: number;
|
|
|
|
content: string;
|
|
|
|
}
|
2020-05-03 19:03:55 +00:00
|
|
|
export interface EnsureCommentRemovalConfig {
|
|
|
|
number: number;
|
|
|
|
content?: string;
|
2020-05-12 21:21:58 +00:00
|
|
|
topic?: string;
|
2020-05-03 19:03:55 +00:00
|
|
|
}
|
2019-09-10 07:50:29 +00:00
|
|
|
|
2020-02-25 08:42:24 +00:00
|
|
|
export type EnsureIssueResult = 'updated' | 'created';
|
|
|
|
|
2019-09-10 07:50:29 +00:00
|
|
|
export interface Platform {
|
2020-02-25 08:42:24 +00:00
|
|
|
findIssue(title: string): Promise<Issue | null>;
|
2019-09-10 07:50:29 +00:00
|
|
|
getIssueList(): Promise<Issue[]>;
|
|
|
|
getVulnerabilityAlerts(): Promise<VulnerabilityAlert[]>;
|
|
|
|
getCommitMessages(): Promise<string[]>;
|
|
|
|
setBranchPrefix(branchPrefix: string): Promise<void>;
|
|
|
|
initRepo(config: RepoParams): Promise<RepoConfig>;
|
|
|
|
cleanRepo(): Promise<void>;
|
|
|
|
getPrFiles(prNo: number): Promise<string[]>;
|
|
|
|
getPrList(): Promise<Pr[]>;
|
|
|
|
getAllRenovateBranches(branchPrefix: string): Promise<string[]>;
|
|
|
|
ensureIssueClosing(title: string): Promise<void>;
|
|
|
|
getFileList(): Promise<string[]>;
|
|
|
|
ensureIssue(
|
2020-01-07 10:40:53 +00:00
|
|
|
issueConfig: EnsureIssueConfig
|
2020-02-25 08:42:24 +00:00
|
|
|
): Promise<EnsureIssueResult | null>;
|
2019-09-10 07:50:29 +00:00
|
|
|
getPrBody(prBody: string): string;
|
|
|
|
updatePr(number: number, prTitle: string, prBody?: string): Promise<void>;
|
|
|
|
mergePr(number: number, branchName: string): Promise<boolean>;
|
|
|
|
addReviewers(number: number, reviewers: string[]): Promise<void>;
|
|
|
|
addAssignees(number: number, assignees: string[]): Promise<void>;
|
2020-01-07 15:33:19 +00:00
|
|
|
createPr(prConfig: CreatePRConfig): Promise<Pr>;
|
2019-09-10 07:50:29 +00:00
|
|
|
getBranchLastCommitTime(branchName: string): Promise<Date>;
|
|
|
|
getRepos(): Promise<string[]>;
|
|
|
|
isBranchStale(branchName: string): Promise<boolean>;
|
|
|
|
getRepoForceRebase(): Promise<boolean>;
|
|
|
|
deleteLabel(number: number, label: string): Promise<void>;
|
2020-01-07 09:59:14 +00:00
|
|
|
setBranchStatus(branchStatusConfig: BranchStatusConfig): Promise<void>;
|
2020-03-08 14:03:19 +00:00
|
|
|
getBranchStatusCheck(
|
|
|
|
branchName: string,
|
|
|
|
context: string
|
|
|
|
): Promise<BranchStatus | null>;
|
2020-05-03 19:03:55 +00:00
|
|
|
ensureCommentRemoval(
|
2020-05-12 21:21:58 +00:00
|
|
|
ensureCommentRemoval:
|
|
|
|
| EnsureCommentRemovalConfigByTopic
|
|
|
|
| EnsureCommentRemovalConfigByContent
|
2020-05-03 19:03:55 +00:00
|
|
|
): Promise<void>;
|
2019-09-10 07:50:29 +00:00
|
|
|
deleteBranch(branchName: string, closePr?: boolean): Promise<void>;
|
2020-01-14 11:13:35 +00:00
|
|
|
ensureComment(ensureComment: EnsureCommentConfig): Promise<boolean>;
|
2019-09-10 07:50:29 +00:00
|
|
|
branchExists(branchName: string): Promise<boolean>;
|
2020-05-03 18:38:09 +00:00
|
|
|
setBaseBranch(baseBranch?: string): Promise<string>;
|
2020-02-24 04:33:51 +00:00
|
|
|
commitFilesToBranch(commitFile: CommitFilesConfig): Promise<string | null>;
|
2019-09-10 07:50:29 +00:00
|
|
|
getPr(number: number): Promise<Pr>;
|
2020-01-14 15:12:14 +00:00
|
|
|
findPr(findPRConfig: FindPRConfig): Promise<Pr>;
|
2019-09-10 07:50:29 +00:00
|
|
|
mergeBranch(branchName: string): Promise<void>;
|
|
|
|
getBranchStatus(
|
|
|
|
branchName: string,
|
|
|
|
requiredStatusChecks?: string[] | null
|
|
|
|
): Promise<BranchStatus>;
|
2019-11-26 15:13:07 +00:00
|
|
|
getBranchPr(branchName: string): Promise<Pr | null>;
|
2019-09-10 07:50:29 +00:00
|
|
|
getRepoStatus(): Promise<Git.StatusResult>;
|
|
|
|
getFile(lockFileName: string, branchName?: string): Promise<string>;
|
|
|
|
initPlatform(config: RenovateConfig): Promise<PlatformConfig>;
|
|
|
|
}
|