Skip to content

Commit

Permalink
Fix GitHub Integration tests (#20363)
Browse files Browse the repository at this point in the history
  • Loading branch information
filiptronicek authored Nov 14, 2024
1 parent 4c69ad0 commit 177367e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion components/server/src/dev/dev-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export namespace DevData {
export function createGitHubTestToken(): Token {
if (!process.env.GITPOD_TEST_TOKEN_GITHUB) {
console.error(
`GITPOD_TEST_TOKEN_GITHUB env var is not set\n\n\t export GITPOD_TEST_TOKEN_GITHUB='{"username": "gitpod-test", "token": $AZURE_TOKEN}'`,
`GITPOD_TEST_TOKEN_GITHUB env var is not set\n\n\t export GITPOD_TEST_TOKEN_GITHUB='{"username": "gitpod-test", "value": $GITHUB_TOKEN}'`,
);
}
return {
Expand Down
2 changes: 1 addition & 1 deletion components/server/src/errors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export namespace NotFoundError {
repoName: string,
errorMessage: string = "Repository not found.",
) {
const lastUpdate = (token && token.updateDate) || "";
const lastUpdate = (token && token.updateDate) ?? "";
const userScopes = token ? [...token.scopes] : [];

const userIsOwner = owner == user.name; // TODO: shouldn't this be a comparison with `identity.authName`?
Expand Down
7 changes: 4 additions & 3 deletions components/server/src/github/github-context-parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,12 @@ class TestGithubContextParser {

static readonly BLO_BLA_ERROR_DATA = {
host: "github.com",
lastUpdate: undefined,
lastUpdate: "",
owner: "blo",
repoName: "bla",
userIsOwner: false,
userScopes: ["user:email", "public_repo", "repo"],
errorMessage: "Could not resolve to a Repository with the name 'blo/bla'.",
};

protected getTestBranches(): BranchRef[] {
Expand Down Expand Up @@ -180,12 +181,12 @@ class TestGithubContextParser {
const result = await this.parser.handle(
{},
this.user,
"https://github.com/eclipse-theia/theia/tree/master/LICENSE",
"https://github.com/eclipse-theia/theia/tree/master/LICENSE-EPL",
);
expect(result).to.deep.include({
ref: "master",
refType: "branch",
path: "LICENSE",
path: "LICENSE-EPL",
isFile: true,
repository: {
host: "github.com",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class TestGithubContextRepositoryProvider {

@test public async testGetUserRepos() {
const result = await this.provider.getUserRepos(this.user);
expect(result).to.include({ url: "https://github.com/gitpod-io/gitpod", name: "gitpod" });
expect(result).to.deep.include({ url: "https://github.com/gitpod-integration-test/example", name: "example" });
}
}
module.exports = new TestGithubContextRepositoryProvider(); // Only to circumvent no usage warning :-/
7 changes: 4 additions & 3 deletions components/server/src/github/github-repository-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,19 +215,20 @@ export class GithubRepositoryProvider implements RepositoryProvider {
}`,
);

let repos: RepositoryInfo[] = [];

const repos: RepositoryInfo[] = [];
for (const type of ["contributedTo", "original", "forked"]) {
const nodes = result.data.viewer[type]?.nodes;
if (nodes) {
repos = nodes.map((n: any): RepositoryInfo => {
const reposInSection: RepositoryInfo[] = nodes.map((n: any) => {
return {
name: n.name,
url: n.url,
};
});
repos.push(...reposInSection);
}
}

return repos;
}

Expand Down

0 comments on commit 177367e

Please sign in to comment.