Skip to content

Commit 1a1155e

Browse files
author
Adam Duncan
committed
Update to octokit
1 parent ac85275 commit 1a1155e

File tree

5 files changed

+2119
-59
lines changed

5 files changed

+2119
-59
lines changed

lib/files-changed-determiner.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1-
const { promisify } = require('util')
21
const getCommit = gh => async data => {
3-
let commitData = null
42
const options = {
5-
user: data.repo.namespace,
3+
owner: data.repo.namespace,
64
repo: data.repo.name
75
}
86

97
let action = 'compareCommits'
108
// github sends this in some instances: first commit on a new branch?
119
if (!data.build.before || data.build.before === '0000000000000000000000000000000000000000') {
12-
options.sha = data.build.after
10+
options.ref = data.build.after
1311
action = 'getCommit'
1412
} else {
1513
options.base = data.build.before
1614
options.head = data.build.after
1715
}
1816

19-
const comparison = await promisify(gh.repos[action])(options)
17+
const comparison = await gh.rest.repos[action](options)
2018
return comparison.files.map(f => f.filename)
2119
}
2220

lib/parsed-yaml-retriever.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
const { promisify } = require('util')
21
const yaml = require('yaml')
32
const getParsedYaml = gh => async data => {
43
let contents = data.yaml
54
if (!contents) {
65
const options = {
7-
user: data.repo.namespace,
6+
owner: data.repo.namespace,
87
repo: data.repo.name,
98
ref: data.build.ref,
109
path: data.repo.config_path
1110
}
12-
const file = await promisify(gh.repos.getContent)(options)
11+
const file = gh.rest.repos.getContent(options)
1312
if (!file.content) {
1413
console.log('GH Response:', file)
1514
throw new Error('Unexpected response from GitHub')

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
"dependencies": {
1212
"body-parser": "^1.18.3",
1313
"express": "^4.16.4",
14-
"github4": "^1.1.1",
1514
"globule": "^1.2.1",
1615
"http-signature": "^1.2.0",
16+
"octokit": "^1.0.5",
1717
"yaml": "^1.7.1"
1818
}
1919
}

plugin.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const express = require('express')
22
const bodyParser = require('body-parser')
3-
const GhApi = require('github4')
3+
const { Octokit } = require('@octokit/rest')
44
const yaml = require('yaml')
55
const glob = require('globule')
66
const createFilesChangedDeterminer = require('./lib/files-changed-determiner')
@@ -10,8 +10,9 @@ const isValidSig = require('./lib/signature-validator')
1010
const githubToken = process.env.GITHUB_TOKEN
1111
const sharedKey = process.env.PLUGIN_SECRET
1212

13-
const gh = new GhApi({ version: '3.0.0' })
14-
gh.authenticate({ type: 'token', token: githubToken })
13+
const gh = new Octokit({
14+
auth: githubToken
15+
})
1516

1617
const determineFilesChanged = createFilesChangedDeterminer(gh)
1718
const getParsedYaml = createParsedYamlRetriever(gh)

0 commit comments

Comments
 (0)