Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/timeout axios #352

Merged
merged 2 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
],
"homepage": "https://github.com/snyk-tech-services/snyk-api-import#readme",
"dependencies": {
"@gitbeaker/core": "35.6.1",
"@gitbeaker/node": "35.6.1",
"@gitbeaker/core": "35.7.0",
"@gitbeaker/node": "35.7.0",
"@octokit/rest": "18.12.0",
"@types/base-64": "^1.0.0",
"base-64": "^1.0.0",
Expand All @@ -51,7 +51,7 @@
"p-map": "4.0.0",
"parse-link-header": "2.0.0",
"sleep-promise": "8.0.1",
"snyk-request-manager": "1.7.1",
"snyk-request-manager": "1.8.0",
"source-map-support": "^0.5.16",
"split": "1.0.1",
"yargs": "16.2.0"
Expand Down
9 changes: 2 additions & 7 deletions src/lib/api/group/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,8 @@ export async function listOrgsPerPage(
page: pageNumber,
};
const orgs = await listOrgs(requestManager, groupId, params);
let hasNextPage;
if (orgs.length) {
hasNextPage = true;
data.push(...orgs);
} else {
hasNextPage = false;
}
const hasNextPage = orgs.length ? true : false;
data.push(...orgs);
return { orgs: data, hasNextPage };
}

Expand Down
28 changes: 12 additions & 16 deletions src/lib/source-handlers/github/list-repos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,18 @@ export async function fetchReposForPage(
};
const res = await octokit.repos.listForOrg(params);
const repos = res && res.data;
let hasNextPage;
if (repos.length) {
hasNextPage = true;
repoData.push(
...repos
.filter((repo) => !repo.archived)
.map((repo) => ({
fork: repo.fork,
name: repo.name,
owner: repo.owner?.login,
branch: repo.default_branch,
})),
);
} else {
hasNextPage = false;
}
const hasNextPage = repos.length ? true : false;
repoData.push(
...repos
.filter((repo) => !repo.archived)
.map((repo) => ({
fork: repo.fork,
name: repo.name,
owner: repo.owner?.login,
branch: repo.default_branch,
})),
);

return { repos: repoData, hasNextPage };
}

Expand Down
22 changes: 8 additions & 14 deletions src/lib/source-handlers/gitlab/list-groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,16 @@ async function fetchOrgsForPage(
perPage: 100,
page: pageNumber,
};
let hasNextPage;

const orgs = await client.Groups.all(params);
if (orgs.length) {
hasNextPage = true;
const hasNextPage = orgs.length ? true : false;
orgsData.push(
...orgs.map((org: any) => ({
name: org.full_path,
id: org.id,
url: org.web_url,
})),
);

orgsData.push(
...orgs.map((org: any) => ({
name: org.full_path,
id: org.id,
url: org.web_url,
})),
);
} else {
hasNextPage = false;
}
return {
orgs: orgsData,
hasNextPage,
Expand Down
65 changes: 32 additions & 33 deletions src/lib/source-handlers/gitlab/list-repos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import * as debugLib from 'debug';
import { getToken } from './get-token';

import { getBaseUrl } from './get-base-url';
import * as types from '@gitbeaker/core/dist/types';
import * as gitBeakerTypes from '@gitbeaker/core';
import { GitlabRepoData } from './types';

const debug = debugLib('snyk:list-repos-script');

export async function fetchGitlabReposForPage(
client: types.Gitlab,
client: gitBeakerTypes.Gitlab,
groupName: string,
pageNumber = 1,
perPage = 100,
Expand All @@ -23,42 +23,41 @@ export async function fetchGitlabReposForPage(
perPage,
page: pageNumber,
};
const projects = await client.Groups.projects(groupName, params);
let hasNextPage;
if (projects.length) {
hasNextPage = true;
repoData.push(
...projects
.filter((project) => {
const {
archived,
shared_with_groups,
default_branch,
} = project as types.Types.ProjectExtendedSchema;
if (
archived ||
!default_branch ||
(shared_with_groups && shared_with_groups.length > 0)
) {
return false;
}
return true;
})
.map((project) => ({
fork: !!project.forked_from_project,
name: project.path_with_namespace,
id: project.id,
branch: project.default_branch,
})),
);
} else {
hasNextPage = false;
const projects = (await client.Groups.projects(
groupName,
params,
)) as gitBeakerTypes.Types.ProjectExtendedSchema[];
const hasNextPage = projects.length ? true : false;

for (const project of projects) {
const {
archived,
shared_with_groups,
default_branch,
forked_from_project,
path_with_namespace,
id,
} = project;
if (
archived ||
!default_branch ||
(shared_with_groups && shared_with_groups.length > 0)
) {
continue;
}

repoData.push({
fork: forked_from_project ? true : false,
name: path_with_namespace,
id,
branch: default_branch,
});
}
return { repos: repoData, hasNextPage };
}

async function fetchAllRepos(
client: types.Gitlab,
client: gitBeakerTypes.Gitlab,
groupName: string,
page = 0,
): Promise<GitlabRepoData[]> {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/source-handlers/gitlab/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export interface GitlabRepoData {
// fork: boolean;
fork: boolean;
branch: string;
id: number;
name: string;
Expand Down
4 changes: 2 additions & 2 deletions test/scripts/generate-targets-data.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('generateTargetsImportDataFile Github script', () => {
});
it('generate Github repo data', async () => {
process.env.GITHUB_TOKEN = process.env.GH_TOKEN;
filesToDelete.push(path.resolve(__dirname + '/github-import-targets.json'));
filesToDelete.push(path.resolve(__dirname + '/github-enterprise-import-targets.json'));
const orgsData: CreatedOrg[] = [
{
orgId: 'org-id',
Expand Down Expand Up @@ -54,7 +54,7 @@ describe('generateTargetsImportDataFile Github script', () => {
it('generate Github Enterprise repo data', async () => {
process.env.GITHUB_TOKEN = process.env.TEST_GHE_TOKEN;
const GHE_URL = process.env.TEST_GHE_URL;
filesToDelete.push(path.resolve(__dirname + '/github-import-targets.json'));
filesToDelete.push(path.resolve(__dirname + '/github-enterprise-import-targets.json'));
const orgsData: CreatedOrg[] = [
{
orgId: 'org-id',
Expand Down