Skip to content

Commit

Permalink
fix: merge manifest release PRs unless separatePullRequests is config…
Browse files Browse the repository at this point in the history
…ured (#1129)

* fix: merge manifest release PRs unless separatePullRequests is configured or there is only a single package

* fix formatting

* test: fix assertion - combined PR should not have a version attached

* chore: fix lint

Co-authored-by: Benjamin E. Coe <bencoe@google.com>
  • Loading branch information
chingor13 and bcoe committed Dec 1, 2021
1 parent 25f6811 commit 328009d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
9 changes: 7 additions & 2 deletions src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,9 @@ export class Manifest {
this.releasedVersions = releasedVersions;
this.manifestPath =
manifestOptions?.manifestPath || DEFAULT_RELEASE_PLEASE_MANIFEST;
this.separatePullRequests = manifestOptions?.separatePullRequests || false;
this.separatePullRequests =
manifestOptions?.separatePullRequests ??
Object.keys(repositoryConfig).length === 1;
this.plugins = manifestOptions?.plugins || [];
this.fork = manifestOptions?.fork || false;
this.signoffUser = manifestOptions?.signoff;
Expand Down Expand Up @@ -316,7 +318,10 @@ export class Manifest {
targetBranch,
repositoryConfig,
releasedVersions,
manifestOptions
{
separatePullRequests: true,
...manifestOptions,
}
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class Merge extends ManifestPlugin {
async run(
candidates: CandidateReleasePullRequest[]
): Promise<CandidateReleasePullRequest[]> {
if (candidates.length < 2) {
if (candidates.length < 1) {
return candidates;
}

Expand Down
1 change: 1 addition & 0 deletions src/util/pull-request-title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export class PullRequestTitle {
.replace('${scope}', scope)
.replace('${component}', component)
.replace('${version}', version.toString())
.replace('${branch}', this.targetBranch || '')
.trim();
}
}
6 changes: 5 additions & 1 deletion test/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,11 @@ describe('Manifest', () => {
const manifest = await Manifest.fromManifest(github, 'main');
const pullRequests = await manifest.buildPullRequests();
expect(pullRequests).lengthOf(1);
expect(pullRequests[0].version?.toString()).to.eql('1.2.4');
expect(pullRequests[0].body.releaseData).lengthOf(1);
expect(pullRequests[0].body.releaseData[0].component).to.eql('pkg1');
expect(pullRequests[0].body.releaseData[0].version?.toString()).to.eql(
'1.2.4'
);
});

describe('with plugins', () => {
Expand Down
7 changes: 5 additions & 2 deletions test/plugins/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,16 @@ describe('Merge plugin', () => {
expect(newCandidates).lengthOf(0);
});

it('ignores a single pull request', async () => {
it('merges a single pull request', async () => {
const candidates: CandidateReleasePullRequest[] = [
buildMockCandidatePullRequest('python', 'python', '1.0.0'),
];
const plugin = new Merge(github, 'main', {});
const newCandidates = await plugin.run(candidates);
expect(newCandidates).to.eql(candidates);
expect(newCandidates).lengthOf(1);
expect(newCandidates[0].pullRequest.title.toString()).to.eql(
'chore: release main'
);
});

it('merges multiple pull requests into an aggregate', async () => {
Expand Down

0 comments on commit 328009d

Please sign in to comment.