Skip to content

Commit

Permalink
Updates the usage of octokit to remove warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
orta committed Feb 2, 2019
1 parent e1ea3dc commit ac268aa
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 31 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
},
"dependencies": {
"@babel/polyfill": "^7.2.5",
"@octokit/rest": "^16.3.0",
"@octokit/rest": "^16.14.1",
"chalk": "^2.3.0",
"commander": "^2.18.0",
"debug": "^4.1.1",
Expand Down
16 changes: 8 additions & 8 deletions source/platforms/github/GitHubAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,21 @@ export class GitHubAPI {
* but for now that's just a refactor someone can try.
*/
getExternalAPI = (accessTokenForApp?: string): GitHubNodeAPI => {
// A token should have been set by this point
const token = accessTokenForApp || this.token!

const host = process.env["DANGER_GITHUB_API_BASE_URL"] || process.env["GITHUB_URL"] || undefined
const options: GitHubNodeAPI.Options & { debug: boolean } = {
debug: !!process.env.LOG_FETCH_REQUESTS,
baseUrl: host,
headers: {
...this.additionalHeaders,
},
auth: `token ${token}`,
}
// A token should have been set by this point
const token = accessTokenForApp || this.token!

const api = new GitHubNodeAPI(options)
api.authenticate({ type: "token", token: token })
if (this.additionalHeaders) {
options.headers = this.additionalHeaders
}

return api
return new GitHubNodeAPI(options)
}

/**
Expand Down
17 changes: 12 additions & 5 deletions source/runner/jsonToDSL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,21 @@ const apiForDSL = (dsl: DangerDSLJSONType): OctoKit | BitBucketServerAPI => {
const options: OctoKit.Options & { debug: boolean } = {
debug: !!process.env.LOG_FETCH_REQUESTS,
baseUrl: dsl.settings.github.baseURL,
headers: {
...dsl.settings.github.additionalHeaders,
},
}

const api = new OctoKit(options)
// Peril will need changes for this
if (
dsl.settings.github &&
dsl.settings.github.additionalHeaders &&
Object.keys(dsl.settings.github.additionalHeaders).length
) {
options.headers = dsl.settings.github.additionalHeaders
}

if (dsl.settings.github && dsl.settings.github.accessToken) {
api.authenticate({ type: "token", token: dsl.settings.github.accessToken })
options.auth = `token ${dsl.settings.github.accessToken}`
}

const api = new OctoKit(options)
return api
}
28 changes: 11 additions & 17 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@
resolved "https://registry.yarnpkg.com/@nodelib/fs.stat/-/fs.stat-1.1.2.tgz#54c5a964462be3d4d78af631363c18d6fa91ac26"
integrity sha512-yprFYuno9FtNsSHVlSWd+nRlmGoAbqbeCwOryP6sC/zoCjhpArcRMYp19EvpSUSizJAlsXEwJv+wcWS9XaXdMw==

"@octokit/endpoint@^3.0.0":
"@octokit/endpoint@^3.1.1":
version "3.1.1"
resolved "https://registry.yarnpkg.com/@octokit/endpoint/-/endpoint-3.1.1.tgz#ede9afefaa4d6b7584169e12346425c6fbb45cc3"
integrity sha512-KPkoTvKwCTetu/UqonLs1pfwFO5HAqTv/Ksp9y4NAg//ZgUCpvJsT4Hrst85uEzJvkB8+LxKyR4Bfv2X8O4cmQ==
Expand All @@ -703,12 +703,12 @@
universal-user-agent "^2.0.1"
url-template "^2.0.8"

"@octokit/request@2.2.0":
version "2.2.0"
resolved "https://registry.yarnpkg.com/@octokit/request/-/request-2.2.0.tgz#f4b2d1ad7c4c8a0b148193610c912046961f8be5"
integrity sha512-4P9EbwKZ4xfyupVMb3KVuHmM+aO2fye3nufjGKz/qDssvdJj9Rlx44O0FdFvUp4kIzToy3AHLTOulEIDAL+dpg==
"@octokit/request@2.3.0":
version "2.3.0"
resolved "https://registry.yarnpkg.com/@octokit/request/-/request-2.3.0.tgz#da2672308bcf0b9376ef66f51bddbe5eb87cc00a"
integrity sha512-5YRqYNZOAaL7+nt7w3Scp6Sz4P2g7wKFP9npx1xdExMomk8/M/ICXVLYVam2wzxeY0cIc6wcKpjC5KI4jiNbGw==
dependencies:
"@octokit/endpoint" "^3.0.0"
"@octokit/endpoint" "^3.1.1"
is-plain-object "^2.0.4"
node-fetch "^2.3.0"
universal-user-agent "^2.0.1"
Expand All @@ -728,16 +728,15 @@
node-fetch "^2.1.1"
url-template "^2.0.8"

"@octokit/rest@^16.3.0":
version "16.3.0"
resolved "https://registry.yarnpkg.com/@octokit/rest/-/rest-16.3.0.tgz#98a24a3334312a87fff8a2a54c1dca4d0900d54d"
integrity sha512-u0HkROLB0nOSfJhkF5FKMg6I12m6cN5S3S73Lwtfgrs9u4LhgUCZN2hC2KDyIaT7nhvNe9Kx0PgxhhD6li6QsA==
"@octokit/rest@^16.14.1":
version "16.14.1"
resolved "https://registry.yarnpkg.com/@octokit/rest/-/rest-16.14.1.tgz#d7c65be7b8c78c889b121619422e7cf5335b1239"
integrity sha512-etBdt7br4aSUmgTnaO3pRodzVLhwGQTqUbMrEIdFBGjWlJYfoTa9LieIAtdig6UaDs6InPk0isguPZxU7vCTlQ==
dependencies:
"@octokit/request" "2.2.0"
"@octokit/request" "2.3.0"
before-after-hook "^1.2.0"
btoa-lite "^1.0.0"
lodash.get "^4.4.2"
lodash.pick "^4.4.0"
lodash.set "^4.3.2"
lodash.uniq "^4.5.0"
octokit-pagination-methods "^1.1.0"
Expand Down Expand Up @@ -5852,11 +5851,6 @@ lodash.once@^4.0.0:
resolved "https://registry.yarnpkg.com/lodash.once/-/lodash.once-4.1.1.tgz#0dd3971213c7c56df880977d504c88fb471a97ac"
integrity sha1-DdOXEhPHxW34gJd9UEyI+0cal6w=

lodash.pick@^4.4.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/lodash.pick/-/lodash.pick-4.4.0.tgz#52f05610fff9ded422611441ed1fc123a03001b3"
integrity sha1-UvBWEP/53tQiYRRB7R/BI6AwAbM=

lodash.set@^4.3.2:
version "4.3.2"
resolved "https://registry.yarnpkg.com/lodash.set/-/lodash.set-4.3.2.tgz#d8757b1da807dde24816b0d6a84bea1a76230b23"
Expand Down

0 comments on commit ac268aa

Please sign in to comment.