Skip to content

Commit

Permalink
fix: making compatible linked-versions + includeComponentInTag=false …
Browse files Browse the repository at this point in the history
…\n\n Continues this: googleapis#1749
  • Loading branch information
nrodriguezmore committed Feb 1, 2024
1 parent 72b0ab3 commit 62d6262
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 34 deletions.
4 changes: 2 additions & 2 deletions __snapshots__/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ exports['Manifest buildPullRequests should handle mixing componentless configs 1
---
<details><summary>1.0.1</summary>
<details><summary>pkg1: 1.0.1</summary>
## [1.0.1](https://github.com/fake-owner/fake-repo/compare/v1.0.0...v1.0.1) (1983-10-10)
## [1.0.1](https://github.com/fake-owner/fake-repo/compare/pkg1-v1.0.0...v1.0.1) (1983-10-10)
### Bug Fixes
Expand Down
11 changes: 10 additions & 1 deletion src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ export class Manifest {
*/
async buildPullRequests(): Promise<ReleasePullRequest[]> {
this.logger.info('Building pull requests');
const pathsByComponent = await this.getPathsByComponent();
const pathsByComponent = await this.getPathsByComponent() || this.getComponentlessPackage();

Check failure on line 504 in src/manifest.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `·await·this.getPathsByComponent(` with `⏎······(await·this.getPathsByComponent()`
const strategiesByPath = await this.getStrategiesByPath();

// Collect all the SHAs of the latest release packages
Expand Down Expand Up @@ -797,6 +797,15 @@ export class Manifest {
);
}

private getComponentlessPackage(): string {
for (const path in this.repositoryConfig) {
if (!this.repositoryConfig[path].includeComponentInTag) {
return path;
}
}
return '';
}

private async backfillReleasesFromTags(
missingPaths: string[],
strategiesByPath: Record<string, Strategy>
Expand Down
3 changes: 0 additions & 3 deletions src/strategies/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,6 @@ export abstract class BaseStrategy implements Strategy {
* @returns {string}
*/
async getComponent(): Promise<string | undefined> {
if (!this.includeComponentInTag) {
return '';
}
return this.component || (await this.getDefaultComponent());
}

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/release-notes/grouped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---


<details><summary>1.0.1</summary>
<details><summary>base: 1.0.1</summary>

## [1.0.1](https://github.com/testOwner/testRepo/compare/v1.0.0...v1.0.1) (2022-07-16)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
:robot: I have created a release \*beep\* \*boop\*
---
<details><summary>3.2.0</summary>
<details><summary>@google-automation/bot-config-utils: 3.2.0</summary>


### Features
Expand Down
48 changes: 23 additions & 25 deletions test/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3152,6 +3152,12 @@ describe('Manifest', () => {
},
},
]);
mockTags(sandbox, github, [
{
name: 'pkg1-v1.0.0',
sha: 'abc123',
},
]);
const manifest = new Manifest(
github,
'main',
Expand Down Expand Up @@ -5228,47 +5234,39 @@ describe('Manifest', () => {
}
);
const releases = await manifest.buildReleases();
expect(releases).lengthOf(5);
// 3.3.0
expect(releases[0].tag.toString()).to.eql('v3.3.0');
expect(releases).lengthOf(4);
// @google-automations/bot-config-utils: 3.2.0
expect(releases[0].tag.toString()).to.eql('bot-config-utils-v3.2.0');
expect(releases[0].sha).to.eql('abc123');
expect(releases[0].notes)
.to.be.a('string')
.and.satisfy((msg: string) => msg.startsWith('### Features'));
expect(releases[0].path).to.eql('.');
expect(releases[0].name).to.eql('v3.3.0');
// @google-automations/bot-config-utils: 3.2.0
expect(releases[1].tag.toString()).to.eql('bot-config-utils-v3.2.0');
expect(releases[0].path).to.eql('packages/bot-config-utils');
expect(releases[0].name).to.eql('bot-config-utils: v3.2.0');
// @google-automations/label-utils: 1.1.0
expect(releases[1].tag.toString()).to.eql('label-utils-v1.1.0');
expect(releases[1].sha).to.eql('abc123');
expect(releases[1].notes)
.to.be.a('string')
.and.satisfy((msg: string) => msg.startsWith('### Features'));
expect(releases[1].path).to.eql('packages/bot-config-utils');
expect(releases[1].name).to.eql('bot-config-utils: v3.2.0');
// @google-automations/label-utils: 1.1.0
expect(releases[2].tag.toString()).to.eql('label-utils-v1.1.0');
expect(releases[1].path).to.eql('packages/label-utils');
expect(releases[1].name).to.eql('label-utils: v1.1.0');
// @google-automations/object-selector: 1.1.0
expect(releases[2].tag.toString()).to.eql('object-selector-v1.1.0');
expect(releases[2].sha).to.eql('abc123');
expect(releases[2].notes)
.to.be.a('string')
.and.satisfy((msg: string) => msg.startsWith('### Features'));
expect(releases[2].path).to.eql('packages/label-utils');
expect(releases[2].name).to.eql('label-utils: v1.1.0');
// @google-automations/object-selector: 1.1.0
expect(releases[3].tag.toString()).to.eql('object-selector-v1.1.0');
expect(releases[2].path).to.eql('packages/object-selector');
expect(releases[2].name).to.eql('object-selector: v1.1.0');
// @google-automations/datastore-lock: 2.1.0
expect(releases[3].tag.toString()).to.eql('datastore-lock-v2.1.0');
expect(releases[3].sha).to.eql('abc123');
expect(releases[3].notes)
.to.be.a('string')
.and.satisfy((msg: string) => msg.startsWith('### Features'));
expect(releases[3].path).to.eql('packages/object-selector');
expect(releases[3].name).to.eql('object-selector: v1.1.0');
// @google-automations/datastore-lock: 2.1.0
expect(releases[4].tag.toString()).to.eql('datastore-lock-v2.1.0');
expect(releases[4].sha).to.eql('abc123');
expect(releases[4].notes)
.to.be.a('string')
.and.satisfy((msg: string) => msg.startsWith('### Features'));
expect(releases[4].path).to.eql('packages/datastore-lock');
expect(releases[4].name).to.eql('datastore-lock: v2.1.0');
expect(releases[3].path).to.eql('packages/datastore-lock');
expect(releases[3].name).to.eql('datastore-lock: v2.1.0');
});

it('should skip component releases for non-component configs', async () => {
Expand Down
4 changes: 3 additions & 1 deletion test/util/pull-request-body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ describe('PullRequestBody', () => {
expect(pullRequestBody).to.not.be.undefined;
const releaseData = pullRequestBody!.releaseData;
expect(releaseData).lengthOf(2);
expect(releaseData[0].component).to.be.undefined;
expect(releaseData[0].component).to.eq(
'@google-automation/bot-config-utils'
);
expect(releaseData[0].version?.toString()).to.eql('3.2.0');
expect(releaseData[0].notes).matches(/^### Features/);
expect(releaseData[1].component).to.eql(
Expand Down

0 comments on commit 62d6262

Please sign in to comment.