mirror of
https://github.com/renovatebot/renovate.git
synced 2025-03-16 17:13:37 +00:00
refactor: enums to unions (#18747)
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
This commit is contained in:
parent
2a07e91be6
commit
c93154bd24
26 changed files with 95 additions and 156 deletions
lib
modules
datasource
manager/terragrunt
versioning/gradle
util/json-writer
workers/repository/update/pr
|
@ -10,7 +10,7 @@ import { GlobalConfig } from '../../../config/global';
|
|||
import type { RepoGlobalConfig } from '../../../config/types';
|
||||
import { EXTERNAL_HOST_ERROR } from '../../../constants/error-messages';
|
||||
import * as memCache from '../../../util/cache/memory';
|
||||
import { RegistryFlavor, RegistryInfo } from './types';
|
||||
import type { RegistryInfo } from './types';
|
||||
import { CrateDatasource } from '.';
|
||||
|
||||
jest.mock('simple-git');
|
||||
|
@ -361,7 +361,7 @@ describe('modules/datasource/crate/index', () => {
|
|||
const info: RegistryInfo = {
|
||||
rawUrl: 'https://example.com',
|
||||
url: new URL('https://example.com'),
|
||||
flavor: RegistryFlavor.Cloudsmith,
|
||||
flavor: 'cloudsmith',
|
||||
};
|
||||
const crateDatasource = new CrateDatasource();
|
||||
await expect(
|
||||
|
|
|
@ -12,7 +12,7 @@ import { parseUrl } from '../../../util/url';
|
|||
import * as cargoVersioning from '../../versioning/cargo';
|
||||
import { Datasource } from '../datasource';
|
||||
import type { GetReleasesConfig, Release, ReleaseResult } from '../types';
|
||||
import {
|
||||
import type {
|
||||
CrateMetadata,
|
||||
CrateRecord,
|
||||
RegistryFlavor,
|
||||
|
@ -125,7 +125,7 @@ export class CrateDatasource extends Datasource {
|
|||
info: RegistryInfo,
|
||||
packageName: string
|
||||
): Promise<CrateMetadata | null> {
|
||||
if (info.flavor !== RegistryFlavor.CratesIo) {
|
||||
if (info.flavor !== 'crates.io') {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -165,7 +165,7 @@ export class CrateDatasource extends Datasource {
|
|||
return readCacheFile(path, 'utf8');
|
||||
}
|
||||
|
||||
if (info.flavor === RegistryFlavor.CratesIo) {
|
||||
if (info.flavor === 'crates.io') {
|
||||
const crateUrl =
|
||||
CrateDatasource.CRATES_IO_BASE_URL +
|
||||
CrateDatasource.getIndexSuffix(packageName.toLowerCase()).join('/');
|
||||
|
@ -187,9 +187,9 @@ export class CrateDatasource extends Datasource {
|
|||
packageName: string
|
||||
): string {
|
||||
switch (info.flavor) {
|
||||
case RegistryFlavor.CratesIo:
|
||||
case 'crates.io':
|
||||
return `https://crates.io/crates/${packageName}`;
|
||||
case RegistryFlavor.Cloudsmith: {
|
||||
case 'cloudsmith': {
|
||||
// input: https://dl.cloudsmith.io/basic/$org/$repo/cargo/index.git
|
||||
const tokens = info.url.pathname.split('/');
|
||||
const org = tokens[2];
|
||||
|
@ -238,11 +238,11 @@ export class CrateDatasource extends Datasource {
|
|||
|
||||
let flavor: RegistryFlavor;
|
||||
if (url.hostname === 'crates.io') {
|
||||
flavor = RegistryFlavor.CratesIo;
|
||||
flavor = 'crates.io';
|
||||
} else if (url.hostname === 'dl.cloudsmith.io') {
|
||||
flavor = RegistryFlavor.Cloudsmith;
|
||||
flavor = 'cloudsmith';
|
||||
} else {
|
||||
flavor = RegistryFlavor.Other;
|
||||
flavor = 'other';
|
||||
}
|
||||
|
||||
const registry: RegistryInfo = {
|
||||
|
@ -251,7 +251,7 @@ export class CrateDatasource extends Datasource {
|
|||
url,
|
||||
};
|
||||
|
||||
if (flavor !== RegistryFlavor.CratesIo) {
|
||||
if (flavor !== 'crates.io') {
|
||||
if (!GlobalConfig.get('allowCustomCrateRegistries')) {
|
||||
logger.warn(
|
||||
'crate datasource: allowCustomCrateRegistries=true is required for registries other than crates.io, bailing out'
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
// eslint-disable-next-line typescript-enum/no-enum
|
||||
export enum RegistryFlavor {
|
||||
export type RegistryFlavor =
|
||||
/** https://crates.io, supports rawgit access */
|
||||
CratesIo,
|
||||
| 'crates.io'
|
||||
|
||||
/** https://cloudsmith.io, needs git clone */
|
||||
Cloudsmith,
|
||||
| 'cloudsmith'
|
||||
|
||||
/** unknown, assuming private git repository */
|
||||
Other,
|
||||
}
|
||||
| 'other';
|
||||
|
||||
export interface RegistryInfo {
|
||||
flavor: RegistryFlavor;
|
||||
|
|
|
@ -6,11 +6,9 @@ import { getSourceUrl as gitlabSourceUrl } from '../gitlab-tags/util';
|
|||
|
||||
import type { DataSource } from './types';
|
||||
|
||||
// eslint-disable-next-line typescript-enum/no-enum
|
||||
export enum GoproxyFallback {
|
||||
WhenNotFoundOrGone = ',',
|
||||
Always = '|',
|
||||
}
|
||||
export type GoproxyFallback =
|
||||
| ',' // WhenNotFoundOrGone
|
||||
| '|'; // Always
|
||||
|
||||
export function getSourceUrl(
|
||||
dataSource?: DataSource | null
|
||||
|
|
|
@ -8,7 +8,7 @@ import { newlineRegex, regEx } from '../../../util/regex';
|
|||
import { Datasource } from '../datasource';
|
||||
import type { GetReleasesConfig, Release, ReleaseResult } from '../types';
|
||||
import { BaseGoDatasource } from './base';
|
||||
import { GoproxyFallback, getSourceUrl } from './common';
|
||||
import { getSourceUrl } from './common';
|
||||
import { GoDirectDatasource } from './releases-direct';
|
||||
import type { GoproxyItem, VersionInfo } from './types';
|
||||
|
||||
|
@ -84,9 +84,7 @@ export class GoProxyDatasource extends Datasource {
|
|||
} catch (err) {
|
||||
const statusCode = err?.response?.statusCode;
|
||||
const canFallback =
|
||||
fallback === GoproxyFallback.Always
|
||||
? true
|
||||
: statusCode === 404 || statusCode === 410;
|
||||
fallback === '|' ? true : statusCode === 404 || statusCode === 410;
|
||||
const msg = canFallback
|
||||
? 'Goproxy error: trying next URL provided with GOPROXY'
|
||||
: 'Goproxy error: skipping other URLs provided with GOPROXY';
|
||||
|
@ -128,10 +126,7 @@ export class GoProxyDatasource extends Datasource {
|
|||
.map((s) => s.split(/(?=,|\|)/)) // TODO: #12872 lookahead
|
||||
.map(([url, separator]) => ({
|
||||
url,
|
||||
fallback:
|
||||
separator === ','
|
||||
? GoproxyFallback.WhenNotFoundOrGone
|
||||
: GoproxyFallback.Always,
|
||||
fallback: separator === ',' ? ',' : '|',
|
||||
}));
|
||||
|
||||
parsedGoproxy[input] = result;
|
||||
|
|
|
@ -10,13 +10,11 @@ import { Datasource } from '../datasource';
|
|||
import { massageGithubUrl } from '../metadata';
|
||||
import type { GetReleasesConfig, ReleaseResult } from '../types';
|
||||
|
||||
// eslint-disable-next-line typescript-enum/no-enum, typescript-enum/no-const-enum
|
||||
const enum URLFormatOptions {
|
||||
WithShardWithSpec,
|
||||
WithShardWithoutSpec,
|
||||
WithSpecsWithoutShard,
|
||||
WithoutSpecsWithoutShard,
|
||||
}
|
||||
type URLFormatOptions =
|
||||
| 'withShardWithSpec'
|
||||
| 'withShardWithoutSpec'
|
||||
| 'withSpecsWithoutShard'
|
||||
| 'withoutSpecsWithoutShard';
|
||||
|
||||
function shardParts(packageName: string): string[] {
|
||||
return crypto
|
||||
|
@ -144,7 +142,7 @@ export class PodDatasource extends Datasource {
|
|||
opts: { hostURL: string; account: string; repo: string },
|
||||
useShard = true,
|
||||
useSpecs = true,
|
||||
urlFormatOptions = URLFormatOptions.WithShardWithSpec
|
||||
urlFormatOptions: URLFormatOptions = 'withShardWithSpec'
|
||||
): Promise<ReleaseResult | null> {
|
||||
const url = releasesGithubUrl(packageName, { ...opts, useShard, useSpecs });
|
||||
const resp = await this.requestGithub<{ name: string }[]>(url, packageName);
|
||||
|
@ -153,33 +151,33 @@ export class PodDatasource extends Datasource {
|
|||
return { releases };
|
||||
}
|
||||
|
||||
// iterating through enum to support different url formats
|
||||
// support different url formats
|
||||
switch (urlFormatOptions) {
|
||||
case URLFormatOptions.WithShardWithSpec:
|
||||
case 'withShardWithSpec':
|
||||
return this.getReleasesFromGithub(
|
||||
packageName,
|
||||
opts,
|
||||
true,
|
||||
false,
|
||||
URLFormatOptions.WithShardWithoutSpec
|
||||
'withShardWithoutSpec'
|
||||
);
|
||||
case URLFormatOptions.WithShardWithoutSpec:
|
||||
case 'withShardWithoutSpec':
|
||||
return this.getReleasesFromGithub(
|
||||
packageName,
|
||||
opts,
|
||||
false,
|
||||
true,
|
||||
URLFormatOptions.WithSpecsWithoutShard
|
||||
'withSpecsWithoutShard'
|
||||
);
|
||||
case URLFormatOptions.WithSpecsWithoutShard:
|
||||
case 'withSpecsWithoutShard':
|
||||
return this.getReleasesFromGithub(
|
||||
packageName,
|
||||
opts,
|
||||
false,
|
||||
false,
|
||||
URLFormatOptions.WithoutSpecsWithoutShard
|
||||
'withoutSpecsWithoutShard'
|
||||
);
|
||||
case URLFormatOptions.WithoutSpecsWithoutShard:
|
||||
case 'withoutSpecsWithoutShard':
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,2 @@
|
|||
// FIXME #12556
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
|
||||
// eslint-disable-next-line typescript-enum/no-enum
|
||||
export enum TerragruntResourceTypes {
|
||||
unknown = 'unknown',
|
||||
}
|
||||
|
||||
// eslint-disable-next-line typescript-enum/no-enum
|
||||
export enum TerragruntDependencyTypes {
|
||||
unknown = 'unknown',
|
||||
terragrunt = 'terraform',
|
||||
}
|
||||
export type TerragruntResourceTypes = 'unknown';
|
||||
export type TerragruntDependencyTypes = 'unknown' | 'terraform';
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import { logger } from '../../../logger';
|
||||
import { newlineRegex, regEx } from '../../../util/regex';
|
||||
import type { PackageDependency, PackageFile } from '../types';
|
||||
import { TerragruntDependencyTypes } from './common';
|
||||
import { analyseTerragruntModule, extractTerragruntModule } from './modules';
|
||||
import type { ExtractionResult, TerraformManagerData } from './types';
|
||||
import {
|
||||
|
@ -32,7 +31,7 @@ export function extractPackageFile(content: string): PackageFile | null {
|
|||
);
|
||||
let result: ExtractionResult | null = null;
|
||||
switch (tfDepType) {
|
||||
case TerragruntDependencyTypes.terragrunt: {
|
||||
case 'terraform': {
|
||||
result = extractTerragruntModule(lineNumber, lines);
|
||||
break;
|
||||
}
|
||||
|
@ -56,7 +55,7 @@ export function extractPackageFile(content: string): PackageFile | null {
|
|||
deps.forEach((dep) => {
|
||||
// TODO #7154
|
||||
switch (dep.managerData!.terragruntDependencyType) {
|
||||
case TerragruntDependencyTypes.terragrunt:
|
||||
case 'terraform':
|
||||
analyseTerragruntModule(dep);
|
||||
break;
|
||||
/* istanbul ignore next */
|
||||
|
|
|
@ -4,7 +4,6 @@ import { GitTagsDatasource } from '../../datasource/git-tags';
|
|||
import { GithubTagsDatasource } from '../../datasource/github-tags';
|
||||
import { TerraformModuleDatasource } from '../../datasource/terraform-module';
|
||||
import type { PackageDependency } from '../types';
|
||||
import { TerragruntDependencyTypes } from './common';
|
||||
import { extractTerragruntProvider } from './providers';
|
||||
import type { ExtractionResult, TerraformManagerData } from './types';
|
||||
|
||||
|
@ -24,8 +23,7 @@ export function extractTerragruntModule(
|
|||
const result = extractTerragruntProvider(startingLine, lines, moduleName);
|
||||
result.dependencies.forEach((dep) => {
|
||||
// TODO #7154
|
||||
dep.managerData!.terragruntDependencyType =
|
||||
TerragruntDependencyTypes.terragrunt;
|
||||
dep.managerData!.terragruntDependencyType = 'terraform';
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import { newlineRegex, regEx } from '../../../util/regex';
|
||||
import type { PackageDependency } from '../types';
|
||||
import { TerragruntDependencyTypes } from './common';
|
||||
import type { ExtractionResult, TerraformManagerData } from './types';
|
||||
import { keyValueExtractionRegex } from './util';
|
||||
|
||||
|
@ -34,7 +33,7 @@ export function extractTerragruntProvider(
|
|||
const deps: PackageDependency<TerraformManagerData>[] = [];
|
||||
const managerData: TerraformManagerData = {
|
||||
moduleName,
|
||||
terragruntDependencyType: TerragruntDependencyTypes.terragrunt,
|
||||
terragruntDependencyType: 'terraform',
|
||||
};
|
||||
const dep: PackageDependency<TerraformManagerData> = { managerData };
|
||||
const teraformContent = lines
|
||||
|
|
|
@ -1,29 +1,22 @@
|
|||
import { TerragruntDependencyTypes } from './common';
|
||||
import { getTerragruntDependencyType } from './util';
|
||||
|
||||
describe('modules/manager/terragrunt/util', () => {
|
||||
describe('getTerragruntDependencyType()', () => {
|
||||
it('returns TerragruntDependencyTypes.terragrunt', () => {
|
||||
expect(getTerragruntDependencyType('terraform')).toBe(
|
||||
TerragruntDependencyTypes.terragrunt
|
||||
);
|
||||
it('returns terraform', () => {
|
||||
expect(getTerragruntDependencyType('terraform')).toBe('terraform');
|
||||
});
|
||||
|
||||
it('returns TerragruntDependencyTypes.unknown', () => {
|
||||
expect(getTerragruntDependencyType('unknown')).toBe(
|
||||
TerragruntDependencyTypes.unknown
|
||||
);
|
||||
it('returns unknown', () => {
|
||||
expect(getTerragruntDependencyType('unknown')).toBe('unknown');
|
||||
});
|
||||
|
||||
it('returns TerragruntDependencyTypes.unknown on empty string', () => {
|
||||
expect(getTerragruntDependencyType('')).toBe(
|
||||
TerragruntDependencyTypes.unknown
|
||||
);
|
||||
it('returns unknown on empty string', () => {
|
||||
expect(getTerragruntDependencyType('')).toBe('unknown');
|
||||
});
|
||||
|
||||
it('returns TerragruntDependencyTypes.unknown on string with random chars', () => {
|
||||
it('returns unknown on string with random chars', () => {
|
||||
expect(getTerragruntDependencyType('sdfsgdsfadfhfghfhgdfsdf')).toBe(
|
||||
TerragruntDependencyTypes.unknown
|
||||
'unknown'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { regEx } from '../../../util/regex';
|
||||
import { TerragruntDependencyTypes } from './common';
|
||||
import type { TerragruntDependencyTypes } from './common';
|
||||
|
||||
export const keyValueExtractionRegex = regEx(
|
||||
/^\s*source\s+=\s+"(?<value>[^"]+)"\s*$/
|
||||
|
@ -10,10 +10,10 @@ export function getTerragruntDependencyType(
|
|||
): TerragruntDependencyTypes {
|
||||
switch (value) {
|
||||
case 'terraform': {
|
||||
return TerragruntDependencyTypes.terragrunt;
|
||||
return 'terraform';
|
||||
}
|
||||
default: {
|
||||
return TerragruntDependencyTypes.unknown;
|
||||
return 'unknown';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -223,11 +223,7 @@ interface PrefixRange {
|
|||
tokens: Token[];
|
||||
}
|
||||
|
||||
// eslint-disable-next-line typescript-enum/no-enum
|
||||
export enum RangeBound {
|
||||
Inclusive = 1,
|
||||
Exclusive,
|
||||
}
|
||||
export type RangeBound = 'inclusive' | 'exclusive';
|
||||
|
||||
interface MavenBasedRange {
|
||||
leftBound: RangeBound;
|
||||
|
@ -293,14 +289,9 @@ export function parseMavenBasedRange(input: string): MavenBasedRange | null {
|
|||
) {
|
||||
return null;
|
||||
}
|
||||
const leftBound =
|
||||
leftBoundStr.trim() === '['
|
||||
? RangeBound.Inclusive
|
||||
: RangeBound.Exclusive;
|
||||
const leftBound = leftBoundStr.trim() === '[' ? 'inclusive' : 'exclusive';
|
||||
const rightBound =
|
||||
rightBoundStr.trim() === ']'
|
||||
? RangeBound.Inclusive
|
||||
: RangeBound.Exclusive;
|
||||
rightBoundStr.trim() === ']' ? 'inclusive' : 'exclusive';
|
||||
return {
|
||||
leftBound,
|
||||
leftBoundStr,
|
||||
|
|
|
@ -2,7 +2,6 @@ import type { RangeStrategy } from '../../../types/versioning';
|
|||
import { regEx } from '../../../util/regex';
|
||||
import type { NewValueConfig, VersioningApi } from '../types';
|
||||
import {
|
||||
RangeBound,
|
||||
TokenType,
|
||||
compare,
|
||||
isValid,
|
||||
|
@ -139,14 +138,14 @@ const matches = (a: string, b: string): boolean => {
|
|||
|
||||
if (leftVal) {
|
||||
leftResult =
|
||||
leftBound === RangeBound.Exclusive
|
||||
leftBound === 'exclusive'
|
||||
? compare(leftVal, a) === -1
|
||||
: compare(leftVal, a) !== 1;
|
||||
}
|
||||
|
||||
if (rightVal) {
|
||||
rightResult =
|
||||
rightBound === RangeBound.Exclusive
|
||||
rightBound === 'exclusive'
|
||||
? compare(a, rightVal) === -1
|
||||
: compare(a, rightVal) !== 1;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ import { Fixtures } from '../../../test/fixtures';
|
|||
import { configFileNames } from '../../config/app-strings';
|
||||
import { GlobalConfig } from '../../config/global';
|
||||
import { EditorConfig } from './editor-config';
|
||||
import { IndentationType } from './indentation-type';
|
||||
|
||||
// use real fs to read wasm files for `@one-ini/wasm`
|
||||
jest.mock('fs', () => ({
|
||||
|
@ -48,7 +47,7 @@ describe('util/json-writer/editor-config', () => {
|
|||
});
|
||||
const format = await EditorConfig.getCodeFormat(defaultConfigFile);
|
||||
expect(format.indentationSize).toBe(6);
|
||||
expect(format.indentationType).toBe(IndentationType.Space);
|
||||
expect(format.indentationType).toBe('space');
|
||||
});
|
||||
|
||||
it('should return undefined in case of exception', async () => {
|
||||
|
@ -85,6 +84,6 @@ describe('util/json-writer/editor-config', () => {
|
|||
});
|
||||
const format = await EditorConfig.getCodeFormat(defaultConfigFile);
|
||||
|
||||
expect(format.indentationType).toBe(IndentationType.Tab);
|
||||
expect(format.indentationType).toBe('tab');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -3,7 +3,7 @@ import upath from 'upath';
|
|||
import { GlobalConfig } from '../../config/global';
|
||||
import { logger } from '../../logger';
|
||||
import type { CodeFormat } from './code-format';
|
||||
import { IndentationType } from './indentation-type';
|
||||
import type { IndentationType } from './indentation-type';
|
||||
|
||||
export class EditorConfig {
|
||||
public static async getCodeFormat(fileName: string): Promise<CodeFormat> {
|
||||
|
@ -26,11 +26,11 @@ export class EditorConfig {
|
|||
const { indent_style: indentStyle } = knownProps;
|
||||
|
||||
if (indentStyle === 'tab') {
|
||||
return IndentationType.Tab;
|
||||
return 'tab';
|
||||
}
|
||||
|
||||
if (indentStyle === 'space') {
|
||||
return IndentationType.Space;
|
||||
return 'space';
|
||||
}
|
||||
|
||||
return undefined;
|
||||
|
|
|
@ -1,5 +1 @@
|
|||
// eslint-disable-next-line typescript-enum/no-enum
|
||||
export enum IndentationType {
|
||||
Space = 'space',
|
||||
Tab = 'tab',
|
||||
}
|
||||
export type IndentationType = 'space' | 'tab';
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import { IndentationType } from './indentation-type';
|
||||
import { JSONWriter } from './json-writer';
|
||||
|
||||
describe('util/json-writer/json-writer', () => {
|
||||
|
@ -14,7 +13,7 @@ describe('util/json-writer/json-writer', () => {
|
|||
|
||||
it('should apply indentation size', () => {
|
||||
const jsonWriter = new JSONWriter({
|
||||
indentationType: IndentationType.Space,
|
||||
indentationType: 'space',
|
||||
indentationSize: 10,
|
||||
});
|
||||
|
||||
|
@ -23,7 +22,7 @@ describe('util/json-writer/json-writer', () => {
|
|||
|
||||
it('should apply indentation type', () => {
|
||||
const jsonWriter = new JSONWriter({
|
||||
indentationType: IndentationType.Tab,
|
||||
indentationType: 'tab',
|
||||
});
|
||||
|
||||
expect(jsonWriter.write(DATA)).toBe('{\n\t"value": 1\n}\n');
|
||||
|
@ -31,7 +30,7 @@ describe('util/json-writer/json-writer', () => {
|
|||
|
||||
it('new line at the end should be optional', () => {
|
||||
const jsonWriter = new JSONWriter({
|
||||
indentationType: IndentationType.Space,
|
||||
indentationType: 'space',
|
||||
indentationSize: 10,
|
||||
});
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import type { CodeFormat } from './code-format';
|
||||
import { IndentationType } from './indentation-type';
|
||||
import type { IndentationType } from './indentation-type';
|
||||
|
||||
export class JSONWriter {
|
||||
private readonly indentationType: IndentationType;
|
||||
|
@ -8,7 +8,7 @@ export class JSONWriter {
|
|||
|
||||
constructor(codeFormat: CodeFormat = {}) {
|
||||
this.indentationSize = codeFormat.indentationSize ?? 2;
|
||||
this.indentationType = codeFormat.indentationType ?? IndentationType.Space;
|
||||
this.indentationType = codeFormat.indentationType ?? 'space';
|
||||
}
|
||||
|
||||
public write(json: unknown, newLineAtTheEnd = true): string {
|
||||
|
@ -22,7 +22,7 @@ export class JSONWriter {
|
|||
}
|
||||
|
||||
private get indentation(): string | number {
|
||||
if (this.indentationType === IndentationType.Tab) {
|
||||
if (this.indentationType === 'tab') {
|
||||
return '\t';
|
||||
}
|
||||
|
||||
|
|
|
@ -16,16 +16,14 @@ import type { BranchConfig } from '../../../types';
|
|||
import { isScheduledNow } from '../branch/schedule';
|
||||
import { resolveBranchStatus } from '../branch/status-checks';
|
||||
|
||||
// eslint-disable-next-line typescript-enum/no-enum
|
||||
export enum PrAutomergeBlockReason {
|
||||
BranchModified = 'BranchModified',
|
||||
BranchNotGreen = 'BranchNotGreen',
|
||||
Conflicted = 'Conflicted',
|
||||
DryRun = 'DryRun',
|
||||
PlatformNotReady = 'PlatformNotReady',
|
||||
PlatformRejection = 'PlatformRejection',
|
||||
OffSchedule = 'off schedule',
|
||||
}
|
||||
export type PrAutomergeBlockReason =
|
||||
| 'BranchModified'
|
||||
| 'BranchNotGreen'
|
||||
| 'Conflicted'
|
||||
| 'DryRun'
|
||||
| 'PlatformNotReady'
|
||||
| 'PlatformRejection'
|
||||
| 'off schedule';
|
||||
|
||||
export interface AutomergePrResult {
|
||||
automerged: boolean;
|
||||
|
@ -52,7 +50,7 @@ export async function checkAutoMerge(
|
|||
logger.debug(`PR automerge is off schedule`);
|
||||
return {
|
||||
automerged: false,
|
||||
prAutomergeBlockReason: PrAutomergeBlockReason.OffSchedule,
|
||||
prAutomergeBlockReason: 'off schedule',
|
||||
};
|
||||
}
|
||||
const isConflicted =
|
||||
|
@ -62,7 +60,7 @@ export async function checkAutoMerge(
|
|||
logger.debug('PR is conflicted');
|
||||
return {
|
||||
automerged: false,
|
||||
prAutomergeBlockReason: PrAutomergeBlockReason.Conflicted,
|
||||
prAutomergeBlockReason: 'Conflicted',
|
||||
};
|
||||
}
|
||||
if (!ignoreTests && pr.cannotMergeReason) {
|
||||
|
@ -71,7 +69,7 @@ export async function checkAutoMerge(
|
|||
);
|
||||
return {
|
||||
automerged: false,
|
||||
prAutomergeBlockReason: PrAutomergeBlockReason.PlatformNotReady,
|
||||
prAutomergeBlockReason: 'PlatformNotReady',
|
||||
};
|
||||
}
|
||||
const branchStatus = await resolveBranchStatus(
|
||||
|
@ -84,7 +82,7 @@ export async function checkAutoMerge(
|
|||
);
|
||||
return {
|
||||
automerged: false,
|
||||
prAutomergeBlockReason: PrAutomergeBlockReason.BranchNotGreen,
|
||||
prAutomergeBlockReason: 'BranchNotGreen',
|
||||
};
|
||||
}
|
||||
// Check if it's been touched
|
||||
|
@ -92,7 +90,7 @@ export async function checkAutoMerge(
|
|||
logger.debug('PR is ready for automerge but has been modified');
|
||||
return {
|
||||
automerged: false,
|
||||
prAutomergeBlockReason: PrAutomergeBlockReason.BranchModified,
|
||||
prAutomergeBlockReason: 'BranchModified',
|
||||
};
|
||||
}
|
||||
if (automergeType === 'pr-comment') {
|
||||
|
@ -105,7 +103,7 @@ export async function checkAutoMerge(
|
|||
);
|
||||
return {
|
||||
automerged: false,
|
||||
prAutomergeBlockReason: PrAutomergeBlockReason.DryRun,
|
||||
prAutomergeBlockReason: 'DryRun',
|
||||
};
|
||||
}
|
||||
if (rebaseRequested) {
|
||||
|
@ -133,7 +131,7 @@ export async function checkAutoMerge(
|
|||
);
|
||||
return {
|
||||
automerged: false,
|
||||
prAutomergeBlockReason: PrAutomergeBlockReason.DryRun,
|
||||
prAutomergeBlockReason: 'DryRun',
|
||||
};
|
||||
}
|
||||
// TODO: types (#7154)
|
||||
|
@ -160,6 +158,6 @@ export async function checkAutoMerge(
|
|||
}
|
||||
return {
|
||||
automerged: false,
|
||||
prAutomergeBlockReason: PrAutomergeBlockReason.PlatformRejection,
|
||||
prAutomergeBlockReason: 'PlatformRejection',
|
||||
};
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ import { GlobalConfig } from '../../../../../config/global';
|
|||
import * as semverVersioning from '../../../../../modules/versioning/semver';
|
||||
import * as hostRules from '../../../../../util/host-rules';
|
||||
import type { BranchUpgradeConfig } from '../../../../types';
|
||||
import { ChangeLogError, getChangeLogJSON } from '.';
|
||||
import { getChangeLogJSON } from '.';
|
||||
|
||||
jest.mock('../../../../../modules/datasource/npm');
|
||||
|
||||
|
@ -211,7 +211,7 @@ describe('workers/repository/update/pr/changelog/github', () => {
|
|||
...upgrade,
|
||||
sourceUrl: 'https://github.com',
|
||||
})
|
||||
).toEqual({ error: ChangeLogError.MissingGithubToken });
|
||||
).toEqual({ error: 'MissingGithubToken' });
|
||||
});
|
||||
|
||||
it('handles no releases', async () => {
|
||||
|
|
|
@ -4,7 +4,7 @@ import { GlobalConfig } from '../../../../../config/global';
|
|||
import * as semverVersioning from '../../../../../modules/versioning/semver';
|
||||
import * as hostRules from '../../../../../util/host-rules';
|
||||
import type { BranchConfig } from '../../../../types';
|
||||
import { ChangeLogError, getChangeLogJSON } from '.';
|
||||
import { getChangeLogJSON } from '.';
|
||||
|
||||
jest.mock('../../../../../modules/datasource/npm');
|
||||
|
||||
|
@ -233,7 +233,7 @@ describe('workers/repository/update/pr/changelog/index', () => {
|
|||
...upgrade,
|
||||
sourceUrl: 'https://github.com',
|
||||
})
|
||||
).toEqual({ error: ChangeLogError.MissingGithubToken });
|
||||
).toEqual({ error: 'MissingGithubToken' });
|
||||
});
|
||||
|
||||
it('handles no releases', async () => {
|
||||
|
|
|
@ -13,7 +13,7 @@ import { slugifyUrl } from './common';
|
|||
import { getTags } from './github';
|
||||
import { addReleaseNotes } from './release-notes';
|
||||
import { getInRangeReleases } from './releases';
|
||||
import { ChangeLogError, ChangeLogRelease, ChangeLogResult } from './types';
|
||||
import type { ChangeLogRelease, ChangeLogResult } from './types';
|
||||
|
||||
function getCachedTags(
|
||||
endpoint: string,
|
||||
|
@ -69,7 +69,7 @@ export async function getChangeLogJSON(
|
|||
{ manager, depName, sourceUrl },
|
||||
'No github.com token has been configured. Skipping release notes retrieval'
|
||||
);
|
||||
return { error: ChangeLogError.MissingGithubToken };
|
||||
return { error: 'MissingGithubToken' };
|
||||
}
|
||||
logger.debug(
|
||||
{ manager, depName, sourceUrl },
|
||||
|
|
|
@ -33,11 +33,7 @@ export interface ChangeLogProject {
|
|||
sourceDirectory?: string;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line typescript-enum/no-enum
|
||||
export enum ChangeLogError {
|
||||
MissingGithubToken = 1,
|
||||
MissingGitlabToken = 2,
|
||||
}
|
||||
export type ChangeLogError = 'MissingGithubToken' | 'MissingGitlabToken';
|
||||
|
||||
export interface ChangeLogResult {
|
||||
hasReleaseNotes?: boolean;
|
||||
|
|
|
@ -15,11 +15,7 @@ import * as _limits from '../../../global/limits';
|
|||
import type { BranchConfig, BranchUpgradeConfig } from '../../../types';
|
||||
import * as _statusChecks from '../branch/status-checks';
|
||||
import * as _prBody from './body';
|
||||
import {
|
||||
ChangeLogChange,
|
||||
ChangeLogError,
|
||||
ChangeLogRelease,
|
||||
} from './changelog/types';
|
||||
import type { ChangeLogChange, ChangeLogRelease } from './changelog/types';
|
||||
import * as _participants from './participants';
|
||||
import { ensurePr } from '.';
|
||||
|
||||
|
@ -635,7 +631,7 @@ describe('workers/repository/update/pr/index', () => {
|
|||
upgrades: [
|
||||
{
|
||||
...dummyUpgrade,
|
||||
logJSON: { error: ChangeLogError.MissingGithubToken },
|
||||
logJSON: { error: 'MissingGithubToken' },
|
||||
prBodyNotes: [],
|
||||
},
|
||||
],
|
||||
|
|
|
@ -28,10 +28,8 @@ import type {
|
|||
PrBlockedBy,
|
||||
} from '../../../types';
|
||||
import { embedChangelogs } from '../../changelog';
|
||||
// import { embedChangelogs } from '../../changelog';
|
||||
import { resolveBranchStatus } from '../branch/status-checks';
|
||||
import { getPrBody } from './body';
|
||||
import { ChangeLogError } from './changelog/types';
|
||||
import { prepareLabels } from './labels';
|
||||
import { addParticipants } from './participants';
|
||||
|
||||
|
@ -237,7 +235,7 @@ export async function ensurePr(
|
|||
}
|
||||
}
|
||||
}
|
||||
} else if (logJSON.error === ChangeLogError.MissingGithubToken) {
|
||||
} else if (logJSON.error === 'MissingGithubToken') {
|
||||
upgrade.prBodyNotes ??= [];
|
||||
upgrade.prBodyNotes = [
|
||||
...upgrade.prBodyNotes,
|
||||
|
|
Loading…
Reference in a new issue