diff --git a/nodejs/rest.js b/nodejs/rest.js index e200f14..40482de 100644 --- a/nodejs/rest.js +++ b/nodejs/rest.js @@ -54,21 +54,4 @@ export default class API { } -export class CodeScan extends API { - async listForOrg(org) { - const {data} = await this.client.codeScanning.listAlertsForOrg({ - org, - }); - return data - } - - async listForRepo(org, repo) { - const {data} = await this.client.codeScanning.listAlertsForRepo({ - repo: repo, - owner: org - }) - return data - } -} - diff --git a/nodejs/security.js b/nodejs/security.js new file mode 100644 index 0000000..ea12eac --- /dev/null +++ b/nodejs/security.js @@ -0,0 +1,45 @@ +import API from "./rest.js"; + +export class CodeScan extends API { + async listForOrg(org) { + const {data} = await this.client.codeScanning.listAlertsForOrg({ + org, + }); + return data + } + + async listForRepo(org, repo) { + const {data} = await this.client.codeScanning.listAlertsForRepo({ + repo, + owner: org + }) + return data + } +} + +export class SecretScan extends API { + async listForOrg(org) { + const {data} = await this.client.secretScanning.listAlertsForOrg({org}) + return data + } + + async listForRepo(org, repo) { + const {data} = await this.client.secretScanning.listAlertsForRepo({ + owner: org, + repo + }) + return data + } +} + +export class Dependabot extends API { + async listForOrg(org) { + const {data} = await this.client.dependabot.listAlertsForOrg({org}) + return data + } + + async listForRepo(org, repo) { + const {data} = await this.client.dependabot.listAlertsForRepo({owner: org, repo}) + return data + } +} \ No newline at end of file diff --git a/nodejs/test/rest.js b/nodejs/test/rest.js index b4b7550..c9bb199 100644 --- a/nodejs/test/rest.js +++ b/nodejs/test/rest.js @@ -1,4 +1,4 @@ -import API, {CodeScan} from '../rest.js'; +import API from '../rest.js'; import assert from 'assert'; describe('octokit:rest module', function () { @@ -26,22 +26,3 @@ describe('octokit:rest module', function () { assert.equal(user_view_type, 'private') }) }) -describe('codeScan', function () { - this.timeout(0) - - it('list for repos', async () => { - const pat = process.env.GITHUB_TOKEN - const api = new CodeScan({pat}) - const org = 'davidkhala' - const repo = 'ci-cd-utils' - const data = await api.listForRepo(org, repo) - console.debug(data) - }) - it('list for org', async () => { - const pat = process.env.GITHUB_TOKEN - const api = new CodeScan({pat}) - const org = 'stage4fish' - const data = await api.listForOrg(org) - console.debug(data) - }) -}) \ No newline at end of file diff --git a/nodejs/test/security.js b/nodejs/test/security.js new file mode 100644 index 0000000..c3260a8 --- /dev/null +++ b/nodejs/test/security.js @@ -0,0 +1,56 @@ +import {CodeScan, Dependabot, SecretScan} from "../security.js"; +import assert from "assert"; +const pat = process.env.GITHUB_TOKEN +describe('codeScan', function () { + this.timeout(0) + const api = new CodeScan({pat}) + it('list for repos', async () => { + + const org = 'davidkhala' + const repo = 'ci-cd-utils' + const data = await api.listForRepo(org, repo) + console.debug(data) + await assert.rejects(async()=>{ + await api.listForRepo(undefined, `${org}/${repo}`) + }, 'HttpError: Not Found - https://docs.github.com/rest') + + }) + it('list for org', async () => { + + const org = 'stage4fish' + const data = await api.listForOrg(org) + console.debug(data) + }) +}) +describe('secretScans', function () { + this.timeout(0) + const api = new SecretScan({pat}) + it('list for repos', async () => { + + const org = 'davidkhala' + const repo = 'ci-cd-utils' + const data = await api.listForRepo(org, repo) + console.debug(data) + }) + it('list for org', async () => { + const org = 'stage4fish' + const data = await api.listForOrg(org) + console.debug(data) + }) +}) +describe('Dependabot', function (){ + this.timeout(0) + const api = new Dependabot({pat}) + it('list for repos', async ()=>{ + + const org = 'davidkhala' + const repo = 'ci-cd-utils' + const data = await api.listForRepo(org, repo) + console.debug(data) + }) + it('list for org', async ()=>{ + const org = 'stage4fish' + const data = await api.listForOrg(org) + console.debug(data) + }) +}) \ No newline at end of file