Skip to content

Commit

Permalink
refactor(function): Update Artifact Function (#5139)
Browse files Browse the repository at this point in the history
1. Create interface UpdateArtifact
2. Update function call
3. Update Test
  • Loading branch information
souravdasslg authored and rarkins committed Jan 17, 2020
1 parent 9024eda commit 982d5e9
Show file tree
Hide file tree
Showing 18 changed files with 423 additions and 162 deletions.
22 changes: 11 additions & 11 deletions lib/manager/bundler/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
matches,
sortVersions,
} from '../../versioning/ruby';
import { UpdateArtifactsConfig, UpdateArtifactsResult } from '../common';
import { UpdateArtifact, UpdateArtifactsResult } from '../common';
import { platform } from '../../platform';
import {
BUNDLER_INVALID_CREDENTIALS,
Expand All @@ -22,12 +22,12 @@ import {
BINARY_SOURCE_GLOBAL,
} from '../../constants/data-binary-source';

export async function updateArtifacts(
packageFileName: string,
updatedDeps: string[],
newPackageFileContent: string,
config: UpdateArtifactsConfig
): Promise<UpdateArtifactsResult[] | null> {
export async function updateArtifacts({
packageFileName,
updatedDeps,
newPackageFileContent,
config,
}: UpdateArtifact): Promise<UpdateArtifactsResult[] | null> {
logger.debug(`bundler.updateArtifacts(${packageFileName})`);
// istanbul ignore if
if (global.repoCache.bundlerArtifactsError) {
Expand Down Expand Up @@ -190,12 +190,12 @@ export async function updateArtifacts(
const newUpdatedDeps = [
...new Set([...updatedDeps, ...resolveMatches]),
];
return updateArtifacts(
return updateArtifacts({
packageFileName,
newUpdatedDeps,
updatedDeps: newUpdatedDeps,
newPackageFileContent,
config
);
config,
});
}
logger.info(
{ err },
Expand Down
14 changes: 7 additions & 7 deletions lib/manager/cargo/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import { outputFile, readFile } from 'fs-extra';
import { exec } from '../../util/exec';
import { getChildProcessEnv } from '../../util/exec/env';
import { logger } from '../../logger';
import { UpdateArtifactsConfig, UpdateArtifactsResult } from '../common';
import { UpdateArtifact, UpdateArtifactsResult } from '../common';
import { platform } from '../../platform';
import { BINARY_SOURCE_DOCKER } from '../../constants/data-binary-source';

export async function updateArtifacts(
packageFileName: string,
updatedDeps: string[],
newPackageFileContent: string,
config: UpdateArtifactsConfig
): Promise<UpdateArtifactsResult[] | null> {
export async function updateArtifacts({
packageFileName,
updatedDeps,
newPackageFileContent,
config,
}: UpdateArtifact): Promise<UpdateArtifactsResult[] | null> {
logger.debug(`cargo.updateArtifacts(${packageFileName})`);
if (updatedDeps === undefined || updatedDeps.length < 1) {
logger.debug('No updated cargo deps - returning null');
Expand Down
11 changes: 7 additions & 4 deletions lib/manager/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ export interface UpdateArtifactsResult {
file?: { name: string; contents: string };
}

export interface UpdateArtifact {
packageFileName: string;
updatedDeps: string[];
newPackageFileContent: string;
config: UpdateArtifactsConfig;
}
export interface ManagerApi {
language?: string;
supportsLockFileMaintenance?: boolean;
Expand All @@ -195,10 +201,7 @@ export interface ManagerApi {
getRangeStrategy(config: RangeConfig): RangeStrategy;

updateArtifacts?(
packageFileName: string,
updatedDeps: string[],
newPackageFileContent: string,
config: UpdateArtifactsConfig
updateArtifact: UpdateArtifact
): Result<UpdateArtifactsResult[] | null>;

updateDependency(
Expand Down
14 changes: 7 additions & 7 deletions lib/manager/composer/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import URL from 'url';
import fs from 'fs-extra';
import upath from 'upath';
import { exec } from '../../util/exec';
import { UpdateArtifactsConfig, UpdateArtifactsResult } from '../common';
import { UpdateArtifact, UpdateArtifactsResult } from '../common';
import { logger } from '../../logger';
import * as hostRules from '../../util/host-rules';
import { getChildProcessEnv } from '../../util/exec/env';
Expand All @@ -15,12 +15,12 @@ import {
BINARY_SOURCE_GLOBAL,
} from '../../constants/data-binary-source';

export async function updateArtifacts(
packageFileName: string,
updatedDeps: string[],
newPackageFileContent: string,
config: UpdateArtifactsConfig
): Promise<UpdateArtifactsResult[] | null> {
export async function updateArtifacts({
packageFileName,
updatedDeps,
newPackageFileContent,
config,
}: UpdateArtifact): Promise<UpdateArtifactsResult[] | null> {
logger.debug(`composer.updateArtifacts(${packageFileName})`);
const env = getChildProcessEnv(['COMPOSER_CACHE_DIR']);
env.COMPOSER_CACHE_DIR =
Expand Down
11 changes: 4 additions & 7 deletions lib/manager/git-submodules/artifacts.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { UpdateArtifactsConfig, UpdateArtifactsResult } from '../common';
import { UpdateArtifact, UpdateArtifactsResult } from '../common';

export default function updateArtifacts(
packageFileName: string,
updatedDeps: string[],
newPackageFileContent: string,
config: UpdateArtifactsConfig
): UpdateArtifactsResult[] | null {
export default function updateArtifacts({
updatedDeps,
}: UpdateArtifact): UpdateArtifactsResult[] | null {
return [
{
file: {
Expand Down
14 changes: 7 additions & 7 deletions lib/manager/gomod/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ import { exec } from '../../util/exec';
import { find } from '../../util/host-rules';
import { getChildProcessEnv } from '../../util/exec/env';
import { logger } from '../../logger';
import { UpdateArtifactsConfig, UpdateArtifactsResult } from '../common';
import { UpdateArtifact, UpdateArtifactsResult } from '../common';
import { platform } from '../../platform';
import {
BINARY_SOURCE_AUTO,
BINARY_SOURCE_DOCKER,
BINARY_SOURCE_GLOBAL,
} from '../../constants/data-binary-source';

export async function updateArtifacts(
goModFileName: string,
_updatedDeps: string[],
newGoModContent: string,
config: UpdateArtifactsConfig
): Promise<UpdateArtifactsResult[] | null> {
export async function updateArtifacts({
packageFileName: goModFileName,
updatedDeps: _updatedDeps,
newPackageFileContent: newGoModContent,
config,
}: UpdateArtifact): Promise<UpdateArtifactsResult[] | null> {
logger.debug(`gomod.updateArtifacts(${goModFileName})`);
const customEnv = ['GOPATH', 'GOPROXY', 'GONOSUMDB'];
const env = getChildProcessEnv(customEnv);
Expand Down
14 changes: 7 additions & 7 deletions lib/manager/mix/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import fs from 'fs-extra';
import { platform } from '../../platform';
import { exec } from '../../util/exec';
import { logger } from '../../logger';
import { UpdateArtifactsConfig, UpdateArtifactsResult } from '../common';
import { UpdateArtifact, UpdateArtifactsResult } from '../common';
import { BINARY_SOURCE_DOCKER } from '../../constants/data-binary-source';

export async function updateArtifacts(
packageFileName: string,
updatedDeps: string[],
newPackageFileContent: string,
config: UpdateArtifactsConfig
): Promise<UpdateArtifactsResult[] | null> {
export async function updateArtifacts({
packageFileName,
updatedDeps,
newPackageFileContent,
config,
}: UpdateArtifact): Promise<UpdateArtifactsResult[] | null> {
logger.debug(`mix.getArtifacts(${packageFileName})`);
if (updatedDeps.length < 1) {
logger.debug('No updated mix deps - returning null');
Expand Down
14 changes: 7 additions & 7 deletions lib/manager/pipenv/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import { join, dirname } from 'upath';
import { exec } from '../../util/exec';
import { getChildProcessEnv } from '../../util/exec/env';
import { logger } from '../../logger';
import { UpdateArtifactsResult, UpdateArtifactsConfig } from '../common';
import { UpdateArtifactsResult, UpdateArtifact } from '../common';
import { platform } from '../../platform';
import { BINARY_SOURCE_DOCKER } from '../../constants/data-binary-source';

export async function updateArtifacts(
pipfileName: string,
_updatedDeps: string[],
newPipfileContent: string,
config: UpdateArtifactsConfig
): Promise<UpdateArtifactsResult[] | null> {
export async function updateArtifacts({
packageFileName: pipfileName,
updatedDeps: _updatedDeps,
newPackageFileContent: newPipfileContent,
config,
}: UpdateArtifact): Promise<UpdateArtifactsResult[] | null> {
logger.debug(`pipenv.updateArtifacts(${pipfileName})`);

const env = getChildProcessEnv(['LC_ALL', 'LANG', 'PIPENV_CACHE_DIR']);
Expand Down
14 changes: 7 additions & 7 deletions lib/manager/poetry/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import { parse, join } from 'upath';
import { outputFile, readFile } from 'fs-extra';
import { exec, ExecOptions } from '../../util/exec';
import { logger } from '../../logger';
import { UpdateArtifactsConfig, UpdateArtifactsResult } from '../common';
import { UpdateArtifact, UpdateArtifactsResult } from '../common';
import { platform } from '../../platform';
import { BINARY_SOURCE_DOCKER } from '../../constants/data-binary-source';

export async function updateArtifacts(
packageFileName: string,
updatedDeps: string[],
newPackageFileContent: string,
config: UpdateArtifactsConfig
): Promise<UpdateArtifactsResult[] | null> {
export async function updateArtifacts({
packageFileName,
updatedDeps,
newPackageFileContent,
config,
}: UpdateArtifact): Promise<UpdateArtifactsResult[] | null> {
logger.debug(`poetry.updateArtifacts(${packageFileName})`);
if (!is.nonEmptyArray(updatedDeps)) {
logger.debug('No updated poetry deps - returning null');
Expand Down
22 changes: 11 additions & 11 deletions lib/workers/branch/get-updated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ export async function getUpdatedPackageFiles(
const updatedDeps = packageFileUpdatedDeps[packageFile.name];
const updateArtifacts = get(manager, 'updateArtifacts');
if (updateArtifacts) {
const results = await updateArtifacts(
packageFile.name,
const results = await updateArtifacts({
packageFileName: packageFile.name,
updatedDeps,
packageFile.contents,
config
);
newPackageFileContent: packageFile.contents,
config,
});
if (is.nonEmptyArray(results)) {
for (const res of results) {
const { file, artifactError } = res;
Expand All @@ -118,12 +118,12 @@ export async function getUpdatedPackageFiles(
const packageFileContents =
updatedFileContents[packageFile] ||
(await platform.getFile(packageFile, config.parentBranch));
const results = await updateArtifacts(
packageFile,
[],
packageFileContents,
config
);
const results = await updateArtifacts({
packageFileName: packageFile,
updatedDeps: [],
newPackageFileContent: packageFileContents,
config,
});
if (is.nonEmptyArray(results)) {
for (const res of results) {
const { file, artifactError } = res;
Expand Down
64 changes: 48 additions & 16 deletions test/manager/bundler/artifacts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ describe('bundler.updateArtifacts()', () => {
env.getChildProcessEnv.mockReturnValue(envMock.basic);
});
it('returns null by default', async () => {
expect(await updateArtifacts('', [], '', config)).toBeNull();
expect(
await updateArtifacts({
packageFileName: '',
updatedDeps: [],
newPackageFileContent: '',
config,
})
).toBeNull();
});
it('returns null if Gemfile.lock was not changed', async () => {
platform.getFile.mockResolvedValueOnce('Current Gemfile.lock');
Expand All @@ -49,7 +56,12 @@ describe('bundler.updateArtifacts()', () => {
} as Git.StatusResult);
fs.readFile.mockResolvedValueOnce('Updated Gemfile.lock' as any);
expect(
await updateArtifacts('Gemfile', [], 'Updated Gemfile content', config)
await updateArtifacts({
packageFileName: 'Gemfile',
updatedDeps: [],
newPackageFileContent: 'Updated Gemfile content',
config,
})
).toMatchSnapshot();
expect(execSnapshots).toMatchSnapshot();
});
Expand All @@ -62,7 +74,12 @@ describe('bundler.updateArtifacts()', () => {
} as Git.StatusResult);
fs.readFile.mockResolvedValueOnce('Updated Gemfile.lock' as any);
expect(
await updateArtifacts('Gemfile', [], 'Updated Gemfile content', config)
await updateArtifacts({
packageFileName: 'Gemfile',
updatedDeps: [],
newPackageFileContent: 'Updated Gemfile content',
config,
})
).toMatchSnapshot();
expect(execSnapshots).toMatchSnapshot();
});
Expand All @@ -75,9 +92,14 @@ describe('bundler.updateArtifacts()', () => {
} as Git.StatusResult);
fs.readFile.mockResolvedValueOnce('Updated Gemfile.lock' as any);
expect(
await updateArtifacts('Gemfile', [], 'Updated Gemfile content', {
...config,
binarySource: BINARY_SOURCE_GLOBAL,
await updateArtifacts({
packageFileName: 'Gemfile',
updatedDeps: [],
newPackageFileContent: 'Updated Gemfile content',
config: {
...config,
binarySource: BINARY_SOURCE_GLOBAL,
},
})
).toMatchSnapshot();
expect(execSnapshots).toMatchSnapshot();
Expand All @@ -100,9 +122,14 @@ describe('bundler.updateArtifacts()', () => {
} as Git.StatusResult);
fs.readFile.mockResolvedValueOnce('Updated Gemfile.lock' as any);
expect(
await updateArtifacts('Gemfile', [], 'Updated Gemfile content', {
...config,
binarySource: BINARY_SOURCE_DOCKER,
await updateArtifacts({
packageFileName: 'Gemfile',
updatedDeps: [],
newPackageFileContent: 'Updated Gemfile content',
config: {
...config,
binarySource: BINARY_SOURCE_DOCKER,
},
})
).toMatchSnapshot();
expect(execSnapshots).toMatchSnapshot();
Expand All @@ -123,13 +150,18 @@ describe('bundler.updateArtifacts()', () => {
} as Git.StatusResult);
fs.readFile.mockResolvedValueOnce('Updated Gemfile.lock' as any);
expect(
await updateArtifacts('Gemfile', [], 'Updated Gemfile content', {
...config,
binarySource: BINARY_SOURCE_DOCKER,
dockerUser: 'foobar',
compatibility: {
ruby: '1.2.5',
bundler: '3.2.1',
await updateArtifacts({
packageFileName: 'Gemfile',
updatedDeps: [],
newPackageFileContent: 'Updated Gemfile content',
config: {
...config,
binarySource: BINARY_SOURCE_DOCKER,
dockerUser: 'foobar',
compatibility: {
ruby: '1.2.5',
bundler: '3.2.1',
},
},
})
).toMatchSnapshot();
Expand Down
Loading

0 comments on commit 982d5e9

Please sign in to comment.