Skip to content

Commit 52a42e1

Browse files
squash: Gitlab bulk import fix typization (#2)
* feat(bulk-import-backend): fix typization for @gitbeaker/rest Signed-off-by: Oleksandr Andriienko <oandriie@redhat.com> * squash: updates to make the tests work --------- Signed-off-by: Oleksandr Andriienko <oandriie@redhat.com> Co-authored-by: Oleksandr Andriienko <oandriie@redhat.com>
1 parent 03fb723 commit 52a42e1

File tree

6 files changed

+210
-223
lines changed

6 files changed

+210
-223
lines changed

workspaces/bulk-import/plugins/bulk-import-backend/src/gitlab/gitlabApiService.ts

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
ScmIntegrations,
2525
} from '@backstage/integration';
2626

27+
import { Gitlab, GroupSchema } from '@gitbeaker/rest';
2728
import gitUrlParse from 'git-url-parse';
2829

2930
import { getBranchName, getCatalogFilename } from '../catalog/catalogUtils';
@@ -108,18 +109,10 @@ export class GitlabApiService {
108109
{ credential, owner: gitUrl.owner },
109110
glConfig.baseUrl,
110111
);
111-
const resp = await glKit.Projects.show(`${gitUrl.owner}/${gitUrl.name}`);
112-
const repo = resp;
112+
const repo = await glKit.Projects.show(`${gitUrl.owner}/${gitUrl.name}`);
113113
if (!repo) {
114114
continue;
115115
}
116-
117-
// name: repo.name,
118-
// full_name: repo.path_with_namespace,
119-
// url: repo._links.self,
120-
// html_url: repo.web_url,
121-
// default_branch: repo.default_branch,
122-
// updated_at: repo.updated_at,
123116
repository = {
124117
name: repo.name,
125118
full_name: repo.path_with_namespace,
@@ -152,7 +145,7 @@ export class GitlabApiService {
152145
this.integrations,
153146
{
154147
dataFetcher: async (
155-
glApi: any,
148+
glApi: InstanceType<typeof Gitlab<false>>,
156149
credential: ExtendedGitlabCredentials,
157150
glConfig: GitLabIntegrationConfig,
158151
) => {
@@ -207,7 +200,7 @@ export class GitlabApiService {
207200
this.integrations,
208201
{
209202
dataFetcher: async (
210-
glApi: any,
203+
glApi: InstanceType<typeof Gitlab<false>>,
211204
credential: ExtendedGitlabCredentials,
212205
glConfig: GitLabIntegrationConfig,
213206
) => {
@@ -268,7 +261,7 @@ export class GitlabApiService {
268261
this.integrations,
269262
{
270263
dataFetcher: async (
271-
glApi: any,
264+
glApi: InstanceType<typeof Gitlab<false>>,
272265
credential: ExtendedGitlabCredentials,
273266
glConfig: GitLabIntegrationConfig,
274267
) => {
@@ -322,19 +315,19 @@ export class GitlabApiService {
322315
},
323316
this.integrations,
324317
{
325-
dataFetcher: async (gitlab: any) => {
318+
dataFetcher: async (gitlab: InstanceType<typeof Gitlab<false>>) => {
326319
// find authenticated gitlab owner...
327320
const username = (await gitlab.Users.showCurrentUser()).username;
328321
if (username) {
329322
allAccessibleUsernames.add(username);
330323
}
331324
// ... along with orgs accessible from the token auth
332-
(
333-
await gitlab.Groups.all({
334-
all_available: false,
335-
})
336-
)
337-
?.map((org: { path: any }) => org.path)
325+
326+
const allGroups = await gitlab.Groups.all<false, 'offset'>({
327+
allAvailable: false,
328+
});
329+
allGroups
330+
.map(org => org.path)
338331
?.forEach((orgName: string) => allAccessibleTokenOrgs.add(orgName));
339332
return {};
340333
},
@@ -441,7 +434,7 @@ export class GitlabApiService {
441434
repoUrl: input.repoUrl,
442435
fn: async (
443436
validatedRepo: ValidatedRepo,
444-
gitlab: any,
437+
gitlab: InstanceType<typeof Gitlab<false>>,
445438
): Promise<{
446439
successful: boolean;
447440
result?: {
@@ -618,7 +611,10 @@ export class GitlabApiService {
618611
this.integrations,
619612
{
620613
repoUrl: input.repoUrl,
621-
fn: async (validatedRepo: ValidatedRepo, gitlab: any) => {
614+
fn: async (
615+
validatedRepo: ValidatedRepo,
616+
gitlab: InstanceType<typeof Gitlab<false>>,
617+
) => {
622618
const { owner, repo } = validatedRepo;
623619
const exists = await fileExistsInDefaultBranch(
624620
this.logger,
@@ -663,7 +659,10 @@ export class GitlabApiService {
663659
this.integrations,
664660
{
665661
repoUrl: input.repoUrl,
666-
fn: async (validatedRepo: ValidatedRepo, gitlab: any) => {
662+
fn: async (
663+
validatedRepo: ValidatedRepo,
664+
gitlab: InstanceType<typeof Gitlab<false>>,
665+
) => {
667666
const { owner, repo, branchName } = validatedRepo;
668667
try {
669668
const existingPrForBranch = await findOpenPRForBranch(
@@ -711,7 +710,10 @@ export class GitlabApiService {
711710
this.integrations,
712711
{
713712
repoUrl: input.repoUrl,
714-
fn: async (validatedRepo: ValidatedRepo, gitlab: any) => {
713+
fn: async (
714+
validatedRepo: ValidatedRepo,
715+
gitlab: InstanceType<typeof Gitlab<false>>,
716+
) => {
715717
const { owner, repo, branchName } = validatedRepo;
716718
try {
717719
await gitlab.Branches.remove(`${owner}/${repo}`, branchName);
@@ -740,14 +742,15 @@ export class GitlabApiService {
740742
this.integrations,
741743
{
742744
repoUrl: input.repoUrl,
743-
fn: async (validatedRepo: ValidatedRepo, gitlab: any) => {
745+
fn: async (
746+
validatedRepo: ValidatedRepo,
747+
gitlab: InstanceType<typeof Gitlab<false>>,
748+
) => {
744749
const { owner, repo } = validatedRepo;
745750
const resp = await gitlab.Repositories.allContributors(
746751
`${owner}/${repo}`,
747752
{
748753
showExpanded: true,
749-
perPage: 1,
750-
page: 1,
751754
},
752755
);
753756
return { successful: true, result: resp?.data?.length < 1 };

workspaces/bulk-import/plugins/bulk-import-backend/src/gitlab/utils/glUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export function buildGitlab(
4545
errors?: Map<number, GitlabFetchError>;
4646
},
4747
baseUrl: string = GITLAB_BASEURL_ENDPOINT,
48-
): any {
48+
): InstanceType<typeof Gitlab<false>> {
4949
const apiThing = new Gitlab({
5050
host: baseUrl,
5151
token: input.credential.token,

workspaces/bulk-import/plugins/bulk-import-backend/src/gitlab/utils/orgUtils.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import type { LoggerService } from '@backstage/backend-plugin-api';
1818
import type { GitlabCredentials } from '@backstage/integration';
1919

20+
import { Gitlab } from '@gitbeaker/rest';
21+
2022
import {
2123
DefaultPageNumber,
2224
DefaultPageSize,
@@ -28,7 +30,7 @@ export async function addGitlabTokenGroups(
2830
deps: {
2931
logger: LoggerService;
3032
},
31-
gitlab: any,
33+
gitlab: InstanceType<typeof Gitlab<false>>,
3234
credential: GitlabCredentials,
3335
params: {
3436
search: string | undefined;
@@ -51,8 +53,8 @@ export async function addGitlabTokenGroups(
5153
// Use the group api with the search param.
5254
// I noticed that using this api will only return values when 3 or more characters are used for the search
5355
// that api gives us all the things the token has access
54-
const { data, paginationInfo } = await gitlab.Groups.all({
55-
all_available: false,
56+
const { data, paginationInfo } = await gitlab.Groups.all<true, 'offset'>({
57+
allAvailable: false,
5658
search: search,
5759
perPage: pageSize,
5860
page: pageNumber,
@@ -71,8 +73,8 @@ export async function addGitlabTokenGroups(
7173
* The Groups all endpoint will grab all the groups the gitlab token has explicit access to.
7274
*/
7375

74-
const { data, paginationInfo } = await gitlab.Groups.all({
75-
all_available: false,
76+
const { data, paginationInfo } = await gitlab.Groups.all<true, 'offset'>({
77+
allAvailable: false,
7678
perPage: pageSize,
7779
page: pageNumber,
7880
showExpanded: true,
@@ -98,9 +100,9 @@ export async function addGitlabTokenGroups(
98100
url: group.web_url,
99101
avatar_url: group.avatar_url,
100102
// From here down gitlab doesn't really have while calling the group api
101-
public_repos: group?.data?.public_repos,
102-
total_private_repos: group?.data?.total_private_repos,
103-
owned_private_repos: group?.data?.owned_private_repos,
103+
// public_repos: group?.data?.public_repos,
104+
// total_private_repos: group?.data?.total_private_repos,
105+
// owned_private_repos: group?.data?.owned_private_repos,
104106
};
105107
groups.set(group.path, glGroup);
106108
}

0 commit comments

Comments
 (0)