Skip to content

Commit 626c309

Browse files
author
Pelle Wessman
committed
Accept issueRules argument to report upload
1 parent 007e0f2 commit 626c309

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ const { SocketSdk } = require('@socketsecurity/sdk')
4848

4949
### Report methods
5050

51-
* `createReportFromFilePaths(filePaths, pathsRelativeTo=.)`
51+
* `createReportFromFilePaths(filePaths, pathsRelativeTo=., [issueRules])`
5252
* `filePaths`: An `array` of absolute or relative `string` paths to `package.json` and any corresponding `package-lock.json` files
5353
* `pathsRelativeTo`: A `string` path that the absolute paths `filePaths` are relative to. This to calculate where in your project the `package.json`/`package-lock.json` files lives
54+
* `issueRules`: An object that follows the format of the [`socket.yml`](https://docs.socket.dev/docs/socket-yml) issue rules. Keys being issue names, values being a boolean that activates or deactivates it. Is applied on top of default config and organization config.
5455
* `getReportList()`
5556
* `getReport(id)`
5657
* `id`: A `string` representing the id of a created report

index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,15 @@ class SocketSdk {
7474
/**
7575
* @param {string[]} filePaths
7676
* @param {string} pathsRelativeTo
77+
* @param {{ [key: string]: boolean }} [issueRules]
7778
* @returns {Promise<SocketSdkResultType<'createReport'>>}
7879
*/
79-
async createReportFromFilePaths (filePaths, pathsRelativeTo = '.') {
80+
async createReportFromFilePaths (filePaths, pathsRelativeTo = '.', issueRules) {
8081
const basePath = path.resolve(process.cwd(), pathsRelativeTo)
8182
const absoluteFilePaths = filePaths.map(filePath => path.resolve(basePath, filePath))
8283

8384
const [
84-
{ FormData },
85+
{ FormData, Blob },
8586
{ fileFromPath },
8687
client
8788
] = await Promise.all([
@@ -92,6 +93,11 @@ class SocketSdk {
9293

9394
const body = new FormData()
9495

96+
if (issueRules) {
97+
const issueRulesBlob = new Blob([JSON.stringify(issueRules)], { type: 'application/json' })
98+
body.set('issueRules', issueRulesBlob, 'issueRules')
99+
}
100+
95101
const files = await Promise.all(absoluteFilePaths.map(absoluteFilePath => fileFromPath(absoluteFilePath)))
96102

97103
for (let i = 0, length = files.length; i < length; i++) {

0 commit comments

Comments
 (0)