diff --git a/components/server/src/bitbucket-server/bitbucket-server-repository-provider.spec.ts b/components/server/src/bitbucket-server/bitbucket-server-repository-provider.spec.ts index 377e4d80246717..00a20db6a4c975 100644 --- a/components/server/src/bitbucket-server/bitbucket-server-repository-provider.spec.ts +++ b/components/server/src/bitbucket-server/bitbucket-server-repository-provider.spec.ts @@ -153,6 +153,30 @@ class TestBitbucketServerRepositoryProvider { name: "browser-extension-test", }); } + + @test async test_searchRepos_ok() { + const result = await this.service.searchRepos(this.user, "2k-repos-1076", 100); + expect(result.length).to.be.eq(1); + } + + @test async test_searchRepos_shortSearch() { + const resultA = await this.service.searchRepos(this.user, "2", 100); + expect(resultA).to.not.be.empty; + + const resultB = await this.service.searchRepos(this.user, "2k", 100); + expect(resultB).to.not.be.empty; + } + + // bitbucket searches for repo and project names, not for the full path + @test async test_searchRepos_pathSubstring() { + const result = await this.service.searchRepos(this.user, "/2k-repos-1076", 100); + expect(result).to.be.empty; + } + + @test async test_searchRepos_nameSubstring() { + const result = await this.service.searchRepos(this.user, "repos-1076", 100); + expect(result).to.be.empty; + } } module.exports = new TestBitbucketServerRepositoryProvider(); diff --git a/components/server/src/bitbucket/bitbucket-repository-provider.spec.ts b/components/server/src/bitbucket/bitbucket-repository-provider.spec.ts index c486a6f64c261c..294ed88e7d8bb9 100644 --- a/components/server/src/bitbucket/bitbucket-repository-provider.spec.ts +++ b/components/server/src/bitbucket/bitbucket-repository-provider.spec.ts @@ -96,6 +96,30 @@ class TestBitbucketRepositoryProvider { const result = await this.repoProvider.hasReadAccess(this.user, "foobar", "private-repo"); expect(result).to.be.false; } + + // In contrast to Bitbucket Server, bitbucket.org supports matching against a substring, not just a prefix. + @test public async testSearchRepos_matchesSubstring() { + const result = await this.repoProvider.searchRepos(this.user, "amp", 100); + expect(result).to.deep.include({ + url: "https://bitbucket.org/gitpod-integration-tests/exampul-repo", + name: "exampul-repo", + }); + } + + // Bitbucket supports searching for repos with arbitrary length search strings. + @test public async testSearchRepos_shortSearchString() { + const resultA = await this.repoProvider.searchRepos(this.user, "e", 100); + expect(resultA.length).to.be.gt(0); + + const resultB = await this.repoProvider.searchRepos(this.user, "ex", 100); + expect(resultB.length).to.be.gt(0); + } + + // Bitbucket only searches for repositories by their name, not by their full path. + @test public async testSearchRepos_doesNotMatchPath() { + const result = await this.repoProvider.searchRepos(this.user, "gitpod-integration-tests/exampul-repo", 100); + expect(result).to.be.empty; + } } module.exports = new TestBitbucketRepositoryProvider(); diff --git a/components/server/src/github/github-repository-provider.spec.ts b/components/server/src/github/github-repository-provider.spec.ts index 121d65a6131082..316f0f86b84fe5 100644 --- a/components/server/src/github/github-repository-provider.spec.ts +++ b/components/server/src/github/github-repository-provider.spec.ts @@ -62,7 +62,9 @@ class TestGithubContextRepositoryProvider { description: "", icon: "", host: "github.com", - oauth: "not-used" as any, + oauth: { + callBackUrl: "https://gitpod.example.com/auth/github/callback", + } as any, }; @test public async testFetchCommitHistory() { @@ -79,6 +81,26 @@ class TestGithubContextRepositoryProvider { ]); } + @test public async testSearchRepos_onlyMatchesByPrefix() { + const resultA = await this.provider.searchRepos(this.user, "xample", 100); + expect(resultA.length).to.be.eq(0); + + const resultB = await this.provider.searchRepos(this.user, "e", 100); + expect(resultB.length).to.be.eq(1); + } + + @test public async testSearchRepos_matchesAgainstWholePath() { + const resultMatchesSuffix = await this.provider.searchRepos(this.user, "-integration-test/example", 100); + expect(resultMatchesSuffix.length).to.be.eq(1); + + const resultDoesNotMatchSubstring = await this.provider.searchRepos( + this.user, + "gitpod-integration-test/exampl", + 100, + ); + expect(resultDoesNotMatchSubstring.length).to.be.eq(0); + } + @test public async testGetUserRepos() { const result = await this.provider.getUserRepos(this.user); expect(result).to.deep.include({ url: "https://github.com/gitpod-integration-test/example", name: "example" }); diff --git a/components/server/src/gitlab/gitlab-repository-provider.spec.ts b/components/server/src/gitlab/gitlab-repository-provider.spec.ts index b41b0df5c1508a..1c004c21c2bd33 100644 --- a/components/server/src/gitlab/gitlab-repository-provider.spec.ts +++ b/components/server/src/gitlab/gitlab-repository-provider.spec.ts @@ -64,6 +64,31 @@ class TestGitlabRepositoryProvider { "f2d9790f2752a794517b949c65a773eb864844cd", ]); } + + @test public async testSearchRepos_matchesSubstring() { + const result = await this.repositoryProvider.searchRepos(this.user, "est", 100); + expect(result.length).to.be.eq(1); + } + + // The minimum search string length is 3 characters (unless there is an exact match). + @test public async testSearchRepos_shortSearchString_looseMatch() { + const resultA = await this.repositoryProvider.searchRepos(this.user, "t", 100); + expect(resultA.length).to.be.eq(0); + + const resultB = await this.repositoryProvider.searchRepos(this.user, "te", 100); + expect(resultB.length).to.be.eq(0); + } + + @test public async testSearchRepos_shortSearchString_exactMatch() { + const result = await this.repositoryProvider.searchRepos(this.user, "g", 100); + expect(result.length).to.be.eq(1); + } + + // GitLab API does not support searching for repositories by their full path, only by their name. + @test public async testSearchRepos_noMatchAgainstWholePath() { + const result = await this.repositoryProvider.searchRepos(this.user, "gitpod-integration-tests/test", 100); + expect(result.length).to.be.eq(0); + } } module.exports = new TestGitlabRepositoryProvider();