Skip to content

Commit

Permalink
feat: improve readme & add netrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
lili2311 committed May 29, 2020
1 parent 73d792c commit ccf19d0
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 5 deletions.
39 changes: 35 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,41 @@ You will need to set the following environment variable:
Run the tests with `npm test`


### Running the script
- `SNYK_HOST`
## To kick off an import
This script is intended to help import projects into Snyk with a controlled pace via API. The script will kick off an import in batches, wait for completion and then keep going. Failure logs will be generated at `SNYK_LOG_PATH` directory.
1. Create the `import-projects.json` file:
`orgId` - Can be found in https://app.snyk.io/org/YOUR_ORG/manage/settings
`integrationId` - Can be found in Integrations menu for each SCM https://app.snyk.io/org/YOUR_ORG/manage/settings


```
{
"targets": [
{
"orgId": "******,
"integrationId": "******",
"target": {
"name": "shallow-goof-policy",
"owner": "snyk-fixtures",
"branch": "master" // optional!
}
},
{
"orgId": "******,
"integrationId": "******",
"target": {
"name": "shallow-goof-policy",
"owner": "snyk-fixtures",
"branch": "master"
}
},
]
}
```
2. Set the env vars mentioned:
- `SNYK_API_TOKEN` - your [Snyk api token](https://app.snyk.io/account)
- `SNYK_LOG_PATH` - the path to folder where all logs should be saved
- `CONCURRENT_IMPORTS` (optional) defaults to 5 which is the recommended amount to import at once as a max.

- `CONCURRENT_IMPORTS` (optional) defaults to 5 repos at a time, which is the recommended amount to import at once as a max. Just 1 repo may have many projects inside. (10 may also be okay if all repos are small)
- `SNYK_HOST` (optional) defaults to `https://snyk.io`

3. `npm run build` and then `DEBUG=snyk* node dist/index.js`
13 changes: 13 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as debugLib from 'debug';
const debug = debugLib('snyk:import-projects-script');

export * from './lib';
import { ImportProjects } from './scripts/import-projects';
import { getImportProjectsFile } from './lib/get-import-path';

try {
const importFile = getImportProjectsFile();
ImportProjects(importFile);
} catch (e) {
debug('Failed to kick off import.\n' + e);
}
9 changes: 9 additions & 0 deletions src/lib/get-import-path.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export function getImportProjectsFile(): string {
const snykImportPath = process.env.SNYK_LOG_PATH;
if (!snykImportPath) {
throw new Error(
`Please set the SNYK_IMPORT_PATH e.g. export SNYK_IMPORT_PATH='~/my/path/to/file'`,
);
}
return snykImportPath;
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"importHelpers": true,
"strict": true
},
"include": ["./src/lib/**/*"]
"include": ["./src/**/**/*"]
}

0 comments on commit ccf19d0

Please sign in to comment.