Skip to content

Commit

Permalink
fix: create constants for skipReason (#5660)
Browse files Browse the repository at this point in the history
  • Loading branch information
ViralRuparel committed Mar 9, 2020
1 parent 96c933c commit 92d123a
Show file tree
Hide file tree
Showing 29 changed files with 153 additions and 87 deletions.
5 changes: 3 additions & 2 deletions lib/manager/ansible-galaxy/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { logger } from '../../logger';
import { PackageFile, PackageDependency } from '../common';
import * as datasourceGitTags from '../../datasource/git-tags';
import * as datasourceGalaxy from '../../datasource/galaxy';
import { SkipReason } from '../../types';

function interpretLine(
lineMatch: RegExpMatchArray,
Expand Down Expand Up @@ -40,7 +41,7 @@ function interpretLine(
function finalize(dependency: PackageDependency): boolean {
const dep = dependency;
if (dependency.managerData.version === null) {
dep.skipReason = 'no-version';
dep.skipReason = SkipReason.NoVersion;
return false;
}

Expand All @@ -58,7 +59,7 @@ function finalize(dependency: PackageDependency): boolean {
dep.depName = dep.managerData.src;
dep.lookupName = dep.managerData.src;
} else {
dep.skipReason = 'no-source-match';
dep.skipReason = SkipReason.NoSourceMatch;
return false;
}
if (dep.managerData.name !== null) {
Expand Down
3 changes: 2 additions & 1 deletion lib/manager/bazel/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as dockerVersioning from '../../versioning/docker';
import * as datasourceDocker from '../../datasource/docker';
import * as datasourceGo from '../../datasource/go';
import * as datasourceGithubReleases from '../../datasource/github-releases';
import { SkipReason } from '../../types';

interface UrlParsedResult {
repo: string;
Expand Down Expand Up @@ -202,7 +203,7 @@ export function extractPackageFile(content: string): PackageFile | null {
if (remoteMatch && remoteMatch[0].length === remote.length) {
dep.lookupName = remote.replace('https://', '');
} else {
dep.skipReason = 'unsupported-remote';
dep.skipReason = SkipReason.UnsupportedRemote;
}
}
if (commit) {
Expand Down
9 changes: 5 additions & 4 deletions lib/manager/buildkite/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { logger } from '../../logger';
import { isVersion } from '../../versioning/semver';
import { PackageFile, PackageDependency } from '../common';
import * as datasourceGithubTags from '../../datasource/github-tags';
import { SkipReason } from '../../types';

export function extractPackageFile(content: string): PackageFile | null {
const deps: PackageDependency[] = [];
Expand Down Expand Up @@ -29,17 +30,17 @@ export function extractPackageFile(content: string): PackageFile | null {
} else if (depLineMatch) {
const { depName, currentValue } = depLineMatch.groups;
logger.trace('depLineMatch');
let skipReason: string;
let skipReason: SkipReason;
let repo: string;
if (depName.startsWith('https://') || depName.startsWith('git@')) {
logger.debug({ dependency: depName }, 'Skipping git plugin');
skipReason = 'git-plugin';
skipReason = SkipReason.GitPlugin;
} else if (!isVersion(currentValue)) {
logger.debug(
{ currentValue },
'Skipping non-pinned current version'
);
skipReason = 'invalid-version';
skipReason = SkipReason.InvalidVersion;
} else {
const splitName = depName.split('/');
if (splitName.length === 1) {
Expand All @@ -51,7 +52,7 @@ export function extractPackageFile(content: string): PackageFile | null {
{ dependency: depName },
'Something is wrong with buildkite plugin name'
);
skipReason = 'unknown';
skipReason = SkipReason.Unknown;
}
}
const dep: PackageDependency = {
Expand Down
3 changes: 2 additions & 1 deletion lib/manager/bundler/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { platform } from '../../platform';
import { regEx } from '../../util/regex';
import { extractLockFileEntries } from './locked-version';
import * as datasourceRubygems from '../../datasource/rubygems';
import { SkipReason } from '../../types';

export async function extractPackageFile(
content: string,
Expand Down Expand Up @@ -57,7 +58,7 @@ export async function extractPackageFile(
.replace(regEx(gemDelimiter, 'g'), '')
.trim();
} else {
dep.skipReason = 'no-version';
dep.skipReason = SkipReason.NoVersion;
}
if (!dep.skipReason) {
dep.datasource = datasourceRubygems.id;
Expand Down
13 changes: 7 additions & 6 deletions lib/manager/cargo/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { logger } from '../../logger';
import { PackageDependency, PackageFile } from '../common';
import { CargoConfig, CargoSection } from './types';
import * as datasourceCrate from '../../datasource/crate';
import { SkipReason } from '../../types';

function extractFromSection(
parsedContent: CargoSection,
Expand All @@ -15,7 +16,7 @@ function extractFromSection(
return [];
}
Object.keys(sectionContent).forEach(depName => {
let skipReason: string;
let skipReason: SkipReason;
let currentValue = sectionContent[depName];
let nestedVersion = false;
if (typeof currentValue !== 'string') {
Expand All @@ -26,20 +27,20 @@ function extractFromSection(
currentValue = version;
nestedVersion = true;
if (path) {
skipReason = 'path-dependency';
skipReason = SkipReason.PathDependency;
}
if (git) {
skipReason = 'git-dependency';
skipReason = SkipReason.GitDependency;
}
} else if (path) {
currentValue = '';
skipReason = 'path-dependency';
skipReason = SkipReason.PathDependency;
} else if (git) {
currentValue = '';
skipReason = 'git-dependency';
skipReason = SkipReason.GitDependency;
} else {
currentValue = '';
skipReason = 'invalid-dependency-specification';
skipReason = SkipReason.InvalidDependencySpecification;
}
}
const dep: PackageDependency = {
Expand Down
7 changes: 4 additions & 3 deletions lib/manager/cocoapods/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { logger } from '../../logger';
import { PackageDependency, PackageFile } from '../common';
import * as datasourcePod from '../../datasource/pod';
import * as datasourceGithubTags from '../../datasource/github-tags';
import { SkipReason } from '../../types';

const regexMappings = [
/^\s*pod\s+(['"])(?<spec>[^'"/]+)(\/(?<subspec>[^'"]+))?\1/,
Expand Down Expand Up @@ -96,7 +97,7 @@ export function extractPackageFile(content: string): PackageFile | null {
let dep: PackageDependency = {
depName,
groupName,
skipReason: 'unknown-version',
skipReason: SkipReason.UnknownVersion,
};

if (currentValue) {
Expand All @@ -115,14 +116,14 @@ export function extractPackageFile(content: string): PackageFile | null {
dep = {
depName,
groupName,
skipReason: 'git-dependency',
skipReason: SkipReason.GitDependency,
};
}
} else if (path) {
dep = {
depName,
groupName,
skipReason: 'path-dependency',
skipReason: SkipReason.PathDependency,
};
}

Expand Down
4 changes: 2 additions & 2 deletions lib/manager/common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ReleaseType } from 'semver';
import { RangeStrategy } from '../types';
import { RangeStrategy, SkipReason } from '../types';
import { ValidationMessage, GlobalConfig, UpdateType } from '../config/common';

export type Result<T> = T | Promise<T>;
Expand Down Expand Up @@ -149,7 +149,7 @@ export interface PackageDependency<T = Record<string, any>> extends Package<T> {
propSource?: string;
registryUrls?: string[];
rangeStrategy?: RangeStrategy;
skipReason?: string;
skipReason?: SkipReason;
source?: string;
sourceLine?: number;
toVersion?: string;
Expand Down
6 changes: 3 additions & 3 deletions lib/manager/composer/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { logger } from '../../logger';
import { api as semverComposer } from '../../versioning/composer';
import { PackageFile, PackageDependency } from '../common';
import { platform } from '../../platform';

import { SkipReason } from '../../types';
import * as datasourceGitTags from '../../datasource/git-tags';
import * as datasourcePackagist from '../../datasource/packagist';

Expand Down Expand Up @@ -154,10 +154,10 @@ export async function extractPackageFile(
dep.lookupName = lookupName;
}
if (!depName.includes('/')) {
dep.skipReason = 'unsupported';
dep.skipReason = SkipReason.Unsupported;
}
if (currentValue === '*') {
dep.skipReason = 'any-version';
dep.skipReason = SkipReason.AnyVersion;
}
if (lockParsed) {
const lockedDep = lockParsed.packages.find(
Expand Down
3 changes: 2 additions & 1 deletion lib/manager/dockerfile/extract.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { logger } from '../../logger';
import { PackageDependency, PackageFile } from '../common';
import * as datasourceDocker from '../../datasource/docker';
import { SkipReason } from '../../types';

export function splitImageParts(currentFrom: string): PackageDependency {
if (currentFrom.includes('$')) {
return {
skipReason: 'contains-variable',
skipReason: SkipReason.ContainsVariable,
};
}
const [currentDepTag, currentDigest] = currentFrom.split('@');
Expand Down
3 changes: 2 additions & 1 deletion lib/manager/gitlabci-include/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import yaml from 'js-yaml';
import { logger } from '../../logger';
import { PackageDependency, ExtractConfig, PackageFile } from '../common';
import * as datasourceGitlabTags from '../../datasource/gitlab-tags';
import { SkipReason } from '../../types';

function extractDepFromInclude(includeObj: {
file: any;
Expand All @@ -18,7 +19,7 @@ function extractDepFromInclude(includeObj: {
depType: 'repository',
};
if (!includeObj.ref) {
dep.skipReason = 'unknown-version';
dep.skipReason = SkipReason.UnknownVersion;
return dep;
}
dep.currentValue = includeObj.ref;
Expand Down
3 changes: 2 additions & 1 deletion lib/manager/gomod/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { logger } from '../../logger';
import { isVersion } from '../../versioning/semver';
import { PackageDependency, PackageFile } from '../common';
import * as datasourceGo from '../../datasource/go';
import { SkipReason } from '../../types';

function getDep(
lineNumber: number,
Expand All @@ -20,7 +21,7 @@ function getDep(
currentValue,
};
if (!isVersion(currentValue)) {
dep.skipReason = 'unsupported-version';
dep.skipReason = SkipReason.UnsupportedVersion;
} else {
if (depName.startsWith('gopkg.in/')) {
const [pkg] = depName.replace('gopkg.in/', '').split('.');
Expand Down
10 changes: 5 additions & 5 deletions lib/manager/helm-requirements/extract.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import is from '@sindresorhus/is';
import upath from 'upath';
import yaml from 'js-yaml';

import { SkipReason } from '../../types';
import { logger } from '../../logger';
import { PackageFile, PackageDependency, ExtractConfig } from '../common';
import { platform } from '../../platform';
Expand Down Expand Up @@ -59,20 +59,20 @@ export async function extractPackageFile(
return res;
}

res.skipReason = 'placeholder-url';
res.skipReason = SkipReason.PlaceholderUrl;
} else {
try {
const url = new URL(dep.repository);
if (url.protocol === 'file:') {
res.skipReason = 'local-dependency';
res.skipReason = SkipReason.LocalDependency;
}
} catch (err) {
logger.debug({ err }, 'Error parsing url');
res.skipReason = 'invalid-url';
res.skipReason = SkipReason.InvalidUrl;
}
}
} else {
res.skipReason = 'no-repository';
res.skipReason = SkipReason.NoRepository;
}
return res;
});
Expand Down
8 changes: 4 additions & 4 deletions lib/manager/helmfile/extract.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import is from '@sindresorhus/is';
import yaml from 'js-yaml';

import { SkipReason } from '../../types';
import { logger } from '../../logger';
import { PackageFile, PackageDependency, ExtractConfig } from '../common';
import * as datasourceHelm from '../../datasource/helm';
Expand Down Expand Up @@ -65,18 +65,18 @@ export function extractPackageFile(

// If version is null is probably a local chart
if (!res.currentValue) {
res.skipReason = 'local-chart';
res.skipReason = SkipReason.LocalChart;
}

// By definition on helm the chart name should be lowecase letter + number + -
// However helmfile support templating of that field
if (!isValidChartName(res.depName)) {
res.skipReason = 'unsupported-chart-type';
res.skipReason = SkipReason.UnsupportedChartType;
}

// Skip in case we cannot locate the registry
if (is.emptyArray(res.registryUrls)) {
res.skipReason = 'unknown-registry';
res.skipReason = SkipReason.UnknownRegistry;
}

return res;
Expand Down
7 changes: 4 additions & 3 deletions lib/manager/homebrew/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { skip, isSpace, removeComments } from './util';
import { logger } from '../../logger';
import { PackageFile, PackageDependency } from '../common';
import * as datasourceGithubTags from '../../datasource/github-tags';
import { SkipReason } from '../../types';

function parseSha256(idx: number, content: string): string | null {
let i = idx;
Expand Down Expand Up @@ -167,7 +168,7 @@ export function extractPackageFile(content: string): PackageFile | null {
logger.debug('Invalid URL field');
}
const urlPathResult = parseUrlPath(url);
let skipReason: string;
let skipReason: SkipReason;
let currentValue: string = null;
let ownerName: string = null;
let repoName: string = null;
Expand All @@ -177,12 +178,12 @@ export function extractPackageFile(content: string): PackageFile | null {
repoName = urlPathResult.repoName;
} else {
logger.debug('Error: Unsupported URL field');
skipReason = 'unsupported-url';
skipReason = SkipReason.UnsupportedUrl;
}
const sha256 = extractSha256(cleanContent);
if (!sha256 || sha256.length !== 64) {
logger.debug('Error: Invalid sha256 field');
skipReason = 'invalid-sha256';
skipReason = SkipReason.InvalidSha256;
}
const dep: PackageDependency = {
depName: `${ownerName}/${repoName}`,
Expand Down
5 changes: 3 additions & 2 deletions lib/manager/maven/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ExtractConfig, PackageFile, PackageDependency } from '../common';
import { platform } from '../../platform';
import * as datasourceMaven from '../../datasource/maven';
import { MAVEN_REPO } from '../../datasource/maven/common';
import { SkipReason } from '../../types';

export function parsePom(raw: string): XmlDocument | null {
let project: XmlDocument;
Expand Down Expand Up @@ -125,9 +126,9 @@ function applyProps(
}

if (containsPlaceholder(depName)) {
result.skipReason = 'name-placeholder';
result.skipReason = SkipReason.NamePlaceholder;
} else if (containsPlaceholder(currentValue)) {
result.skipReason = 'version-placeholder';
result.skipReason = SkipReason.VersionPlaceholder;
}

return result;
Expand Down
3 changes: 2 additions & 1 deletion lib/manager/mix/extract.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { logger } from '../../logger';
import { PackageDependency, PackageFile } from '../common';
import * as datasourceHex from '../../datasource/hex';
import { SkipReason } from '../../types';

const depSectionRegExp = /defp\s+deps.*do/g;
const depMatchRegExp = /{:(\w+),\s*([^:"]+)?:?\s*"([^"]+)",?\s*(organization: "(.*)")?.*}/gm;
Expand Down Expand Up @@ -45,7 +46,7 @@ export function extractPackageFile(content: string): PackageFile {
}

if (dep.datasource !== datasourceHex.id) {
dep.skipReason = 'non-hex depTypes';
dep.skipReason = SkipReason.NonHexDeptypes;
}

// Find dep's line number
Expand Down

0 comments on commit 92d123a

Please sign in to comment.