Skip to content

Commit

Permalink
feat: Support custom artifact notice (#28957)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
Co-authored-by: Rhys Arkins <rhys@arkins.net>
  • Loading branch information
3 people committed May 16, 2024
1 parent 66de046 commit 1c8eb34
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 19 deletions.
7 changes: 7 additions & 0 deletions lib/modules/manager/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ export interface Upgrade<T = Record<string, any>> extends PackageDependency<T> {
replaceString?: string;
}

export interface ArtifactNotice {
file: string;
message: string;
}

export interface ArtifactError {
lockFile?: string;
stderr?: string;
Expand All @@ -190,10 +195,12 @@ export interface ArtifactError {
export type UpdateArtifactsResult =
| {
file?: FileChange;
notice?: ArtifactNotice;
artifactError?: undefined;
}
| {
file?: undefined;
notice?: undefined;
artifactError?: ArtifactError;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() bumps versions in autoReplace managers 1`] = `
{
"artifactErrors": [],
"artifactNotices": [],
"reuseExistingBranch": undefined,
"updatedArtifacts": [],
"updatedPackageFiles": [
Expand All @@ -18,6 +19,7 @@ exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() b
exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() bumps versions in updateDependency managers 1`] = `
{
"artifactErrors": [],
"artifactNotices": [],
"reuseExistingBranch": undefined,
"updatedArtifacts": [],
"updatedPackageFiles": [
Expand All @@ -33,6 +35,7 @@ exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() b
exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() handles autoreplace base updated 1`] = `
{
"artifactErrors": [],
"artifactNotices": [],
"reuseExistingBranch": undefined,
"updatedArtifacts": [],
"updatedPackageFiles": [
Expand All @@ -48,6 +51,7 @@ exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() h
exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() handles autoreplace branch needs update 1`] = `
{
"artifactErrors": [],
"artifactNotices": [],
"reuseExistingBranch": false,
"updatedArtifacts": [],
"updatedPackageFiles": [
Expand All @@ -63,6 +67,7 @@ exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() h
exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() handles content change 1`] = `
{
"artifactErrors": [],
"artifactNotices": [],
"reuseExistingBranch": false,
"updatedArtifacts": [],
"updatedPackageFiles": [
Expand All @@ -78,6 +83,7 @@ exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() h
exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() handles git submodules 1`] = `
{
"artifactErrors": [],
"artifactNotices": [],
"reuseExistingBranch": undefined,
"updatedArtifacts": [],
"updatedPackageFiles": [
Expand All @@ -93,6 +99,7 @@ exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() h
exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() handles isRemediation rebase 1`] = `
{
"artifactErrors": [],
"artifactNotices": [],
"reuseExistingBranch": false,
"updatedArtifacts": [],
"updatedPackageFiles": [
Expand All @@ -108,6 +115,7 @@ exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() h
exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() handles isRemediation success 1`] = `
{
"artifactErrors": [],
"artifactNotices": [],
"reuseExistingBranch": undefined,
"updatedArtifacts": [],
"updatedPackageFiles": [
Expand All @@ -128,6 +136,7 @@ exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() h
"stderr": "some error",
},
],
"artifactNotices": [],
"reuseExistingBranch": true,
"updatedArtifacts": [],
"updatedPackageFiles": [
Expand All @@ -143,6 +152,7 @@ exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() h
exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() handles lock files 1`] = `
{
"artifactErrors": [],
"artifactNotices": [],
"reuseExistingBranch": true,
"updatedArtifacts": [
{
Expand All @@ -164,6 +174,7 @@ exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() h
exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() handles lockFileMaintenance 1`] = `
{
"artifactErrors": [],
"artifactNotices": [],
"reuseExistingBranch": undefined,
"updatedArtifacts": [
{
Expand All @@ -184,6 +195,7 @@ exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() h
"stderr": "some error",
},
],
"artifactNotices": [],
"reuseExistingBranch": undefined,
"updatedArtifacts": [],
"updatedPackageFiles": [],
Expand All @@ -193,6 +205,7 @@ exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() h
exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() update artifacts on update-lockfile strategy 1`] = `
{
"artifactErrors": [],
"artifactNotices": [],
"reuseExistingBranch": undefined,
"updatedArtifacts": [
{
Expand All @@ -214,6 +227,7 @@ exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() u
exports[`workers/repository/update/branch/get-updated getUpdatedPackageFiles() update artifacts on update-lockfile strategy with no updateLockedDependency 1`] = `
{
"artifactErrors": [],
"artifactNotices": [],
"reuseExistingBranch": undefined,
"updatedArtifacts": [
{
Expand Down
58 changes: 58 additions & 0 deletions lib/workers/repository/update/branch/get-updated.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { mockDeep } from 'jest-mock-extended';
import { git, mocked } from '../../../../../test/util';
import { GitRefsDatasource } from '../../../../modules/datasource/git-refs';
import * as _batectWrapper from '../../../../modules/manager/batect-wrapper';
import * as _bundler from '../../../../modules/manager/bundler';
import * as _composer from '../../../../modules/manager/composer';
import * as _gitSubmodules from '../../../../modules/manager/git-submodules';
import * as _gomod from '../../../../modules/manager/gomod';
import * as _helmv3 from '../../../../modules/manager/helmv3';
import * as _npm from '../../../../modules/manager/npm';
import * as _pep621 from '../../../../modules/manager/pep621';
Expand All @@ -16,6 +18,7 @@ import { getUpdatedPackageFiles } from './get-updated';
const bundler = mocked(_bundler);
const composer = mocked(_composer);
const gitSubmodules = mocked(_gitSubmodules);
const gomod = mocked(_gomod);
const helmv3 = mocked(_helmv3);
const npm = mocked(_npm);
const batectWrapper = mocked(_batectWrapper);
Expand All @@ -28,6 +31,7 @@ jest.mock('../../../../modules/manager/composer');
jest.mock('../../../../modules/manager/helmv3');
jest.mock('../../../../modules/manager/npm');
jest.mock('../../../../modules/manager/git-submodules');
jest.mock('../../../../modules/manager/gomod', () => mockDeep());
jest.mock('../../../../modules/manager/batect-wrapper');
jest.mock('../../../../modules/manager/pep621');
jest.mock('../../../../modules/manager/poetry');
Expand Down Expand Up @@ -77,6 +81,7 @@ describe('workers/repository/update/branch/get-updated', () => {
reuseExistingBranch: undefined,
updatedArtifacts: [],
updatedPackageFiles: [],
artifactNotices: [],
});
});

Expand Down Expand Up @@ -110,6 +115,7 @@ describe('workers/repository/update/branch/get-updated', () => {
reuseExistingBranch: undefined,
updatedArtifacts: [],
updatedPackageFiles: [],
artifactNotices: [],
});
});

Expand Down Expand Up @@ -178,6 +184,54 @@ describe('workers/repository/update/branch/get-updated', () => {
});
});

it('handles artifact notices', async () => {
config.reuseExistingBranch = true;
config.upgrades.push({
packageFile: 'go.mod',
manager: 'gomod',
branchName: 'foo/bar',
});
gomod.updateDependency.mockReturnValue('some new content');
gomod.updateArtifacts.mockResolvedValueOnce([
{
file: {
type: 'addition',
path: 'go.mod',
contents: 'some content',
},
notice: {
file: 'go.mod',
message: 'some notice',
},
},
]);
const res = await getUpdatedPackageFiles(config);
expect(res).toEqual({
artifactErrors: [],
artifactNotices: [
{
file: 'go.mod',
message: 'some notice',
},
],
reuseExistingBranch: false,
updatedArtifacts: [
{
contents: 'some content',
path: 'go.mod',
type: 'addition',
},
],
updatedPackageFiles: [
{
contents: 'some new content',
path: 'go.mod',
type: 'addition',
},
],
});
});

it('handles lockFileMaintenance', async () => {
config.upgrades.push({
manager: 'composer',
Expand Down Expand Up @@ -353,6 +407,7 @@ describe('workers/repository/update/branch/get-updated', () => {
expect(res).toMatchInlineSnapshot(`
{
"artifactErrors": [],
"artifactNotices": [],
"reuseExistingBranch": undefined,
"updatedArtifacts": [],
"updatedPackageFiles": [],
Expand Down Expand Up @@ -533,6 +588,7 @@ describe('workers/repository/update/branch/get-updated', () => {
expect(res).toMatchInlineSnapshot(`
{
"artifactErrors": [],
"artifactNotices": [],
"reuseExistingBranch": undefined,
"updatedArtifacts": [],
"updatedPackageFiles": [],
Expand All @@ -556,6 +612,7 @@ describe('workers/repository/update/branch/get-updated', () => {
expect(res).toMatchInlineSnapshot(`
{
"artifactErrors": [],
"artifactNotices": [],
"reuseExistingBranch": false,
"updatedArtifacts": [],
"updatedPackageFiles": [],
Expand All @@ -581,6 +638,7 @@ describe('workers/repository/update/branch/get-updated', () => {
expect(res).toMatchInlineSnapshot(`
{
"artifactErrors": [],
"artifactNotices": [],
"reuseExistingBranch": false,
"updatedArtifacts": [],
"updatedPackageFiles": [],
Expand Down
31 changes: 26 additions & 5 deletions lib/workers/repository/update/branch/get-updated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { logger } from '../../../../logger';
import { get } from '../../../../modules/manager';
import type {
ArtifactError,
ArtifactNotice,
PackageDependency,
PackageFile,
UpdateArtifact,
Expand All @@ -21,6 +22,7 @@ export interface PackageFilesResult {
reuseExistingBranch?: boolean;
updatedPackageFiles: FileChange[];
updatedArtifacts: FileChange[];
artifactNotices: ArtifactNotice[];
}

async function getFileContent(
Expand Down Expand Up @@ -288,6 +290,7 @@ export async function getUpdatedPackageFiles(
}));
const updatedArtifacts: FileChange[] = [];
const artifactErrors: ArtifactError[] = [];
const artifactNotices: ArtifactNotice[] = [];
// istanbul ignore if
if (is.nonEmptyArray(updatedPackageFiles)) {
logger.debug('updateArtifacts for updatedPackageFiles');
Expand All @@ -308,7 +311,12 @@ export async function getUpdatedPackageFiles(
packageFile.path,
),
});
processUpdateArtifactResults(results, updatedArtifacts, artifactErrors);
processUpdateArtifactResults(
results,
updatedArtifacts,
artifactErrors,
artifactNotices,
);
}
}
}
Expand Down Expand Up @@ -339,7 +347,12 @@ export async function getUpdatedPackageFiles(
packageFile.path,
),
});
processUpdateArtifactResults(results, updatedArtifacts, artifactErrors);
processUpdateArtifactResults(
results,
updatedArtifacts,
artifactErrors,
artifactNotices,
);
if (is.nonEmptyArray(results)) {
updatedPackageFiles.push(packageFile);
}
Expand Down Expand Up @@ -373,6 +386,7 @@ export async function getUpdatedPackageFiles(
results,
updatedArtifacts,
artifactErrors,
artifactNotices,
);
}
}
Expand All @@ -383,6 +397,7 @@ export async function getUpdatedPackageFiles(
updatedPackageFiles,
updatedArtifacts,
artifactErrors,
artifactNotices,
};
}

Expand Down Expand Up @@ -425,16 +440,22 @@ function processUpdateArtifactResults(
results: UpdateArtifactsResult[] | null,
updatedArtifacts: FileChange[],
artifactErrors: ArtifactError[],
artifactNotices: ArtifactNotice[],
): void {
if (is.nonEmptyArray(results)) {
for (const res of results) {
const { file, artifactError } = res;
// istanbul ignore else
const { file, notice, artifactError } = res;
if (file) {
updatedArtifacts.push(file);
} else if (artifactError) {
}

if (artifactError) {
artifactErrors.push(artifactError);
}

if (notice) {
artifactNotices.push(notice);
}
}
}
}

0 comments on commit 1c8eb34

Please sign in to comment.