Skip to content

Commit ba7dce5

Browse files
Fix SCM integration tests and run them on build (#20379)
* Fix SCM integration tests * fixup bbs test expectation with official testing token * Add note about GitLab search * Update GHA * Add ADO token definition
1 parent e8fff57 commit ba7dce5

File tree

8 files changed

+28
-47
lines changed

8 files changed

+28
-47
lines changed

.github/workflows/build.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,15 @@ jobs:
245245
CODECOV_TOKEN: "${{ secrets.CODECOV_TOKEN }}"
246246
LEEWAY_REMOTE_CACHE_BUCKET: ${{needs.configuration.outputs.leeway_cache_bucket}}
247247
IMAGE_REPO_BASE: ${{needs.configuration.outputs.image_repo_base}}/build
248+
249+
# SCM tokens for integration tests
250+
GITPOD_TEST_TOKEN_BITBUCKET: "${{ secrets.GITPOD_TEST_TOKEN_BITBUCKET }}"
251+
GITPOD_TEST_TOKEN_BITBUCKET_SERVER: "${{ secrets.GITPOD_TEST_TOKEN_BITBUCKET_SERVER }}"
252+
GITPOD_TEST_TOKEN_BITBUCKET_SERVER_WRITE: "${{ secrets.GITPOD_TEST_TOKEN_BITBUCKET_SERVER_WRITE }}"
253+
GITPOD_TEST_TOKEN_BITBUCKET_SERVER_READ: "${{ secrets.GITPOD_TEST_TOKEN_BITBUCKET_SERVER_READ }}"
254+
GITPOD_TEST_TOKEN_GITHUB: "${{ secrets.GITPOD_TEST_TOKEN_GITHUB }}"
255+
GITPOD_TEST_TOKEN_GITLAB: "${{ secrets.GITPOD_TEST_TOKEN_GITLAB }}"
256+
GITPOD_TEST_TOKEN_AZURE_DEVOPS: "${{ secrets.GITPOD_TEST_TOKEN_AZURE_DEVOPS }}"
248257
run: |
249258
[[ "$PR_NO_CACHE" = "true" ]] && CACHE="none" || CACHE="remote"
250259
[[ "$PR_NO_TEST" = "true" ]] && TEST="--dont-test" || TEST=""

components/server/src/bitbucket-server/bitbucket-server-api.spec.ts

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,17 @@ class TestBitbucketServerApi {
7878
};
7979
}
8080

