Skip to content

Commit

Permalink
Merge pull request #407 from snyk-tech-services/fix/gitlab-imports
Browse files Browse the repository at this point in the history
fix: fix Gitlab target check
  • Loading branch information
lili2311 authored Dec 19, 2022
2 parents 44c4837 + 02aaa9a commit 0c6c31c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
6 changes: 1 addition & 5 deletions src/lib/api/import/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export async function importTarget(
try {
const body = {
target: isGitlabTarget(target)
? _.pick(target, ...targetPropsWithId)
? _.pick(target, 'id', 'branch')
: _.pick(target, ...targetProps),
files,
exclusionGlobs,
Expand Down Expand Up @@ -161,10 +161,6 @@ export async function importTargets(

function isGitlabTarget(target: Target): boolean {
const keys = Object.keys(target);

if (keys.length !== 2) {
return false;
}
if (keys.find((k) => k === 'id') && keys.find((k) => k === 'branch')) {
return true;
}
Expand Down
14 changes: 14 additions & 0 deletions test/scripts/fixtures/import-projects-gitlab.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"targets": [
{
"orgId": "74e2f385-a54f-491e-9034-76c53e72927a",
"integrationId": "5b9a5e7f-56ac-45a3-85f1-a60e887643da",
"target": {
"name": "test-maven",
"branch": "develop",
"id": 226,
"fork": false
}
}
]
}
23 changes: 23 additions & 0 deletions test/scripts/import-projects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,34 @@ describe('Import projects script', () => {
targetFile: expect.any(String),
});
const logFile = fs.readFileSync(logFiles.importLogPath, 'utf8');
// Github project
expect(logFile).toMatch(
`"target":{"name":"ruby-with-versions","owner":"api-import-circle-test","branch":"master"}`,
);
discoveredProjects.push(...projects);
}, 2400000);

it.skip('succeeds to import Gitlab project from file', async () => {
const logFiles = generateLogsPaths(__dirname, ORG_ID);
logs = Object.values(logFiles);

const { projects } = await importProjects(
path.resolve(__dirname + `/fixtures/import-projects-gitlab.json`),
__dirname,
);
expect(projects).not.toBe([]);
expect(projects[0]).toMatchObject({
projectUrl: expect.any(String),
success: true,
targetFile: expect.any(String),
});
const logFile = fs.readFileSync(logFiles.importLogPath, 'utf8');
// Gitlab project
expect(logFile).toMatch(
`"target":{"name":"test-maven","branch":"develop"}`,
);
discoveredProjects.push(...projects);
}, 2400000);
});

describe('Import skips previously imported', () => {
Expand Down

0 comments on commit 0c6c31c

Please sign in to comment.