Skip to content

Commit 542d412

Browse files
authored
fix(java-yoshi): throw MissingRequiredFile error if no versions.txt found (#1794)
* test: failing test for missing required file * fix: java-yoshi strategy should throw MissingRequiredFile error if no versions.txt found
1 parent 9baf736 commit 542d412

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

src/strategies/java-yoshi.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {VersionsManifest} from '../updaters/java/versions-manifest';
1717
import {Version, VersionsMap} from '../version';
1818
import {Changelog} from '../updaters/changelog';
1919
import {GitHubFileContents} from '@google-automations/git-file-utils';
20-
import {GitHubAPIError, MissingRequiredFileError} from '../errors';
20+
import {MissingRequiredFileError, FileNotFoundError} from '../errors';
2121
import {ConventionalCommit} from '../commit';
2222
import {Java, JavaBuildUpdatesOption} from './java';
2323
import {JavaUpdate} from '../updaters/java/java-update';
@@ -70,7 +70,7 @@ export class JavaYoshi extends Java {
7070
this.targetBranch
7171
);
7272
} catch (err) {
73-
if (err instanceof GitHubAPIError) {
73+
if (err instanceof FileNotFoundError) {
7474
throw new MissingRequiredFileError(
7575
this.addPath('versions.txt'),
7676
JavaYoshi.name,

test/strategies/java-yoshi.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {Changelog} from '../../src/updaters/changelog';
2929
import {JavaUpdate} from '../../src/updaters/java/java-update';
3030
import {VersionsManifest} from '../../src/updaters/java/versions-manifest';
3131
import {CompositeUpdater} from '../../src/updaters/composite';
32+
import {FileNotFoundError, MissingRequiredFileError} from '../../src/errors';
3233

3334
const sandbox = sinon.createSandbox();
3435
const fixturesPath = './test/fixtures/strategies/java-yoshi';
@@ -180,6 +181,34 @@ describe('JavaYoshi', () => {
180181
versionsMap.get('grpc-google-cloud-trace-v1beta1')?.toString()
181182
).to.eql('0.74.0');
182183
});
184+
it('throws on missing required versions.txt', async () => {
185+
const strategy = new JavaYoshi({
186+
targetBranch: 'main',
187+
github,
188+
component: 'google-cloud-automl',
189+
});
190+
sandbox.stub(github, 'findFilesByFilenameAndRef').resolves([]);
191+
const getFileContentsStub = sandbox.stub(
192+
github,
193+
'getFileContentsOnBranch'
194+
);
195+
getFileContentsStub
196+
.withArgs('versions.txt', 'main')
197+
.throws(new FileNotFoundError('versions.txt'));
198+
const latestRelease = {
199+
tag: new TagName(Version.parse('0.123.4'), 'google-cloud-automl'),
200+
sha: 'abc123',
201+
notes: 'some notes',
202+
};
203+
let failed = false;
204+
try {
205+
await strategy.buildReleasePullRequest(COMMITS, latestRelease);
206+
} catch (e) {
207+
expect(e).instanceof(MissingRequiredFileError);
208+
failed = true;
209+
}
210+
expect(failed).to.be.true;
211+
});
183212
});
184213
describe('buildUpdates', () => {
185214
it('builds common files', async () => {

0 commit comments

Comments
 (0)