From de10722ca536423cbb6b0d20a528ea452efb8337 Mon Sep 17 00:00:00 2001 From: Aleksey Ostapenko Date: Tue, 15 Mar 2016 20:13:20 +0300 Subject: [PATCH] Support github enterprise urls from config --- lib/cmds/gists.js | 7 +++++-- lib/cmds/issue.js | 4 +++- lib/cmds/pull-request.js | 4 +++- lib/cmds/repo.js | 7 +++++-- lib/configs.js | 10 ++++++++++ lib/logger.js | 14 +++++++------- 6 files changed, 33 insertions(+), 13 deletions(-) diff --git a/lib/cmds/gists.js b/lib/cmds/gists.js index 36cf961d..3c517939 100644 --- a/lib/cmds/gists.js +++ b/lib/cmds/gists.js @@ -17,7 +17,8 @@ var base = require('../base'), hooks = require('../hooks'), inquirer = require('inquirer'), logger = require('../logger'), - openUrl = require('open'); + openUrl = require('open'), + config = base.getConfig(); // -- Constructor ---------------------------------------------------------------------------------- @@ -74,6 +75,8 @@ Gists.prototype.run = function () { operations, options = instance.options; + instance.config = config; + if (options.paste) { logger.error('Sorry, this functionality was removed.'); return; @@ -168,7 +171,7 @@ Gists.prototype.run = function () { }; Gists.prototype.browser = function (gist) { - openUrl('https://gist.github.com/' + gist); + openUrl(config.github_gist_host + gist); }; Gists.prototype.delete = function (id, opt_callback) { diff --git a/lib/cmds/issue.js b/lib/cmds/issue.js index cf844a6e..b84df399 100644 --- a/lib/cmds/issue.js +++ b/lib/cmds/issue.js @@ -110,6 +110,8 @@ Issue.prototype.run = function () { var instance = this, options = instance.options; + instance.config = config; + options.state = options.state || Issue.STATE_OPEN; if (options.browser) { @@ -217,7 +219,7 @@ Issue.prototype.browser = function (user, repo, number) { number = ''; } - openUrl('https://github.com/' + user + '/' + repo + '/issues/' + number); + openUrl(config.github_host + user + '/' + repo + '/issues/' + number); }; Issue.prototype.close = function (opt_callback) { diff --git a/lib/cmds/pull-request.js b/lib/cmds/pull-request.js index 7e224ff0..ffbddda1 100755 --- a/lib/cmds/pull-request.js +++ b/lib/cmds/pull-request.js @@ -135,6 +135,8 @@ PullRequest.prototype.run = function () { var instance = this, options = instance.options; + instance.config = config; + options.number = options.number || instance.getPullRequestNumberFromBranch_(); options.pullBranch = instance.getBranchNameFromPullNumber_(options.number); options.state = options.state || PullRequest.STATE_OPEN; @@ -226,7 +228,7 @@ PullRequest.prototype.addComplexityParamToPulls_ = function (pulls, opt_callback }; PullRequest.prototype.browser = function (user, repo, number) { - openUrl('https://github.com/' + user + '/' + repo + '/pull/' + number); + openUrl(config.github_host + user + '/' + repo + '/pull/' + number); }; PullRequest.prototype.calculateComplexity_ = function (metrics) { diff --git a/lib/cmds/repo.js b/lib/cmds/repo.js index bdfce4fb..e38ecaca 100644 --- a/lib/cmds/repo.js +++ b/lib/cmds/repo.js @@ -19,7 +19,8 @@ var base = require('../base'), logger = require('../logger'), openUrl = require('open'), inquirer = require('inquirer'), - url = require('url'); + url = require('url'), + config = base.getConfig(); // -- Constructor ---------------------------------------------------------------------------------- @@ -92,6 +93,8 @@ Repo.prototype.run = function () { options = instance.options, user = options.loggedUser; + instance.config = config; + if (options.browser) { instance.browser(options.user, options.repo); } @@ -204,7 +207,7 @@ Repo.prototype.run = function () { }; Repo.prototype.browser = function (user, repo) { - openUrl('https://github.com/' + user + '/' + repo); + openUrl(config.github_host + user + '/' + repo); }; Repo.prototype.clone_ = function (user, repo, repo_url) { diff --git a/lib/configs.js b/lib/configs.js index 08d1a2ed..57decf45 100644 --- a/lib/configs.js +++ b/lib/configs.js @@ -81,6 +81,16 @@ exports.getConfig = function (opt_plugin) { cache[opt_plugin] = config; } + var protocol = config.api.protocol + '://', + is_enterprise = (config.api.host !== 'api.github.com'); + + if (config.github_host === undefined) { + config.github_host = protocol + (is_enterprise ? config.api.host : 'github.com') + '/'; + } + if (config.github_gist_host === undefined) { + config.github_gist_host = protocol + (is_enterprise ? config.api.host + '/gist' : 'gist.github.com') + '/'; + } + return config; }; diff --git a/lib/logger.js b/lib/logger.js index 4ddd03bb..f63af5d5 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -158,36 +158,36 @@ logger.registerHelpers_ = function () { }); handlebars.registerHelper('compareLink', function () { - return 'https://github.com/' + this.options.user + '/' + this.options.repo + + return this.config.github_host + this.options.user + '/' + this.options.repo + '/compare/' + this.options.pullHeadSHA + '...' + this.options.currentSHA; }); handlebars.registerHelper('forwardedLink', function () { - return 'https://github.com/' + this.options.fwd + '/' + this.options.repo + '/pull/' + + return this.config.github_host + this.options.fwd + '/' + this.options.repo + '/pull/' + this.options.forwardedPull; }); handlebars.registerHelper('link', function () { - return 'https://github.com/' + this.options.user + '/' + this.options.repo + '/pull/' + + return this.config.github_host + this.options.user + '/' + this.options.repo + '/pull/' + this.options.number; }); handlebars.registerHelper('submittedLink', function () { - return 'https://github.com/' + this.options.submit + '/' + this.options.repo + '/pull/' + + return this.config.github_host + this.options.submit + '/' + this.options.repo + '/pull/' + this.options.submittedPull; }); handlebars.registerHelper('issueLink', function () { - return 'https://github.com/' + this.options.user + '/' + this.options.repo + '/issues/' + + return this.config.github_host + this.options.user + '/' + this.options.repo + '/issues/' + this.options.number; }); handlebars.registerHelper('gistLink', function () { - return 'https://gist.github.com/' + this.options.loggedUser + '/' + this.options.id; + return this.config.github_gist_host + this.options.loggedUser + '/' + this.options.id; }); handlebars.registerHelper('repoLink', function () { - return 'https://github.com/' + this.options.user + '/' + this.options.repo; + return this.config.github_host + this.options.user + '/' + this.options.repo; }); handlebars.registerHelper('wordwrap', function (text, padding, stripNewLines) {