Skip to content
This repository has been archived by the owner on Nov 4, 2022. It is now read-only.

Commit

Permalink
Support github enterprise urls from config
Browse files Browse the repository at this point in the history
  • Loading branch information
kbakba committed Mar 15, 2016
1 parent d187c99 commit de10722
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 13 deletions.
7 changes: 5 additions & 2 deletions lib/cmds/gists.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ----------------------------------------------------------------------------------

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion lib/cmds/issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -217,7 +219,7 @@ Issue.prototype.browser = function (user, repo, number) {
number = '';
}

openUrl('https:/' + user + '/' + repo + '/issues/' + number);
openUrl(config.github_host + user + '/' + repo + '/issues/' + number);
};

Issue.prototype.close = function (opt_callback) {
Expand Down
4 changes: 3 additions & 1 deletion lib/cmds/pull-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -226,7 +228,7 @@ PullRequest.prototype.addComplexityParamToPulls_ = function (pulls, opt_callback
};

PullRequest.prototype.browser = function (user, repo, number) {
openUrl('https:/' + user + '/' + repo + '/pull/' + number);
openUrl(config.github_host + user + '/' + repo + '/pull/' + number);
};

PullRequest.prototype.calculateComplexity_ = function (metrics) {
Expand Down
7 changes: 5 additions & 2 deletions lib/cmds/repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ----------------------------------------------------------------------------------

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -204,7 +207,7 @@ Repo.prototype.run = function () {
};

Repo.prototype.browser = function (user, repo) {
openUrl('https:/' + user + '/' + repo);
openUrl(config.github_host + user + '/' + repo);
};

Repo.prototype.clone_ = function (user, repo, repo_url) {
Expand Down
10 changes: 10 additions & 0 deletions lib/configs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
14 changes: 7 additions & 7 deletions lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,36 +158,36 @@ logger.registerHelpers_ = function () {
});

handlebars.registerHelper('compareLink', function () {
return 'https:/' + 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:/' + 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:/' + 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:/' + 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:/' + 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:/' + this.options.user + '/' + this.options.repo;
return this.config.github_host + this.options.user + '/' + this.options.repo;
});

handlebars.registerHelper('wordwrap', function (text, padding, stripNewLines) {
Expand Down

0 comments on commit de10722

Please sign in to comment.