Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use package name to build aggregate if present #2219

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions __snapshots__/merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,25 @@ exports['Merge plugin run merges multiple pull requests into an aggregate 1'] =
---


<details><summary>python-pkg: 1.0.0</summary>

Release notes for path: python, releaseType: python
</details>

<details><summary>@here/pkgA: 3.3.4</summary>

Release notes for path: node, releaseType: node
</details>

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
`

exports['Merge plugin run merges multiple pull requests into an aggregate and uses packageName as default for branch name if present 1'] = `
:robot: I have created a release *beep* *boop*
---


<details><summary>python-pkg: 1.0.0</summary>

Release notes for path: python, releaseType: python
Expand Down
3 changes: 3 additions & 0 deletions src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,9 @@ export class Manifest {
) {
mergeOptions.pullRequestFooter = config.pullRequestFooter;
}
if ('packageName' in config) {
mergeOptions.packageName = config.packageName;
}
}
this.plugins.push(
new Merge(
Expand Down
12 changes: 9 additions & 3 deletions src/plugins/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {mergeUpdates} from '../updaters/composite';
import {GitHub} from '../github';

export interface MergeOptions {
packageName?: string;
pullRequestTitlePattern?: string;
pullRequestHeader?: string;
pullRequestFooter?: string;
Expand All @@ -46,6 +47,7 @@ export class Merge extends ManifestPlugin {
private pullRequestFooter?: string;
private headBranchName?: string;
private forceMerge: boolean;
private packageName: string;

constructor(
github: GitHub,
Expand All @@ -60,6 +62,7 @@ export class Merge extends ManifestPlugin {
this.pullRequestFooter = options.pullRequestFooter;
this.headBranchName = options.headBranchName;
this.forceMerge = options.forceMerge ?? false;
this.packageName = options.packageName ?? '';
}

async run(
Expand All @@ -83,7 +86,6 @@ export class Merge extends ManifestPlugin {
},
[[], []]
);

const releaseData: ReleaseData[] = [];
const labels = new Set<string>();
let rawUpdates: Update[] = [];
Expand All @@ -100,7 +102,6 @@ export class Merge extends ManifestPlugin {
}
}
const updates = mergeUpdates(rawUpdates);

const pullRequest = {
title: PullRequestTitle.ofComponentTargetBranchVersion(
rootRelease?.pullRequest.title.component,
Expand All @@ -117,7 +118,12 @@ export class Merge extends ManifestPlugin {
labels: Array.from(labels),
headRefName:
this.headBranchName ??
BranchName.ofTargetBranch(this.targetBranch).toString(),
(this.packageName
? BranchName.ofComponentTargetBranch(
this.packageName,
this.targetBranch
).toString()
: BranchName.ofTargetBranch(this.targetBranch).toString()),
draft: !candidates.some(candidate => !candidate.pullRequest.draft),
};

Expand Down
47 changes: 47 additions & 0 deletions test/plugins/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,53 @@ describe('Merge plugin', () => {
assertHasUpdate(updates, 'path1/foo', CompositeUpdater);
assertHasUpdate(updates, 'path2/foo', RawContent);
snapshot(dateSafe(candidate!.pullRequest.body.toString()));
expect(
newCandidates[0].pullRequest.headRefName ===
'release-please--branches--main'
);
});

it('merges multiple pull requests into an aggregate and uses packageName as default for branch name if present', async () => {
const candidates: CandidateReleasePullRequest[] = [
buildMockCandidatePullRequest('python', 'python', '1.0.0', {
component: 'python-pkg',
updates: [
{
path: 'path1/foo',
createIfMissing: false,
updater: new RawContent('foo'),
},
],
}),
buildMockCandidatePullRequest('node', 'node', '3.3.4', {
component: '@here/pkgA',
updates: [
{
path: 'path1/foo',
createIfMissing: false,
updater: new RawContent('bar'),
},
{
path: 'path2/foo',
createIfMissing: false,
updater: new RawContent('asdf'),
},
],
}),
];
const plugin = new Merge(github, 'main', {}, {packageName: '@here/pkgA'});
const newCandidates = await plugin.run(candidates);
expect(newCandidates).lengthOf(1);
const candidate = newCandidates[0];
const updates = candidate!.pullRequest.updates;
expect(updates).lengthOf(2);
assertHasUpdate(updates, 'path1/foo', CompositeUpdater);
assertHasUpdate(updates, 'path2/foo', RawContent);
snapshot(dateSafe(candidate!.pullRequest.body.toString()));
expect(
newCandidates[0].pullRequest.headRefName ===
'release-please--branches--main--components--@here/pkgA'
);
});

it('merges multiple pull requests as a draft', async () => {
Expand Down
Loading