Skip to content

Commit

Permalink
fix: search for files on target branch, not default branch (googleapi…
Browse files Browse the repository at this point in the history
  • Loading branch information
chingor13 committed Jan 18, 2022
1 parent 597e6dd commit d891f00
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 36 deletions.
9 changes: 6 additions & 3 deletions src/strategies/java-yoshi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,19 @@ export class JavaYoshi extends BaseStrategy {
}),
});

const pomFilesSearch = this.github.findFilesByFilename(
const pomFilesSearch = this.github.findFilesByFilenameAndRef(
'pom.xml',
this.targetBranch,
this.path
);
const buildFilesSearch = this.github.findFilesByFilename(
const buildFilesSearch = this.github.findFilesByFilenameAndRef(
'build.gradle',
this.targetBranch,
this.path
);
const dependenciesSearch = this.github.findFilesByFilename(
const dependenciesSearch = this.github.findFilesByFilenameAndRef(
'dependencies.properties',
this.targetBranch,
this.path
);

Expand Down
3 changes: 2 additions & 1 deletion src/strategies/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ export class Python extends BaseStrategy {
}

// There should be only one version.py, but foreach in case that is incorrect
const versionPyFilesSearch = this.github.findFilesByFilename(
const versionPyFilesSearch = this.github.findFilesByFilenameAndRef(
'version.py',
this.targetBranch,
this.path
);
const versionPyFiles = await versionPyFilesSearch;
Expand Down
15 changes: 12 additions & 3 deletions src/strategies/terraform-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ export class TerraformModule extends BaseStrategy {

// Update version in README to current candidate version.
// A module may have submodules, so find all submodules.
const readmeFiles = await this.github.findFilesByFilename(
const readmeFiles = await this.github.findFilesByFilenameAndRef(
'readme.md',
this.targetBranch,
this.path
);
readmeFiles.forEach(path => {
Expand All @@ -56,8 +57,16 @@ export class TerraformModule extends BaseStrategy {
// Update versions.tf to current candidate version.
// A module may have submodules, so find all versions.tfand versions.tf.tmpl to update.
const versionFiles = await Promise.all([
this.github.findFilesByFilename('versions.tf', this.path),
this.github.findFilesByFilename('versions.tf.tmpl', this.path),
this.github.findFilesByFilenameAndRef(
'versions.tf',
this.targetBranch,
this.path
),
this.github.findFilesByFilenameAndRef(
'versions.tf.tmpl',
this.targetBranch,
this.path
),
]).then(([v, vt]) => {
return v.concat(vt);
});
Expand Down
2 changes: 1 addition & 1 deletion test/strategies/dart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('Dart', () => {
github,
component: 'google-cloud-automl',
});
sandbox.stub(github, 'findFilesByFilename').resolves([]);
sandbox.stub(github, 'findFilesByFilenameAndRef').resolves([]);
const latestRelease = undefined;
const release = await strategy.buildReleasePullRequest(
commits,
Expand Down
2 changes: 1 addition & 1 deletion test/strategies/elixir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('Elixir', () => {
github,
component: 'google-cloud-automl',
});
sandbox.stub(github, 'findFilesByFilename').resolves([]);
sandbox.stub(github, 'findFilesByFilenameAndRef').resolves([]);
const latestRelease = undefined;
const release = await strategy.buildReleasePullRequest(
commits,
Expand Down
28 changes: 14 additions & 14 deletions test/strategies/java-yoshi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('JavaYoshi', () => {
github,
component: 'google-cloud-automl',
});
sandbox.stub(github, 'findFilesByFilename').resolves([]);
sandbox.stub(github, 'findFilesByFilenameAndRef').resolves([]);
const getFileContentsStub = sandbox.stub(
github,
'getFileContentsOnBranch'
Expand All @@ -85,7 +85,7 @@ describe('JavaYoshi', () => {
github,
component: 'google-cloud-automl',
});
sandbox.stub(github, 'findFilesByFilename').resolves([]);
sandbox.stub(github, 'findFilesByFilenameAndRef').resolves([]);
const getFileContentsStub = sandbox.stub(
github,
'getFileContentsOnBranch'
Expand All @@ -111,7 +111,7 @@ describe('JavaYoshi', () => {
github,
component: 'google-cloud-automl',
});
sandbox.stub(github, 'findFilesByFilename').resolves([]);
sandbox.stub(github, 'findFilesByFilenameAndRef').resolves([]);
const getFileContentsStub = sandbox.stub(
github,
'getFileContentsOnBranch'
Expand Down Expand Up @@ -142,7 +142,7 @@ describe('JavaYoshi', () => {
github,
component: 'google-cloud-automl',
});
sandbox.stub(github, 'findFilesByFilename').resolves([]);
sandbox.stub(github, 'findFilesByFilenameAndRef').resolves([]);
const getFileContentsStub = sandbox.stub(
github,
'getFileContentsOnBranch'
Expand Down Expand Up @@ -186,7 +186,7 @@ describe('JavaYoshi', () => {
github,
component: 'google-cloud-automl',
});
sandbox.stub(github, 'findFilesByFilename').resolves([]);
sandbox.stub(github, 'findFilesByFilenameAndRef').resolves([]);
const getFileContentsStub = sandbox.stub(
github,
'getFileContentsOnBranch'
Expand All @@ -210,15 +210,15 @@ describe('JavaYoshi', () => {
github,
component: 'google-cloud-automl',
});
const findFilesStub = sandbox.stub(github, 'findFilesByFilename');
const findFilesStub = sandbox.stub(github, 'findFilesByFilenameAndRef');
findFilesStub
.withArgs('pom.xml', '.')
.withArgs('pom.xml', 'main', '.')
.resolves(['path1/pom.xml', 'path2/pom.xml']);
findFilesStub
.withArgs('build.gradle', '.')
.withArgs('build.gradle', 'main', '.')
.resolves(['path1/build.gradle', 'path2/build.gradle']);
findFilesStub
.withArgs('dependencies.properties', '.')
.withArgs('dependencies.properties', 'main', '.')
.resolves(['dependencies.properties']);
const getFileContentsStub = sandbox.stub(
github,
Expand Down Expand Up @@ -250,7 +250,7 @@ describe('JavaYoshi', () => {
component: 'google-cloud-automl',
extraFiles: ['foo/bar.java', 'src/version.java'],
});
sandbox.stub(github, 'findFilesByFilename').resolves([]);
sandbox.stub(github, 'findFilesByFilenameAndRef').resolves([]);
const getFileContentsStub = sandbox.stub(
github,
'getFileContentsOnBranch'
Expand All @@ -276,15 +276,15 @@ describe('JavaYoshi', () => {
github,
component: 'google-cloud-automl',
});
const findFilesStub = sandbox.stub(github, 'findFilesByFilename');
const findFilesStub = sandbox.stub(github, 'findFilesByFilenameAndRef');
findFilesStub
.withArgs('pom.xml', '.')
.withArgs('pom.xml', 'main', '.')
.resolves(['path1/pom.xml', 'path2/pom.xml']);
findFilesStub
.withArgs('build.gradle', '.')
.withArgs('build.gradle', 'main', '.')
.resolves(['path1/build.gradle', 'path2/build.gradle']);
findFilesStub
.withArgs('dependencies.properties', '.')
.withArgs('dependencies.properties', 'main', '.')
.resolves(['dependencies.properties']);
const getFileContentsStub = sandbox.stub(
github,
Expand Down
2 changes: 1 addition & 1 deletion test/strategies/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe('Node', () => {
github,
component: 'google-cloud-automl',
});
sandbox.stub(github, 'findFilesByFilename').resolves([]);
sandbox.stub(github, 'findFilesByFilenameAndRef').resolves([]);
const latestRelease = undefined;
const release = await strategy.buildReleasePullRequest(
commits,
Expand Down
12 changes: 7 additions & 5 deletions test/strategies/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('Python', () => {
github,
component: 'google-cloud-automl',
});
sandbox.stub(github, 'findFilesByFilename').resolves([]);
sandbox.stub(github, 'findFilesByFilenameAndRef').resolves([]);
const latestRelease = undefined;
const release = await strategy.buildReleasePullRequest(
COMMITS,
Expand All @@ -74,7 +74,7 @@ describe('Python', () => {
github,
component: 'google-cloud-automl',
});
sandbox.stub(github, 'findFilesByFilename').resolves([]);
sandbox.stub(github, 'findFilesByFilenameAndRef').resolves([]);
const latestRelease = {
tag: new TagName(Version.parse('0.123.4'), 'google-cloud-automl'),
sha: 'abc123',
Expand All @@ -94,7 +94,7 @@ describe('Python', () => {
github,
component: 'google-cloud-automl',
});
sandbox.stub(github, 'findFilesByFilename').resolves([]);
sandbox.stub(github, 'findFilesByFilenameAndRef').resolves([]);
const latestRelease = undefined;
const release = await strategy.buildReleasePullRequest(
COMMITS,
Expand Down Expand Up @@ -127,7 +127,7 @@ describe('Python', () => {
.resolves(
buildGitHubFileContent('./test/updaters/fixtures', 'pyproject.toml')
);
sandbox.stub(github, 'findFilesByFilename').resolves([]);
sandbox.stub(github, 'findFilesByFilenameAndRef').resolves([]);
const latestRelease = undefined;
const release = await strategy.buildReleasePullRequest(
COMMITS,
Expand All @@ -143,7 +143,9 @@ describe('Python', () => {
github,
component: 'google-cloud-automl',
});
sandbox.stub(github, 'findFilesByFilename').resolves(['src/version.py']);
sandbox
.stub(github, 'findFilesByFilenameAndRef')
.resolves(['src/version.py']);
const latestRelease = undefined;
const release = await strategy.buildReleasePullRequest(
COMMITS,
Expand Down
14 changes: 7 additions & 7 deletions test/strategies/terraform-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('TerraformModule', () => {
github,
component: 'google-cloud-automl',
});
sandbox.stub(github, 'findFilesByFilename').resolves([]);
sandbox.stub(github, 'findFilesByFilenameAndRef').resolves([]);
const latestRelease = undefined;
const release = await strategy.buildReleasePullRequest(
COMMITS,
Expand All @@ -71,7 +71,7 @@ describe('TerraformModule', () => {
github,
component: 'google-cloud-automl',
});
sandbox.stub(github, 'findFilesByFilename').resolves([]);
sandbox.stub(github, 'findFilesByFilenameAndRef').resolves([]);
const latestRelease = {
tag: new TagName(Version.parse('0.123.4'), 'google-cloud-automl'),
sha: 'abc123',
Expand All @@ -91,7 +91,7 @@ describe('TerraformModule', () => {
github,
component: 'google-cloud-automl',
});
sandbox.stub(github, 'findFilesByFilename').resolves([]);
sandbox.stub(github, 'findFilesByFilenameAndRef').resolves([]);
const latestRelease = undefined;
const release = await strategy.buildReleasePullRequest(
COMMITS,
Expand All @@ -107,15 +107,15 @@ describe('TerraformModule', () => {
github,
component: 'google-cloud-automl',
});
const findFilesStub = sandbox.stub(github, 'findFilesByFilename');
const findFilesStub = sandbox.stub(github, 'findFilesByFilenameAndRef');
findFilesStub
.withArgs('readme.md', '.')
.withArgs('readme.md', 'main', '.')
.resolves(['path1/readme.md', 'path2/readme.md']);
findFilesStub
.withArgs('versions.tf', '.')
.withArgs('versions.tf', 'main', '.')
.resolves(['path1/versions.tf', 'path2/versions.tf']);
findFilesStub
.withArgs('versions.tf.tmpl', '.')
.withArgs('versions.tf.tmpl', 'main', '.')
.resolves(['path1/versions.tf.tmpl', 'path2/versions.tf.tmpl']);
const latestRelease = undefined;
const release = await strategy.buildReleasePullRequest(
Expand Down

0 comments on commit d891f00

Please sign in to comment.