diff --git a/src/lib/api/import/index.ts b/src/lib/api/import/index.ts index 2b8dddae..4ac0cbcd 100644 --- a/src/lib/api/import/index.ts +++ b/src/lib/api/import/index.ts @@ -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, @@ -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; } diff --git a/test/scripts/fixtures/import-projects-gitlab.json b/test/scripts/fixtures/import-projects-gitlab.json new file mode 100644 index 00000000..0098b0d1 --- /dev/null +++ b/test/scripts/fixtures/import-projects-gitlab.json @@ -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 + } + } + ] +} diff --git a/test/scripts/import-projects.test.ts b/test/scripts/import-projects.test.ts index 3e162a17..3f2c5a6f 100644 --- a/test/scripts/import-projects.test.ts +++ b/test/scripts/import-projects.test.ts @@ -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', () => {