Skip to content

Commit

Permalink
add ci
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkhala committed Jan 9, 2025
1 parent 26e2a81 commit a0a2489
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 8 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/nodejs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: nodejs
on:
push
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
- uses: actions/setup-node@main
with:
check-latest: true
node-version: lts/*
- run: npm i
working-directory: nodejs
- run: npm test
working-directory: nodejs
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
25 changes: 21 additions & 4 deletions nodejs/rest.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Octokit} from 'octokit';


export default class GithubRestAPI {
export default class API {
isPublic

/**
Expand All @@ -20,19 +20,19 @@ export default class GithubRestAPI {
opts.baseUrl = baseUrl
}

this.client = new Octokit(opts);
this.client = new Octokit(opts).rest;
}

async me() {
const {data} = await this.client.rest.users.getAuthenticated()
const {data} = await this.client.users.getAuthenticated()
return data
}

async connect() {

try {
if (this.isPublic) {
await this.client.rest.repos.listForOrg({
await this.client.repos.listForOrg({
org: "octokit",
type: "public",
})
Expand All @@ -54,4 +54,21 @@ export default class GithubRestAPI {

}

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
}
}


27 changes: 23 additions & 4 deletions nodejs/test/rest.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import GithubRestAPI from '../rest.js';
import API, {CodeScan} from '../rest.js';
import assert from 'assert';

describe('octokit:rest module', function () {
this.timeout(0)
it('public access', async () => {
const api = new GithubRestAPI();
const api = new API();
assert.ok(await api.connect())
const {data} = await api.client.rest.repos.listForOrg({
const {data} = await api.client.repos.listForOrg({
org: "octokit",
type: "public",
})
Expand All @@ -16,7 +16,7 @@ describe('octokit:rest module', function () {

it('connect', async () => {
const pat = process.env.GITHUB_TOKEN
const api = new GithubRestAPI({pat})
const api = new API({pat})
assert.ok(await api.connect())
const {login, type, user_view_type} = await api.me()

Expand All @@ -25,4 +25,23 @@ describe('octokit:rest module', function () {
assert.equal(type, 'User')
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)
})
})

0 comments on commit a0a2489

Please sign in to comment.