Skip to content

Commit 849e69c

Browse files
Select exact match if multiple repos with same prefix (#137)
https://user-images.githubusercontent.com/88345179/197825352-91c7178e-95b1-4030-b048-3d9bbfe9161b.mov Co-authored-by: Fabian Jakobs <fabian.jakobs@databricks.com>
1 parent 70c6668 commit 849e69c

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

packages/databricks-sdk-js/src/services/Repos.integ.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,12 @@ describe(__filename, function () {
8484
assert.notEqual(await response, undefined);
8585
assert.ok((await response).length > 0);
8686
});
87+
88+
it("Should find the exact matching repo if multiple repos with same prefix in fromPath", async () => {
89+
const actual = await Repo.fromPath(
90+
integSetup.client,
91+
testRepoDetails.path!
92+
);
93+
assert.equal(actual.path, testRepoDetails.path);
94+
});
8795
});

packages/databricks-sdk-js/src/services/Repos.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,11 @@ export class Repo {
7474
_token
7575
);
7676

77-
if (repos.length !== 1) {
77+
const exactRepo = repos.find((repo) => repo.path === path);
78+
if (repos.length !== 1 && !exactRepo) {
7879
throw new RepoError(`${repos.length} repos match prefix ${path}`);
7980
}
8081

81-
return repos[0];
82+
return exactRepo ?? repos[0];
8283
}
8384
}

0 commit comments

Comments
 (0)