diff --git a/lib/modules/datasource/docker/index.spec.ts b/lib/modules/datasource/docker/index.spec.ts index 113d9562f0d7e6..5ccae2c3af5819 100644 --- a/lib/modules/datasource/docker/index.spec.ts +++ b/lib/modules/datasource/docker/index.spec.ts @@ -13,7 +13,6 @@ import { } from '../../../constants/error-messages'; import * as _hostRules from '../../../util/host-rules'; import { Http } from '../../../util/http'; -import { MediaType } from './types'; import { DockerDatasource, getAuthHeaders, getRegistryRepository } from '.'; const hostRules = mocked(_hostRules); @@ -616,11 +615,14 @@ describe('modules/datasource/docker/index', () => { 'Bearer realm="https://auth.docker.io/token",service="registry.docker.io",scope="repository:library/some-dep:pull"', }) .head('/library/some-dep/manifests/' + currentDigest) - .reply(200, '', { 'content-type': MediaType.manifestV2 }) + .reply(200, '', { + 'content-type': + 'application/vnd.docker.distribution.manifest.v2+json', + }) .get('/library/some-dep/manifests/' + currentDigest) .reply(200, { schemaVersion: 2, - mediaType: MediaType.manifestV2, + mediaType: 'application/vnd.docker.distribution.manifest.v2+json', config: { digest: 'some-config-digest' }, }) .get('/library/some-dep/blobs/some-config-digest') @@ -637,7 +639,8 @@ describe('modules/datasource/docker/index', () => { .get('/library/some-dep/manifests/some-new-value') .reply(200, { schemaVersion: 2, - mediaType: MediaType.manifestListV2, + mediaType: + 'application/vnd.docker.distribution.manifest.list.v2+json', manifests: [ { digest: @@ -704,11 +707,14 @@ describe('modules/datasource/docker/index', () => { 'Bearer realm="https://auth.docker.io/token",service="registry.docker.io",scope="repository:library/some-dep:pull"', }) .head('/library/some-dep/manifests/' + currentDigest) - .reply(200, '', { 'content-type': MediaType.manifestV2 }) + .reply(200, '', { + 'content-type': + 'application/vnd.docker.distribution.manifest.v2+json', + }) .get('/library/some-dep/manifests/' + currentDigest) .reply(200, { schemaVersion: 2, - mediaType: MediaType.manifestV2, + mediaType: 'application/vnd.docker.distribution.manifest.v2+json', config: { digest: 'some-config-digest' }, }) .get('/library/some-dep/blobs/some-config-digest') @@ -726,7 +732,8 @@ describe('modules/datasource/docker/index', () => { .get('/library/some-dep/manifests/some-new-value') .reply(200, { schemaVersion: 2, - mediaType: MediaType.manifestListV2, + mediaType: + 'application/vnd.docker.distribution.manifest.list.v2+json', manifests: [ { digest: @@ -792,11 +799,13 @@ describe('modules/datasource/docker/index', () => { 'Bearer realm="https://auth.docker.io/token",service="registry.docker.io",scope="repository:library/some-dep:pull"', }) .head('/library/some-dep/manifests/' + currentDigest) - .reply(200, '', { 'content-type': MediaType.ociManifestV1 }) + .reply(200, '', { + 'content-type': 'application/vnd.oci.image.manifest.v1+json', + }) .get('/library/some-dep/manifests/' + currentDigest) .reply(200, { schemaVersion: 2, - mediaType: MediaType.ociManifestV1, + mediaType: 'application/vnd.oci.image.manifest.v1+json', config: { digest: 'some-config-digest' }, }) .get('/library/some-dep/blobs/some-config-digest') @@ -815,7 +824,7 @@ describe('modules/datasource/docker/index', () => { 200, { schemaVersion: 2, - mediaType: MediaType.ociManifestIndexV1, + mediaType: 'application/vnd.oci.image.index.v1+json', manifests: [ { digest: 'some-new-image-digest', @@ -864,7 +873,9 @@ describe('modules/datasource/docker/index', () => { 'Bearer realm="https://auth.docker.io/token",service="registry.docker.io",scope="repository:library/some-dep:pull"', }) .head('/library/some-dep/manifests/' + currentDigest) - .reply(200, '', { 'content-type': MediaType.ociManifestV1 }) + .reply(200, '', { + 'content-type': 'application/vnd.oci.image.manifest.v1+json', + }) .get('/library/some-dep/manifests/' + currentDigest) .reply(200, { schemaVersion: 2, @@ -929,7 +940,10 @@ describe('modules/datasource/docker/index', () => { 'Bearer realm="https://auth.docker.io/token",service="registry.docker.io",scope="repository:library/some-dep:pull"', }) .head('/library/some-dep/manifests/' + currentDigest) - .reply(200, '', { 'content-type': MediaType.manifestV2 }) + .reply(200, '', { + 'content-type': + 'application/vnd.docker.distribution.manifest.v2+json', + }) .get('/library/some-dep/manifests/' + currentDigest) .reply(404, {}); httpMock @@ -945,7 +959,8 @@ describe('modules/datasource/docker/index', () => { .get('/library/some-dep/manifests/some-new-value') .reply(200, { schemaVersion: 2, - mediaType: MediaType.manifestListV2, + mediaType: + 'application/vnd.docker.distribution.manifest.list.v2+json', manifests: [ { digest: @@ -1008,7 +1023,9 @@ describe('modules/datasource/docker/index', () => { 'Bearer realm="https://auth.docker.io/token",service="registry.docker.io",scope="repository:library/some-dep:pull"', }) .head('/library/some-dep/manifests/' + currentDigest) - .reply(200, '', { 'content-type': MediaType.ociManifestV1 }) + .reply(200, '', { + 'content-type': 'application/vnd.oci.image.manifest.v1+json', + }) .get('/library/some-dep/manifests/' + currentDigest) .reply(200, { schemaVersion: 2, @@ -1298,7 +1315,7 @@ describe('modules/datasource/docker/index', () => { .get('/node/manifests/some') .reply(200, { schemaVersion: 2, - mediaType: MediaType.manifestV2, + mediaType: 'application/vnd.docker.distribution.manifest.v2+json', config: { digest: 'some-config-digest' }, }) .get('/') @@ -1698,7 +1715,7 @@ describe('modules/datasource/docker/index', () => { .get('/node/manifests/2-alpine') .reply(200, { schemaVersion: 2, - mediaType: MediaType.manifestV2, + mediaType: 'application/vnd.docker.distribution.manifest.v2+json', config: { digest: 'some-config-digest' }, }) .get('/node/blobs/some-config-digest') @@ -1758,7 +1775,7 @@ describe('modules/datasource/docker/index', () => { .get('/node/manifests/2-alpine') .reply(200, { schemaVersion: 2, - mediaType: MediaType.manifestV2, + mediaType: 'application/vnd.docker.distribution.manifest.v2+json', config: { digest: 'some-config-digest' }, }) .get('/node/blobs/some-config-digest') @@ -1798,13 +1815,14 @@ describe('modules/datasource/docker/index', () => { .get('/node/manifests/abc') .reply(200, { schemaVersion: 2, - mediaType: MediaType.manifestListV2, + mediaType: + 'application/vnd.docker.distribution.manifest.list.v2+json', manifests: [{ digest: 'some-image-digest' }], }) .get('/node/manifests/some-image-digest') .reply(200, { schemaVersion: 2, - mediaType: MediaType.manifestV2, + mediaType: 'application/vnd.docker.distribution.manifest.v2+json', config: { digest: 'some-config-digest' }, }) .get('/node/blobs/some-config-digest') @@ -1839,7 +1857,8 @@ describe('modules/datasource/docker/index', () => { .get('/node/manifests/latest') .reply(200, { schemaVersion: 2, - mediaType: MediaType.manifestListV2, + mediaType: + 'application/vnd.docker.distribution.manifest.list.v2+json', manifests: [], }); const res = await getPkgReleases({ @@ -1864,7 +1883,7 @@ describe('modules/datasource/docker/index', () => { .get('/node/manifests/latest') .reply(200, { schemaVersion: 2, - mediaType: MediaType.manifestV1, + mediaType: 'application/vnd.docker.distribution.manifest.v1+json', }); const res = await getPkgReleases({ datasource: DockerDatasource.id, @@ -1910,13 +1929,13 @@ describe('modules/datasource/docker/index', () => { .get('/node/manifests/1') .reply(200, { schemaVersion: 2, - mediaType: MediaType.ociManifestIndexV1, + mediaType: 'application/vnd.oci.image.index.v1+json', manifests: [{ digest: 'some-image-digest' }], }) .get('/node/manifests/some-image-digest') .reply(200, { schemaVersion: 2, - mediaType: MediaType.ociManifestV1, + mediaType: 'application/vnd.oci.image.manifest.v1+json', config: { digest: 'some-config-digest' }, }) .get('/node/blobs/some-config-digest') @@ -1956,7 +1975,7 @@ describe('modules/datasource/docker/index', () => { .get('/node/manifests/1') .reply(200, { schemaVersion: 2, - mediaType: MediaType.ociManifestIndexV1, + mediaType: 'application/vnd.oci.image.index.v1+json', manifests: [{ digest: 'some-image-digest' }], }) .get('/node/manifests/some-image-digest') @@ -2000,7 +2019,7 @@ describe('modules/datasource/docker/index', () => { .get('/node/manifests/latest') .reply(200, { schemaVersion: 2, - mediaType: MediaType.ociManifestIndexV1, + mediaType: 'application/vnd.oci.image.index.v1+json', manifests: [], }); const res = await getPkgReleases({ @@ -2038,7 +2057,7 @@ describe('modules/datasource/docker/index', () => { .get('/node/manifests/latest') .reply(200, { schemaVersion: 2, - mediaType: MediaType.manifestV2, + mediaType: 'application/vnd.docker.distribution.manifest.v2+json', config: { digest: 'some-config-digest' }, }) .get('/node/blobs/some-config-digest') @@ -2096,7 +2115,7 @@ describe('modules/datasource/docker/index', () => { .get('/visualon/drone-git/manifests/latest') .reply(200, { schemaVersion: 2, - mediaType: MediaType.manifestV2, + mediaType: 'application/vnd.docker.distribution.manifest.v2+json', config: { digest: 'some-config-digest' }, }) .get('/visualon/drone-git/blobs/some-config-digest') diff --git a/lib/modules/datasource/docker/index.ts b/lib/modules/datasource/docker/index.ts index e71d254e8da20a..624646ce1afe90 100644 --- a/lib/modules/datasource/docker/index.ts +++ b/lib/modules/datasource/docker/index.ts @@ -36,11 +36,10 @@ import { import { Datasource } from '../datasource'; import type { DigestConfig, GetReleasesConfig, ReleaseResult } from '../types'; import { gitRefLabel, isArtifactoryServer, sourceLabels } from './common'; -import { +import type { Image, ImageConfig, ImageList, - MediaType, OciImage, OciImageList, RegistryRepository, @@ -407,10 +406,10 @@ export class DockerDatasource extends Datasource { return null; } headers.accept = [ - MediaType.manifestListV2, - MediaType.manifestV2, - MediaType.ociManifestV1, - MediaType.ociManifestIndexV1, + 'application/vnd.docker.distribution.manifest.list.v2+json', + 'application/vnd.docker.distribution.manifest.v2+json', + 'application/vnd.oci.image.manifest.v1+json', + 'application/vnd.oci.image.index.v1+json', ].join(', '); const url = `${registryHost}/v2/${dockerRepository}/manifests/${tag}`; const manifestResponse = await this.http[mode](url, { @@ -540,7 +539,10 @@ export class DockerDatasource extends Datasource { return null; } - if (manifest.mediaType === MediaType.manifestListV2) { + if ( + manifest.mediaType === + 'application/vnd.docker.distribution.manifest.list.v2+json' + ) { if (manifest.manifests.length) { logger.trace( { registry, dockerRepository, tag }, @@ -561,7 +563,8 @@ export class DockerDatasource extends Datasource { } if ( - manifest.mediaType === MediaType.manifestV2 && + manifest.mediaType === + 'application/vnd.docker.distribution.manifest.v2+json' && is.string(manifest.config?.digest) ) { return manifest.config?.digest; @@ -569,7 +572,7 @@ export class DockerDatasource extends Datasource { // OCI image lists are not required to specify a mediaType if ( - manifest.mediaType === MediaType.ociManifestIndexV1 || + manifest.mediaType === 'application/vnd.oci.image.index.v1+json' || (!manifest.mediaType && 'manifests' in manifest) ) { if (manifest.manifests.length) { @@ -593,7 +596,7 @@ export class DockerDatasource extends Datasource { // OCI manifests are not required to specify a mediaType if ( - (manifest.mediaType === MediaType.ociManifestV1 || + (manifest.mediaType === 'application/vnd.oci.image.manifest.v1+json' || (!manifest.mediaType && 'config' in manifest)) && is.string(manifest.config?.digest) ) { @@ -627,8 +630,10 @@ export class DockerDatasource extends Datasource { ); if ( - manifestResponse?.headers['content-type'] !== MediaType.manifestV2 && - manifestResponse?.headers['content-type'] !== MediaType.ociManifestV1 + manifestResponse?.headers['content-type'] !== + 'application/vnd.docker.distribution.manifest.v2+json' && + manifestResponse?.headers['content-type'] !== + 'application/vnd.oci.image.manifest.v1+json' ) { return null; } @@ -1058,8 +1063,10 @@ export class DockerDatasource extends Datasource { | OciImage; if ( manifestList.schemaVersion === 2 && - (manifestList.mediaType === MediaType.manifestListV2 || - manifestList.mediaType === MediaType.ociManifestIndexV1 || + (manifestList.mediaType === + 'application/vnd.docker.distribution.manifest.list.v2+json' || + manifestList.mediaType === + 'application/vnd.oci.image.index.v1+json' || (!manifestList.mediaType && 'manifests' in manifestList)) ) { for (const manifest of manifestList.manifests) { diff --git a/lib/modules/datasource/docker/types.ts b/lib/modules/datasource/docker/types.ts index 98af9a88a92d02..3b5a6440140b64 100644 --- a/lib/modules/datasource/docker/types.ts +++ b/lib/modules/datasource/docker/types.ts @@ -1,19 +1,14 @@ -// FIXME #12556 -/* eslint-disable @typescript-eslint/naming-convention */ /** * Media Types * https://docs.docker.com/registry/spec/manifest-v2-2/#media-types * https://github.com/opencontainers/image-spec/blob/main/media-types.md */ -// eslint-disable-next-line typescript-enum/no-enum -export enum MediaType { - manifestV1 = 'application/vnd.docker.distribution.manifest.v1+json', - manifestV2 = 'application/vnd.docker.distribution.manifest.v2+json', - manifestListV2 = 'application/vnd.docker.distribution.manifest.list.v2+json', - ociManifestV1 = 'application/vnd.oci.image.manifest.v1+json', - ociManifestIndexV1 = 'application/vnd.oci.image.index.v1+json', -} -/* eslint-enable @typescript-eslint/naming-convention */ +export type MediaType = + | 'application/vnd.docker.distribution.manifest.v1+json' // manifestV1 + | 'application/vnd.docker.distribution.manifest.v2+json' // manifestV2 + | 'application/vnd.docker.distribution.manifest.list.v2+json' // manifestListV2 + | 'application/vnd.oci.image.manifest.v1+json' // ociManifestV1 + | 'application/vnd.oci.image.index.v1+json'; // ociManifestIndexV1 export interface MediaObject { readonly digest: string; @@ -22,7 +17,9 @@ export interface MediaObject { } export interface ImageListImage extends MediaObject { - readonly mediaType: MediaType.manifestV1 | MediaType.manifestV2; + readonly mediaType: + | 'application/vnd.docker.distribution.manifest.v1+json' + | 'application/vnd.docker.distribution.manifest.v2+json'; readonly platform: OciPlatform; } @@ -33,7 +30,7 @@ export interface ImageListImage extends MediaObject { */ export interface ImageList { readonly schemaVersion: 2; - readonly mediaType: MediaType.manifestListV2; + readonly mediaType: 'application/vnd.docker.distribution.manifest.list.v2+json'; readonly manifests: ImageListImage[]; } @@ -43,8 +40,7 @@ export interface ImageList { */ export interface Image extends MediaObject { readonly schemaVersion: 2; - readonly mediaType: MediaType.manifestV2; - + readonly mediaType: 'application/vnd.docker.distribution.manifest.v2+json'; readonly config: MediaObject; } @@ -80,14 +76,16 @@ export interface OciDescriptor { */ export interface OciImage { readonly schemaVersion: 2; - readonly mediaType?: MediaType.ociManifestV1; + readonly mediaType?: 'application/vnd.oci.image.manifest.v1+json'; readonly config: OciDescriptor; readonly layers: OciDescriptor[]; readonly annotations: Record; } export interface OciImageListManifest extends OciDescriptor { - readonly mediaType?: MediaType.ociManifestV1 | MediaType.ociManifestIndexV1; + readonly mediaType?: + | 'application/vnd.oci.image.manifest.v1+json' + | 'application/vnd.oci.image.index.v1+json'; readonly platform: OciPlatform; } @@ -98,7 +96,7 @@ export interface OciImageListManifest extends OciDescriptor { */ export interface OciImageList { readonly schemaVersion: 2; - readonly mediaType?: MediaType.ociManifestIndexV1; + readonly mediaType?: 'application/vnd.oci.image.index.v1+json'; readonly manifests: OciImageListManifest[]; } diff --git a/lib/modules/manager/terraform/common.ts b/lib/modules/manager/terraform/common.ts index 8e123299a04d28..03c32691519999 100644 --- a/lib/modules/manager/terraform/common.ts +++ b/lib/modules/manager/terraform/common.ts @@ -1,15 +1,10 @@ -// FIXME #12556 -/* eslint-disable @typescript-eslint/naming-convention */ - -// eslint-disable-next-line typescript-enum/no-enum -export enum TerraformDependencyTypes { - unknown = 'unknown', - module = 'module', - provider = 'provider', - required_providers = 'required_providers', - resource = 'resource', - terraform_version = 'terraform_version', -} +export type TerraformDependencyTypes = + | 'unknown' + | 'module' + | 'provider' + | 'required_providers' + | 'resource' + | 'terraform_version'; export const TerraformResourceTypes: Record = { unknown: ['unknown'], diff --git a/lib/modules/manager/terraform/extract.ts b/lib/modules/manager/terraform/extract.ts index 73df9d7b295e52..296ca3b2962e7a 100644 --- a/lib/modules/manager/terraform/extract.ts +++ b/lib/modules/manager/terraform/extract.ts @@ -2,7 +2,6 @@ import is from '@sindresorhus/is'; import { logger } from '../../../logger'; import { newlineRegex, regEx } from '../../../util/regex'; import type { ExtractConfig, PackageDependency, PackageFile } from '../types'; -import { TerraformDependencyTypes } from './common'; import type { ProviderLock } from './lockfile/types'; import { extractLocks, findLockFile, readLockFile } from './lockfile/util'; import { analyseTerraformModule, extractTerraformModule } from './modules'; @@ -71,11 +70,11 @@ export async function extractPackageFile( ); let result: ExtractionResult | null = null; switch (tfDepType) { - case TerraformDependencyTypes.required_providers: { + case 'required_providers': { result = extractTerraformRequiredProviders(lineNumber, lines); break; } - case TerraformDependencyTypes.provider: { + case 'provider': { result = extractTerraformProvider( lineNumber, lines, @@ -83,7 +82,7 @@ export async function extractPackageFile( ); break; } - case TerraformDependencyTypes.module: { + case 'module': { result = extractTerraformModule( lineNumber, lines, @@ -91,11 +90,11 @@ export async function extractPackageFile( ); break; } - case TerraformDependencyTypes.resource: { + case 'resource': { result = extractTerraformResource(lineNumber, lines); break; } - case TerraformDependencyTypes.terraform_version: { + case 'terraform_version': { result = extractTerraformRequiredVersion(lineNumber, lines); break; } @@ -131,19 +130,19 @@ export async function extractPackageFile( deps.forEach((dep) => { switch (dep.managerData?.terraformDependencyType) { - case TerraformDependencyTypes.required_providers: + case 'required_providers': analyzeTerraformRequiredProvider(dep, locks); break; - case TerraformDependencyTypes.provider: + case 'provider': analyzeTerraformProvider(dep, locks); break; - case TerraformDependencyTypes.module: + case 'module': analyseTerraformModule(dep); break; - case TerraformDependencyTypes.resource: + case 'resource': analyseTerraformResource(dep); break; - case TerraformDependencyTypes.terraform_version: + case 'terraform_version': analyseTerraformVersion(dep); break; /* istanbul ignore next */ diff --git a/lib/modules/manager/terraform/extract/kubernetes.ts b/lib/modules/manager/terraform/extract/kubernetes.ts index b7cb79b3d68d84..55d09f5c35f869 100644 --- a/lib/modules/manager/terraform/extract/kubernetes.ts +++ b/lib/modules/manager/terraform/extract/kubernetes.ts @@ -2,7 +2,6 @@ import is from '@sindresorhus/is'; import { logger } from '../../../../logger'; import { regEx } from '../../../../util/regex'; import type { PackageDependency } from '../../types'; -import { TerraformDependencyTypes } from '../common'; import type { ExtractionResult, ResourceManagerData } from '../types'; import { keyValueExtractionRegex } from '../util'; @@ -42,7 +41,7 @@ export function extractTerraformKubernetesResource( } const managerData: ResourceManagerData = { - terraformDependencyType: TerraformDependencyTypes.resource, + terraformDependencyType: 'resource', resourceType, }; const dep: PackageDependency = { diff --git a/lib/modules/manager/terraform/modules.ts b/lib/modules/manager/terraform/modules.ts index 2e8542463fe8e6..bb151f687d99e1 100644 --- a/lib/modules/manager/terraform/modules.ts +++ b/lib/modules/manager/terraform/modules.ts @@ -5,7 +5,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 { TerraformDependencyTypes } from './common'; import { extractTerraformProvider } from './providers'; import type { ExtractionResult } from './types'; @@ -31,7 +30,7 @@ export function extractTerraformModule( const result = extractTerraformProvider(startingLine, lines, moduleName); result.dependencies.forEach((dep) => { // TODO #7154 - dep.managerData!.terraformDependencyType = TerraformDependencyTypes.module; + dep.managerData!.terraformDependencyType = 'module'; }); return result; } diff --git a/lib/modules/manager/terraform/providers.ts b/lib/modules/manager/terraform/providers.ts index b1251cf77dbce5..4c20e6d0e6ead5 100644 --- a/lib/modules/manager/terraform/providers.ts +++ b/lib/modules/manager/terraform/providers.ts @@ -3,7 +3,6 @@ import { logger } from '../../../logger'; import { regEx } from '../../../util/regex'; import { TerraformProviderDatasource } from '../../datasource/terraform-provider'; import type { PackageDependency } from '../types'; -import { TerraformDependencyTypes } from './common'; import type { ProviderLock } from './lockfile/types'; import type { ExtractionResult, TerraformManagerData } from './types'; import { @@ -26,7 +25,7 @@ export function extractTerraformProvider( const dep: PackageDependency = { managerData: { moduleName, - terraformDependencyType: TerraformDependencyTypes.provider, + terraformDependencyType: 'provider', }, }; let braceCounter = 0; diff --git a/lib/modules/manager/terraform/required-providers.ts b/lib/modules/manager/terraform/required-providers.ts index 537e40b25c1db9..5e48455bae229f 100644 --- a/lib/modules/manager/terraform/required-providers.ts +++ b/lib/modules/manager/terraform/required-providers.ts @@ -1,6 +1,5 @@ import { regEx } from '../../../util/regex'; import type { PackageDependency } from '../types'; -import { TerraformDependencyTypes } from './common'; import type { ProviderLock } from './lockfile/types'; import { analyzeTerraformProvider } from './providers'; import type { ExtractionResult, TerraformManagerData } from './types'; @@ -49,7 +48,7 @@ export function extractTerraformRequiredProviders( do { const dep: PackageDependency = { managerData: { - terraformDependencyType: TerraformDependencyTypes.required_providers, + terraformDependencyType: 'required_providers', }, }; diff --git a/lib/modules/manager/terraform/required-version.ts b/lib/modules/manager/terraform/required-version.ts index f958217bc3b4ff..9db85821ede821 100644 --- a/lib/modules/manager/terraform/required-version.ts +++ b/lib/modules/manager/terraform/required-version.ts @@ -2,7 +2,6 @@ import { logger } from '../../../logger'; import { regEx } from '../../../util/regex'; import { GithubReleasesDatasource } from '../../datasource/github-releases'; import type { PackageDependency } from '../types'; -import { TerraformDependencyTypes } from './common'; import type { ExtractionResult, TerraformManagerData } from './types'; import { keyValueExtractionRegex } from './util'; @@ -31,7 +30,7 @@ export function extractTerraformRequiredVersion( currentValue: kvMatch.groups.value, lineNumber, managerData: { - terraformDependencyType: TerraformDependencyTypes.terraform_version, + terraformDependencyType: 'terraform_version', }, }; deps.push(dep); diff --git a/lib/modules/manager/terraform/resources.ts b/lib/modules/manager/terraform/resources.ts index 47bb534e292dc1..cd58ba0961e27d 100644 --- a/lib/modules/manager/terraform/resources.ts +++ b/lib/modules/manager/terraform/resources.ts @@ -4,7 +4,7 @@ import { regEx } from '../../../util/regex'; import { HelmDatasource } from '../../datasource/helm'; import { getDep } from '../dockerfile/extract'; import type { PackageDependency } from '../types'; -import { TerraformDependencyTypes, TerraformResourceTypes } from './common'; +import { TerraformResourceTypes } from './common'; import { extractTerraformKubernetesResource } from './extract/kubernetes'; import { analyseTerraformVersion } from './required-version'; import type { ExtractionResult, ResourceManagerData } from './types'; @@ -30,7 +30,7 @@ export function extractTerraformResource( const line = lines[lineNumber]; const deps: PackageDependency[] = []; const managerData: ResourceManagerData = { - terraformDependencyType: TerraformDependencyTypes.resource, + terraformDependencyType: 'resource', }; const dep: PackageDependency = { managerData, diff --git a/lib/modules/manager/terraform/util.spec.ts b/lib/modules/manager/terraform/util.spec.ts index 3395cf791fef79..a1109e6e3b222f 100644 --- a/lib/modules/manager/terraform/util.spec.ts +++ b/lib/modules/manager/terraform/util.spec.ts @@ -1,41 +1,32 @@ -import { TerraformDependencyTypes } from './common'; import { getTerraformDependencyType } from './util'; describe('modules/manager/terraform/util', () => { describe('getTerraformDependencyType()', () => { - it('returns TerraformDependencyTypes.module', () => { - expect(getTerraformDependencyType('module')).toBe( - TerraformDependencyTypes.module - ); + it('returns module', () => { + expect(getTerraformDependencyType('module')).toBe('module'); }); - it('returns TerraformDependencyTypes.provider', () => { - expect(getTerraformDependencyType('provider')).toBe( - TerraformDependencyTypes.provider - ); + it('returns provider', () => { + expect(getTerraformDependencyType('provider')).toBe('provider'); }); - it('returns TerraformDependencyTypes.unknown', () => { - expect(getTerraformDependencyType('unknown')).toBe( - TerraformDependencyTypes.unknown - ); + it('returns unknown', () => { + expect(getTerraformDependencyType('unknown')).toBe('unknown'); }); - it('returns TerraformDependencyTypes.required_providers', () => { + it('returns required_providers', () => { expect(getTerraformDependencyType('required_providers')).toBe( - TerraformDependencyTypes.required_providers + 'required_providers' ); }); - it('returns TerraformDependencyTypes.unknown on empty string', () => { - expect(getTerraformDependencyType('')).toBe( - TerraformDependencyTypes.unknown - ); + it('returns unknown on empty string', () => { + expect(getTerraformDependencyType('')).toBe('unknown'); }); - it('returns TerraformDependencyTypes.unknown on string with random chars', () => { + it('returns unknown on string with random chars', () => { expect(getTerraformDependencyType('sdfsgdsfadfhfghfhgdfsdf')).toBe( - TerraformDependencyTypes.unknown + 'unknown' ); }); }); diff --git a/lib/modules/manager/terraform/util.ts b/lib/modules/manager/terraform/util.ts index d5fa89d66508a2..696f775bca5565 100644 --- a/lib/modules/manager/terraform/util.ts +++ b/lib/modules/manager/terraform/util.ts @@ -1,7 +1,7 @@ import { regEx } from '../../../util/regex'; import { TerraformProviderDatasource } from '../../datasource/terraform-provider'; import type { PackageDependency } from '../types'; -import { TerraformDependencyTypes } from './common'; +import type { TerraformDependencyTypes } from './common'; import type { ProviderLock } from './lockfile/types'; export const keyValueExtractionRegex = regEx( @@ -16,22 +16,22 @@ export function getTerraformDependencyType( ): TerraformDependencyTypes { switch (value) { case 'module': { - return TerraformDependencyTypes.module; + return 'module'; } case 'provider': { - return TerraformDependencyTypes.provider; + return 'provider'; } case 'required_providers': { - return TerraformDependencyTypes.required_providers; + return 'required_providers'; } case 'resource': { - return TerraformDependencyTypes.resource; + return 'resource'; } case 'terraform': { - return TerraformDependencyTypes.terraform_version; + return 'terraform_version'; } default: { - return TerraformDependencyTypes.unknown; + return 'unknown'; } } } diff --git a/lib/modules/platform/azure/index.spec.ts b/lib/modules/platform/azure/index.spec.ts index 716603e0e8db90..36358385f3e393 100644 --- a/lib/modules/platform/azure/index.spec.ts +++ b/lib/modules/platform/azure/index.spec.ts @@ -12,7 +12,6 @@ import { REPOSITORY_NOT_FOUND, } from '../../../constants/error-messages'; import type { logger as _logger } from '../../../logger'; -import { BranchStatus } from '../../../types'; import type * as _git from '../../../util/git'; import type * as _hostRules from '../../../util/host-rules'; import type { Platform, RepoParams } from '../types'; @@ -413,7 +412,7 @@ describe('modules/platform/azure/index', () => { 'somebranch', 'a-genre/a-name' ); - expect(res).toBe(BranchStatus.green); + expect(res).toBe('green'); }); it('should return green if status is not applicable', async () => { @@ -434,7 +433,7 @@ describe('modules/platform/azure/index', () => { 'somebranch', 'a-genre/a-name' ); - expect(res).toBe(BranchStatus.green); + expect(res).toBe('green'); }); it('should return red if status is failed', async () => { @@ -455,7 +454,7 @@ describe('modules/platform/azure/index', () => { 'somebranch', 'a-genre/a-name' ); - expect(res).toBe(BranchStatus.red); + expect(res).toBe('red'); }); it('should return red if context status is error', async () => { @@ -476,7 +475,7 @@ describe('modules/platform/azure/index', () => { 'somebranch', 'a-genre/a-name' ); - expect(res).toEqual(BranchStatus.red); + expect(res).toBe('red'); }); it('should return yellow if status is pending', async () => { @@ -497,7 +496,7 @@ describe('modules/platform/azure/index', () => { 'somebranch', 'a-genre/a-name' ); - expect(res).toBe(BranchStatus.yellow); + expect(res).toBe('yellow'); }); it('should return yellow if status is not set', async () => { @@ -518,7 +517,7 @@ describe('modules/platform/azure/index', () => { 'somebranch', 'a-genre/a-name' ); - expect(res).toBe(BranchStatus.yellow); + expect(res).toBe('yellow'); }); it('should return yellow if status is unknown', async () => { @@ -540,7 +539,7 @@ describe('modules/platform/azure/index', () => { 'somebranch', 'a-genre/a-name' ); - expect(res).toBe(BranchStatus.yellow); + expect(res).toBe('yellow'); }); it('should return null if status not found', async () => { @@ -576,7 +575,7 @@ describe('modules/platform/azure/index', () => { } as any) ); const res = await azure.getBranchStatus('somebranch'); - expect(res).toEqual(BranchStatus.green); + expect(res).toBe('green'); }); it('should pass through failed', async () => { @@ -589,7 +588,7 @@ describe('modules/platform/azure/index', () => { } as any) ); const res = await azure.getBranchStatus('somebranch'); - expect(res).toEqual(BranchStatus.red); + expect(res).toBe('red'); }); it('should pass through pending', async () => { @@ -602,7 +601,7 @@ describe('modules/platform/azure/index', () => { } as any) ); const res = await azure.getBranchStatus('somebranch'); - expect(res).toEqual(BranchStatus.yellow); + expect(res).toBe('yellow'); }); it('should fall back to yellow if no statuses returned', async () => { @@ -615,7 +614,7 @@ describe('modules/platform/azure/index', () => { } as any) ); const res = await azure.getBranchStatus('somebranch'); - expect(res).toEqual(BranchStatus.yellow); + expect(res).toBe('yellow'); }); }); @@ -1111,7 +1110,7 @@ describe('modules/platform/azure/index', () => { branchName: 'test', context: 'test', description: 'test', - state: BranchStatus.yellow, + state: 'yellow', url: 'test.com', }); expect(createCommitStatusMock).toHaveBeenCalledWith( @@ -1143,7 +1142,7 @@ describe('modules/platform/azure/index', () => { branchName: 'test', context: 'renovate/artifact/test', description: 'test', - state: BranchStatus.green, + state: 'green', url: 'test.com', }); expect(createCommitStatusMock).toHaveBeenCalledWith( diff --git a/lib/modules/platform/azure/index.ts b/lib/modules/platform/azure/index.ts index 9133cf5363ddac..c2ea8376bfd81c 100644 --- a/lib/modules/platform/azure/index.ts +++ b/lib/modules/platform/azure/index.ts @@ -16,7 +16,7 @@ import { REPOSITORY_NOT_FOUND, } from '../../../constants/error-messages'; import { logger } from '../../../logger'; -import { BranchStatus, VulnerabilityAlert } from '../../../types'; +import type { BranchStatus, VulnerabilityAlert } from '../../../types'; import * as git from '../../../util/git'; import * as hostRules from '../../../util/host-rules'; import { regEx } from '../../../util/regex'; @@ -359,12 +359,12 @@ async function getStatusCheck(branchName: string): Promise { } const azureToRenovateStatusMapping: Record = { - [GitStatusState.Succeeded]: BranchStatus.green, - [GitStatusState.NotApplicable]: BranchStatus.green, - [GitStatusState.NotSet]: BranchStatus.yellow, - [GitStatusState.Pending]: BranchStatus.yellow, - [GitStatusState.Error]: BranchStatus.red, - [GitStatusState.Failed]: BranchStatus.red, + [GitStatusState.Succeeded]: 'green', + [GitStatusState.NotApplicable]: 'green', + [GitStatusState.NotSet]: 'yellow', + [GitStatusState.Pending]: 'yellow', + [GitStatusState.Error]: 'red', + [GitStatusState.Failed]: 'red', }; export async function getBranchStatusCheck( @@ -375,7 +375,7 @@ export async function getBranchStatusCheck( for (const check of res) { if (getGitStatusContextCombinedName(check.context) === context) { // TODO #7154 - return azureToRenovateStatusMapping[check.state!] ?? BranchStatus.yellow; + return azureToRenovateStatusMapping[check.state!] ?? 'yellow'; } } return null; @@ -389,7 +389,7 @@ export async function getBranchStatus( logger.debug({ branch: branchName, statuses }, 'branch status check result'); if (!statuses.length) { logger.debug('empty branch status check result = returning "pending"'); - return BranchStatus.yellow; + return 'yellow'; } const noOfFailures = statuses.filter( (status: GitStatus) => @@ -397,7 +397,7 @@ export async function getBranchStatus( status.state === GitStatusState.Failed ).length; if (noOfFailures) { - return BranchStatus.red; + return 'red'; } const noOfPending = statuses.filter( (status: GitStatus) => @@ -405,9 +405,9 @@ export async function getBranchStatus( status.state === GitStatusState.Pending ).length; if (noOfPending) { - return BranchStatus.yellow; + return 'yellow'; } - return BranchStatus.green; + return 'green'; } export async function createPr({ @@ -623,10 +623,9 @@ export async function ensureCommentRemoval( } const renovateToAzureStatusMapping: Record = { - [BranchStatus.green]: [GitStatusState.Succeeded], - [BranchStatus.green]: GitStatusState.Succeeded, - [BranchStatus.yellow]: GitStatusState.Pending, - [BranchStatus.red]: GitStatusState.Failed, + ['green']: GitStatusState.Succeeded, + ['yellow']: GitStatusState.Pending, + ['red']: GitStatusState.Failed, }; export async function setBranchStatus({ diff --git a/lib/modules/platform/azure/types.ts b/lib/modules/platform/azure/types.ts index 07f245580f0f9e..f58a6e5d9fb0a5 100644 --- a/lib/modules/platform/azure/types.ts +++ b/lib/modules/platform/azure/types.ts @@ -10,4 +10,4 @@ export const AzurePrVote = { WaitingForAuthor: -5, ApprovedWithSuggestions: 5, Approved: 10, -}; +} as const; diff --git a/lib/modules/platform/bitbucket-server/index.spec.ts b/lib/modules/platform/bitbucket-server/index.spec.ts index a7d9aeb416b93c..7b9b5a346321fa 100644 --- a/lib/modules/platform/bitbucket-server/index.spec.ts +++ b/lib/modules/platform/bitbucket-server/index.spec.ts @@ -5,7 +5,6 @@ import { REPOSITORY_EMPTY, REPOSITORY_NOT_FOUND, } from '../../../constants/error-messages'; -import { BranchStatus } from '../../../types'; import type * as _git from '../../../util/git'; import type { Platform } from '../types'; @@ -1750,9 +1749,7 @@ Followed by some information. failed: 0, }); - expect(await bitbucket.getBranchStatus('somebranch')).toEqual( - BranchStatus.green - ); + expect(await bitbucket.getBranchStatus('somebranch')).toBe('green'); }); it('should be pending', async () => { @@ -1767,9 +1764,7 @@ Followed by some information. failed: 0, }); - expect(await bitbucket.getBranchStatus('somebranch')).toEqual( - BranchStatus.yellow - ); + expect(await bitbucket.getBranchStatus('somebranch')).toBe('yellow'); scope .get( @@ -1781,9 +1776,7 @@ Followed by some information. failed: 0, }); - expect(await bitbucket.getBranchStatus('somebranch')).toEqual( - BranchStatus.yellow - ); + expect(await bitbucket.getBranchStatus('somebranch')).toBe('yellow'); }); it('should be failed', async () => { @@ -1798,9 +1791,7 @@ Followed by some information. failed: 1, }); - expect(await bitbucket.getBranchStatus('somebranch')).toEqual( - BranchStatus.red - ); + expect(await bitbucket.getBranchStatus('somebranch')).toBe('red'); scope .get( @@ -1808,9 +1799,7 @@ Followed by some information. ) .replyWithError('requst-failed'); - expect(await bitbucket.getBranchStatus('somebranch')).toEqual( - BranchStatus.red - ); + expect(await bitbucket.getBranchStatus('somebranch')).toBe('red'); }); it('throws repository-changed', async () => { @@ -1842,7 +1831,7 @@ Followed by some information. expect( await bitbucket.getBranchStatusCheck('somebranch', 'context-2') - ).toEqual(BranchStatus.green); + ).toBe('green'); }); it('should be pending', async () => { @@ -1864,7 +1853,7 @@ Followed by some information. expect( await bitbucket.getBranchStatusCheck('somebranch', 'context-2') - ).toEqual(BranchStatus.yellow); + ).toBe('yellow'); }); it('should be failure', async () => { @@ -1886,7 +1875,7 @@ Followed by some information. expect( await bitbucket.getBranchStatusCheck('somebranch', 'context-2') - ).toEqual(BranchStatus.red); + ).toBe('red'); }); it('should be null', async () => { @@ -1942,7 +1931,7 @@ Followed by some information. branchName: 'somebranch', context: 'context-2', description: null as any, - state: BranchStatus.green, + state: 'green', }) ).toResolve(); }); @@ -1972,7 +1961,7 @@ Followed by some information. branchName: 'somebranch', context: 'context-2', description: null as any, - state: BranchStatus.red, + state: 'red', }) ).toResolve(); }); @@ -2002,7 +1991,7 @@ Followed by some information. branchName: 'somebranch', context: 'context-2', description: null as any, - state: BranchStatus.red, + state: 'red', }) ).toResolve(); }); @@ -2032,7 +2021,7 @@ Followed by some information. branchName: 'somebranch', context: 'context-2', description: null as any, - state: BranchStatus.yellow, + state: 'yellow', }) ).toResolve(); }); @@ -2057,7 +2046,7 @@ Followed by some information. branchName: 'somebranch', context: 'context-2', description: null as any, - state: BranchStatus.green, + state: 'green', }) ).toResolve(); }); @@ -2078,7 +2067,7 @@ Followed by some information. branchName: 'somebranch', context: 'context-1', description: null as any, - state: BranchStatus.green, + state: 'green', }) ).toResolve(); }); diff --git a/lib/modules/platform/bitbucket-server/index.ts b/lib/modules/platform/bitbucket-server/index.ts index 999c0157d572e8..e71b0311d7fb53 100644 --- a/lib/modules/platform/bitbucket-server/index.ts +++ b/lib/modules/platform/bitbucket-server/index.ts @@ -8,7 +8,7 @@ import { REPOSITORY_NOT_FOUND, } from '../../../constants/error-messages'; import { logger } from '../../../logger'; -import { BranchStatus, VulnerabilityAlert } from '../../../types'; +import type { BranchStatus, VulnerabilityAlert } from '../../../types'; import type { FileData } from '../../../types/platform/bitbucket-server'; import * as git from '../../../util/git'; import { deleteBranch } from '../../../util/git'; @@ -391,17 +391,15 @@ export async function getBranchStatus( logger.debug({ commitStatus }, 'branch status check result'); if (commitStatus.failed > 0) { - return BranchStatus.red; + return 'red'; } if (commitStatus.inProgress > 0) { - return BranchStatus.yellow; + return 'yellow'; } - return commitStatus.successful > 0 - ? BranchStatus.green - : BranchStatus.yellow; + return commitStatus.successful > 0 ? 'green' : 'yellow'; } catch (err) { logger.warn({ err }, `Failed to get branch status`); - return BranchStatus.red; + return 'red'; } } @@ -433,12 +431,12 @@ export async function getBranchStatusCheck( if (state.key === context) { switch (state.state) { case 'SUCCESSFUL': - return BranchStatus.green; + return 'green'; case 'INPROGRESS': - return BranchStatus.yellow; + return 'yellow'; case 'FAILED': default: - return BranchStatus.red; + return 'red'; } } } @@ -473,13 +471,13 @@ export async function setBranchStatus({ }; switch (state) { - case BranchStatus.green: + case 'green': body.state = 'SUCCESSFUL'; break; - case BranchStatus.yellow: + case 'yellow': body.state = 'INPROGRESS'; break; - case BranchStatus.red: + case 'red': default: body.state = 'FAILED'; break; diff --git a/lib/modules/platform/bitbucket/index.spec.ts b/lib/modules/platform/bitbucket/index.spec.ts index 31f615aa62ff1e..55009a07bcb68c 100644 --- a/lib/modules/platform/bitbucket/index.spec.ts +++ b/lib/modules/platform/bitbucket/index.spec.ts @@ -1,6 +1,5 @@ import * as httpMock from '../../../../test/http-mock'; import type { logger as _logger } from '../../../logger'; -import { BranchStatus } from '../../../types'; import type * as _git from '../../../util/git'; import { setBaseUrl } from '../../../util/http/bitbucket'; import type { Platform, PlatformResult, RepoParams } from '../types'; @@ -226,7 +225,7 @@ describe('modules/platform/bitbucket/index', () => { }, ], }); - expect(await bitbucket.getBranchStatus('master')).toBe(BranchStatus.red); + expect(await bitbucket.getBranchStatus('master')).toBe('red'); }); it('getBranchStatus 4', async () => { @@ -251,9 +250,7 @@ describe('modules/platform/bitbucket/index', () => { }, ], }); - expect(await bitbucket.getBranchStatus('branch')).toBe( - BranchStatus.green - ); + expect(await bitbucket.getBranchStatus('branch')).toBe('green'); }); it('getBranchStatus 5', async () => { @@ -278,9 +275,7 @@ describe('modules/platform/bitbucket/index', () => { }, ], }); - expect(await bitbucket.getBranchStatus('pending/branch')).toBe( - BranchStatus.yellow - ); + expect(await bitbucket.getBranchStatus('pending/branch')).toBe('yellow'); }); it('getBranchStatus 6', async () => { @@ -303,7 +298,7 @@ describe('modules/platform/bitbucket/index', () => { values: [], }); expect(await bitbucket.getBranchStatus('branch-with-empty-status')).toBe( - BranchStatus.yellow + 'yellow' ); }); }); @@ -335,9 +330,7 @@ describe('modules/platform/bitbucket/index', () => { }); it('getBranchStatusCheck 2', async () => { - expect(await bitbucket.getBranchStatusCheck('master', 'foo')).toBe( - BranchStatus.red - ); + expect(await bitbucket.getBranchStatusCheck('master', 'foo')).toBe('red'); }); it('getBranchStatusCheck 3', async () => { @@ -376,7 +369,7 @@ describe('modules/platform/bitbucket/index', () => { branchName: 'branch', context: 'context', description: 'description', - state: BranchStatus.red, + state: 'red', url: 'targetUrl', }) ).toResolve(); diff --git a/lib/modules/platform/bitbucket/index.ts b/lib/modules/platform/bitbucket/index.ts index 329f78537adc49..c1db3ea9620374 100644 --- a/lib/modules/platform/bitbucket/index.ts +++ b/lib/modules/platform/bitbucket/index.ts @@ -3,7 +3,7 @@ import is from '@sindresorhus/is'; import JSON5 from 'json5'; import { REPOSITORY_NOT_FOUND } from '../../../constants/error-messages'; import { logger } from '../../../logger'; -import { BranchStatus, VulnerabilityAlert } from '../../../types'; +import type { BranchStatus, VulnerabilityAlert } from '../../../types'; import * as git from '../../../util/git'; import * as hostRules from '../../../util/host-rules'; import { BitbucketHttp, setBaseUrl } from '../../../util/http/bitbucket'; @@ -360,28 +360,28 @@ export async function getBranchStatus( logger.debug({ branch: branchName, statuses }, 'branch status check result'); if (!statuses.length) { logger.debug('empty branch status check result = returning "pending"'); - return BranchStatus.yellow; + return 'yellow'; } const noOfFailures = statuses.filter( (status: { state: string }) => status.state === 'FAILED' || status.state === 'STOPPED' ).length; if (noOfFailures) { - return BranchStatus.red; + return 'red'; } const noOfPending = statuses.filter( (status: { state: string }) => status.state === 'INPROGRESS' ).length; if (noOfPending) { - return BranchStatus.yellow; + return 'yellow'; } - return BranchStatus.green; + return 'green'; } const bbToRenovateStatusMapping: Record = { - SUCCESSFUL: BranchStatus.green, - INPROGRESS: BranchStatus.yellow, - FAILED: BranchStatus.red, + SUCCESSFUL: 'green', + INPROGRESS: 'yellow', + FAILED: 'red', }; export async function getBranchStatusCheck( diff --git a/lib/modules/platform/codecommit/index.ts b/lib/modules/platform/codecommit/index.ts index e04bead60a242c..a9a28c740d1a82 100644 --- a/lib/modules/platform/codecommit/index.ts +++ b/lib/modules/platform/codecommit/index.ts @@ -13,7 +13,7 @@ import { REPOSITORY_NOT_FOUND, } from '../../../constants/error-messages'; import { logger } from '../../../logger'; -import { BranchStatus, PrState, VulnerabilityAlert } from '../../../types'; +import type { BranchStatus, PrState, VulnerabilityAlert } from '../../../types'; import * as git from '../../../util/git'; import { regEx } from '../../../util/regex'; import { sanitize } from '../../../util/sanitize'; @@ -582,7 +582,7 @@ export function getBranchStatus(branchName: string): Promise { logger.debug( 'returning branch status yellow, because getBranchStatus isnt supported on aws yet' ); - return Promise.resolve(BranchStatus.yellow); + return Promise.resolve('yellow'); } /* istanbul ignore next */ diff --git a/lib/modules/platform/gitea/gitea-helper.ts b/lib/modules/platform/gitea/gitea-helper.ts index 55921a26c33c77..188211d6028685 100644 --- a/lib/modules/platform/gitea/gitea-helper.ts +++ b/lib/modules/platform/gitea/gitea-helper.ts @@ -1,4 +1,4 @@ -import { BranchStatus } from '../../../types'; +import type { BranchStatus } from '../../../types'; import { GiteaHttp, GiteaHttpOptions } from '../../../util/http/gitea'; import { getQueryString } from '../../../util/url'; import type { @@ -377,12 +377,12 @@ export const giteaToRenovateStatusMapping: Record< CommitStatusType, BranchStatus | null > = { - unknown: BranchStatus.yellow, - success: BranchStatus.green, - pending: BranchStatus.yellow, - warning: BranchStatus.red, - failure: BranchStatus.red, - error: BranchStatus.red, + unknown: 'yellow', + success: 'green', + pending: 'yellow', + warning: 'red', + failure: 'red', + error: 'red', }; export const renovateToGiteaStatusMapping: Record< diff --git a/lib/modules/platform/gitea/index.spec.ts b/lib/modules/platform/gitea/index.spec.ts index 92078dca71cc4b..8a27641c73037d 100644 --- a/lib/modules/platform/gitea/index.spec.ts +++ b/lib/modules/platform/gitea/index.spec.ts @@ -16,7 +16,7 @@ import { REPOSITORY_MIRRORED, } from '../../../constants/error-messages'; import type { logger as _logger } from '../../../logger'; -import { BranchStatus, PrState } from '../../../types'; +import type { BranchStatus, PrState } from '../../../types'; import type * as _git from '../../../util/git'; import { setBaseUrl } from '../../../util/http/gitea'; import type { PlatformResult } from '../types'; @@ -562,7 +562,7 @@ describe('modules/platform/gitea/index', () => { await initFakeRepo(); await gitea.setBranchStatus({ branchName: 'some-branch', - state: BranchStatus.green, + state: 'green', context: 'some-context', description: 'some-description', ...bsc, @@ -636,19 +636,19 @@ describe('modules/platform/gitea/index', () => { }; it('should return yellow for unknown result', async () => { - expect(await getBranchStatus('unknown')).toEqual(BranchStatus.yellow); + expect(await getBranchStatus('unknown')).toBe('yellow'); }); it('should return pending state for pending result', async () => { - expect(await getBranchStatus('pending')).toEqual(BranchStatus.yellow); + expect(await getBranchStatus('pending')).toBe('yellow'); }); it('should return success state for success result', async () => { - expect(await getBranchStatus('success')).toEqual(BranchStatus.green); + expect(await getBranchStatus('success')).toBe('green'); }); it('should return null for all other results', async () => { - expect(await getBranchStatus('invalid')).toEqual(BranchStatus.yellow); + expect(await getBranchStatus('invalid')).toBe('yellow'); }); it('should abort when branch status returns 404', async () => { @@ -708,7 +708,7 @@ describe('modules/platform/gitea/index', () => { expect( await gitea.getBranchStatusCheck('some-branch', 'some-context') - ).toEqual(BranchStatus.yellow); + ).toBe('yellow'); }); it('should return green of matching result', async () => { @@ -725,7 +725,7 @@ describe('modules/platform/gitea/index', () => { expect( await gitea.getBranchStatusCheck('some-branch', 'some-context') - ).toEqual(BranchStatus.green); + ).toBe('green'); }); }); diff --git a/lib/modules/platform/gitea/index.ts b/lib/modules/platform/gitea/index.ts index e7bfcc3a780c22..e4ef0f9a974d51 100644 --- a/lib/modules/platform/gitea/index.ts +++ b/lib/modules/platform/gitea/index.ts @@ -10,7 +10,7 @@ import { REPOSITORY_MIRRORED, } from '../../../constants/error-messages'; import { logger } from '../../../logger'; -import { BranchStatus, VulnerabilityAlert } from '../../../types'; +import type { BranchStatus, VulnerabilityAlert } from '../../../types'; import * as git from '../../../util/git'; import { setBaseUrl } from '../../../util/http/gitea'; import { sanitize } from '../../../util/sanitize'; @@ -405,10 +405,7 @@ const platform: Platform = { } logger.debug({ ccs }, 'Branch status check result'); - return ( - helper.giteaToRenovateStatusMapping[ccs.worstStatus] ?? - BranchStatus.yellow - ); + return helper.giteaToRenovateStatusMapping[ccs.worstStatus] ?? 'yellow'; }, async getBranchStatusCheck( @@ -431,7 +428,7 @@ const platform: Platform = { { check: cs }, 'Could not map Gitea status value to Renovate status' ); - return BranchStatus.yellow; + return 'yellow'; }, getPrList(): Promise { diff --git a/lib/modules/platform/github/index.spec.ts b/lib/modules/platform/github/index.spec.ts index 59a8ce864d5ca8..d148c418747810 100644 --- a/lib/modules/platform/github/index.spec.ts +++ b/lib/modules/platform/github/index.spec.ts @@ -7,7 +7,7 @@ import { REPOSITORY_NOT_FOUND, REPOSITORY_RENAMED, } from '../../../constants/error-messages'; -import { BranchStatus, VulnerabilityAlert } from '../../../types'; +import type { VulnerabilityAlert } from '../../../types'; import * as repository from '../../../util/cache/repository'; import * as _git from '../../../util/git'; import * as _hostRules from '../../../util/host-rules'; @@ -992,7 +992,7 @@ describe('modules/platform/github/index', () => { await github.initRepo({ repository: 'some/repo' }); const res = await github.getBranchStatus('somebranch'); - expect(res).toEqual(BranchStatus.green); + expect(res).toBe('green'); }); it('should pass through failed', async () => { @@ -1008,7 +1008,7 @@ describe('modules/platform/github/index', () => { await github.initRepo({ repository: 'some/repo' }); const res = await github.getBranchStatus('somebranch'); - expect(res).toEqual(BranchStatus.red); + expect(res).toBe('red'); }); it('defaults to pending', async () => { @@ -1023,7 +1023,7 @@ describe('modules/platform/github/index', () => { .reply(200, []); await github.initRepo({ repository: 'some/repo' }); const res = await github.getBranchStatus('somebranch'); - expect(res).toEqual(BranchStatus.yellow); + expect(res).toBe('yellow'); }); it('should fail if a check run has failed', async () => { @@ -1055,7 +1055,7 @@ describe('modules/platform/github/index', () => { }); await github.initRepo({ repository: 'some/repo' }); const res = await github.getBranchStatus('somebranch'); - expect(res).toEqual(BranchStatus.red); + expect(res).toBe('red'); }); it('should succeed if no status and all passed check runs', async () => { @@ -1093,7 +1093,7 @@ describe('modules/platform/github/index', () => { }); await github.initRepo({ repository: 'some/repo' }); const res = await github.getBranchStatus('somebranch'); - expect(res).toEqual(BranchStatus.green); + expect(res).toBe('green'); }); it('should fail if a check run is pending', async () => { @@ -1124,7 +1124,7 @@ describe('modules/platform/github/index', () => { }); await github.initRepo({ repository: 'some/repo' }); const res = await github.getBranchStatus('somebranch'); - expect(res).toEqual(BranchStatus.yellow); + expect(res).toBe('yellow'); }); }); @@ -1155,7 +1155,7 @@ describe('modules/platform/github/index', () => { 'renovate/future_branch', 'context-2' ); - expect(res).toEqual(BranchStatus.yellow); + expect(res).toBe('yellow'); }); it('returns null', async () => { @@ -1205,7 +1205,7 @@ describe('modules/platform/github/index', () => { branchName: 'some-branch', context: 'some-context', description: 'some-description', - state: BranchStatus.yellow, + state: 'yellow', url: 'some-url', }) ).toResolve(); @@ -1249,7 +1249,7 @@ describe('modules/platform/github/index', () => { branchName: 'some-branch', context: 'some-context', description: 'some-description', - state: BranchStatus.green, + state: 'green', url: 'some-url', }) ).toResolve(); diff --git a/lib/modules/platform/github/index.ts b/lib/modules/platform/github/index.ts index 4e79154915c777..282366acea1093 100644 --- a/lib/modules/platform/github/index.ts +++ b/lib/modules/platform/github/index.ts @@ -21,7 +21,7 @@ import { REPOSITORY_RENAMED, } from '../../../constants/error-messages'; import { logger } from '../../../logger'; -import { BranchStatus, VulnerabilityAlert } from '../../../types'; +import type { BranchStatus, VulnerabilityAlert } from '../../../types'; import { ExternalHostError } from '../../../types/errors/external-host-error'; import * as git from '../../../util/git'; import { listCommitTree, pushCommitToRenovateRef } from '../../../util/git'; @@ -880,18 +880,18 @@ export async function getBranchStatus( } if (checkRuns.length === 0) { if (commitStatus.state === 'success') { - return BranchStatus.green; + return 'green'; } if (commitStatus.state === 'failure') { - return BranchStatus.red; + return 'red'; } - return BranchStatus.yellow; + return 'yellow'; } if ( commitStatus.state === 'failure' || checkRuns.some((run) => run.conclusion === 'failure') ) { - return BranchStatus.red; + return 'red'; } if ( (commitStatus.state === 'success' || commitStatus.statuses.length === 0) && @@ -899,9 +899,9 @@ export async function getBranchStatus( ['skipped', 'neutral', 'success'].includes(run.conclusion) ) ) { - return BranchStatus.green; + return 'green'; } - return BranchStatus.yellow; + return 'yellow'; } async function getStatusCheck( @@ -915,11 +915,14 @@ async function getStatusCheck( return (await githubApi.getJson(url, { useCache })).body; } -const githubToRenovateStatusMapping = { - success: BranchStatus.green, - error: BranchStatus.red, - failure: BranchStatus.red, - pending: BranchStatus.yellow, +interface GithubToRenovateStatusMapping { + [index: string]: BranchStatus; +} +const githubToRenovateStatusMapping: GithubToRenovateStatusMapping = { + success: 'green', + error: 'red', + failure: 'red', + pending: 'yellow', }; export async function getBranchStatusCheck( @@ -930,9 +933,7 @@ export async function getBranchStatusCheck( const res = await getStatusCheck(branchName); for (const check of res) { if (check.context === context) { - return ( - githubToRenovateStatusMapping[check.state] || BranchStatus.yellow - ); + return githubToRenovateStatusMapping[check.state] || 'yellow'; } } return null; diff --git a/lib/modules/platform/gitlab/index.spec.ts b/lib/modules/platform/gitlab/index.spec.ts index 43adce854cc8c1..be45fcb3eeb60a 100644 --- a/lib/modules/platform/gitlab/index.spec.ts +++ b/lib/modules/platform/gitlab/index.spec.ts @@ -10,7 +10,7 @@ import { REPOSITORY_MIRRORED, } from '../../../constants/error-messages'; import type { logger as _logger } from '../../../logger'; -import { BranchStatus } from '../../../types'; +import type { BranchStatus } from '../../../types'; import type * as _git from '../../../util/git'; import type * as _hostRules from '../../../util/host-rules'; import { toBase64 } from '../../../util/string'; @@ -533,7 +533,7 @@ describe('modules/platform/gitlab/index', () => { ) .reply(200, []); const res = await gitlab.getBranchStatus('somebranch'); - expect(res).toEqual(BranchStatus.yellow); + expect(res).toBe('yellow'); }); it('returns success if no results but head pipeline success', async () => { @@ -575,7 +575,7 @@ describe('modules/platform/gitlab/index', () => { }, }); const res = await gitlab.getBranchStatus('some-branch'); - expect(res).toEqual(BranchStatus.green); + expect(res).toBe('green'); }); it('returns success if all are success', async () => { @@ -590,7 +590,7 @@ describe('modules/platform/gitlab/index', () => { ) .reply(200, []); const res = await gitlab.getBranchStatus('somebranch'); - expect(res).toEqual(BranchStatus.green); + expect(res).toBe('green'); }); it('returns success if optional jobs fail', async () => { @@ -608,7 +608,7 @@ describe('modules/platform/gitlab/index', () => { ) .reply(200, []); const res = await gitlab.getBranchStatus('somebranch'); - expect(res).toEqual(BranchStatus.green); + expect(res).toBe('green'); }); it('returns success if all are optional', async () => { @@ -623,7 +623,7 @@ describe('modules/platform/gitlab/index', () => { ) .reply(200, []); const res = await gitlab.getBranchStatus('somebranch'); - expect(res).toEqual(BranchStatus.green); + expect(res).toBe('green'); }); it('returns success if job is skipped', async () => { @@ -638,7 +638,7 @@ describe('modules/platform/gitlab/index', () => { ) .reply(200, []); const res = await gitlab.getBranchStatus('somebranch'); - expect(res).toEqual(BranchStatus.green); + expect(res).toBe('green'); }); it('returns yellow if there are no jobs expect skipped', async () => { @@ -653,7 +653,7 @@ describe('modules/platform/gitlab/index', () => { ) .reply(200, []); const res = await gitlab.getBranchStatus('somebranch'); - expect(res).toEqual(BranchStatus.yellow); + expect(res).toBe('yellow'); }); it('returns failure if any mandatory jobs fails and one job is skipped', async () => { @@ -668,7 +668,7 @@ describe('modules/platform/gitlab/index', () => { ) .reply(200, []); const res = await gitlab.getBranchStatus('somebranch'); - expect(res).toEqual(BranchStatus.red); + expect(res).toBe('red'); }); it('returns failure if any mandatory jobs fails', async () => { @@ -687,7 +687,7 @@ describe('modules/platform/gitlab/index', () => { ) .reply(200, []); const res = await gitlab.getBranchStatus('somebranch'); - expect(res).toEqual(BranchStatus.red); + expect(res).toBe('red'); }); it('maps custom statuses to yellow', async () => { @@ -702,7 +702,7 @@ describe('modules/platform/gitlab/index', () => { ) .reply(200, []); const res = await gitlab.getBranchStatus('somebranch'); - expect(res).toEqual(BranchStatus.yellow); + expect(res).toBe('yellow'); }); it('throws repository-changed', async () => { @@ -759,36 +759,35 @@ describe('modules/platform/gitlab/index', () => { 'somebranch', 'some-context' ); - expect(res).toEqual(BranchStatus.green); + expect(res).toBe('green'); }); }); describe('setBranchStatus', () => { - it.each([BranchStatus.green, BranchStatus.yellow, BranchStatus.red])( - 'sets branch status %s', - async (state) => { - const scope = await initRepo(); - scope - .post( - '/api/v4/projects/some%2Frepo/statuses/0d9c7726c3d628b7e28af234595cfd20febdbf8e' - ) - .reply(200, {}) - .get( - '/api/v4/projects/some%2Frepo/repository/commits/0d9c7726c3d628b7e28af234595cfd20febdbf8e/statuses' - ) - .reply(200, []); - - await expect( - gitlab.setBranchStatus({ - branchName: 'some-branch', - context: 'some-context', - description: 'some-description', - state, - url: 'some-url', - }) - ).toResolve(); - } - ); + const states: BranchStatus[] = ['green', 'yellow', 'red']; + + it.each(states)('sets branch status %s', async (state) => { + const scope = await initRepo(); + scope + .post( + '/api/v4/projects/some%2Frepo/statuses/0d9c7726c3d628b7e28af234595cfd20febdbf8e' + ) + .reply(200, {}) + .get( + '/api/v4/projects/some%2Frepo/repository/commits/0d9c7726c3d628b7e28af234595cfd20febdbf8e/statuses' + ) + .reply(200, []); + + await expect( + gitlab.setBranchStatus({ + branchName: 'some-branch', + context: 'some-context', + description: 'some-description', + state, + url: 'some-url', + }) + ).toResolve(); + }); }); describe('findIssue()', () => { diff --git a/lib/modules/platform/gitlab/index.ts b/lib/modules/platform/gitlab/index.ts index 491d3c63c00a29..47a70abb0a7eb0 100644 --- a/lib/modules/platform/gitlab/index.ts +++ b/lib/modules/platform/gitlab/index.ts @@ -16,7 +16,7 @@ import { TEMPORARY_ERROR, } from '../../../constants/error-messages'; import { logger } from '../../../logger'; -import { BranchStatus, VulnerabilityAlert } from '../../../types'; +import type { BranchStatus, VulnerabilityAlert } from '../../../types'; import * as git from '../../../util/git'; import * as hostRules from '../../../util/host-rules'; import { setBaseUrl } from '../../../util/http/gitlab'; @@ -382,16 +382,16 @@ async function getStatus( } const gitlabToRenovateStatusMapping: Record = { - pending: BranchStatus.yellow, - created: BranchStatus.yellow, - manual: BranchStatus.yellow, - running: BranchStatus.yellow, - waiting_for_resource: BranchStatus.yellow, - success: BranchStatus.green, - failed: BranchStatus.red, - canceled: BranchStatus.red, - skipped: BranchStatus.red, - scheduled: BranchStatus.yellow, + pending: 'yellow', + created: 'yellow', + manual: 'yellow', + running: 'yellow', + waiting_for_resource: 'yellow', + success: 'green', + failed: 'red', + canceled: 'red', + skipped: 'red', + scheduled: 'yellow', }; // Returns the combined status for a branch. @@ -411,7 +411,7 @@ export async function getBranchStatus( { branchName, branchStatuses }, 'Empty or unexpected branch statuses' ); - return BranchStatus.yellow; + return 'yellow'; } logger.debug(`Got res with ${branchStatuses.length} results`); @@ -426,13 +426,13 @@ export async function getBranchStatus( const res = branchStatuses.filter((check) => check.status !== 'skipped'); if (res.length === 0) { // Return 'pending' if we have no status checks - return BranchStatus.yellow; + return 'yellow'; } - let status: BranchStatus = BranchStatus.green; // default to green + let status: BranchStatus = 'green'; // default to green res .filter((check) => !check.allow_failure) .forEach((check) => { - if (status !== BranchStatus.red) { + if (status !== 'red') { // if red, stay red let mappedStatus: BranchStatus = gitlabToRenovateStatusMapping[check.status]; @@ -441,9 +441,9 @@ export async function getBranchStatus( { check }, 'Could not map GitLab check.status to Renovate status' ); - mappedStatus = BranchStatus.yellow; + mappedStatus = 'yellow'; } - if (mappedStatus !== BranchStatus.green) { + if (mappedStatus !== 'green') { logger.trace({ check }, 'Found non-green check'); status = mappedStatus; } @@ -763,7 +763,7 @@ export async function getBranchStatusCheck( logger.debug(`Got res with ${res.length} results`); for (const check of res) { if (check.name === context) { - return gitlabToRenovateStatusMapping[check.status] || BranchStatus.yellow; + return gitlabToRenovateStatusMapping[check.status] || 'yellow'; } } return null; @@ -782,9 +782,9 @@ export async function setBranchStatus({ // TODO: types (#7154) const url = `projects/${config.repository}/statuses/${branchSha!}`; let state = 'success'; - if (renovateState === BranchStatus.yellow) { + if (renovateState === 'yellow') { state = 'pending'; - } else if (renovateState === BranchStatus.red) { + } else if (renovateState === 'red') { state = 'failed'; } const options: any = { diff --git a/lib/modules/versioning/gradle/compare.ts b/lib/modules/versioning/gradle/compare.ts index 646c3416fd1b31..ed858b98a7f40c 100644 --- a/lib/modules/versioning/gradle/compare.ts +++ b/lib/modules/versioning/gradle/compare.ts @@ -1,14 +1,13 @@ import is from '@sindresorhus/is'; import { regEx } from '../../../util/regex'; -// eslint-disable-next-line typescript-enum/no-enum -export enum TokenType { - Number = 1, - String, -} +export const TokenType = { + Number: 1, + String: 2, +}; type Token = { - type: TokenType; + type: number; val: string | number; }; @@ -95,7 +94,7 @@ export const QualifierRank = { GA: 4, Release: 5, SP: 6, -}; +} as const; export function qualifierRank(input: string): number { const val = input.toLowerCase(); diff --git a/lib/modules/versioning/maven/compare.ts b/lib/modules/versioning/maven/compare.ts index 8cb60d4c963528..e65c1f2de2446f 100644 --- a/lib/modules/versioning/maven/compare.ts +++ b/lib/modules/versioning/maven/compare.ts @@ -174,7 +174,7 @@ export const QualifierTypes = { Snapshot: 5, Release: 6, SP: 7, -}; +} as const; export function qualifierType(token: Token): number | null { const val = token.val; diff --git a/lib/types/branch-status.ts b/lib/types/branch-status.ts index 01083ebdfbb324..cfad7b00285cb2 100644 --- a/lib/types/branch-status.ts +++ b/lib/types/branch-status.ts @@ -1,9 +1,4 @@ -// FIXME #12556 -/* eslint-disable @typescript-eslint/naming-convention */ - -// eslint-disable-next-line typescript-enum/no-enum -export enum BranchStatus { - green = 'green', // 'success' - yellow = 'yellow', // 'created', 'running' - red = 'red', // 'error', 'failed' -} +export type BranchStatus = + | 'green' // 'success' + | 'yellow' // 'created', 'running' + | 'red'; // 'error', 'failed' diff --git a/lib/types/index.ts b/lib/types/index.ts index bceb6c6344512e..8c4a98d7ff625f 100644 --- a/lib/types/index.ts +++ b/lib/types/index.ts @@ -1,10 +1,15 @@ export type { CommitMessageJSON } from './commit-message-json'; -export * from './host-rules'; -export * from './skip-reason'; -export * from './versioning'; -export * from './branch-status'; -export * from './vulnerability-alert'; -export * from './pr-state'; -export * from './base'; +export type { HostRule, HostRuleSearchResult } from './host-rules'; +export type { SkipReason } from './skip-reason'; +export type { RangeStrategy } from './versioning'; +export type { BranchStatus } from './branch-status'; +export type { + VulnerabilityPackage, + SecurityVulnerability, + SecurityAdvisory, + VulnerabilityAlert, +} from './vulnerability-alert'; +export type { PrState } from './pr-state'; +export type { ModuleApi, RenovatePackageJson } from './base'; export type AutoMergeType = 'branch' | 'pr' | 'pr-comment'; diff --git a/lib/workers/repository/dependency-dashboard.spec.ts b/lib/workers/repository/dependency-dashboard.spec.ts index e88a1e5774674f..f2a748c7f2d81c 100644 --- a/lib/workers/repository/dependency-dashboard.spec.ts +++ b/lib/workers/repository/dependency-dashboard.spec.ts @@ -19,7 +19,7 @@ import { massageMarkdown, } from '../../modules/platform/github'; import { regEx } from '../../util/regex'; -import { BranchConfig, BranchResult, BranchUpgradeConfig } from '../types'; +import type { BranchConfig, BranchUpgradeConfig } from '../types'; import * as dependencyDashboard from './dependency-dashboard'; import { PackageFiles } from './package-files'; @@ -213,12 +213,12 @@ describe('workers/repository/dependency-dashboard', () => { { ...mock(), prTitle: 'pr1', - result: BranchResult.Automerged, + result: 'automerged', }, { ...mock(), prTitle: 'pr2', - result: BranchResult.Automerged, + result: 'automerged', dependencyDashboardApproval: false, }, ]; @@ -289,63 +289,63 @@ describe('workers/repository/dependency-dashboard', () => { ...mock(), prTitle: 'pr1', upgrades: [{ ...mock(), depName: 'dep1' }], - result: BranchResult.NeedsApproval, + result: 'needs-approval', branchName: 'branchName1', }, { ...mock(), prTitle: 'pr2', upgrades: [{ ...mock(), depName: 'dep2' }], - result: BranchResult.NeedsApproval, + result: 'needs-approval', branchName: 'branchName2', }, { ...mock(), prTitle: 'pr3', upgrades: [{ ...mock(), depName: 'dep3' }], - result: BranchResult.NotScheduled, + result: 'not-scheduled', branchName: 'branchName3', }, { ...mock(), prTitle: 'pr4', upgrades: [{ ...mock(), depName: 'dep4' }], - result: BranchResult.NotScheduled, + result: 'not-scheduled', branchName: 'branchName4', }, { ...mock(), prTitle: 'pr5', upgrades: [{ ...mock(), depName: 'dep5' }], - result: BranchResult.PrLimitReached, + result: 'pr-limit-reached', branchName: 'branchName5', }, { ...mock(), prTitle: 'pr6', upgrades: [{ ...mock(), depName: 'dep6' }], - result: BranchResult.PrLimitReached, + result: 'pr-limit-reached', branchName: 'branchName6', }, { ...mock(), prTitle: 'pr7', upgrades: [{ ...mock(), depName: 'dep7' }], - result: BranchResult.Error, + result: 'error', branchName: 'branchName7', }, { ...mock(), prTitle: 'pr8', upgrades: [{ ...mock(), depName: 'dep8' }], - result: BranchResult.Error, + result: 'error', branchName: 'branchName8', }, { ...mock(), prTitle: 'pr9', upgrades: [{ ...mock(), depName: 'dep9' }], - result: BranchResult.Done, + result: 'done', prBlockedBy: 'BranchAutomerge', branchName: 'branchName9', }, @@ -372,7 +372,7 @@ describe('workers/repository/dependency-dashboard', () => { prNo: 1, prTitle: 'pr1', upgrades: [{ ...mock(), depName: 'dep1' }], - result: BranchResult.PrEdited, + result: 'pr-edited', branchName: 'branchName1', }, { @@ -383,7 +383,7 @@ describe('workers/repository/dependency-dashboard', () => { { ...mock(), depName: 'dep2' }, { ...mock(), depName: 'dep3' }, ], - result: BranchResult.PrEdited, + result: 'pr-edited', branchName: 'branchName2', }, ]; @@ -408,7 +408,7 @@ describe('workers/repository/dependency-dashboard', () => { ...mock(), prTitle: 'pr1', upgrades: [{ ...mock(), depName: 'dep1' }], - result: BranchResult.Rebase, + result: 'rebase', prNo: 1, branchName: 'branchName1', }, @@ -420,7 +420,7 @@ describe('workers/repository/dependency-dashboard', () => { { ...mock(), depName: 'dep2' }, { ...mock(), depName: 'dep3' }, ], - result: BranchResult.Rebase, + result: 'rebase', branchName: 'branchName2', }, { @@ -428,7 +428,7 @@ describe('workers/repository/dependency-dashboard', () => { prTitle: 'pr3', prNo: 3, upgrades: [{ ...mock(), depName: 'dep3' }], - result: BranchResult.Rebase, + result: 'rebase', branchName: 'branchName3', }, ]; @@ -453,7 +453,7 @@ describe('workers/repository/dependency-dashboard', () => { ...mock(), prTitle: 'pr1', upgrades: [{ ...mock(), depName: 'dep1' }], - result: BranchResult.AlreadyExisted, + result: 'already-existed', branchName: 'branchName1', }, { @@ -463,7 +463,7 @@ describe('workers/repository/dependency-dashboard', () => { { ...mock(), depName: 'dep2' }, { ...mock(), depName: 'dep3' }, ], - result: BranchResult.AlreadyExisted, + result: 'already-existed', branchName: 'branchName2', }, ]; @@ -488,7 +488,7 @@ describe('workers/repository/dependency-dashboard', () => { ...mock(), prTitle: 'pr1', upgrades: [{ ...mock(), depName: 'dep1' }], - result: BranchResult.NeedsPrApproval, + result: 'needs-pr-approval', branchName: 'branchName1', }, { @@ -498,21 +498,21 @@ describe('workers/repository/dependency-dashboard', () => { { ...mock(), depName: 'dep2' }, { ...mock(), depName: 'dep3' }, ], - result: BranchResult.NeedsPrApproval, + result: 'needs-pr-approval', branchName: 'branchName2', }, { ...mock(), prTitle: 'pr3', upgrades: [{ ...mock(), depName: 'dep3' }], - result: BranchResult.NeedsPrApproval, + result: 'needs-pr-approval', branchName: 'branchName3', }, { ...mock(), prTitle: 'pr4', upgrades: [{ ...mock(), depName: 'dep4' }], - result: BranchResult.Pending, + result: 'pending', branchName: 'branchName4', }, ]; @@ -540,7 +540,7 @@ describe('workers/repository/dependency-dashboard', () => { upgrades: [ { ...mock(), depName: 'dep1', repository: 'repo1' }, ], - result: BranchResult.Pending, + result: 'pending', branchName: 'branchName1', }, ]; @@ -587,14 +587,14 @@ describe('workers/repository/dependency-dashboard', () => { ...mock(), prTitle: 'pr1', upgrades: [{ ...mock(), depName: 'dep1' }], - result: BranchResult.NeedsApproval, + result: 'needs-approval', branchName: 'branchName1', }, { ...mock(), prTitle: 'pr2', upgrades: [{ ...mock(), depName: 'dep2' }], - result: BranchResult.NeedsApproval, + result: 'needs-approval', branchName: 'branchName2', }, ]; @@ -649,14 +649,14 @@ describe('workers/repository/dependency-dashboard', () => { ...mock(), prTitle: 'pr1', upgrades: [{ ...mock(), depName: 'dep1' }], - result: BranchResult.BranchLimitReached, + result: 'branch-limit-reached', branchName: 'branchName1', }, { ...mock(), prTitle: 'pr2', upgrades: [{ ...mock(), depName: 'dep2' }], - result: BranchResult.PrLimitReached, + result: 'pr-limit-reached', branchName: 'branchName2', }, ]; @@ -704,21 +704,21 @@ describe('workers/repository/dependency-dashboard', () => { ...mock(), prTitle: 'pr1', upgrades: [{ ...mock(), depName: 'dep1' }], - result: BranchResult.NeedsApproval, + result: 'needs-approval', branchName: 'branchName1', }, { ...mock(), prTitle: 'pr2', upgrades: [{ ...mock(), depName: 'dep2' }], - result: BranchResult.NeedsApproval, + result: 'needs-approval', branchName: 'branchName2', }, { ...mock(), prTitle: 'pr3', upgrades: [{ ...mock(), depName: 'dep3' }], - result: BranchResult.NotScheduled, + result: 'not-scheduled', branchName: 'branchName3', }, ]; diff --git a/lib/workers/repository/dependency-dashboard.ts b/lib/workers/repository/dependency-dashboard.ts index 0d1919cd13122f..ac00cdd0fe527e 100644 --- a/lib/workers/repository/dependency-dashboard.ts +++ b/lib/workers/repository/dependency-dashboard.ts @@ -1,4 +1,3 @@ -// TODO #7154 import is from '@sindresorhus/is'; import { nameFromLevel } from 'bunyan'; import { GlobalConfig } from '../../config/global'; @@ -9,7 +8,7 @@ import { platform } from '../../modules/platform'; import { GitHubMaxPrBodyLen } from '../../modules/platform/github'; import { regEx } from '../../util/regex'; import * as template from '../../util/template'; -import { BranchConfig, BranchResult, SelectAllConfig } from '../types'; +import type { BranchConfig, SelectAllConfig } from '../types'; import { getDepWarningsDashboard } from './errors-warnings'; import { PackageFiles } from './package-files'; @@ -172,7 +171,7 @@ export async function ensureDependencyDashboard( const reuseTitle = 'Update Dependencies (Renovate Bot)'; const branches = allBranches.filter( (branch) => - branch.result !== BranchResult.Automerged && + branch.result !== 'automerged' && !branch.upgrades?.every((upgrade) => upgrade.remediationNotPossible) ); if ( @@ -226,7 +225,7 @@ export async function ensureDependencyDashboard( issueBody = appendRepoProblems(config, issueBody); const pendingApprovals = branches.filter( - (branch) => branch.result === BranchResult.NeedsApproval + (branch) => branch.result === 'needs-approval' ); if (pendingApprovals.length) { issueBody += '## Pending Approval\n\n'; @@ -242,7 +241,7 @@ export async function ensureDependencyDashboard( issueBody += '\n'; } const awaitingSchedule = branches.filter( - (branch) => branch.result === BranchResult.NotScheduled + (branch) => branch.result === 'not-scheduled' ); if (awaitingSchedule.length) { issueBody += '## Awaiting Schedule\n\n'; @@ -255,9 +254,9 @@ export async function ensureDependencyDashboard( } const rateLimited = branches.filter( (branch) => - branch.result === BranchResult.BranchLimitReached || - branch.result === BranchResult.PrLimitReached || - branch.result === BranchResult.CommitLimitReached + branch.result === 'branch-limit-reached' || + branch.result === 'pr-limit-reached' || + branch.result === 'commit-limit-reached' ); if (rateLimited.length) { issueBody += '## Rate-Limited\n\n'; @@ -273,9 +272,7 @@ export async function ensureDependencyDashboard( } issueBody += '\n'; } - const errorList = branches.filter( - (branch) => branch.result === BranchResult.Error - ); + const errorList = branches.filter((branch) => branch.result === 'error'); if (errorList.length) { issueBody += '## Errored\n\n'; issueBody += @@ -286,7 +283,7 @@ export async function ensureDependencyDashboard( issueBody += '\n'; } const awaitingPr = branches.filter( - (branch) => branch.result === BranchResult.NeedsPrApproval + (branch) => branch.result === 'needs-pr-approval' ); if (awaitingPr.length) { issueBody += '## PR Creation Approval Required\n\n'; @@ -297,9 +294,7 @@ export async function ensureDependencyDashboard( } issueBody += '\n'; } - const prEdited = branches.filter( - (branch) => branch.result === BranchResult.PrEdited - ); + const prEdited = branches.filter((branch) => branch.result === 'pr-edited'); if (prEdited.length) { issueBody += '## Edited/Blocked\n\n'; issueBody += `These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.\n\n`; @@ -308,9 +303,7 @@ export async function ensureDependencyDashboard( } issueBody += '\n'; } - const prPending = branches.filter( - (branch) => branch.result === BranchResult.Pending - ); + const prPending = branches.filter((branch) => branch.result === 'pending'); if (prPending.length) { issueBody += '## Pending Status Checks\n\n'; issueBody += `These updates await pending status checks. To force their creation now, click the checkbox below.\n\n`; @@ -338,17 +331,17 @@ export async function ensureDependencyDashboard( } const otherRes = [ - BranchResult.Pending, - BranchResult.NeedsApproval, - BranchResult.NeedsPrApproval, - BranchResult.NotScheduled, - BranchResult.PrLimitReached, - BranchResult.CommitLimitReached, - BranchResult.BranchLimitReached, - BranchResult.AlreadyExisted, - BranchResult.Error, - BranchResult.Automerged, - BranchResult.PrEdited, + 'pending', + 'needs-approval', + 'needs-pr-approval', + 'not-scheduled', + 'pr-limit-reached', + 'commit-limit-reached', + 'branch-limit-reached', + 'already-existed', + 'error', + 'automerged', + 'pr-edited', ]; let inProgress = branches.filter( (branch) => @@ -386,7 +379,7 @@ export async function ensureDependencyDashboard( issueBody += '\n'; } const alreadyExisted = branches.filter( - (branch) => branch.result === BranchResult.AlreadyExisted + (branch) => branch.result === 'already-existed' ); if (alreadyExisted.length) { issueBody += '## Ignored or Blocked\n\n'; diff --git a/lib/workers/repository/process/write.spec.ts b/lib/workers/repository/process/write.spec.ts index c11aa041bf5dcf..5e79e449380d1a 100644 --- a/lib/workers/repository/process/write.spec.ts +++ b/lib/workers/repository/process/write.spec.ts @@ -16,7 +16,7 @@ import type { } from '../../../util/cache/repository/types'; import { fingerprint } from '../../../util/fingerprint'; import { isLimitReached } from '../../global/limits'; -import { BranchConfig, BranchResult, BranchUpgradeConfig } from '../../types'; +import type { BranchConfig, BranchUpgradeConfig } from '../../types'; import * as _branchWorker from '../update/branch'; import * as _limits from './limits'; import { @@ -86,19 +86,19 @@ describe('workers/repository/process/write', () => { git.branchExists.mockReturnValue(true); branchWorker.processBranch.mockResolvedValueOnce({ branchExists: true, - result: BranchResult.PrCreated, + result: 'pr-created', }); branchWorker.processBranch.mockResolvedValueOnce({ branchExists: false, - result: BranchResult.AlreadyExisted, + result: 'already-existed', }); branchWorker.processBranch.mockResolvedValueOnce({ branchExists: false, - result: BranchResult.Automerged, + result: 'automerged', }); branchWorker.processBranch.mockResolvedValueOnce({ branchExists: false, - result: BranchResult.Automerged, + result: 'automerged', }); GlobalConfig.set({ dryRun: 'full' }); const res = await writeUpdates(config, branches); @@ -115,7 +115,7 @@ describe('workers/repository/process/write', () => { repoCache.getCache.mockReturnValueOnce({}); branchWorker.processBranch.mockResolvedValueOnce({ branchExists: true, - result: BranchResult.PrCreated, + result: 'pr-created', }); git.branchExists.mockReturnValueOnce(false).mockReturnValueOnce(true); limits.getBranchesRemaining.mockResolvedValueOnce(1); @@ -158,7 +158,7 @@ describe('workers/repository/process/write', () => { }); branchWorker.processBranch.mockResolvedValueOnce({ branchExists: true, - result: BranchResult.NoWork, + result: 'no-work', }); expect(await writeUpdates(config, branches)).toBe('done'); }); @@ -187,7 +187,7 @@ describe('workers/repository/process/write', () => { branchWorker.processBranch.mockResolvedValueOnce({ branchExists: true, updatesVerified: true, - result: BranchResult.Done, + result: 'done', commitSha: 'some-value', }); const branch = branches[0]; @@ -243,7 +243,7 @@ describe('workers/repository/process/write', () => { }); branchWorker.processBranch.mockResolvedValueOnce({ branchExists: true, - result: BranchResult.Done, + result: 'done', }); git.branchExists.mockReturnValue(true); config.repositoryCache = 'enabled'; @@ -287,7 +287,7 @@ describe('workers/repository/process/write', () => { }); branchWorker.processBranch.mockResolvedValueOnce({ branchExists: true, - result: BranchResult.Done, + result: 'done', }); expect(await writeUpdates(config, branches)).toBe('done'); expect(branch.branchFingerprint).toBe(branchFingerprint); @@ -310,7 +310,7 @@ describe('workers/repository/process/write', () => { repoCache.getCache.mockReturnValueOnce(repoCacheObj); branchWorker.processBranch.mockResolvedValueOnce({ branchExists: true, - result: BranchResult.NoWork, + result: 'no-work', }); git.getBranchCommit .mockReturnValueOnce('sha') diff --git a/lib/workers/repository/process/write.ts b/lib/workers/repository/process/write.ts index 9bda0ee763ed17..13c3c695fbd166 100644 --- a/lib/workers/repository/process/write.ts +++ b/lib/workers/repository/process/write.ts @@ -8,11 +8,7 @@ import { fingerprint } from '../../../util/fingerprint'; import { branchExists, getBranchCommit } from '../../../util/git'; import { setBranchNewCommit } from '../../../util/git/set-branch-commit'; import { incLimitedValue, setMaxLimit } from '../../global/limits'; -import { - BranchConfig, - BranchResult, - UpgradeFingerprintConfig, -} from '../../types'; +import type { BranchConfig, UpgradeFingerprintConfig } from '../../types'; import { processBranch } from '../update/branch'; import { upgradeFingerprintFields } from './fingerprint-fields'; import { getBranchesRemaining, getPrsRemaining } from './limits'; @@ -172,7 +168,7 @@ export async function writeUpdates( setBranchNewCommit(branchName, baseBranch, res.commitSha); } if ( - branch.result === BranchResult.Automerged && + branch.result === 'automerged' && branch.automergeType !== 'pr-comment' ) { // Stop processing other branches because base branch has been changed diff --git a/lib/workers/repository/update/branch/artifacts.spec.ts b/lib/workers/repository/update/branch/artifacts.spec.ts index 2a0e942dfe4432..ca63fa5ec3db7b 100644 --- a/lib/workers/repository/update/branch/artifacts.spec.ts +++ b/lib/workers/repository/update/branch/artifacts.spec.ts @@ -1,6 +1,5 @@ import { getConfig, platform } from '../../../../../test/util'; import { GlobalConfig } from '../../../../config/global'; -import { BranchStatus } from '../../../../types'; import type { BranchConfig } from '../../../types'; import { setArtifactErrorStatus } from './artifacts'; @@ -28,7 +27,7 @@ describe('workers/repository/update/branch/artifacts', () => { }); it('skips status', async () => { - platform.getBranchStatusCheck.mockResolvedValueOnce(BranchStatus.red); + platform.getBranchStatusCheck.mockResolvedValueOnce('red'); await setArtifactErrorStatus(config); expect(platform.setBranchStatus).not.toHaveBeenCalled(); }); diff --git a/lib/workers/repository/update/branch/artifacts.ts b/lib/workers/repository/update/branch/artifacts.ts index 6a4ec5d1d87769..9acc2798e8b1f5 100644 --- a/lib/workers/repository/update/branch/artifacts.ts +++ b/lib/workers/repository/update/branch/artifacts.ts @@ -1,7 +1,6 @@ import { GlobalConfig } from '../../../../config/global'; import { logger } from '../../../../logger'; import { platform } from '../../../../modules/platform'; -import { BranchStatus } from '../../../../types'; import type { BranchConfig } from '../../../types'; export async function setArtifactErrorStatus( @@ -14,7 +13,7 @@ export async function setArtifactErrorStatus( const context = `renovate/artifacts`; const description = 'Artifact file update failure'; - const state = BranchStatus.red; + const state = 'red'; const existingState = await platform.getBranchStatusCheck( config.branchName, context diff --git a/lib/workers/repository/update/branch/automerge.spec.ts b/lib/workers/repository/update/branch/automerge.spec.ts index 623182f44eaa11..81bafafe388f26 100644 --- a/lib/workers/repository/update/branch/automerge.spec.ts +++ b/lib/workers/repository/update/branch/automerge.spec.ts @@ -1,7 +1,6 @@ import { getConfig, git, platform } from '../../../../../test/util'; import { GlobalConfig } from '../../../../config/global'; import type { RenovateConfig } from '../../../../config/types'; -import { BranchStatus } from '../../../../types'; import * as schedule from '../branch/schedule'; import { tryBranchAutomerge } from './automerge'; @@ -38,14 +37,14 @@ describe('workers/repository/update/branch/automerge', () => { it('returns false if branch status is not success', async () => { config.automerge = true; config.automergeType = 'branch'; - platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.yellow); + platform.getBranchStatus.mockResolvedValueOnce('yellow'); expect(await tryBranchAutomerge(config)).toBe('no automerge'); }); it('returns branch status error if branch status is failure', async () => { config.automerge = true; config.automergeType = 'branch'; - platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.red); + platform.getBranchStatus.mockResolvedValueOnce('red'); expect(await tryBranchAutomerge(config)).toBe('branch status error'); }); @@ -53,7 +52,7 @@ describe('workers/repository/update/branch/automerge', () => { platform.getBranchPr.mockResolvedValueOnce({} as never); config.automerge = true; config.automergeType = 'branch'; - platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.green); + platform.getBranchStatus.mockResolvedValueOnce('green'); expect(await tryBranchAutomerge(config)).toBe( 'automerge aborted - PR exists' ); @@ -63,7 +62,7 @@ describe('workers/repository/update/branch/automerge', () => { config.automerge = true; config.automergeType = 'branch'; config.baseBranch = 'test-branch'; - platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.green); + platform.getBranchStatus.mockResolvedValueOnce('green'); git.mergeBranch.mockImplementationOnce(() => { throw new Error('merge error'); }); @@ -78,7 +77,7 @@ describe('workers/repository/update/branch/automerge', () => { config.automerge = true; config.automergeType = 'branch'; config.baseBranch = 'test-branch'; - platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.green); + platform.getBranchStatus.mockResolvedValueOnce('green'); const res = await tryBranchAutomerge(config); @@ -90,7 +89,7 @@ describe('workers/repository/update/branch/automerge', () => { config.automerge = true; config.automergeType = 'branch'; GlobalConfig.set({ dryRun: 'full' }); - platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.green); + platform.getBranchStatus.mockResolvedValueOnce('green'); expect(await tryBranchAutomerge(config)).toBe('automerged'); }); }); diff --git a/lib/workers/repository/update/branch/automerge.ts b/lib/workers/repository/update/branch/automerge.ts index 99808bf23eb5da..8d1339ad5013b3 100644 --- a/lib/workers/repository/update/branch/automerge.ts +++ b/lib/workers/repository/update/branch/automerge.ts @@ -1,9 +1,7 @@ -// TODO #7154 import { GlobalConfig } from '../../../../config/global'; import type { RenovateConfig } from '../../../../config/types'; import { logger } from '../../../../logger'; import { platform } from '../../../../modules/platform'; -import { BranchStatus } from '../../../../types'; import { checkoutBranch, mergeBranch } from '../../../../util/git'; import { isScheduledNow } from './schedule'; import { resolveBranchStatus } from './status-checks'; @@ -36,7 +34,7 @@ export async function tryBranchAutomerge( config.branchName!, config.ignoreTests ); - if (branchStatus === BranchStatus.green) { + if (branchStatus === 'green') { logger.debug(`Automerging branch`); try { if (GlobalConfig.get('dryRun')) { @@ -88,7 +86,7 @@ export async function tryBranchAutomerge( logger.warn({ err }, 'Unknown error when attempting branch automerge'); return 'failed'; } - } else if (branchStatus === BranchStatus.red) { + } else if (branchStatus === 'red') { return 'branch status error'; } else { logger.debug(`Branch status is "${branchStatus}" - skipping automerge`); diff --git a/lib/workers/repository/update/branch/index.spec.ts b/lib/workers/repository/update/branch/index.spec.ts index 4fec9d8003e16d..a53ca5dc3b6563 100644 --- a/lib/workers/repository/update/branch/index.spec.ts +++ b/lib/workers/repository/update/branch/index.spec.ts @@ -25,7 +25,6 @@ import * as _mergeConfidence from '../../../../util/merge-confidence'; import * as _sanitize from '../../../../util/sanitize'; import * as _limits from '../../../global/limits'; import type { BranchConfig, BranchUpgradeConfig } from '../../../types'; -import { BranchResult } from '../../../types'; import { needsChangelogs } from '../../changelog'; import * as _prWorker from '../pr'; import type { ResultWithPr } from '../pr'; @@ -765,7 +764,7 @@ describe('workers/repository/update/branch/index', () => { }; await expect(branchWorker.processBranch(inconfig)).resolves.toEqual({ branchExists: true, - result: BranchResult.NotScheduled, + result: 'not-scheduled', commitSha: null, }); expect(logger.debug).toHaveBeenCalledWith( @@ -1793,7 +1792,7 @@ describe('workers/repository/update/branch/index', () => { commit.commitFilesToBranch.mockResolvedValueOnce(null); expect( await branchWorker.processBranch({ ...config, rebaseWhen: 'never' }) - ).toMatchObject({ result: BranchResult.NoWork }); + ).toMatchObject({ result: 'no-work' }); expect(commit.commitFilesToBranch).not.toHaveBeenCalled(); }); @@ -1813,7 +1812,7 @@ describe('workers/repository/update/branch/index', () => { rebaseWhen: 'never', dependencyDashboardChecks: { 'renovate/some-branch': 'other' }, }) - ).toMatchObject({ result: BranchResult.Done }); + ).toMatchObject({ result: 'done' }); expect(commit.commitFilesToBranch).toHaveBeenCalled(); }); diff --git a/lib/workers/repository/update/branch/index.ts b/lib/workers/repository/update/branch/index.ts index a82074da5ae30b..88ad96ef8741b4 100644 --- a/lib/workers/repository/update/branch/index.ts +++ b/lib/workers/repository/update/branch/index.ts @@ -22,7 +22,6 @@ import { ensureCommentRemoval, } from '../../../../modules/platform/comment'; import { hashBody } from '../../../../modules/platform/pr-body'; -import { BranchStatus } from '../../../../types'; import { ExternalHostError } from '../../../../types/errors/external-host-error'; import { getElapsedDays } from '../../../../util/date'; import { emojify } from '../../../../util/emoji'; @@ -41,7 +40,7 @@ import { } from '../../../../util/merge-confidence'; import * as template from '../../../../util/template'; import { isLimitReached } from '../../../global/limits'; -import { BranchConfig, BranchResult, PrBlockedBy } from '../../../types'; +import type { BranchConfig, BranchResult, PrBlockedBy } from '../../../types'; import { embedChangelog, needsChangelogs } from '../../changelog'; import { ensurePr, getPlatformPrOptions, updatePrDebugData } from '../pr'; import { checkAutoMerge } from '../pr/automerge'; @@ -124,7 +123,7 @@ export async function processBranch( return { branchExists: false, prNo: existingPr.number, - result: BranchResult.AlreadyExisted, + result: 'already-existed', }; } // istanbul ignore if @@ -136,7 +135,7 @@ export async function processBranch( return { branchExists, prNo: branchPr?.number, - result: BranchResult.NeedsApproval, + result: 'needs-approval', }; } } @@ -150,7 +149,7 @@ export async function processBranch( return { branchExists, prNo: branchPr?.number, - result: BranchResult.BranchLimitReached, + result: 'branch-limit-reached', }; } if ( @@ -162,7 +161,7 @@ export async function processBranch( return { branchExists, prNo: branchPr?.number, - result: BranchResult.CommitLimitReached, + result: 'commit-limit-reached', }; } if ( @@ -173,7 +172,7 @@ export async function processBranch( return { branchExists: false, prNo: branchPr?.number, - result: BranchResult.Pending, + result: 'pending', }; } if (branchExists) { @@ -192,7 +191,7 @@ export async function processBranch( return { branchExists: true, prNo: branchPr?.number, - result: BranchResult.NoWork, + result: 'no-work', }; } } @@ -242,7 +241,7 @@ export async function processBranch( return { branchExists, prNo: branchPr.number, - result: BranchResult.PrEdited, + result: 'pr-edited', }; } } @@ -255,7 +254,7 @@ export async function processBranch( logger.debug('Branch has been edited but found no PR - skipping'); return { branchExists, - result: BranchResult.PrEdited, + result: 'pr-edited', }; } const branchSha = getBranchCommit(config.branchName); @@ -272,7 +271,7 @@ export async function processBranch( ); return { branchExists, - result: BranchResult.PrEdited, + result: 'pr-edited', }; } } @@ -286,7 +285,7 @@ export async function processBranch( return { branchExists, prNo: branchPr?.number, - result: BranchResult.NotScheduled, + result: 'not-scheduled', }; } if (config.updateNotScheduled === false && !config.rebaseRequested) { @@ -294,7 +293,7 @@ export async function processBranch( return { branchExists, prNo: branchPr?.number, - result: BranchResult.UpdateNotScheduled, + result: 'update-not-scheduled', }; } // istanbul ignore if @@ -302,7 +301,7 @@ export async function processBranch( logger.debug('Skipping PR creation out of schedule'); return { branchExists, - result: BranchResult.NotScheduled, + result: 'not-scheduled', }; } logger.debug( @@ -319,7 +318,7 @@ export async function processBranch( ) { // Only set a stability status check if one or more of the updates contain // both a stabilityDays setting and a releaseTimestamp - config.stabilityStatus = BranchStatus.green; + config.stabilityStatus = 'green'; // Default to 'success' but set 'pending' if any update is pending for (const upgrade of config.upgrades) { if (is.number(upgrade.stabilityDays) && upgrade.releaseTimestamp) { @@ -333,7 +332,7 @@ export async function processBranch( }, 'Update has not passed stability days' ); - config.stabilityStatus = BranchStatus.yellow; + config.stabilityStatus = 'yellow'; continue; } } @@ -352,22 +351,22 @@ export async function processBranch( updateType ); if (satisfiesConfidenceLevel(confidence, minimumConfidence)) { - config.confidenceStatus = BranchStatus.green; + config.confidenceStatus = 'green'; } else { logger.debug( { depName, confidence, minimumConfidence }, 'Update does not meet minimum confidence scores' ); - config.confidenceStatus = BranchStatus.yellow; + config.confidenceStatus = 'yellow'; continue; } } } - // Don't create a branch if we know it will be status ProcessBranchResult.Pending + // Don't create a branch if we know it will be status 'pending' if ( !dependencyDashboardCheck && !branchExists && - config.stabilityStatus === BranchStatus.yellow && + config.stabilityStatus === 'yellow' && ['not-pending', 'status-success'].includes(config.prCreation!) ) { logger.debug( @@ -376,7 +375,7 @@ export async function processBranch( return { branchExists, prNo: branchPr?.number, - result: BranchResult.Pending, + result: 'pending', }; } } @@ -407,7 +406,7 @@ export async function processBranch( return { branchExists, prNo: branchPr?.number, - result: BranchResult.NoWork, + result: 'no-work', }; } else { config = { ...config, ...(await shouldReuseExistingBranch(config)) }; @@ -541,7 +540,7 @@ export async function processBranch( return { branchExists, prNo: branchPr?.number, - result: BranchResult.NoWork, + result: 'no-work', }; } if (commitSha) { @@ -567,7 +566,7 @@ export async function processBranch( return { branchExists: true, updatesVerified, - result: BranchResult.Pending, + result: 'pending', commitSha, }; } @@ -585,7 +584,7 @@ export async function processBranch( await deleteBranchSilently(config.branchName); } logger.debug('Branch is automerged - returning'); - return { branchExists: false, result: BranchResult.Automerged }; + return { branchExists: false, result: 'automerged' }; } if (mergeStatus === 'off schedule') { logger.debug( @@ -593,7 +592,7 @@ export async function processBranch( ); return { branchExists, - result: BranchResult.NotScheduled, + result: 'not-scheduled', commitSha, }; } @@ -675,7 +674,7 @@ export async function processBranch( branchExists: true, updatesVerified, prNo: branchPr?.number, - result: BranchResult.Error, + result: 'error', commitSha, }; } else if ( @@ -699,7 +698,7 @@ export async function processBranch( return { branchExists, prNo: branchPr?.number, - result: BranchResult.Error, + result: 'error', commitSha, }; } @@ -719,7 +718,7 @@ export async function processBranch( return { branchExists, prBlockedBy, - result: BranchResult.PrLimitReached, + result: 'pr-limit-reached', commitSha, }; } @@ -728,7 +727,7 @@ export async function processBranch( return { branchExists, prBlockedBy, - result: BranchResult.NeedsPrApproval, + result: 'needs-pr-approval', commitSha, }; } @@ -736,7 +735,7 @@ export async function processBranch( return { branchExists, prBlockedBy, - result: BranchResult.Pending, + result: 'pending', commitSha, }; } @@ -744,7 +743,7 @@ export async function processBranch( return { branchExists, prBlockedBy, - result: BranchResult.Done, + result: 'done', commitSha, }; } @@ -752,7 +751,7 @@ export async function processBranch( return { branchExists, prBlockedBy, - result: BranchResult.Error, + result: 'error', commitSha, }; } @@ -760,7 +759,7 @@ export async function processBranch( return { branchExists, prBlockedBy, - result: BranchResult.Error, + result: 'error', commitSha, }; } @@ -821,7 +820,7 @@ export async function processBranch( if (prAutomergeResult?.automerged) { return { branchExists, - result: BranchResult.Automerged, + result: 'automerged', commitSha, }; } @@ -846,7 +845,7 @@ export async function processBranch( branchExists: true, updatesVerified, prNo: branchPr?.number, - result: BranchResult.PrCreated, + result: 'pr-created', commitSha, }; } @@ -854,7 +853,7 @@ export async function processBranch( branchExists, updatesVerified, prNo: branchPr?.number, - result: BranchResult.Done, + result: 'done', commitSha, }; } diff --git a/lib/workers/repository/update/branch/status-checks.spec.ts b/lib/workers/repository/update/branch/status-checks.spec.ts index f83044a6cce889..bd2ba5bf5e7aec 100644 --- a/lib/workers/repository/update/branch/status-checks.spec.ts +++ b/lib/workers/repository/update/branch/status-checks.spec.ts @@ -1,5 +1,4 @@ import { getConfig, platform } from '../../../../../test/util'; -import { BranchStatus } from '../../../../types'; import { ConfidenceConfig, StabilityConfig, @@ -29,22 +28,22 @@ describe('workers/repository/update/branch/status-checks', () => { }); it('sets status yellow', async () => { - config.stabilityStatus = BranchStatus.yellow; + config.stabilityStatus = 'yellow'; await setStability(config); expect(platform.getBranchStatusCheck).toHaveBeenCalledTimes(1); expect(platform.setBranchStatus).toHaveBeenCalledTimes(1); }); it('sets status green', async () => { - config.stabilityStatus = BranchStatus.green; + config.stabilityStatus = 'green'; await setStability(config); expect(platform.getBranchStatusCheck).toHaveBeenCalledTimes(1); expect(platform.setBranchStatus).toHaveBeenCalledTimes(1); }); it('skips status if already set', async () => { - config.stabilityStatus = BranchStatus.green; - platform.getBranchStatusCheck.mockResolvedValueOnce(BranchStatus.green); + config.stabilityStatus = 'green'; + platform.getBranchStatusCheck.mockResolvedValueOnce('green'); await setStability(config); expect(platform.getBranchStatusCheck).toHaveBeenCalledTimes(1); expect(platform.setBranchStatus).toHaveBeenCalledTimes(0); @@ -72,7 +71,7 @@ describe('workers/repository/update/branch/status-checks', () => { it('sets status yellow', async () => { config.minimumConfidence = 'high'; - config.confidenceStatus = BranchStatus.yellow; + config.confidenceStatus = 'yellow'; await setConfidence(config); expect(platform.getBranchStatusCheck).toHaveBeenCalledTimes(1); expect(platform.setBranchStatus).toHaveBeenCalledTimes(1); @@ -80,7 +79,7 @@ describe('workers/repository/update/branch/status-checks', () => { it('sets status green', async () => { config.minimumConfidence = 'high'; - config.confidenceStatus = BranchStatus.green; + config.confidenceStatus = 'green'; await setConfidence(config); expect(platform.getBranchStatusCheck).toHaveBeenCalledTimes(1); expect(platform.setBranchStatus).toHaveBeenCalledTimes(1); @@ -88,8 +87,8 @@ describe('workers/repository/update/branch/status-checks', () => { it('skips status if already set', async () => { config.minimumConfidence = 'high'; - config.confidenceStatus = BranchStatus.green; - platform.getBranchStatusCheck.mockResolvedValueOnce(BranchStatus.green); + config.confidenceStatus = 'green'; + platform.getBranchStatusCheck.mockResolvedValueOnce('green'); await setConfidence(config); expect(platform.getBranchStatusCheck).toHaveBeenCalledTimes(1); expect(platform.setBranchStatus).toHaveBeenCalledTimes(0); @@ -98,9 +97,7 @@ describe('workers/repository/update/branch/status-checks', () => { describe('getBranchStatus', () => { it('should return green if ignoreTests=true', async () => { - expect(await resolveBranchStatus('somebranch', true)).toBe( - BranchStatus.green - ); + expect(await resolveBranchStatus('somebranch', true)).toBe('green'); }); }); }); diff --git a/lib/workers/repository/update/branch/status-checks.ts b/lib/workers/repository/update/branch/status-checks.ts index 93aa9366184a16..361147de9ab53d 100644 --- a/lib/workers/repository/update/branch/status-checks.ts +++ b/lib/workers/repository/update/branch/status-checks.ts @@ -1,7 +1,7 @@ import type { RenovateConfig } from '../../../../config/types'; import { logger } from '../../../../logger'; import { platform } from '../../../../modules/platform'; -import { BranchStatus } from '../../../../types'; +import type { BranchStatus } from '../../../../types'; import { MergeConfidence, isActiveConfidenceLevel, @@ -17,7 +17,7 @@ export async function resolveBranchStatus( if (ignoreTests) { logger.debug('Ignore tests. Return green'); - return BranchStatus.green; + return 'green'; } const status = await platform.getBranchStatus(branchName); @@ -62,7 +62,7 @@ export async function setStability(config: StabilityConfig): Promise { } const context = `renovate/stability-days`; const description = - config.stabilityStatus === BranchStatus.green + config.stabilityStatus === 'green' ? 'Updates have met stability days requirement' : 'Updates have not met stability days requirement'; await setStatusCheck( @@ -90,7 +90,7 @@ export async function setConfidence(config: ConfidenceConfig): Promise { } const context = `renovate/merge-confidence`; const description = - config.confidenceStatus === BranchStatus.green + config.confidenceStatus === 'green' ? 'Updates have met Merge Confidence requirement' : 'Updates have not met Merge Confidence requirement'; await setStatusCheck( diff --git a/lib/workers/repository/update/pr/automerge.spec.ts b/lib/workers/repository/update/pr/automerge.spec.ts index c5fdfa8685fdc7..d8b0c711cc28c3 100644 --- a/lib/workers/repository/update/pr/automerge.spec.ts +++ b/lib/workers/repository/update/pr/automerge.spec.ts @@ -1,7 +1,6 @@ import { getConfig, git, partial, platform } from '../../../../../test/util'; import { GlobalConfig } from '../../../../config/global'; import type { Pr } from '../../../../modules/platform'; -import { BranchStatus } from '../../../../types'; import type { BranchConfig } from '../../../types'; import * as schedule from '../branch/schedule'; import * as prAutomerge from './automerge'; @@ -36,7 +35,7 @@ describe('workers/repository/update/pr/automerge', () => { it('should automerge if enabled and pr is mergeable', async () => { config.automerge = true; config.pruneBranchAfterAutomerge = true; - platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.green); + platform.getBranchStatus.mockResolvedValueOnce('green'); platform.mergePr.mockResolvedValueOnce(true); const res = await prAutomerge.checkAutoMerge(pr, config); expect(res).toEqual({ automerged: true, branchRemoved: true }); @@ -45,7 +44,7 @@ describe('workers/repository/update/pr/automerge', () => { it('should indicate if automerge failed', async () => { config.automerge = true; - platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.green); + platform.getBranchStatus.mockResolvedValueOnce('green'); platform.mergePr.mockResolvedValueOnce(false); const res = await prAutomerge.checkAutoMerge(pr, config); expect(res).toEqual({ @@ -59,7 +58,7 @@ describe('workers/repository/update/pr/automerge', () => { config.automerge = true; config.automergeType = 'pr-comment'; config.automergeComment = '!merge'; - platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.green); + platform.getBranchStatus.mockResolvedValueOnce('green'); platform.ensureComment.mockResolvedValueOnce(true); const res = await prAutomerge.checkAutoMerge(pr, config); expect(res).toEqual({ automerged: true, branchRemoved: false }); @@ -72,7 +71,7 @@ describe('workers/repository/update/pr/automerge', () => { config.automergeType = 'pr-comment'; config.automergeComment = '!merge'; config.rebaseRequested = true; - platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.green); + platform.getBranchStatus.mockResolvedValueOnce('green'); platform.ensureComment.mockResolvedValueOnce(true); const res = await prAutomerge.checkAutoMerge(pr, config); expect(res).toEqual({ automerged: true, branchRemoved: false }); @@ -83,7 +82,7 @@ describe('workers/repository/update/pr/automerge', () => { it('should skip branch deletion after automerge if prune is disabled', async () => { config.automerge = true; config.pruneBranchAfterAutomerge = false; - platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.green); + platform.getBranchStatus.mockResolvedValueOnce('green'); platform.mergePr.mockResolvedValueOnce(true); const res = await prAutomerge.checkAutoMerge(pr, config); expect(res).toEqual({ automerged: true, branchRemoved: false }); @@ -92,7 +91,7 @@ describe('workers/repository/update/pr/automerge', () => { it('should not automerge if enabled and pr is mergeable but cannot rebase', async () => { config.automerge = true; - platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.green); + platform.getBranchStatus.mockResolvedValueOnce('green'); git.isBranchModified.mockResolvedValueOnce(true); const res = await prAutomerge.checkAutoMerge(pr, config); expect(res).toEqual({ @@ -104,7 +103,7 @@ describe('workers/repository/update/pr/automerge', () => { it('should not automerge if enabled and pr is mergeable but branch status is not success', async () => { config.automerge = true; - platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.yellow); + platform.getBranchStatus.mockResolvedValueOnce('yellow'); const res = await prAutomerge.checkAutoMerge(pr, config); expect(res).toEqual({ automerged: false, @@ -138,7 +137,7 @@ describe('workers/repository/update/pr/automerge', () => { it('dryRun full should not automerge', async () => { config.automerge = true; GlobalConfig.set({ dryRun: 'full' }); - platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.green); + platform.getBranchStatus.mockResolvedValueOnce('green'); const res = await prAutomerge.checkAutoMerge(pr, config); expect(res).toEqual({ automerged: false, @@ -153,7 +152,7 @@ describe('workers/repository/update/pr/automerge', () => { automerged: false, prAutomergeBlockReason: 'DryRun', }; - platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.green); + platform.getBranchStatus.mockResolvedValueOnce('green'); GlobalConfig.set({ dryRun: 'full' }); const res = await prAutomerge.checkAutoMerge(pr, config); expect(res).toEqual(expectedResult); diff --git a/lib/workers/repository/update/pr/automerge.ts b/lib/workers/repository/update/pr/automerge.ts index 97ef1596eb7981..b2c66e68641eb3 100644 --- a/lib/workers/repository/update/pr/automerge.ts +++ b/lib/workers/repository/update/pr/automerge.ts @@ -6,7 +6,6 @@ import { ensureComment, ensureCommentRemoval, } from '../../../../modules/platform/comment'; -import { BranchStatus } from '../../../../types'; import { deleteBranch, isBranchConflicted, @@ -76,7 +75,7 @@ export async function checkAutoMerge( config.branchName, config.ignoreTests ); - if (branchStatus !== BranchStatus.green) { + if (branchStatus !== 'green') { logger.debug( `PR is not ready for merge (branch status is ${branchStatus})` ); diff --git a/lib/workers/repository/update/pr/index.spec.ts b/lib/workers/repository/update/pr/index.spec.ts index 6940023ff030ea..db355ade891712 100644 --- a/lib/workers/repository/update/pr/index.spec.ts +++ b/lib/workers/repository/update/pr/index.spec.ts @@ -9,7 +9,6 @@ import { import * as _comment from '../../../../modules/platform/comment'; import { getPrBodyStruct } from '../../../../modules/platform/pr-body'; import type { Pr } from '../../../../modules/platform/types'; -import { BranchStatus } from '../../../../types'; import { ExternalHostError } from '../../../../types/errors/external-host-error'; import * as _limits from '../../../global/limits'; import type { BranchConfig, BranchUpgradeConfig } from '../../../types'; @@ -114,7 +113,7 @@ describe('workers/repository/update/pr/index', () => { }); it('skips PR creation due to non-green branch check', async () => { - checks.resolveBranchStatus.mockResolvedValueOnce(BranchStatus.yellow); + checks.resolveBranchStatus.mockResolvedValueOnce('yellow'); const res = await ensurePr({ ...config, prCreation: 'status-success' }); @@ -125,7 +124,7 @@ describe('workers/repository/update/pr/index', () => { }); it('creates PR for green branch checks', async () => { - checks.resolveBranchStatus.mockResolvedValueOnce(BranchStatus.green); + checks.resolveBranchStatus.mockResolvedValueOnce('green'); platform.createPr.mockResolvedValueOnce(pr); const res = await ensurePr({ ...config, prCreation: 'status-success' }); @@ -135,7 +134,7 @@ describe('workers/repository/update/pr/index', () => { }); it('skips PR creation for unapproved dependencies', async () => { - checks.resolveBranchStatus.mockResolvedValueOnce(BranchStatus.yellow); + checks.resolveBranchStatus.mockResolvedValueOnce('yellow'); const res = await ensurePr({ ...config, prCreation: 'approval' }); @@ -149,7 +148,7 @@ describe('workers/repository/update/pr/index', () => { const now = DateTime.now(); const then = now.minus({ hours: 1 }); - checks.resolveBranchStatus.mockResolvedValueOnce(BranchStatus.yellow); + checks.resolveBranchStatus.mockResolvedValueOnce('yellow'); git.getBranchLastCommitTime.mockResolvedValueOnce(then.toJSDate()); const res = await ensurePr({ @@ -168,13 +167,13 @@ describe('workers/repository/update/pr/index', () => { const now = DateTime.now(); const then = now.minus({ hours: 1 }); - checks.resolveBranchStatus.mockResolvedValueOnce(BranchStatus.yellow); + checks.resolveBranchStatus.mockResolvedValueOnce('yellow'); git.getBranchLastCommitTime.mockResolvedValueOnce(then.toJSDate()); const res = await ensurePr({ ...config, prCreation: 'not-pending', - stabilityStatus: BranchStatus.green, + stabilityStatus: 'green', }); expect(res).toEqual({ @@ -187,7 +186,7 @@ describe('workers/repository/update/pr/index', () => { const now = DateTime.now(); const then = now.minus({ hours: 2 }); - checks.resolveBranchStatus.mockResolvedValueOnce(BranchStatus.yellow); + checks.resolveBranchStatus.mockResolvedValueOnce('yellow'); git.getBranchLastCommitTime.mockResolvedValueOnce(then.toJSDate()); platform.createPr.mockResolvedValueOnce(pr); @@ -325,7 +324,7 @@ describe('workers/repository/update/pr/index', () => { it('skips automerge failure comment', async () => { platform.createPr.mockResolvedValueOnce(pr); - checks.resolveBranchStatus.mockResolvedValueOnce(BranchStatus.red); + checks.resolveBranchStatus.mockResolvedValueOnce('red'); platform.massageMarkdown.mockReturnValueOnce('markdown content'); await ensurePr({ @@ -365,7 +364,7 @@ describe('workers/repository/update/pr/index', () => { hasReviewers: false, }; platform.getBranchPr.mockResolvedValueOnce(changedPr); - checks.resolveBranchStatus.mockResolvedValueOnce(BranchStatus.red); + checks.resolveBranchStatus.mockResolvedValueOnce('red'); const res = await ensurePr({ ...config, @@ -398,14 +397,14 @@ describe('workers/repository/update/pr/index', () => { const then = now.minus({ hours: 2 }); git.getBranchLastCommitTime.mockResolvedValueOnce(then.toJSDate()); - checks.resolveBranchStatus.mockResolvedValueOnce(BranchStatus.yellow); + checks.resolveBranchStatus.mockResolvedValueOnce('yellow'); platform.createPr.mockResolvedValueOnce(pr); const res = await ensurePr({ ...config, automerge: true, automergeType: 'branch', - stabilityStatus: BranchStatus.green, + stabilityStatus: 'green', prNotPendingHours: 1, }); @@ -418,14 +417,14 @@ describe('workers/repository/update/pr/index', () => { const then = now.minus({ hours: 1 }); git.getBranchLastCommitTime.mockResolvedValueOnce(then.toJSDate()); - checks.resolveBranchStatus.mockResolvedValueOnce(BranchStatus.yellow); + checks.resolveBranchStatus.mockResolvedValueOnce('yellow'); platform.createPr.mockResolvedValueOnce(pr); const res = await ensurePr({ ...config, automerge: true, automergeType: 'branch', - stabilityStatus: BranchStatus.green, + stabilityStatus: 'green', prNotPendingHours: 2, }); @@ -438,7 +437,7 @@ describe('workers/repository/update/pr/index', () => { it('comments on automerge failure', async () => { platform.createPr.mockResolvedValueOnce(pr); - checks.resolveBranchStatus.mockResolvedValueOnce(BranchStatus.red); + checks.resolveBranchStatus.mockResolvedValueOnce('red'); jest .spyOn(platform, 'massageMarkdown') .mockImplementation((prBody) => 'markdown content'); @@ -461,7 +460,7 @@ describe('workers/repository/update/pr/index', () => { it('handles ensureComment error', async () => { platform.createPr.mockResolvedValueOnce(pr); - checks.resolveBranchStatus.mockResolvedValueOnce(BranchStatus.red); + checks.resolveBranchStatus.mockResolvedValueOnce('red'); platform.massageMarkdown.mockReturnValueOnce('markdown content'); comment.ensureComment.mockRejectedValueOnce(new Error('unknown')); @@ -483,7 +482,7 @@ describe('workers/repository/update/pr/index', () => { hasReviewers: false, }; platform.getBranchPr.mockResolvedValueOnce(changedPr); - checks.resolveBranchStatus.mockResolvedValueOnce(BranchStatus.red); + checks.resolveBranchStatus.mockResolvedValueOnce('red'); const err = new Error('unknown'); participants.addParticipants.mockRejectedValueOnce(err); @@ -508,7 +507,7 @@ describe('workers/repository/update/pr/index', () => { hasReviewers: false, }; platform.getBranchPr.mockResolvedValueOnce(changedPr); - checks.resolveBranchStatus.mockResolvedValueOnce(BranchStatus.red); + checks.resolveBranchStatus.mockResolvedValueOnce('red'); const err = new ExternalHostError(new Error('unknown')); participants.addParticipants.mockRejectedValueOnce(err); @@ -537,7 +536,7 @@ describe('workers/repository/update/pr/index', () => { hasReviewers: false, }; platform.getBranchPr.mockResolvedValueOnce(changedPr); - checks.resolveBranchStatus.mockResolvedValueOnce(BranchStatus.red); + checks.resolveBranchStatus.mockResolvedValueOnce('red'); const err = new Error(message); participants.addParticipants.mockRejectedValueOnce(err); diff --git a/lib/workers/repository/update/pr/index.ts b/lib/workers/repository/update/pr/index.ts index 1a17aed95be0f6..be6813cc43f66e 100644 --- a/lib/workers/repository/update/pr/index.ts +++ b/lib/workers/repository/update/pr/index.ts @@ -16,7 +16,6 @@ import { } from '../../../../modules/platform'; import { ensureComment } from '../../../../modules/platform/comment'; import { hashBody } from '../../../../modules/platform/pr-body'; -import { BranchStatus } from '../../../../types'; import { ExternalHostError } from '../../../../types/errors/external-host-error'; import { stripEmojis } from '../../../../util/emoji'; import { deleteBranch, getBranchLastCommitTime } from '../../../../util/git'; @@ -109,8 +108,8 @@ export async function ensurePr( ) { logger.debug(`Branch automerge is enabled`); if ( - config.stabilityStatus !== BranchStatus.yellow && - (await getBranchStatus()) === BranchStatus.yellow && + config.stabilityStatus !== 'yellow' && + (await getBranchStatus()) === 'yellow' && is.number(config.prNotPendingHours) ) { logger.debug('Checking how long this branch has been pending'); @@ -125,7 +124,7 @@ export async function ensurePr( config.forcePr = true; } } - if (config.forcePr || (await getBranchStatus()) === BranchStatus.red) { + if (config.forcePr || (await getBranchStatus()) === 'red') { logger.debug(`Branch tests failed, so will create PR`); } else { // Branch should be automerged, so we don't want to create a PR @@ -134,7 +133,7 @@ export async function ensurePr( } if (config.prCreation === 'status-success') { logger.debug('Checking branch combined status'); - if ((await getBranchStatus()) !== BranchStatus.green) { + if ((await getBranchStatus()) !== 'green') { logger.debug(`Branch status isn't green - not creating PR`); return { type: 'without-pr', prBlockedBy: 'AwaitingTests' }; } @@ -151,7 +150,7 @@ export async function ensurePr( !config.forcePr ) { logger.debug('Checking branch combined status'); - if ((await getBranchStatus()) === BranchStatus.yellow) { + if ((await getBranchStatus()) === 'yellow') { logger.debug(`Branch status is yellow - checking timeout`); const lastCommitTime = await getBranchLastCommitTime(branchName); const currentTime = new Date(); @@ -161,8 +160,7 @@ export async function ensurePr( ); if ( !dependencyDashboardCheck && - ((config.stabilityStatus && - config.stabilityStatus !== BranchStatus.yellow) || + ((config.stabilityStatus && config.stabilityStatus !== 'yellow') || (is.number(config.prNotPendingHours) && elapsedHours < config.prNotPendingHours)) ) { @@ -288,7 +286,7 @@ export async function ensurePr( !existingPr.hasReviewers && config.automerge && !config.assignAutomerge && - (await getBranchStatus()) === BranchStatus.red + (await getBranchStatus()) === 'red' ) { logger.debug(`Setting assignees and reviewers as status checks failed`); await addParticipants(config, existingPr); @@ -417,7 +415,7 @@ export async function ensurePr( if ( config.automerge && !config.assignAutomerge && - (await getBranchStatus()) !== BranchStatus.red + (await getBranchStatus()) !== 'red' ) { logger.debug( `Skipping assignees and reviewers as automerge=${config.automerge}` diff --git a/lib/workers/types.ts b/lib/workers/types.ts index a8d956aa36c59f..fe8fa178ee3fed 100644 --- a/lib/workers/types.ts +++ b/lib/workers/types.ts @@ -86,25 +86,23 @@ export type PrBlockedBy = | 'RateLimited' | 'Error'; -// eslint-disable-next-line typescript-enum/no-enum -export enum BranchResult { - AlreadyExisted = 'already-existed', - Automerged = 'automerged', - Done = 'done', - Error = 'error', - NeedsApproval = 'needs-approval', - NeedsPrApproval = 'needs-pr-approval', - NotScheduled = 'not-scheduled', - NoWork = 'no-work', - Pending = 'pending', - PrCreated = 'pr-created', - PrEdited = 'pr-edited', - PrLimitReached = 'pr-limit-reached', - CommitLimitReached = 'commit-limit-reached', - BranchLimitReached = 'branch-limit-reached', - Rebase = 'rebase', - UpdateNotScheduled = 'update-not-scheduled', -} +export type BranchResult = + | 'already-existed' + | 'automerged' + | 'done' + | 'error' + | 'needs-approval' + | 'needs-pr-approval' + | 'not-scheduled' + | 'no-work' + | 'pending' + | 'pr-created' + | 'pr-edited' + | 'pr-limit-reached' + | 'commit-limit-reached' + | 'branch-limit-reached' + | 'rebase' + | 'update-not-scheduled'; export interface BranchConfig extends BranchUpgradeConfig,