Skip to content

Commit

Permalink
fix(github): refactor to support latest octokit
Browse files Browse the repository at this point in the history
  • Loading branch information
wyvern8 committed Jun 30, 2018
1 parent 2c840b4 commit 66efe20
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 25 deletions.
22 changes: 7 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
}
},
"dependencies": {
"@octokit/rest": "14.0.5",
"@octokit/rest": "15.9.4",
"app-root-path": "^2.0.1",
"babel-plugin-source-map-support": "^2.0.1",
"babel-plugin-transform-runtime": "^6.23.0",
Expand Down
2 changes: 1 addition & 1 deletion serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ provider:
name: aws
runtime: nodejs8.10
memorySize: 2048 # optional, in MB, default is 1024
timeout: 30 # optional, in seconds, default is 6
timeout: 60 # optional, in seconds, default is 6

stage: ${env:GTM_AWS_STAGE, 'dev'}
region: ${env:GTM_AWS_REGION}
Expand Down
20 changes: 12 additions & 8 deletions src/serverless/gtmGithubUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ let json = require('format-json');
if (process.env.GTM_GITHUB_DEBUG) process.env.DEBUG = 'octokit:rest*';
let GitHubApi = require('@octokit/rest');
let crypto = require('crypto');
let https = require('https');
let githubUpdaters = {
pull_request: updateGitHubPullRequest,
comment: updateGitHubComment,
Expand All @@ -17,13 +18,16 @@ async function connect(context) {
console.log('Connecting to GitHub');
console.log('GitHub SSL Validation: ' + String(ghEnforceValidSsl));
let githubOptions = {
host: process.env.GTM_GITHUB_HOST || 'api.github.com',
debug: process.env.GTM_GITHUB_DEBUG || false,
timeout: parseInt(process.env.GTM_GITHUB_TIMEOUT) || 5000,
pathPrefix: process.env.GTM_GITHUB_PATH_PREFIX || '',
proxy: process.env.GTM_GITHUB_PROXY || '',
rejectUnauthorized: ghEnforceValidSsl
baseUrl: `https://${process.env.GTM_GITHUB_HOST || 'api.github.com'}${process.env.GTM_GITHUB_PATH_PREFIX ||
''}`,
timeout: parseInt(process.env.GTM_GITHUB_TIMEOUT) || 5000
};
if (process.env.GTM_GITHUB_PROXY) {
githubOptions.agent = new https.Agent({
proxy: process.env.GTM_GITHUB_PROXY,
rejectUnauthorized: false
});
}

console.log('Creating GitHub API Connection');
let github = new GitHubApi(githubOptions);
Expand All @@ -44,8 +48,8 @@ async function connect(context) {

// test connection
try {
let meta = await github.misc.getMeta();
console.log(`Connected to GitHub at ${githubOptions.host}. metadata: ${json.plain(meta)}`);
let meta = await github.misc.getMeta({});
console.log(`Connected to GitHub at ${githubOptions.baseUrl}. metadata: ${json.plain(meta)}`);
} catch (e) {
console.log(e);
throw e;
Expand Down

0 comments on commit 66efe20

Please sign in to comment.