Skip to content

Commit b2a13f4

Browse files
committed
Update gitlab rest client
1 parent a8ec98a commit b2a13f4

File tree

9 files changed

+78
-211
lines changed

9 files changed

+78
-211
lines changed

components/server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"@authzed/authzed-node": "^0.10.0",
3838
"@bufbuild/connect": "^0.8.1",
3939
"@bufbuild/connect-express": "^0.8.1",
40-
"@gitbeaker/node": "^35.8.1",
40+
"@gitbeaker/rest": "^39.12.0",
4141
"@gitpod/content-service": "0.1.5",
4242
"@gitpod/gitpod-db": "0.1.5",
4343
"@gitpod/gitpod-protocol": "0.1.5",

components/server/src/gitlab/api.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import { injectable, inject } from "inversify";
88
import { User } from "@gitpod/gitpod-protocol";
99

10-
import { Gitlab } from "@gitbeaker/node";
10+
import { Gitlab } from "@gitbeaker/rest";
1111
import {
1212
Projects,
1313
Users,
@@ -19,10 +19,11 @@ import {
1919
MergeRequests,
2020
Issues,
2121
RepositoryFiles,
22+
NamespaceSchema,
23+
UserSchema,
24+
ExpandedUserSchema,
25+
ProjectSchema,
2226
} from "@gitbeaker/core";
23-
import { ProjectExtendedSchema } from "@gitbeaker/core/dist/types/resources/Projects";
24-
import { NamespaceSchema } from "@gitbeaker/core/dist/types/resources/Namespaces";
25-
import { UserExtendedSchema, UserSchema } from "@gitbeaker/core/dist/types/resources/Users";
2627
import { log } from "@gitpod/gitpod-protocol/lib/util/logging";
2728
import { GitLabScope } from "./scopes";
2829
import { AuthProviderParams } from "../auth/auth-provider";
@@ -90,9 +91,7 @@ export class GitLabApi {
9091
path: string,
9192
): Promise<string | undefined> {
9293
const projectId = `${org}/${name}`;
93-
const result = await this.run<string>(user, (api) =>
94-
api.RepositoryFiles.showRaw(projectId, path, { ref: commitish }),
95-
);
94+
const result = await this.run<string>(user, (api) => api.RepositoryFiles.showRaw(projectId, path, commitish));
9695
if (GitLab.ApiError.is(result)) {
9796
return undefined; // e.g. 404 error, because the file isn't found
9897
}
@@ -137,7 +136,7 @@ export namespace GitLab {
137136
/**
138137
* https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/projects.md#get-single-project
139138
*/
140-
export interface Project extends ProjectExtendedSchema {
139+
export interface Project extends ProjectSchema {
141140
visibility: "public" | "private" | "internal";
142141
archived: boolean;
143142
path: string; // "diaspora-project-site"
@@ -227,7 +226,7 @@ export namespace GitLab {
227226
merge_requests_count: number;
228227
}
229228
// https://docs.gitlab.com/ee/api/users.html#list-current-user-for-normal-users
230-
export interface User extends UserExtendedSchema {
229+
export interface User extends ExpandedUserSchema {
231230
email: string;
232231
state: "active" | string;
233232
}
@@ -256,19 +255,19 @@ export namespace GitLab {
256255
export namespace Permissions {
257256
export function hasWriteAccess(repo: Project): boolean {
258257
if (repo.permissions.project_access) {
259-
return repo.permissions.project_access.access_level >= 30;
258+
return (repo.permissions.project_access as unknown as { access_level: number }).access_level >= 30;
260259
}
261260
if (repo.permissions.group_access) {
262-
return repo.permissions.group_access.access_level >= 30;
261+
return (repo.permissions.group_access as unknown as { access_level: number }).access_level >= 30;
263262
}
264263
return false;
265264
}
266265
export function hasMaintainerAccess(repo: Project): boolean {
267266
if (repo.permissions.project_access) {
268-
return repo.permissions.project_access.access_level >= 40;
267+
return (repo.permissions.project_access as unknown as { access_level: number }).access_level >= 40;
269268
}
270269
if (repo.permissions.group_access) {
271-
return repo.permissions.group_access.access_level >= 40;
270+
return (repo.permissions.group_access as unknown as { access_level: number }).access_level >= 40;
272271
}
273272
return false;
274273
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class GitlabFileProvider implements FileProvider {
3030
path: string,
3131
): Promise<string> {
3232
const result = await this.gitlabApi.run<GitLab.Commit[]>(user, async (g) => {
33-
return g.Commits.all(`${repository.owner}/${repository.name}`, { path, ref_name: revisionOrBranch });
33+
return g.Commits.all(`${repository.owner}/${repository.name}`, { path, refName: revisionOrBranch });
3434
});
3535

3636
if (GitLab.ApiError.is(result)) {

components/server/src/gitlab/gitlab-app-support.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import { AuthProviderInfo, ProviderRepository, User } from "@gitpod/gitpod-protocol";
88
import { inject, injectable } from "inversify";
9-
import { Gitlab } from "@gitbeaker/node";
9+
import { Gitlab } from "@gitbeaker/rest";
1010
import { GitLab } from "./api";
1111
import { TokenProvider } from "../user/token-provider";
1212

@@ -36,7 +36,7 @@ export class GitLabAppSupport {
3636
// also cf. https://docs.gitlab.com/ee/api/members.html#valid-access-levels
3737
//
3838
const projectsWithAccess = await api.Projects.all({
39-
min_access_level: "40",
39+
minAccessLevel: 40,
4040
perPage: 100,
4141
});
4242
for (const project of projectsWithAccess) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export class GitLabAuthProvider extends GenericAuthProvider {
6666
host: this.baseURL,
6767
});
6868
const getCurrentUser = async () => {
69-
const response = await api.Users.current();
69+
const response = await api.Users.showCurrentUser();
7070
return response as unknown as GitLab.User;
7171
};
7272
const unconfirmedUserMessage = "Please confirm your GitLab account and try again.";

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ export class GitlabContextParser extends AbstractContextParser implements IConte
222222
}
223223

224224
const result = await this.gitlabApi.run<GitLab.TreeObject[]>(user, async (g) => {
225-
return g.Repositories.tree(`${owner}/${repoName}`, {
225+
return g.Repositories.allRepositoryTrees(`${owner}/${repoName}`, {
226226
ref: branchOrTag.name,
227227
path: path.dirname(branchOrTag.fullPath),
228228
});
@@ -421,7 +421,7 @@ export class GitlabContextParser extends AbstractContextParser implements IConte
421421
): Promise<IssueContext> {
422422
const ctxPromise = this.handleDefaultContext(user, host, owner, repoName);
423423
const result = await this.gitlabApi.run<GitLab.Issue>(user, async (g) => {
424-
return g.Issues.show(`${owner}/${repoName}`, nr);
424+
return g.Issues.show(nr, { projectId: `${owner}/${repoName}` });
425425
});
426426
if (GitLab.ApiError.is(result)) {
427427
throw await NotFoundError.create(await this.tokenHelper.getCurrentToken(user), user, host, owner, repoName);

components/server/src/gitlab/gitlab-file-provider.spec.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,8 @@ class TestFileProvider {
7575
const project = await api.run<GitLab.Project>(this.user, (g) =>
7676
g.Projects.create({
7777
name: `test_project_${i}`,
78-
path: `test_project_${i}`,
79-
namespace_id: 57982169,
80-
initialize_with_readme: true,
78+
namespaceId: 57982169,
79+
initializeWithReadme: true,
8180
description: "generated project to test pagination",
8281
}),
8382
);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ export class GitlabRepositoryProvider implements RepositoryProvider {
126126
const projectId = `${owner}/${repo}`;
127127
const result = await this.gitlab.run<GitLab.Commit[]>(user, async (g) => {
128128
return g.Commits.all(projectId, {
129-
ref_name: ref,
130-
per_page: maxDepth,
129+
refName: ref,
130+
perPage: maxDepth,
131131
page: 1,
132132
});
133133
});

0 commit comments

Comments
 (0)