Skip to content

Commit a0a2489

Browse files
committed
add ci
1 parent 26e2a81 commit a0a2489

File tree

3 files changed

+62
-8
lines changed

3 files changed

+62
-8
lines changed

.github/workflows/nodejs.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: nodejs
2+
on:
3+
push
4+
jobs:
5+
test:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@main
9+
- uses: actions/setup-node@main
10+
with:
11+
check-latest: true
12+
node-version: lts/*
13+
- run: npm i
14+
working-directory: nodejs
15+
- run: npm test
16+
working-directory: nodejs
17+
env:
18+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

nodejs/rest.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {Octokit} from 'octokit';
22

33

4-
export default class GithubRestAPI {
4+
export default class API {
55
isPublic
66

77
/**
@@ -20,19 +20,19 @@ export default class GithubRestAPI {
2020
opts.baseUrl = baseUrl
2121
}
2222

23-
this.client = new Octokit(opts);
23+
this.client = new Octokit(opts).rest;
2424
}
2525

2626
async me() {
27-
const {data} = await this.client.rest.users.getAuthenticated()
27+
const {data} = await this.client.users.getAuthenticated()
2828
return data
2929
}
3030

3131
async connect() {
3232

3333
try {
3434
if (this.isPublic) {
35-
await this.client.rest.repos.listForOrg({
35+
await this.client.repos.listForOrg({
3636
org: "octokit",
3737
type: "public",
3838
})
@@ -54,4 +54,21 @@ export default class GithubRestAPI {
5454

5555
}
5656

57+
export class CodeScan extends API {
58+
async listForOrg(org) {
59+
const {data} = await this.client.codeScanning.listAlertsForOrg({
60+
org,
61+
});
62+
return data
63+
}
64+
65+
async listForRepo(org, repo) {
66+
const {data} = await this.client.codeScanning.listAlertsForRepo({
67+
repo: repo,
68+
owner: org
69+
})
70+
return data
71+
}
72+
}
73+
5774

nodejs/test/rest.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import GithubRestAPI from '../rest.js';
1+
import API, {CodeScan} from '../rest.js';
22
import assert from 'assert';
33

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

1717
it('connect', async () => {
1818
const pat = process.env.GITHUB_TOKEN
19-
const api = new GithubRestAPI({pat})
19+
const api = new API({pat})
2020
assert.ok(await api.connect())
2121
const {login, type, user_view_type} = await api.me()
2222

@@ -25,4 +25,23 @@ describe('octokit:rest module', function () {
2525
assert.equal(type, 'User')
2626
assert.equal(user_view_type, 'private')
2727
})
28+
})
29+
describe('codeScan', function () {
30+
this.timeout(0)
31+
32+
it('list for repos', async () => {
33+
const pat = process.env.GITHUB_TOKEN
34+
const api = new CodeScan({pat})
35+
const org = 'davidkhala'
36+
const repo = 'ci-cd-utils'
37+
const data = await api.listForRepo(org, repo)
38+
console.debug(data)
39+
})
40+
it('list for org', async () => {
41+
const pat = process.env.GITHUB_TOKEN
42+
const api = new CodeScan({pat})
43+
const org = 'stage4fish'
44+
const data = await api.listForOrg(org)
45+
console.debug(data)
46+
})
2847
})

0 commit comments

Comments
 (0)