-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from snyk-tech-services/feat/bitbucket-server-c…
…ommand feat: bitbucket-server command
- Loading branch information
Showing
60 changed files
with
10,931 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
version: 2.1 | ||
orbs: | ||
snyk: snyk/[email protected] | ||
jobs: | ||
build-test-monitor: | ||
docker: | ||
- image: circleci/node:latest | ||
steps: | ||
- checkout | ||
- run: npm install semantic-release @semantic-release/exec pkg --save-dev --legacy-peer-deps | ||
- run: npm install | ||
- run: npm test | ||
- snyk/scan: | ||
fail-on-issues: true | ||
monitor-on-build: true | ||
token-variable: SNYK_TOKEN | ||
- run: npx semantic-release | ||
build-test: | ||
docker: | ||
- image: circleci/node:latest | ||
steps: | ||
- checkout | ||
- run: npm install | ||
- run: npm test | ||
- snyk/scan: | ||
fail-on-issues: true | ||
monitor-on-build: false | ||
token-variable: SNYK_TOKEN | ||
- run: npx tsc | ||
build-test-from-fork: | ||
docker: | ||
- image: circleci/node:latest | ||
steps: | ||
- checkout | ||
- run: npm install | ||
- run: npm test | ||
- run: npx tsc | ||
|
||
workflows: | ||
version: 2.1 | ||
nightly: | ||
triggers: | ||
- schedule: | ||
cron: "0 0 * * *" | ||
filters: | ||
branches: | ||
only: | ||
- master | ||
jobs: | ||
- build-test-monitor: | ||
context: SNYK | ||
|
||
build-test-monitor: | ||
jobs: | ||
- build-test-monitor: | ||
context: SNYK | ||
filters: | ||
branches: | ||
only: | ||
- master | ||
|
||
build-test: | ||
jobs: | ||
- build-test: | ||
context: SNYK | ||
filters: | ||
branches: | ||
ignore: | ||
- master | ||
- /pull\/[0-9]+/ | ||
- build-test-from-fork: | ||
filters: | ||
branches: | ||
only: | ||
- /pull\/[0-9]+/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[{"/home/antoine/Documents/SnykTSDev/scm-contributors-count/test/lib/common/utils.test.ts":"1","/home/antoine/Documents/SnykTSDev/scm-contributors-count/test/lib/common/exclusion.test.ts":"2","/home/antoine/Documents/SnykTSDev/scm-contributors-count/test/lib/common/hash.test.ts":"3","/home/antoine/Documents/SnykTSDev/scm-contributors-count/test/lib/common/output.test.ts":"4","/home/antoine/Documents/SnykTSDev/scm-contributors-count/test/lib/snyk/index.test.ts":"5","/home/antoine/Documents/SnykTSDev/scm-contributors-count/test/lib/bitbucket-server/bitbucket-server-contributors.test.ts":"6"},{"size":3140,"mtime":1623684489550,"results":"7","hashOfConfig":"8"},{"size":1219,"mtime":1623683037450,"results":"9","hashOfConfig":"8"},{"size":254,"mtime":1623701850597,"results":"10","hashOfConfig":"8"},{"size":2667,"mtime":1623701964541,"results":"11","hashOfConfig":"8"},{"size":3846,"mtime":1623701850705,"results":"12","hashOfConfig":"8"},{"size":5165,"mtime":1623753089277,"results":"13","hashOfConfig":"8"},{"filePath":"14","messages":"15","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"154ct84",{"filePath":"16","messages":"17","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"18","messages":"19","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"20","messages":"21","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"22","messages":"23","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"24","messages":"25","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/home/antoine/Documents/SnykTSDev/scm-contributors-count/test/lib/common/utils.test.ts",[],"/home/antoine/Documents/SnykTSDev/scm-contributors-count/test/lib/common/exclusion.test.ts",[],"/home/antoine/Documents/SnykTSDev/scm-contributors-count/test/lib/common/hash.test.ts",[],"/home/antoine/Documents/SnykTSDev/scm-contributors-count/test/lib/common/output.test.ts",[],"/home/antoine/Documents/SnykTSDev/scm-contributors-count/test/lib/snyk/index.test.ts",[],"/home/antoine/Documents/SnykTSDev/scm-contributors-count/test/lib/bitbucket-server/bitbucket-server-contributors.test.ts",[]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"parser": "@typescript-eslint/parser", | ||
"plugins": ["@typescript-eslint"], | ||
"parserOptions": { | ||
"ecmaVersion": 6 | ||
}, | ||
"env": { | ||
"node": true, | ||
"es6": true | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/eslint-recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"prettier" | ||
], | ||
"rules": { | ||
"@typescript-eslint/explicit-function-return-type": [ | ||
"error", | ||
{ | ||
"allowExpressions": true, | ||
"allowTypedFunctionExpressions": true | ||
} | ||
], | ||
"no-var": "error", | ||
"prefer-arrow-callback": "error", | ||
"prefer-const": "error" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dist | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"arrowParens": "always", | ||
"trailingComma": "all", | ||
"singleQuote": true, | ||
"htmlWhitespaceSensitivity": "ignore" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{ | ||
"prepare": [ | ||
"@semantic-release/npm", | ||
{ | ||
"//": "adds a file to identify a build as a standalone binary", | ||
"path": "@semantic-release/exec", | ||
"cmd": "echo '' > dist/STANDALONE" | ||
}, | ||
{ | ||
"//": "build the alpine, macos, linux and windows binaries", | ||
"path": "@semantic-release/exec", | ||
"cmd": "npx pkg . -t node14-linux-x64,node14-macos-x64,node14-win-x64" | ||
}, | ||
{ | ||
"//": "shasum all binaries", | ||
"path": "@semantic-release/exec", | ||
"cmd": "shasum -a 256 snyk-delta-linux > snyk-delta-linux.sha256 && shasum -a 256 snyk-delta-macos > snyk-delta-macos.sha256 && shasum -a 256 snyk-delta-win.exe > snyk-delta-win.exe.sha256" | ||
}, | ||
{ | ||
"//": "removes the file we use to identify a build as a standalone binary", | ||
"path": "@semantic-release/exec", | ||
"cmd": "rm dist/STANDALONE" | ||
} | ||
], | ||
"publish": [ | ||
"@semantic-release/npm", | ||
{ | ||
"path": "@semantic-release/github", | ||
"assets": [ | ||
{ | ||
"path": "./snyk-delta-linux", | ||
"name": "snyk-delta-linux", | ||
"label": "snyk-delta-linux" | ||
}, | ||
{ | ||
"path": "./snyk-delta-linux.sha256", | ||
"name": "snyk-delta-linux.sha256", | ||
"label": "snyk-delta-linux.sha256" | ||
}, | ||
{ | ||
"path": "./snyk-delta-macos", | ||
"name": "snyk-delta-macos", | ||
"label": "snyk-delta-macos" | ||
}, | ||
{ | ||
"path": "./snyk-delta-macos.sha256", | ||
"name": "snyk-delta-macos.sha256", | ||
"label": "snyk-delta-macos.sha256" | ||
}, | ||
{ | ||
"path": "./snyk-delta-win.exe", | ||
"name": "snyk-delta-win.exe", | ||
"label": "snyk-delta-win.exe" | ||
}, | ||
{ | ||
"path": "./snyk-delta-win.exe.sha256", | ||
"name": "snyk-delta-win.exe.sha256", | ||
"label": "snyk-delta-win.exe.sha256" | ||
} | ||
] | ||
} | ||
], | ||
"branches": ["main"] | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Snyk SCM Contributors counting | ||
|
||
This tool is used to count contributors with commits in the last 90 days in repositories matching the following criteria: | ||
1. Repo name XYZ (single repo mode if available for SCM command - see help) | ||
2. All repos in given projects/org/group (ex: Bitbucket Server project(s)) | ||
3. All repos in given projects/org/group (ex: Bitbucket Server project(s)) AND monitored by Snyk | ||
4. All repos in SCM (varies a little depending on SCM) | ||
5. All repos in SCM (varies a little depending on SCM) AND monitored by Snyk | ||
|
||
### Example | ||
I want to know the countributors count for Snyk monitored projects in bitbucket server project key AN. | ||
|
||
## Installation | ||
``` | ||
npm i snyk-scm-contributor-count | ||
``` | ||
or use corresponding binaries in the [release page](https://github.com/snyk-tech-services/snyk-scm-contributors-count/releases) | ||
|
||
|
||
## Usage | ||
``` | ||
export SNYK_TOKEN=<YOUR-SNYK-TOKEN> | ||
snyk-scm-contributor-count <command> <command-options> | ||
``` | ||
|
||
##### Example: | ||
``` | ||
snyk-scm-contributor-count bitbucket-server --token BITBUCKET-TOKEN --url http://bitbucket-server.mycompany.com --projectKeys Key1,Key2 --exclusionFilePath=./snyk.exclude | ||
``` | ||
|
||
## Common options across commands | ||
- `--skipSnykMonitoredRepos` to skip checking with repos are monitored by Snyk (useful for sizing before Snyk rollout). In that case the SNYK_TOKEN is not required | ||
- `--exclusionFilePath` pointing to snyk.exclude file, simple text file containing emails of committers to exclude (i.e [email protected], etc...) | ||
- `--json` output JSON | ||
|
||
Additional options might be available depending on the command | ||
|
||
### Run in DEBUG MODE | ||
Use DEBUG=snyk* env var before your command, for example: | ||
``` | ||
DEBUG=snyk* snyk-scm-contributor-count bitbucket-server --token BITBUCKET-TOKEN --url http://bitbucket-server.mycompany.com --projectKeys Key1,Key2 --exclusionFilePath=./snyk.exclude | ||
``` | ||
|
||
|
||
|
||
# Development | ||
|
||
|
||
## Add a command and SCM support | ||
|
||
1. Create a new ts file under cmds (duplicate cmds/bitbucket-server.ts) | ||
|
||
2. Fill out command, desc, and builder options, leaving in: | ||
- exclusionFilePath | ||
- json | ||
- skipSnykMonitoredRepos | ||
|
||
3. The handler function will be called with argv which should match the builder options | ||
|
||
4. Create a class with your command name extending SCMHandlerClass. | ||
It'll require you to implement the abstract method `fetchSCMContributors` expecting a `Promise<ContributorMap>` in return | ||
- types can be function in src/lib/types.ts | ||
|
||
5. Once create and asbtract function implemented, in handler, instantiate the class you just created | ||
|
||
6. Call | ||
``` | ||
<classInstance>.scmContributorCount(argv.url,SourceType["YOUR-SOURCE"],argv.skipSnykMonitoredRepos,argv.exclusionFilePath,argv.json) | ||
``` | ||
|
||
7. profit. | ||
|
||
## Build | ||
``` | ||
npm run build | ||
``` | ||
or in watch mode | ||
``` | ||
npm run build-watch | ||
``` | ||
|
||
## Best Practices | ||
- Most SCMs have paginated results, fetch all the relevant pages, only what's useful | ||
- Be gentle with rates against SCM. Use client or throttling libs like bottleneck | ||
- Snyk API interaction is using snyk-api-ts-client with built-in throttling and retries |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
collectCoverageFrom: ['lib/**/*.ts'], | ||
coverageReporters: ['text-summary', 'html'], | ||
}; |
Oops, something went wrong.