Skip to content

Commit

Permalink
fix(dart): throw MissingRequiredFileError if pubspec.yaml is missing (#…
Browse files Browse the repository at this point in the history
…1756)

fix(helm): throw MissingRequiredFileError if Chart.yaml is missing
  • Loading branch information
chingor13 committed Nov 22, 2022
1 parent d790796 commit ada9fd6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
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

0 comments on commit ada9fd6

Please sign in to comment.