Skip to content

Commit

Permalink
Use supplied correlator without concatenation
Browse files Browse the repository at this point in the history
  • Loading branch information
david-wiggs committed Jul 23, 2024
1 parent 2ba839e commit 7592e88
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 22 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ This action writes informations in the repository dependency graph, so if you ar

* `snapshot-dependency-file-name`: An optional user control file path to the POM file, requires `snapshot-include-file-name` to be `true` for the value to be submitted.

* `correlator`: An optional identifier to distinguish between multiple dependency snapshots of the same type. Defaults to the [job_id](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_id) of the current job.

## Examples

Expand Down
1 change: 1 addition & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ inputs:
description: An optional identifier to distinguish between multiple dependency snapshots of the same type
type: string
required: false
default: ''

runs:
using: node20
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ function generateSnapshot(directory, mvnConfig, snapshotConfig) {
const snapshot = new dependency_submission_toolkit_1.Snapshot(detector, snapshotConfig === null || snapshotConfig === void 0 ? void 0 : snapshotConfig.context, snapshotConfig === null || snapshotConfig === void 0 ? void 0 : snapshotConfig.job);
snapshot.addManifest(manifest);
snapshot.job.correlator = (snapshotConfig === null || snapshotConfig === void 0 ? void 0 : snapshotConfig.correlator)
? `${snapshot.job.correlator}-${snapshotConfig.correlator}`
? snapshotConfig.correlator
: (_b = snapshot.job) === null || _b === void 0 ? void 0 : _b.correlator;
const specifiedRef = getNonEmtptyValue(snapshotConfig === null || snapshotConfig === void 0 ? void 0 : snapshotConfig.ref);
if (specifiedRef) {
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

24 changes: 5 additions & 19 deletions src/snapshot-generator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,39 +69,25 @@ describe('snapshot-generator', () => {
expect(snapshot.manifests['problem-dependency-graph-2602'].countDependencies()).toBe(230);
}, 40000);

it('should append correlator from snapshotConfig if it exists', async() => {
it('should use correlator from snapshotConfig if it exists', async() => {
const projectDir = getMavenProjectDirectory('simple');
const mavenSettingsFile = getMavenSettingsFile();
const mavenConfig = {
ignoreMavenWrapper: true,
settingsFile: mavenSettingsFile,
mavenArgs: '-DskipTests'
};
const snapshotConfig = {
correlator: 'configCorrelator',
job: {
correlator: 'jobCorrelator'
}
};
const snapshot = await generateSnapshot(projectDir, mavenConfig, snapshotConfig);
const snapshot = await generateSnapshot(projectDir, undefined, snapshotConfig);

expect(snapshot.job.correlator).toBe('jobCorrelator-configCorrelator');
expect(snapshot.job.correlator).toBe('configCorrelator');
}, 20000);

it('should use existing job correlator if snapshotConfig correlator does not exist', async() => {
it('should use a default job correlator when not specified', async() => {
const projectDir = getMavenProjectDirectory('simple');
const mavenSettingsFile = getMavenSettingsFile();
const mavenConfig = {
ignoreMavenWrapper: true,
settingsFile: mavenSettingsFile,
mavenArgs: '-DskipTests'
};
const snapshotConfig = {
job: {
correlator: 'jobCorrelator'
}
};
const snapshot = await generateSnapshot(projectDir, mavenConfig, snapshotConfig);
const snapshot = await generateSnapshot(projectDir, undefined, snapshotConfig);

expect(snapshot.job.correlator).toBe('jobCorrelator');
}, 20000);
Expand Down
2 changes: 1 addition & 1 deletion src/snapshot-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export async function generateSnapshot(directory: string, mvnConfig?: MavenConfi
snapshot.addManifest(manifest);

snapshot.job.correlator = snapshotConfig?.correlator
? `${snapshot.job.correlator}-${snapshotConfig.correlator}`
? snapshotConfig.correlator
: snapshot.job?.correlator;

const specifiedRef = getNonEmtptyValue(snapshotConfig?.ref);
Expand Down

0 comments on commit 7592e88

Please sign in to comment.