feat(constants): Manager Constants (#5168)

This commit is contained in:
Sourav Das 2020-01-16 20:52:34 +05:30 committed by Rhys Arkins
parent 36a37dada8
commit 4e7c938ec7
12 changed files with 179 additions and 68 deletions

38
lib/constants/managers.ts Normal file
View file

@ -0,0 +1,38 @@
export const MANAGER_ANSIBLE = 'ansible';
export const MANAGER_BAZEL = 'bazel';
export const MANAGER_BUILDKITE = 'buildkite';
export const MANAGER_BUNDLER = 'bundler';
export const MANAGER_CARGO = 'cargo';
export const MANAGER_CIRCLE_CI = 'circleci';
export const MANAGER_COMPOSER = 'composer';
export const MANAGER_DEPS_EDN = 'deps-edn';
export const MANAGER_DOCKERFILE = 'dockerfile';
export const MANAGER_DOCKER_COMPOSE = 'docker-compose';
export const MANAGER_DRONE_CI = 'droneci';
export const MANAGER_GITHUB_ACTIONS = 'github-actions';
export const MANAGER_GITLAB_CI = 'gitlabci';
export const MANAGER_GITLAB_CI_INCLUDE = 'gitlabci-include';
export const MANAGER_GIT_SUBMODULES = 'git-submodules';
export const MANAGER_GO_MOD = 'gomod';
export const MANAGER_GRADLE = 'gradle';
export const MANAGER_GRADLE_WRAPPER = 'gradle-wrapper';
export const MANAGER_HELM_REQUIREMENTS = 'helm-requirements';
export const MANAGER_HOMEBREW = 'homebrew';
export const MANAGER_KUBERNETES = 'kubernetes';
export const MANAGER_LEININGEN = 'leiningen';
export const MANAGER_MAVEN = 'maven';
export const MANAGER_METEOR = 'meteor';
export const MANAGER_MIX = 'mix';
export const MANAGER_NPM = 'npm';
export const MANAGER_NUGET = 'nuget';
export const MANAGER_NVM = 'nvm';
export const MANAGER_PIPENV = 'pipenv';
export const MANAGER_PIP_REQUIREMENTS = 'pip_requirements';
export const MANAGER_PIP_SETUP = 'pip_setup';
export const MANAGER_POETRY = 'poetry';
export const MANAGER_PUB = 'pub';
export const MANAGER_RUBY_VERSION = 'ruby-version';
export const MANAGER_SBT = 'sbt';
export const MANAGER_SWIFT = 'swift';
export const MANAGER_TERRAFORM = 'terraform';
export const MANAGER_TRAVIS = 'travis';

View file

@ -17,6 +17,7 @@ import {
} from './gradle-updates-report';
import { PackageFile, ExtractConfig, Upgrade } from '../common';
import { platform } from '../../platform';
import { MANAGER_GRADLE } from '../../constants/managers';
import {
BINARY_SOURCE_DOCKER,
DATASOURCE_MAVEN,
@ -144,7 +145,7 @@ export async function extractAllPackageFiles(
if (content) {
gradleFiles.push({
packageFile,
manager: 'gradle',
manager: MANAGER_GRADLE,
datasource: DATASOURCE_MAVEN,
deps: dependencies,
});

View file

@ -8,46 +8,86 @@ import {
PackageUpdateResult,
} from './common';
import { RangeStrategy } from '../versioning';
import {
MANAGER_ANSIBLE,
MANAGER_BAZEL,
MANAGER_BUILDKITE,
MANAGER_BUNDLER,
MANAGER_CARGO,
MANAGER_CIRCLE_CI,
MANAGER_COMPOSER,
MANAGER_DEPS_EDN,
MANAGER_DOCKER_COMPOSE,
MANAGER_DOCKERFILE,
MANAGER_DRONE_CI,
MANAGER_GIT_SUBMODULES,
MANAGER_GITHUB_ACTIONS,
MANAGER_GITLAB_CI,
MANAGER_GITLAB_CI_INCLUDE,
MANAGER_GO_MOD,
MANAGER_GRADLE,
MANAGER_GRADLE_WRAPPER,
MANAGER_HELM_REQUIREMENTS,
MANAGER_HOMEBREW,
MANAGER_KUBERNETES,
MANAGER_LEININGEN,
MANAGER_MAVEN,
MANAGER_METEOR,
MANAGER_MIX,
MANAGER_NPM,
MANAGER_NUGET,
MANAGER_NVM,
MANAGER_PIP_REQUIREMENTS,
MANAGER_PIP_SETUP,
MANAGER_PIPENV,
MANAGER_POETRY,
MANAGER_PUB,
MANAGER_RUBY_VERSION,
MANAGER_SBT,
MANAGER_SWIFT,
MANAGER_TERRAFORM,
MANAGER_TRAVIS,
} from '../constants/managers';
const managerList = [
'ansible',
'bazel',
'buildkite',
'bundler',
'cargo',
'circleci',
'composer',
'deps-edn',
'docker-compose',
'dockerfile',
'droneci',
'git-submodules',
'github-actions',
'gitlabci',
'gitlabci-include',
'gomod',
'gradle',
'gradle-wrapper',
'helm-requirements',
'homebrew',
'kubernetes',
'leiningen',
'maven',
'meteor',
'mix',
'npm',
'nuget',
'nvm',
'pip_requirements',
'pip_setup',
'pipenv',
'poetry',
'pub',
'sbt',
'swift',
'terraform',
'travis',
'ruby-version',
MANAGER_ANSIBLE,
MANAGER_BAZEL,
MANAGER_BUILDKITE,
MANAGER_BUNDLER,
MANAGER_CARGO,
MANAGER_CIRCLE_CI,
MANAGER_COMPOSER,
MANAGER_DEPS_EDN,
MANAGER_DOCKER_COMPOSE,
MANAGER_DOCKERFILE,
MANAGER_DRONE_CI,
MANAGER_GIT_SUBMODULES,
MANAGER_GITHUB_ACTIONS,
MANAGER_GITLAB_CI,
MANAGER_GITLAB_CI_INCLUDE,
MANAGER_GO_MOD,
MANAGER_GRADLE,
MANAGER_GRADLE_WRAPPER,
MANAGER_HELM_REQUIREMENTS,
MANAGER_HOMEBREW,
MANAGER_KUBERNETES,
MANAGER_LEININGEN,
MANAGER_MAVEN,
MANAGER_METEOR,
MANAGER_MIX,
MANAGER_NPM,
MANAGER_NUGET,
MANAGER_NVM,
MANAGER_PIP_REQUIREMENTS,
MANAGER_PIP_SETUP,
MANAGER_PIPENV,
MANAGER_POETRY,
MANAGER_PUB,
MANAGER_SBT,
MANAGER_SWIFT,
MANAGER_TERRAFORM,
MANAGER_TRAVIS,
MANAGER_RUBY_VERSION,
];
const managers: Record<string, ManagerApi> = {};

View file

@ -17,6 +17,7 @@ import {
import { NpmPackage } from './common';
import { platform } from '../../../platform';
import { CONFIG_VALIDATION } from '../../../constants/error-messages';
import { MANAGER_NPM } from '../../../constants/managers';
import {
DATASOURCE_GITHUB,
DATASOURCE_NPM,
@ -352,7 +353,7 @@ export async function extractAllPackageFiles(
if (deps) {
npmFiles.push({
packageFile,
manager: 'npm',
manager: MANAGER_NPM,
...deps,
});
}

View file

@ -2,6 +2,7 @@ import { safeLoad } from 'js-yaml';
import { isValid } from '../../versioning/npm/index';
import { logger } from '../../logger';
import { PackageDependency, PackageFile } from '../common';
import { MANAGER_PUB } from '../../constants/managers';
import { DATASOURCE_DART } from '../../constants/data-binary-source';
function getDeps(
@ -50,7 +51,7 @@ export function extractPackageFile(
if (deps.length) {
return {
packageFile,
manager: 'pub',
manager: MANAGER_PUB,
datasource: DATASOURCE_DART,
deps,
};

View file

@ -3,6 +3,11 @@ import { logger } from '../../../../logger';
import { configFileNames } from '../../../../config/app-strings';
import { RenovateConfig } from '../../../../config';
import { PackageFile } from '../../../../manager/common';
import {
MANAGER_CIRCLE_CI,
MANAGER_DOCKER_COMPOSE,
MANAGER_DOCKERFILE,
} from '../../../../constants/managers';
const defaultConfigFile = configFileNames[0];
@ -42,9 +47,9 @@ export function getConfigDesc(
const enabledManagers = packageFiles ? Object.keys(packageFiles) : [];
if (
!(
enabledManagers.includes('dockerfile') ||
enabledManagers.includes('circleci') ||
enabledManagers.includes('docker-compose')
enabledManagers.includes(MANAGER_DOCKERFILE) ||
enabledManagers.includes(MANAGER_CIRCLE_CI) ||
enabledManagers.includes(MANAGER_DOCKER_COMPOSE)
)
) {
descriptionArr = descriptionArr.filter(val => !val.includes('Docker-only'));

View file

@ -1,9 +1,12 @@
import * as manager from '../../lib/manager';
import { MANAGER_DOCKERFILE } from '../../lib/constants/managers';
describe('manager', () => {
describe('get()', () => {
it('gets something', () => {
expect(manager.get('dockerfile', 'extractPackageFile')).not.toBeNull();
expect(
manager.get(MANAGER_DOCKERFILE, 'extractPackageFile')
).not.toBeNull();
});
});
describe('getLanguageList()', () => {
@ -19,7 +22,7 @@ describe('manager', () => {
describe('extractAllPackageFiles()', () => {
it('returns null', () => {
expect(
manager.extractAllPackageFiles('dockerfile', {} as any, [])
manager.extractAllPackageFiles(MANAGER_DOCKERFILE, {} as any, [])
).toBeNull();
});
it('returns non-null', () => {

View file

@ -1,14 +1,18 @@
import { getRangeStrategy } from '../../lib/manager';
import { RangeConfig } from '../../lib/manager/common';
import { MANAGER_CIRCLE_CI, MANAGER_NPM } from '../../lib/constants/managers';
describe('getRangeStrategy', () => {
it('returns same if not auto', () => {
const config: RangeConfig = { manager: 'npm', rangeStrategy: 'widen' };
const config: RangeConfig = {
manager: MANAGER_NPM,
rangeStrategy: 'widen',
};
expect(getRangeStrategy(config)).toEqual('widen');
});
it('returns manager strategy', () => {
const config: RangeConfig = {
manager: 'npm',
manager: MANAGER_NPM,
rangeStrategy: 'auto',
depType: 'dependencies',
packageJsonType: 'app',
@ -17,14 +21,14 @@ describe('getRangeStrategy', () => {
});
it('defaults to replace', () => {
const config: RangeConfig = {
manager: 'circleci',
manager: MANAGER_CIRCLE_CI,
rangeStrategy: 'auto',
};
expect(getRangeStrategy(config)).toEqual('replace');
});
it('returns rangeStrategy if not auto', () => {
const config: RangeConfig = {
manager: 'circleci',
manager: MANAGER_CIRCLE_CI,
rangeStrategy: 'future',
};
expect(getRangeStrategy(config)).toEqual('future');

View file

@ -1,5 +1,12 @@
import { applyPackageRules, Config } from '../../lib/util/package-rules';
import { UpdateType } from '../../lib/config';
import {
MANAGER_DOCKERFILE,
MANAGER_METEOR,
MANAGER_NPM,
MANAGER_PIPENV,
} from '../../lib/constants/managers';
import {
DATASOURCE_DOCKER,
DATASOURCE_ORB,
@ -180,7 +187,7 @@ describe('applyPackageRules()', () => {
const config: TestConfig = {
packageRules: [
{
managers: ['npm', 'meteor'],
managers: [MANAGER_NPM, MANAGER_METEOR],
packageNames: ['node'],
x: 1,
},
@ -189,7 +196,7 @@ describe('applyPackageRules()', () => {
const dep = {
depType: 'dependencies',
language: 'js',
manager: 'meteor',
manager: MANAGER_METEOR,
depName: 'node',
};
const res = applyPackageRules({ ...config, ...dep });
@ -199,7 +206,7 @@ describe('applyPackageRules()', () => {
const config: TestConfig = {
packageRules: [
{
managers: ['dockerfile', 'npm'],
managers: [MANAGER_DOCKERFILE, MANAGER_NPM],
packageNames: ['node'],
x: 1,
},
@ -208,7 +215,7 @@ describe('applyPackageRules()', () => {
const dep = {
depType: 'dependencies',
language: 'python',
manager: 'pipenv',
manager: MANAGER_PIPENV,
depName: 'node',
};
const res = applyPackageRules({ ...config, ...dep });
@ -227,7 +234,7 @@ describe('applyPackageRules()', () => {
const dep = {
depType: 'dependencies',
language: 'js',
manager: 'meteor',
manager: MANAGER_METEOR,
depName: 'node',
};
const res = applyPackageRules({ ...config, ...dep });
@ -246,7 +253,7 @@ describe('applyPackageRules()', () => {
const dep = {
depType: 'dependencies',
language: 'python',
manager: 'pipenv',
manager: MANAGER_PIPENV,
depName: 'node',
};
const res = applyPackageRules({ ...config, ...dep });

View file

@ -3,6 +3,11 @@ import * as _npm from '../../../lib/manager/npm';
import * as _gitSubmodules from '../../../lib/manager/git-submodules';
import { getUpdatedPackageFiles } from '../../../lib/workers/branch/get-updated';
import { mocked, defaultConfig, platform } from '../../util';
import {
MANAGER_COMPOSER,
MANAGER_GIT_SUBMODULES,
MANAGER_NPM,
} from '../../../lib/constants/managers';
import { DATASOURCE_GIT_SUBMODULES } from '../../../lib/constants/data-binary-source';
const composer = mocked(_composer);
@ -31,14 +36,14 @@ describe('workers/branch/get-updated', () => {
it('handles null content', async () => {
config.parentBranch = 'some-branch';
config.upgrades.push({
manager: 'npm',
manager: MANAGER_NPM,
});
await expect(getUpdatedPackageFiles(config)).rejects.toThrow();
});
it('handles content change', async () => {
config.parentBranch = 'some-branch';
config.upgrades.push({
manager: 'npm',
manager: MANAGER_NPM,
});
npm.updateDependency.mockReturnValue('some new content');
const res = await getUpdatedPackageFiles(config);
@ -47,7 +52,7 @@ describe('workers/branch/get-updated', () => {
it('handles lock files', async () => {
config.parentBranch = 'some-branch';
config.upgrades.push({
manager: 'composer',
manager: MANAGER_COMPOSER,
});
composer.updateDependency.mockReturnValue('some new content');
composer.updateArtifacts.mockResolvedValueOnce([
@ -64,7 +69,7 @@ describe('workers/branch/get-updated', () => {
it('handles lockFileMaintenance', async () => {
// config.parentBranch = 'some-branch';
config.upgrades.push({
manager: 'composer',
manager: MANAGER_COMPOSER,
updateType: 'lockFileMaintenance',
});
composer.updateArtifacts.mockResolvedValueOnce([
@ -81,7 +86,7 @@ describe('workers/branch/get-updated', () => {
it('handles lockFileMaintenance error', async () => {
// config.parentBranch = 'some-branch';
config.upgrades.push({
manager: 'composer',
manager: MANAGER_COMPOSER,
updateType: 'lockFileMaintenance',
});
composer.updateArtifacts.mockResolvedValueOnce([
@ -98,7 +103,7 @@ describe('workers/branch/get-updated', () => {
it('handles lock file errors', async () => {
config.parentBranch = 'some-branch';
config.upgrades.push({
manager: 'composer',
manager: MANAGER_COMPOSER,
});
composer.updateDependency.mockReturnValue('some new content');
composer.updateArtifacts.mockResolvedValueOnce([
@ -114,7 +119,7 @@ describe('workers/branch/get-updated', () => {
});
it('handles git submodules', async () => {
config.upgrades.push({
manager: 'git-submodules',
manager: MANAGER_GIT_SUBMODULES,
datasource: DATASOURCE_GIT_SUBMODULES,
});
gitSubmodules.updateDependency.mockResolvedValueOnce('existing content');

View file

@ -3,6 +3,11 @@ import * as _fileMatch from '../../../../lib/workers/repository/extract/file-mat
import * as _dockerfile from '../../../../lib/manager/dockerfile';
import { mocked, platform, getConfig } from '../../../util';
import { RenovateConfig } from '../../../../lib/config';
import {
MANAGER_DOCKERFILE,
MANAGER_NPM,
MANAGER_TRAVIS,
} from '../../../../lib/constants/managers';
jest.mock('../../../../lib/workers/repository/extract/file-match');
jest.mock('../../../../lib/manager/dockerfile');
@ -18,7 +23,7 @@ describe('workers/repository/extract/manager-files', () => {
config = getConfig;
});
it('returns empty of manager is disabled', async () => {
const managerConfig = { manager: 'travis', enabled: false };
const managerConfig = { manager: MANAGER_TRAVIS, enabled: false };
const res = await getManagerPackageFiles(managerConfig);
expect(res).toHaveLength(0);
});
@ -29,13 +34,13 @@ describe('workers/repository/extract/manager-files', () => {
expect(res).toHaveLength(0);
});
it('skips files if null content returned', async () => {
const managerConfig = { manager: 'npm', enabled: true };
const managerConfig = { manager: MANAGER_NPM, enabled: true };
fileMatch.getMatchingFiles.mockReturnValue(['package.json']);
const res = await getManagerPackageFiles(managerConfig);
expect(res).toHaveLength(0);
});
it('returns files with extractPackageFile', async () => {
const managerConfig = { manager: 'dockerfile', enabled: true };
const managerConfig = { manager: MANAGER_DOCKERFILE, enabled: true };
fileMatch.getMatchingFiles.mockReturnValue(['Dockerfile']);
platform.getFile.mockResolvedValue('some content');
dockerfile.extractPackageFile = jest.fn(() => ({
@ -45,7 +50,7 @@ describe('workers/repository/extract/manager-files', () => {
expect(res).toMatchSnapshot();
});
it('returns files with extractAllPackageFiles', async () => {
const managerConfig = { manager: 'npm', enabled: true };
const managerConfig = { manager: MANAGER_NPM, enabled: true };
fileMatch.getMatchingFiles.mockReturnValue(['package.json']);
platform.getFile.mockResolvedValue('{}');
const res = await getManagerPackageFiles(managerConfig);

View file

@ -11,6 +11,7 @@ import * as _docker from '../../../../../lib/datasource/docker';
import * as _gitSubmodules from '../../../../../lib/datasource/git-submodules';
import { mocked, getConfig } from '../../../../util';
import { CONFIG_VALIDATION } from '../../../../../lib/constants/error-messages';
import { MANAGER_PIP_REQUIREMENTS } from '../../../../../lib/constants/managers';
import {
DATASOURCE_DOCKER,
DATASOURCE_GIT_SUBMODULES,
@ -1021,7 +1022,7 @@ describe('workers/repository/process/lookup', () => {
expect((await lookup.lookupUpdates(config)).updates).toMatchSnapshot();
});
it('handles PEP440', async () => {
config.manager = 'pip_requirements';
config.manager = MANAGER_PIP_REQUIREMENTS;
config.versionScheme = 'pep440';
config.rangeStrategy = 'pin';
config.lockedVersion = '0.9.4';