81-
@test.skip async test_currentUsername_ok() {
81+
@test async test_currentUsername_ok() {
8282
const result = await this.api.currentUsername(process.env["GITPOD_TEST_TOKEN_BITBUCKET_SERVER"]!);
83-
expect(result).to.equal("AlexTugarev");
83+
expect(result).to.equal("admin-tester");
8484
}
8585

86-
@test.skip async test_getUserProfile_ok() {
87-
const result = await this.api.getUserProfile(process.env["GITPOD_TEST_TOKEN_BITBUCKET_SERVER"]!, "AlexTugarev");
86+
@test async test_getUserProfile_ok() {
87+
const result = await this.api.getUserProfile(process.env["GITPOD_TEST_TOKEN_BITBUCKET_SERVER"]!, "alex");
8888
expect(result).to.deep.include({
89-
id: 105, // Identity.authId
90-
name: "AlexTugarev", // Identity.authName
91-
slug: "alextugarev", // used in URLs
89+
id: 53, // Identity.authId
90+
name: "alex", // Identity.authName
91+
slug: "alex", // used in URLs
9292
displayName: "Alex Tugarev",
9393
});
9494
}
@@ -97,7 +97,7 @@ class TestBitbucketServerApi {
9797
const result = await this.api.getRepos(process.env["GITPOD_TEST_TOKEN_BITBUCKET_SERVER"]!, {
9898
permission: "REPO_READ",
9999
});
100-
expect(result.length).to.be.equal(9177);
100+
expect(result.length).to.be.equal(10_000);
101101

102102
// BBS: GET https://bitbucket.gitpod-dev.com/rest/api/1.0/repos?permission=REPO_READ&limit=1000&start=0&limit=1000 - OK
103103
// BBS: GET https://bitbucket.gitpod-dev.com/rest/api/1.0/repos?permission=REPO_READ&limit=1000&start=1002&limit=1000 - OK
@@ -174,35 +174,6 @@ class TestBitbucketServerApi {
174174
// ✓ test_getRepos_searchString_wildcards_are_not_supported (172ms)
175175
}
176176

177-
@test async test_getRepos_searchString_single_char_is_ignored() {
178-
const result = await this.api.getRepos(process.env["GITPOD_TEST_TOKEN_BITBUCKET_SERVER"]!, {
179-
permission: "REPO_READ",
180-
searchString: "t",
181-
});
182-
expect(result.length).to.be.equal(9177);
183-
184-
// BBS: GET https://bitbucket.gitpod-dev.com/rest/api/1.0/repos?permission=REPO_READ&limit=1000&start=0&name=t - OK
185-
// BBS: GET https://bitbucket.gitpod-dev.com/rest/api/1.0/repos?permission=REPO_READ&limit=1000&start=1000&name=t - OK
186-
// BBS: GET https://bitbucket.gitpod-dev.com/rest/api/1.0/repos?permission=REPO_READ&limit=1000&start=2000&name=t - OK
187-
// BBS: GET https://bitbucket.gitpod-dev.com/rest/api/1.0/repos?permission=REPO_READ&limit=1000&start=3000&name=t - OK
188-
// BBS: GET https://bitbucket.gitpod-dev.com/rest/api/1.0/repos?permission=REPO_READ&limit=1000&start=4000&name=t - OK
189-
// BBS: GET https://bitbucket.gitpod-dev.com/rest/api/1.0/repos?permission=REPO_READ&limit=1000&start=5000&name=t - OK
190-
// BBS: GET https://bitbucket.gitpod-dev.com/rest/api/1.0/repos?permission=REPO_READ&limit=1000&start=6000&name=t - OK
191-
// BBS: GET https://bitbucket.gitpod-dev.com/rest/api/1.0/repos?permission=REPO_READ&limit=1000&start=7000&name=t - OK
192-
// BBS: GET https://bitbucket.gitpod-dev.com/rest/api/1.0/repos?permission=REPO_READ&limit=1000&start=8000&name=t - OK
193-
// BBS: GET https://bitbucket.gitpod-dev.com/rest/api/1.0/repos?permission=REPO_READ&limit=1000&start=0&projectname=t - OK
194-
// BBS: GET https://bitbucket.gitpod-dev.com/rest/api/1.0/repos?permission=REPO_READ&limit=1000&start=1000&projectname=t - OK
195-
// BBS: GET https://bitbucket.gitpod-dev.com/rest/api/1.0/repos?permission=REPO_READ&limit=1000&start=2000&projectname=t - OK
196-
// BBS: GET https://bitbucket.gitpod-dev.com/rest/api/1.0/repos?permission=REPO_READ&limit=1000&start=3000&projectname=t - OK
197-
// BBS: GET https://bitbucket.gitpod-dev.com/rest/api/1.0/repos?permission=REPO_READ&limit=1000&start=4000&projectname=t - OK
198-
// BBS: GET https://bitbucket.gitpod-dev.com/rest/api/1.0/repos?permission=REPO_READ&limit=1000&start=5000&projectname=t - OK
199-
// BBS: GET https://bitbucket.gitpod-dev.com/rest/api/1.0/repos?permission=REPO_READ&limit=1000&start=6000&projectname=t - OK
200-
// BBS: GET https://bitbucket.gitpod-dev.com/rest/api/1.0/repos?permission=REPO_READ&limit=1000&start=7000&projectname=t - OK
201-
// BBS: GET https://bitbucket.gitpod-dev.com/rest/api/1.0/repos?permission=REPO_READ&limit=1000&start=8000&projectname=t - OK
202-
// BBS: GET https://bitbucket.gitpod-dev.com/rest/api/1.0/repos?permission=REPO_READ&limit=1000&start=9000&projectname=t - OK
203-
// ✓ test_getRepos_searchString_single_char_is_ignored (7329ms)
204-
}
205-
206177
@test async test_getRepos_searchString_unmatched() {
207178
const result = await this.api.getRepos(process.env["GITPOD_TEST_TOKEN_BITBUCKET_SERVER"]!, {
208179
permission: "REPO_READ",

components/server/src/bitbucket-server/bitbucket-server-api.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ export class BitbucketServerApi {
322322
}
323323

324324
/**
325-
* If `searchString` is provided, this tries to match projects and repositorys by name,
325+
* If `searchString` is provided, this tries to match projects and repositories by name,
326326
* otherwise it returns the first n repositories.
327327
*
328328
* Based on:
@@ -333,7 +333,7 @@ export class BitbucketServerApi {
333333
query: {
334334
permission?: "REPO_READ" | "REPO_WRITE" | "REPO_ADMIN";
335335
/**
336-
* If projects and repositorys are matched by by name, otherwise it returns the first n repositories.
336+
* If projects and repositories are matched by name, otherwise it returns the first n repositories.
337337
*/
338338
searchString?: string;
339339
/**
@@ -402,6 +402,7 @@ export class BitbucketServerApi {
402402
start = pageResult.nextPageStart;
403403
}
404404
}
405+
405406
return result;
406407
};
407408

@@ -425,7 +426,7 @@ export class BitbucketServerApi {
425426

426427
return Array.from(results.values());
427428
} else {
428-
return await fetchRepos(baseParams);
429+
return fetchRepos(baseParams);
429430
}
430431
}
431432

components/server/src/bitbucket/bitbucket-repository-provider.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { AuthProviderParams } from "../auth/auth-provider";
1212
import { HostContextProvider } from "../auth/host-context-provider";
1313
import { DevData } from "../dev/dev-data";
1414
import { TokenProvider } from "../user/token-provider";
15-
import { BitbucketApiFactory } from "./bitbucket-api-factory";
15+
import { BasicAuthBitbucketApiFactory, BitbucketApiFactory } from "./bitbucket-api-factory";
1616
import { BitbucketRepositoryProvider } from "./bitbucket-repository-provider";
1717
import { BitbucketTokenHelper } from "./bitbucket-token-handler";
1818
const expect = chai.expect;
@@ -50,7 +50,7 @@ class TestBitbucketRepositoryProvider {
5050
bind(TokenProvider).toConstantValue(<TokenProvider>{
5151
getTokenForHost: async () => DevData.createBitbucketTestToken(),
5252
});
53-
bind(BitbucketApiFactory).toSelf().inSingletonScope();
53+
bind(BitbucketApiFactory).to(BasicAuthBitbucketApiFactory).inSingletonScope();
5454
bind(HostContextProvider).toConstantValue({
5555
get: (hostname: string) => {
5656
authProvider: {

components/server/src/bitbucket/bitbucket-repository-provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export class BitbucketRepositoryProvider implements RepositoryProvider {
187187
workspace: workspaceSlug,
188188
// name includes searchString
189189
q: `name ~ "${searchString}"`,
190-
// sort by most recently updatd first
190+
// sort by most recently updated first
191191
sort: "-updated_on",
192192
// limit to the first 10 results per workspace
193193
pagelen: 10,

components/server/src/github/github-repository-provider.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,8 @@ export class GithubRepositoryProvider implements RepositoryProvider {
262262
}
263263
}`;
264264

265-
let repos: RepositoryInfo[] = [];
266-
267265
const result = await this.githubQueryApi.runQuery<SearchReposQueryResponse>(user, repoSearchQuery);
268-
repos = result.data.search.edges.map((edge) => {
266+
const repos: RepositoryInfo[] = result.data.search.edges.map((edge) => {
269267
return {
270268
name: edge.node.name,
271269
url: edge.node.url,

components/server/src/gitlab/gitlab-context-parser.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ class TestGitlabContextParser {
5252
};
5353
static readonly BLO_BLA_ERROR_DATA = {
5454
host: "gitlab.com",
55-
lastUpdate: undefined,
55+
lastUpdate: "",
56+
errorMessage: 'GitLab responded: "404 Project Not Found"',
5657
owner: "blo",
5758
repoName: "bla",
5859
userIsOwner: false,

components/server/src/gitlab/gitlab-repository-provider.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ export class GitlabRepositoryProvider implements RepositoryProvider {
144144
const result = await this.gitlab.run<GitLab.Project[]>(user, async (gitlab) => {
145145
return gitlab.Projects.all({
146146
membership: true,
147+
// note: GitLab returns an empty project set when there isn't an exact match and the search length is <3
147148
search: searchString,
148149
perPage: limit,
149150
simple: true,

0 commit comments

Comments
 (0)