Skip to content

Commit

Permalink
Merge pull request #416 from snyk-tech-services/fix/include-more-proj…
Browse files Browse the repository at this point in the history
…ects

fix: include more Gitlab projects that are dropped by a bad shared check
  • Loading branch information
lili2311 authored Dec 28, 2022
2 parents 1c7f57f + eb88944 commit db47216
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions docs/orgs.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ This is an opinionated util and will assume every organization in Github.com / G
--sourceOrgPublicId Public id of the organization in Snyk that
can be used as a template to copy all
supported organization settings.
--skipEmptyOrgs Skip organizations that have no targets.
--skipEmptyOrgs Skip organizations that have no targets.
(e.g. Github Organizations that have no repos)
```
## Github.com / Github Enterprise
Expand All @@ -50,7 +50,7 @@ This will create the organization data in a file `group-<snyk_group_id>-github-<
- **Gitlab:** `snyk-api-import orgs:data --source=gitlab --groupId=<snyk_group_id>`
- **Hosted Gitlab:** `snyk-api-import orgs:data --source=gitlab --groupId=<snyk_group_id> -- sourceUrl=https://gitlab.custom.com`

This will create the organization data in a file `group-<snyk_group_id>-gitlab-orgs.json`
This will create the organization data in a file `group-<snyk_group_id>-gitlab-orgs.json`. Both groups & sub-groups will be [listed](https://docs.gitlab.com/ee/api/groups.html) and then these will become Organizations in Snyk.


## Bitbucket Server
Expand Down
2 changes: 1 addition & 1 deletion src/lib/source-handlers/gitlab/list-repos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export async function fetchGitlabReposForPage(
path_with_namespace,
id,
} = project;
if (groupName !== namespace.name) {
if (groupName !== namespace.full_path) {
debug(
`Skipping project ${project.name_with_namespace} as it belong to another group`,
);
Expand Down
16 changes: 12 additions & 4 deletions test/lib/source-handlers/gitlab/list-repos.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,27 @@ describe('listGitlabRepos', () => {
fork: expect.any(Boolean),
});
expect(
repos.filter((r) => r.name === 'snyk-fixtures/shared-with-group'),
repos.filter((r) => r.name === `${GITLAB_ORG_NAME}/shared-with-group`),
).toHaveLength(1);
});
it('list repos (Gitlab Custom URL) excludes a shared project', async () => {
const GITLAB_BASE_URL = process.env.TEST_GITLAB_BASE_URL;
const GITLAB_ORG_NAME = process.env.TEST_GITLAB_ORG_NAME;
process.env.GITLAB_TOKEN = process.env.TEST_GITLAB_TOKEN;
// shared-with-group project is shared with group snyk-test
const gitlabGroupName = 'snyk-test';

const repos = await listGitlabRepos(gitlabGroupName, GITLAB_BASE_URL);
expect(
repos.filter((r) => r.name === 'snyk-fixtures/shared-with-group'),
repos.filter((r) => r.name === `${GITLAB_ORG_NAME}/shared-with-group`),
).toEqual([]);
expect(repos.length === 0).toBeTruthy();
expect(repos.length > 0).toBeTruthy();
});

it('list repos for a sub-group', async () => {
const GITLAB_BASE_URL = process.env.TEST_GITLAB_BASE_URL;
process.env.GITLAB_TOKEN = process.env.TEST_GITLAB_TOKEN;
const gitlabGroupName = 'snyk-fixtures/example-sub-group';
const repos = await listGitlabRepos(gitlabGroupName, GITLAB_BASE_URL);
expect(repos.length > 0).toBeTruthy();
});
});
2 changes: 1 addition & 1 deletion test/system/orgs:data/gitlab.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('General `snyk-api-import orgs:data <...>`', () => {
expect(stderr).toEqual('');
expect(err).toBeNull();
expect(stdout).toMatch(
'Found 14 group(s). Written the data to file: group-hello-gitlab-orgs.json',
'Found 15 group(s). Written the data to file: group-hello-gitlab-orgs.json',
);
deleteFiles([
path.resolve(__dirname, `group-${groupId}-gitlab-orgs.json`),
Expand Down

0 comments on commit db47216

Please sign in to comment.