Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gh

Package Overview
Dependencies
Maintainers
2
Versions
136
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gh - npm Package Compare versions

Comparing version 1.7.0 to 1.7.1

24

bin/gh.js

@@ -23,2 +23,3 @@ #!/usr/bin/env node

User = require('../lib/cmds/user').Impl,
config = base.getConfig(),
command,

@@ -33,2 +34,3 @@ commandDir,

parsed,
plugin,
remain;

@@ -80,8 +82,10 @@

if (!command) {
command = base.getPlugin(remain[0]).Impl;
plugin = base.getPlugin(remain[0]);
if (command) {
if (plugin) {
command = plugin.Impl;
// If plugin command exists, register the executed plugin name on
// process.env.PLUGIN. This may simplify core plugin infrastructure.
process.env.PLUGIN = remain[0];
process.env.NODEGH_PLUGIN = remain[0];
}

@@ -92,12 +96,2 @@ }

function expandAlias(options) {
var alias = base.config.alias;
if (alias) {
options.user = alias[options.user] || options.user;
options.fwd = alias[options.fwd] || options.fwd;
options.submit = alias[options.submit] || options.submit;
}
}
function hasCommandInOptions(commands, options) {

@@ -142,3 +136,3 @@ var found = false;

options.number = options.number || [remain[1]];
options.remote = options.remote || base.config.default_remote;
options.remote = options.remote || config.default_remote;

@@ -176,3 +170,3 @@ operations.push(User.login);

expandAlias(options);
base.expandAliases(options);

@@ -179,0 +173,0 @@ // Try to retrieve iterative values from iterative option key,

@@ -19,19 +19,39 @@ /*

// -- Init ---------------------------------------------------------------------
// -- Constants ----------------------------------------------------------------
exports.clone = function(o) {
return JSON.parse(JSON.stringify(o));
};
exports.TIME_DAY = 1000 * 60 * 60 * 24;
exports.getConfigPath = function() {
return path.join(__dirname, '../', '.gh.json');
// -- Config -------------------------------------------------------------------
exports.addPluginConfig = function(config, plugin) {
var pluginConfig,
userConfig;
try {
// Always use the plugin name without prefix. To be safe removing "gh-"
// prefix from passed plugin.
plugin = exports.getPluginBasename(plugin || process.env.NODEGH_PLUGIN);
pluginConfig = require(path.join(
exports.getNodeModulesGlobalPath(), 'gh-' + plugin, '.gh.json'));
// Merge default plugin configuration with the user's.
userConfig = config.plugins[plugin] || {};
Object.keys(userConfig).forEach(function(key) {
pluginConfig[key] = userConfig[key];
});
config.plugins[plugin] = pluginConfig;
}
catch (e) {}
};
exports.getUserHomePath = function() {
return userhome('.gh.json');
exports.clone = function(o) {
return JSON.parse(JSON.stringify(o));
};
exports.getGlobalConfig = function() {
var configPath,
config,
exports.getConfig = function(opt_plugin) {
var config,
configPath,
userConfig;

@@ -53,3 +73,9 @@

return exports.clone(config);
if (opt_plugin) {
exports.getPlugins().forEach(function(plugin) {
exports.addPluginConfig(config, plugin);
});
}
return config;
}

@@ -61,11 +87,59 @@ catch (err) {

exports.config = exports.getGlobalConfig();
exports.getConfigPath = function() {
return path.join(__dirname, '../', '.gh.json');
};
exports.getUserHomePath = function() {
return userhome('.gh.json');
};
exports.removeGlobalConfig = function(key) {
var config = exports.getConfig();
delete config[key];
fs.writeFileSync(
exports.getUserHomePath(),
JSON.stringify(config, null, 4)
);
};
exports.writeGlobalConfig = function(jsonPath, value) {
var config = exports.getConfig(),
i,
output,
path,
pathLen;
path = jsonPath.split('.');
output = config;
for (i = 0, pathLen = path.length; i < pathLen; i++) {
output[path[i]] = config[path[i]] || (i + 1 === pathLen ? value : {});
output = output[path[i]];
}
fs.writeFileSync(
exports.getUserHomePath(),
JSON.stringify(config, null, 4)
);
};
exports.writeGlobalConfigCredentials = function(user, token) {
var configPath = exports.getUserHomePath();
exports.writeGlobalConfig('github_user', user);
exports.writeGlobalConfig('github_token', token);
logger.success('Writing GH config data: ' + configPath);
};
// -- Utils --------------------------------------------------------------------
var baseConfig = exports.getConfig();
exports.github = new github({
debug: false,
host: exports.config.api.host,
protocol: exports.config.api.protocol,
version: exports.config.api.version
host: baseConfig.api.host,
protocol: baseConfig.api.protocol,
version: baseConfig.api.version
});

@@ -79,3 +153,4 @@

plugins.forEach(function(plugin) {
packagesPath.push(path.join(exports.getNodeModulesGlobalPath(), plugin, 'package'));
packagesPath.push(
path.join(exports.getNodeModulesGlobalPath(), plugin, 'package'));
});

@@ -86,3 +161,3 @@

packagePath: path,
updateCheckInterval: 1000 * 60 * 60 * 24 // 1 day
updateCheckInterval: exports.TIME_DAY
});

@@ -98,2 +173,12 @@

exports.expandAliases = function(options) {
var config = exports.getConfig();
if (config.alias) {
options.fwd = config.alias[options.fwd] || options.fwd;
options.submit = config.alias[options.submit] || options.submit;
options.user = config.alias[options.user] || options.user;
}
};
exports.find = function(filepath, opt_pattern) {

@@ -117,2 +202,8 @@ return fs.readdirSync(filepath).filter(function(file) {

exports.getUser = function() {
return exports.getConfig().github_user;
};
// -- Plugins ------------------------------------------------------------------
exports.getPlugin = function(plugin) {

@@ -126,35 +217,2 @@ plugin = exports.getPluginBasename(plugin);

exports.getPluginConfig = function(opt_plugin) {
var config = exports.getGlobalConfig(),
pluginConfig,
pluginConfigDir,
pluginUserConfig;
opt_plugin = opt_plugin || process.env.PLUGIN;
if (opt_plugin) {
// Always use the plugin name without prefix. To be safe removing "gh-"
// prefix from passed opt_plugin.
opt_plugin = exports.getPluginBasename(opt_plugin);
try {
pluginConfigDir = path.join(
exports.getNodeModulesGlobalPath(), 'gh-' + opt_plugin, '.gh.json');
pluginConfig = require(pluginConfigDir);
// Merge default plugin configuration with the user's.
pluginUserConfig = config.plugins[opt_plugin] || {};
Object.keys(pluginUserConfig).forEach(function(key) {
pluginConfig[key] = pluginUserConfig[key];
});
config.plugins[opt_plugin] = pluginConfig;
}
catch (e) {}
}
return config;
};
exports.getPluginPath = function(plugin) {

@@ -179,11 +237,7 @@ try {

exports.getPluginBasename = function(plugin) {
return plugin.replace('gh-', '');
return plugin && plugin.replace('gh-', '');
};
exports.getUser = function() {
return exports.config.github_user;
};
exports.isPluginIgnored = function(plugin) {
if (exports.config.ignored_plugins.indexOf(exports.getPluginBasename(plugin)) > -1) {
if (exports.getConfig().ignored_plugins.indexOf(exports.getPluginBasename(plugin)) > -1) {
return true;

@@ -194,39 +248,1 @@ }

};
exports.removeGlobalConfig = function(key) {
delete exports.config[key];
fs.writeFileSync(
exports.getUserHomePath(),
JSON.stringify(exports.config, null, 4)
);
};
exports.writeGlobalConfig = function(jsonPath, value) {
var config = exports.getGlobalConfig(),
i,
output,
path,
pathLen;
path = jsonPath.split('.');
output = config;
for (i = 0, pathLen = path.length; i < pathLen; i++) {
output[path[i]] = config[path[i]] || (i + 1 === pathLen ? value : {});
output = output[path[i]];
}
fs.writeFileSync(
exports.getUserHomePath(),
JSON.stringify(config, null, 4)
);
};
exports.writeGlobalConfigCredentials = function(user, token) {
var configPath = exports.getUserHomePath();
exports.writeGlobalConfig('github_user', user);
exports.writeGlobalConfig('github_token', token);
logger.success('Writing GH config data: ' + configPath);
};

@@ -14,3 +14,4 @@ /*

var base = require('../base'),
logger = require('../logger');
logger = require('../logger'),
config = base.getConfig();

@@ -102,3 +103,3 @@ // -- Constructor ----------------------------------------------------------------------------------

Alias.prototype.list = function(opt_callback) {
opt_callback && opt_callback(null, base.config.alias);
opt_callback && opt_callback(null, config.alias);
};

@@ -110,7 +111,7 @@

delete base.config.alias[options.remove];
delete config.alias[options.remove];
base.writeGlobalConfig('alias', base.config.alias);
base.writeGlobalConfig('alias', config.alias);
};
exports.Impl = Alias;

@@ -17,5 +17,5 @@ /*

hooks = require('../hooks'),
inquirer = require('inquirer'),
logger = require('../logger'),
openUrl = require('open'),
prompt = require('prompt');
openUrl = require('open');

@@ -84,18 +84,19 @@ // -- Constructor ----------------------------------------------------------------------------------

prompt.get({
properties: {
confirmation: {
description: 'Are you sure? This action CANNOT be undone. [y/N]'
inquirer.prompt(
[
{
type: 'input',
message: 'Are you sure? This action CANNOT be undone. [y/N]',
name: 'confirmation'
}
}
}, function(err, result) {
if (result.confirmation.toLowerCase() === 'y') {
instance.delete(options.delete, logger.defaultCallback);
], function(answers) {
if (answers.confirmation.toLowerCase() === 'y') {
instance.delete(options.delete, logger.defaultCallback);
afterHooksCallback();
}
else {
logger.info('Not deleted.');
}
});
afterHooksCallback();
}
else {
logger.info('Not deleted.');
}
});
});

@@ -102,0 +103,0 @@ }

@@ -17,3 +17,4 @@ /*

logger = require('../logger'),
openUrl = require('open');
openUrl = require('open'),
config = base.getConfig();

@@ -231,3 +232,3 @@ // -- Constructor ----------------------------------------------------------------------------------

options.comment = logger.applyReplacements(options.comment) + base.config.signature;
options.comment = logger.applyReplacements(options.comment) + config.signature;

@@ -234,0 +235,0 @@ payload = {

@@ -19,3 +19,4 @@ /*

openUrl = require('open'),
issueImpl = require('./issue').Impl;
issueImpl = require('./issue').Impl,
config = base.getConfig();

@@ -138,3 +139,3 @@ // -- Constructor ----------------------------------------------------------------------------------

if (!options.list) {
options.branch = options.branch || base.config.default_branch;
options.branch = options.branch || config.default_branch;
}

@@ -456,3 +457,3 @@

if (number) {
return base.config.pull_branch_name_prefix + number;
return config.pull_branch_name_prefix + number;
}

@@ -466,3 +467,3 @@ };

prefix = base.config.pull_branch_name_prefix;
prefix = config.pull_branch_name_prefix;

@@ -469,0 +470,0 @@ if (options.currentBranch && options.currentBranch.indexOf(prefix) > -1) {

@@ -19,3 +19,3 @@ /*

openUrl = require('open'),
prompt = require('prompt'),
inquirer = require('inquirer'),
url = require('url');

@@ -104,18 +104,19 @@

prompt.get({
properties: {
confirmation: {
description: 'Are you sure? This action CANNOT be undone. [y/N]'
inquirer.prompt(
[
{
type: 'input',
message: 'Are you sure? This action CANNOT be undone. [y/N]',
name: 'confirmation'
}
}
}, function(err, result) {
if (result.confirmation.toLowerCase() === 'y') {
instance.delete(options.user, options.delete, logger.defaultCallback);
], function(answers) {
if (answers.confirmation.toLowerCase() === 'y') {
instance.delete(options.user, options.delete, logger.defaultCallback);
afterHooksCallback();
}
else {
logger.info('Not deleted.');
}
});
afterHooksCallback();
}
else {
logger.info('Not deleted.');
}
});
});

@@ -122,0 +123,0 @@ }

@@ -16,3 +16,4 @@ /*

logger = require('../logger'),
prompt = require('prompt');
inquirer = require('inquirer'),
config = base.getConfig();

@@ -76,5 +77,7 @@ // -- Constructor ----------------------------------------------------------------------------------

User.authorize = function() {
config = base.getConfig();
base.github.authenticate({
type: 'oauth',
token: base.config.github_token
token: config.github_token
});

@@ -86,16 +89,15 @@ };

prompt.get([
inquirer.prompt(
[
{
name: 'username',
message: 'Username',
empty: false
type: 'input',
message: 'Enter your GitHub user',
name: 'user'
},
{
name: 'password',
message: 'Password',
empty: false,
hidden: true
type: 'password',
message: 'Enter your GitHub password',
name: 'password'
}
],
function(err, result) {
], function(answers) {
var payload = {

@@ -109,11 +111,12 @@ note: 'Node GH',

type: 'basic',
username: result.username,
password: result.password
username: answers.user,
password: answers.password
});
base.github.authorization.create(payload, function(err, res) {
logger.defaultCallback(err, null, 'Authentication completed.');
logger.defaultCallback(err, null, 'Authentication succeed.');
if (res.token) {
base.writeGlobalConfigCredentials(result.username, res.token);
base.writeGlobalConfigCredentials(answers.user, res.token);
User.authorize();

@@ -128,3 +131,3 @@ }

User.hasCredentials = function() {
if (base.config.github_token && base.config.github_user) {
if (config.github_token && config.github_user) {
return true;

@@ -131,0 +134,0 @@ }

@@ -16,3 +16,4 @@ /*

truncate = require('truncate'),
logger = require('./logger');
logger = require('./logger'),
config = base.getConfig(true);

@@ -22,3 +23,3 @@ exports.createContext = function(scope) {

options: scope.options,
signature: base.config.signature
signature: config.signature
};

@@ -42,5 +43,5 @@ };

},
function(error, stdout, stdin) {
function(error, stdout) {
if (opt_log) {
logger.log(error, stdout, stdin);
logger.log(stdout);
}

@@ -61,3 +62,3 @@

opt_config = opt_config || base.config;
opt_config = opt_config || config;

@@ -85,4 +86,3 @@ hooks = opt_config.hooks || {};

plugins.forEach(function(plugin) {
var config = base.getPluginConfig(plugin),
pluginConfig;
var pluginConfig;

@@ -107,11 +107,18 @@ plugin = base.getPluginBasename(plugin);

before = exports.getHooksFromPath(path + '.before'),
beforeOperations = [],
afterOperations = [],
beforeOperations,
afterOperations,
context;
if (process.env.NODEGH_HOOK_IS_LOCKED) {
opt_callback && opt_callback();
return;
}
context = exports.createContext(scope);
beforeOperations.push(function(callback) {
exports.setupPlugins_(context, 'setupBeforeHooks', callback);
});
beforeOperations = [
function(callback) {
exports.setupPlugins_(context, 'setupBeforeHooks', callback);
}
];

@@ -122,5 +129,7 @@ before.forEach(function(cmd) {

afterOperations.push(function(callback) {
exports.setupPlugins_(context, 'setupAfterHooks', callback);
});
afterOperations = [
function(callback) {
exports.setupPlugins_(context, 'setupAfterHooks', callback);
}
];

@@ -131,2 +140,9 @@ after.forEach(function(cmd) {

afterOperations.push(function(callback) {
process.env.NODEGH_HOOK_IS_LOCKED = false;
callback();
});
process.env.NODEGH_HOOK_IS_LOCKED = true;
async.series(beforeOperations, function() {

@@ -144,11 +160,8 @@ opt_callback && opt_callback(function() {

plugins.forEach(function(plugin) {
operations.push(function(callback) {
try {
plugin = base.getPlugin(plugin);
plugin = base.getPlugin(plugin);
if (plugin && plugin[setupFn]) {
operations.push(function(callback) {
plugin[setupFn](context, callback);
}
catch (e) {
callback();
}
});
});
}
});

@@ -155,0 +168,0 @@

@@ -30,6 +30,7 @@ /*

logger.applyReplacements = function(output) {
var configReplace,
var config = base.getConfig(),
configReplace,
regexPattern;
configReplace = base.config.replace;
configReplace = config.replace;

@@ -36,0 +37,0 @@ for (regexPattern in configReplace) {

{
"name": "gh",
"description": "GitHub command line tools.",
"version": "1.7.0",
"version": "1.7.1",
"homepage": "http://nodegh.io",

@@ -44,7 +44,7 @@ "author": {

"git-wrapper": "0.1.1",
"github": "0.1.10",
"github": "0.1.11",
"inquirer": "0.3.4",
"wordwrap": "0.0.2",
"nopt": "2.1.1",
"open": "0.0.3",
"prompt": "0.2.9",
"truncate": "1.0.2",

@@ -51,0 +51,0 @@ "update-notifier": "0.1.3",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc