Skip to content

Commit 64c267e

Browse files
authored
fix: convert ReleaserConfig JSON keys when bootstrapping (#1535)
We were directly writing the ReleaserConfig to the `release-please-config.json`, but the keys are actually dasherized. Fixes #1522
1 parent 65232e1 commit 64c267e

4 files changed

Lines changed: 65 additions & 10 deletions

File tree

__snapshots__/bootstrapper.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
exports['Bootstrapper should open a PR 1'] = `
2+
{
3+
"packages": {
4+
".": {
5+
"release-type": "node"
6+
}
7+
}
8+
}
9+
`

src/manifest.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ export interface ReleaserConfig {
9191
pullRequestTitlePattern?: string;
9292
tagSeparator?: string;
9393
separatePullRequests?: boolean;
94+
labels?: string[];
95+
releaseLabels?: string[];
9496

9597
// Changelog options
9698
changelogSections?: ChangelogSection[];
@@ -137,7 +139,7 @@ interface ReleaserConfigJson {
137139
'pull-request-title-pattern'?: string;
138140
'separate-pull-requests'?: boolean;
139141
'tag-separator'?: string;
140-
'extra-files'?: string[];
142+
'extra-files'?: ExtraFile[];
141143
'version-file'?: string;
142144
'snapshot-label'?: string; // Java-only
143145
}
@@ -164,7 +166,7 @@ export interface ManifestOptions {
164166
commitSearchDepth?: number;
165167
}
166168

167-
interface ReleaserPackageConfig extends ReleaserConfigJson {
169+
export interface ReleaserPackageConfig extends ReleaserConfigJson {
168170
'package-name'?: string;
169171
component?: string;
170172
'changelog-path'?: string;
@@ -1169,6 +1171,8 @@ function extractReleaserConfig(
11691171
pullRequestTitlePattern: config['pull-request-title-pattern'],
11701172
tagSeparator: config['tag-separator'],
11711173
separatePullRequests: config['separate-pull-requests'],
1174+
labels: config['label']?.split(','),
1175+
releaseLabels: config['release-label']?.split(','),
11721176
};
11731177
}
11741178

@@ -1212,11 +1216,9 @@ async function parseConfig(
12121216
separatePullRequests: config['separate-pull-requests'],
12131217
groupPullRequestTitlePattern: config['group-pull-request-title-pattern'],
12141218
plugins: config['plugins'],
1215-
labels: configLabel === undefined ? undefined : [configLabel],
1216-
releaseLabels:
1217-
configReleaseLabel === undefined ? undefined : [configReleaseLabel],
1218-
snapshotLabels:
1219-
configSnapshotLabel === undefined ? undefined : [configSnapshotLabel],
1219+
labels: configLabel?.split(','),
1220+
releaseLabels: configReleaseLabel?.split(','),
1221+
snapshotLabels: configSnapshotLabel?.split(','),
12201222
releaseSearchDepth: config['release-search-depth'],
12211223
commitSearchDepth: config['commit-search-depth'],
12221224
sequentialCalls: config['sequential-calls'],

src/updaters/release-please-config.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414

1515
import {jsonStringify} from '../util/json-stringify';
1616
import {Updater} from '../update';
17-
import {ReleaserConfig, ManifestConfig} from '../manifest';
17+
import {
18+
ReleaserConfig,
19+
ManifestConfig,
20+
ReleaserPackageConfig,
21+
} from '../manifest';
1822

1923
export class ReleasePleaseConfig implements Updater {
2024
path: string;
@@ -30,11 +34,43 @@ export class ReleasePleaseConfig implements Updater {
3034
} else {
3135
parsed = {packages: {}};
3236
}
33-
parsed.packages[this.path] = this.config;
37+
parsed.packages[this.path] = releaserConfigToJsonConfig(this.config);
3438
if (content) {
3539
return jsonStringify(parsed, content);
3640
} else {
3741
return JSON.stringify(parsed, null, 2);
3842
}
3943
}
4044
}
45+
46+
function releaserConfigToJsonConfig(
47+
config: ReleaserConfig
48+
): ReleaserPackageConfig {
49+
const jsonConfig: ReleaserPackageConfig = {
50+
'package-name': config.packageName,
51+
component: config.component,
52+
'changelog-path': config.changelogPath,
53+
'release-type': config.releaseType,
54+
'bump-minor-pre-major': config.bumpMinorPreMajor,
55+
'bump-patch-for-minor-pre-major': config.bumpPatchForMinorPreMajor,
56+
'changelog-sections': config.changelogSections,
57+
'release-as': config.releaseAs,
58+
'skip-github-release': config.skipGithubRelease,
59+
draft: config.draft,
60+
prerelease: config.prerelease,
61+
'draft-pull-request': config.draftPullRequest,
62+
label: config.labels?.join(','),
63+
'release-label': config.releaseLabels?.join(','),
64+
'include-component-in-tag': config.includeComponentInTag,
65+
'include-v-in-tag': config.includeVInTag,
66+
'changelog-type': config.changelogType,
67+
'changelog-host': config.changelogHost,
68+
'pull-request-title-pattern': config.pullRequestTitlePattern,
69+
'separate-pull-requests': config.separatePullRequests,
70+
'tag-separator': config.tagSeparator,
71+
'extra-files': config.extraFiles,
72+
'version-file': config.versionFile,
73+
'snapshot-label': config.snapshotLabels?.join(','), // Java-only
74+
};
75+
return jsonConfig;
76+
}

test/bootstrapper.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {GitHub} from '../src/github';
2020
import {assertHasUpdate} from './helpers';
2121
import {ReleasePleaseManifest} from '../src/updaters/release-please-manifest';
2222
import {ReleasePleaseConfig} from '../src/updaters/release-please-config';
23+
import * as snapshot from 'snap-shot-it';
2324

2425
const sandbox = sinon.createSandbox();
2526

@@ -73,6 +74,13 @@ describe('Bootstrapper', () => {
7374
'.release-please-manifest.json',
7475
ReleasePleaseManifest
7576
);
76-
assertHasUpdate(updates, 'release-please-config.json', ReleasePleaseConfig);
77+
const update = assertHasUpdate(
78+
updates,
79+
'release-please-config.json',
80+
ReleasePleaseConfig
81+
);
82+
expect(update.createIfMissing).to.be.true;
83+
const newContent = update.updater.updateContent(undefined);
84+
snapshot(newContent);
7785
});
7886
});

0 commit comments

Comments
 (0)