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(dart): throw MissingRequiredFileError if pubspec.yaml is missing #1756

Merged
merged 1 commit into from Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/strategies/dart.ts
Expand Up @@ -21,6 +21,7 @@ import {PubspecYaml} from '../updaters/dart/pubspec-yaml';
import {BaseStrategy, BuildUpdatesOptions} from './base';
import {GitHubFileContents} from '@google-automations/git-file-utils';
import {Update} from '../update';
import {FileNotFoundError, MissingRequiredFileError} from '../errors';

export class Dart extends BaseStrategy {
private pubspecYmlContents?: GitHubFileContents;
Expand Down Expand Up @@ -64,10 +65,21 @@ export class Dart extends BaseStrategy {

private async getPubspecYmlContents(): Promise<GitHubFileContents> {
if (!this.pubspecYmlContents) {
this.pubspecYmlContents = await this.github.getFileContentsOnBranch(
this.addPath('pubspec.yaml'),
this.targetBranch
);
try {
this.pubspecYmlContents = await this.github.getFileContentsOnBranch(
this.addPath('pubspec.yaml'),
this.targetBranch
);
} catch (e) {
if (e instanceof FileNotFoundError) {
throw new MissingRequiredFileError(
this.addPath('pubspec.yaml'),
Dart.name,
`${this.repository.owner}/${this.repository.repo}`
);
}
throw e;
}
}
return this.pubspecYmlContents;
}
Expand Down
18 changes: 15 additions & 3 deletions src/strategies/helm.ts
Expand Up @@ -21,6 +21,7 @@ import * as yaml from 'js-yaml';
import {ChartYaml} from '../updaters/helm/chart-yaml';
import {BaseStrategy, BuildUpdatesOptions} from './base';
import {Update} from '../update';
import {FileNotFoundError, MissingRequiredFileError} from '../errors';

export class Helm extends BaseStrategy {
private chartYmlContents?: GitHubFileContents;
Expand Down Expand Up @@ -63,9 +64,20 @@ export class Helm extends BaseStrategy {

private async getChartYmlContents(): Promise<GitHubFileContents> {
if (!this.chartYmlContents) {
this.chartYmlContents = await this.github.getFileContents(
this.addPath('Chart.yaml')
);
try {
this.chartYmlContents = await this.github.getFileContents(
this.addPath('Chart.yaml')
);
} catch (e) {
if (e instanceof FileNotFoundError) {
throw new MissingRequiredFileError(
this.addPath('Chart.yaml'),
Helm.name,
`${this.repository.owner}/${this.repository.repo}`
);
}
throw e;
}
}
return this.chartYmlContents;
}
Expand Down