Skip to content

Commit

Permalink
Update to octokit
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Duncan committed Jun 9, 2021
1 parent ac85275 commit 1a1155e
Show file tree
Hide file tree
Showing 5 changed files with 2,119 additions and 59 deletions.
8 changes: 3 additions & 5 deletions lib/files-changed-determiner.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
const { promisify } = require('util')
const getCommit = gh => async data => {
let commitData = null
const options = {
user: data.repo.namespace,
owner: data.repo.namespace,
repo: data.repo.name
}

let action = 'compareCommits'
// github sends this in some instances: first commit on a new branch?
if (!data.build.before || data.build.before === '0000000000000000000000000000000000000000') {
options.sha = data.build.after
options.ref = data.build.after
action = 'getCommit'
} else {
options.base = data.build.before
options.head = data.build.after
}

const comparison = await promisify(gh.repos[action])(options)
const comparison = await gh.rest.repos[action](options)
return comparison.files.map(f => f.filename)
}

Expand Down
5 changes: 2 additions & 3 deletions lib/parsed-yaml-retriever.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
const { promisify } = require('util')
const yaml = require('yaml')
const getParsedYaml = gh => async data => {
let contents = data.yaml
if (!contents) {
const options = {
user: data.repo.namespace,
owner: data.repo.namespace,
repo: data.repo.name,
ref: data.build.ref,
path: data.repo.config_path
}
const file = await promisify(gh.repos.getContent)(options)
const file = gh.rest.repos.getContent(options)
if (!file.content) {
console.log('GH Response:', file)
throw new Error('Unexpected response from GitHub')
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
"dependencies": {
"body-parser": "^1.18.3",
"express": "^4.16.4",
"github4": "^1.1.1",
"globule": "^1.2.1",
"http-signature": "^1.2.0",
"octokit": "^1.0.5",
"yaml": "^1.7.1"
}
}
7 changes: 4 additions & 3 deletions plugin.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const express = require('express')
const bodyParser = require('body-parser')
const GhApi = require('github4')
const { Octokit } = require('@octokit/rest')
const yaml = require('yaml')
const glob = require('globule')
const createFilesChangedDeterminer = require('./lib/files-changed-determiner')
Expand All @@ -10,8 +10,9 @@ const isValidSig = require('./lib/signature-validator')
const githubToken = process.env.GITHUB_TOKEN
const sharedKey = process.env.PLUGIN_SECRET

const gh = new GhApi({ version: '3.0.0' })
gh.authenticate({ type: 'token', token: githubToken })
const gh = new Octokit({
auth: githubToken
})

const determineFilesChanged = createFilesChangedDeterminer(gh)
const getParsedYaml = createParsedYamlRetriever(gh)
Expand Down
Loading

0 comments on commit 1a1155e

Please sign in to comment.