This repository has been archived by the owner on Nov 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## [1.13.8](v1.13.7...v1.13.8) (2019-01-01) ### Bug Fixes * **travis:** run build script on release stage ([d4566c0](d4566c0))
- Loading branch information
1 parent
d4566c0
commit db829b3
Showing
22 changed files
with
4,240 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
"use strict"; | ||
/** | ||
* © 2013 Liferay, Inc. <https://liferay.com> and Node GH contributors | ||
* (see file: CONTRIBUTORS) | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const fs = require("fs"); | ||
const Github = require("github"); | ||
const path = require("path"); | ||
const updateNotifier = require("update-notifier"); | ||
const configs = require("./configs"); | ||
// -- Config ------------------------------------------------------------------- | ||
const config = configs.getConfig(); | ||
function clone(o) { | ||
return JSON.parse(JSON.stringify(o)); | ||
} | ||
exports.clone = clone; | ||
// -- Utils -------------------------------------------------------------------- | ||
function load() { } | ||
exports.load = load; | ||
exports.github = setupGithubClient(config); | ||
function asyncReadPackages(callback) { | ||
function read(err, data) { | ||
if (err) { | ||
throw err; | ||
} | ||
callback(JSON.parse(data)); | ||
} | ||
fs.readFile(path.join(__dirname, '..', 'package.json'), read); | ||
configs.getPlugins().forEach(plugin => { | ||
fs.readFile(path.join(configs.getNodeModulesGlobalPath(), plugin, 'package.json'), read); | ||
}); | ||
} | ||
exports.asyncReadPackages = asyncReadPackages; | ||
function notifyVersion(pkg) { | ||
var notifier = updateNotifier({ pkg }); | ||
if (notifier.update) { | ||
notifier.notify(); | ||
} | ||
} | ||
exports.notifyVersion = notifyVersion; | ||
function checkVersion() { | ||
asyncReadPackages(notifyVersion); | ||
} | ||
exports.checkVersion = checkVersion; | ||
function expandAliases(options) { | ||
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.expandAliases = expandAliases; | ||
function find(filepath, opt_pattern) { | ||
return fs.readdirSync(filepath).filter(file => { | ||
return (opt_pattern || /.*/).test(file); | ||
}); | ||
} | ||
exports.find = find; | ||
function getUser() { | ||
return config.github_user; | ||
} | ||
exports.getUser = getUser; | ||
// Export some config methods to allow plugins to access them | ||
exports.getConfig = configs.getConfig; | ||
exports.writeGlobalConfig = configs.writeGlobalConfig; | ||
function setupGithubClient(config) { | ||
const github = new Github({ | ||
debug: false, | ||
host: config.api.host, | ||
protocol: config.api.protocol, | ||
version: config.api.version, | ||
pathPrefix: config.api.pathPrefix, | ||
}); | ||
function paginate(method) { | ||
return function paginatedMethod(payload, cb) { | ||
let results = []; | ||
const getSubsequentPages = (link, pagesCb) => { | ||
if (github.hasNextPage(link)) { | ||
github.getNextPage(link, (err, res) => { | ||
if (err) { | ||
return pagesCb(err); | ||
} | ||
results = res; | ||
return getSubsequentPages(res.meta.link, pagesCb); | ||
}); | ||
} | ||
pagesCb(); | ||
}; | ||
method(payload, (err, res) => { | ||
if (err) { | ||
return cb(err, null); | ||
} | ||
if (!Array.isArray(res)) { | ||
return cb(err, res); | ||
} | ||
results = res; | ||
getSubsequentPages(res.meta.link, err => { | ||
cb(err, results); | ||
}); | ||
}); | ||
}; | ||
} | ||
for (let key in github.repos) { | ||
if (typeof github.repos[key] === 'function') { | ||
github.repos[key] = paginate(github.repos[key]); | ||
} | ||
} | ||
return github; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
"use strict"; | ||
/** | ||
* © 2013 Liferay, Inc. <https://liferay.com> and Node GH contributors | ||
* (see file: CONTRIBUTORS) | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
function CmdAnonymizer(commandDetails, redaction) { | ||
this.last = null; | ||
this.invoked = []; | ||
this.redaction = redaction; | ||
this.options = commandDetails.options; | ||
this.shorthands = commandDetails.shorthands; | ||
} | ||
CmdAnonymizer.prototype.extractArgument = function (word) { | ||
return word.replace(/-{0,2}/, ''); | ||
}; | ||
CmdAnonymizer.prototype.isOptionValue = function (option, value) { | ||
const choice = this.options[option]; | ||
const booleans = ['true', 'false']; | ||
return ((choice instanceof Array && choice.indexOf(value) !== -1) || | ||
(choice === Boolean && booleans.indexOf(value.toLowerCase()) !== -1) || | ||
(typeof choice === 'string' && choice === value)); | ||
}; | ||
CmdAnonymizer.prototype.isValueInOptions = function (options, value) { | ||
if (!(options instanceof Array)) { | ||
return this.isOptionValue(options, value); | ||
} | ||
return options.some(function (each) { | ||
return this.isOptionValue(this.extractArgument(each), value); | ||
}, this); | ||
}; | ||
CmdAnonymizer.prototype.classify = function (word) { | ||
const arg = this.extractArgument(word); | ||
const whitelist = ['verbose', 'no-hooks']; | ||
if (whitelist.indexOf(arg) === 0) { | ||
this.invoked.push(word); | ||
this.last = arg; | ||
return; | ||
} | ||
if (this.shorthands && this.shorthands[arg]) { | ||
this.invoked.push(word); | ||
this.last = this.shorthands[arg]; | ||
return; | ||
} | ||
if (this.options && this.options[arg]) { | ||
this.invoked.push(word); | ||
this.last = arg; | ||
return; | ||
} | ||
if (this.options && this.isValueInOptions(this.last, word)) { | ||
this.invoked.push(word); | ||
this.last = undefined; | ||
return; | ||
} | ||
if (this.options && | ||
this.options[this.last] instanceof Array && | ||
this.options[this.last].indexOf(word) !== -1) { | ||
this.invoked.push(word); | ||
this.last = undefined; | ||
return; | ||
} | ||
this.invoked.push(this.redaction); | ||
this.last = undefined; | ||
}; | ||
CmdAnonymizer.prototype.resolve = function (cmd) { | ||
// quasi-strict white list approach (best-effort) | ||
this.invoked.push(cmd.shift()); | ||
cmd.forEach(this.classify, this); | ||
return this.invoked; | ||
}; | ||
CmdAnonymizer.prototype.resolveToString = function (cmd) { | ||
return this.resolve(cmd).join(' '); | ||
}; | ||
module.exports = CmdAnonymizer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
"use strict"; | ||
/** | ||
* © 2013 Liferay, Inc. <https://liferay.com> and Node GH contributors | ||
* (see file: CONTRIBUTORS) | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// -- Requires ------------------------------------------------------------------------------------- | ||
// export const hi = 'hi' | ||
const async = require("async"); | ||
const fs = require("fs"); | ||
const nopt = require("nopt"); | ||
const path = require("path"); | ||
const base_1 = require("./base"); | ||
const user_1 = require("./cmds/user"); | ||
const configs = require("./configs"); | ||
const git = require("./git"); | ||
const config = configs.getConfig(); | ||
// -- Utils ---------------------------------------------------------------------------------------- | ||
function hasCommandInOptions(commands, options) { | ||
if (commands) { | ||
return commands.some(c => { | ||
return options[c] !== undefined; | ||
}); | ||
} | ||
return false; | ||
} | ||
function invokePayload(options, command, cooked, remain) { | ||
var payload; | ||
if (command.DETAILS.payload && !hasCommandInOptions(command.DETAILS.commands, options)) { | ||
payload = remain.concat(); | ||
payload.shift(); | ||
command.DETAILS.payload(payload, options); | ||
} | ||
} | ||
function resolveCmd(name, commandDir) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const commandFiles = base_1.find(commandDir, /\.js$/i); | ||
const commandName = commandFiles.filter(file => { | ||
switch (file) { | ||
case 'milestone.js': | ||
if (name === 'ms') | ||
return true; | ||
break; | ||
case 'notification.js': | ||
if (name === 'nt') | ||
return true; | ||
break; | ||
case 'pull-request.js': | ||
if (name === 'pr') | ||
return true; | ||
break; | ||
} | ||
if (file.startsWith(name)) { | ||
return true; | ||
} | ||
return false; | ||
})[0]; | ||
if (commandName) { | ||
return yield Promise.resolve().then(() => require(path.join(commandDir, commandName))); | ||
} | ||
return resolvePlugin(name); | ||
}); | ||
} | ||
function resolvePlugin(name) { | ||
// If plugin command exists, register the executed plugin name on | ||
// process.env. This may simplify core plugin infrastructure. | ||
process.env.NODEGH_PLUGIN = name; | ||
return { default: configs.getPlugin(name).Impl }; | ||
} | ||
function loadCommand(name) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let Command; | ||
const commandDir = path.join(__dirname, 'cmds'); | ||
const commandPath = path.join(commandDir, `${name}.js`); | ||
if (fs.existsSync(commandPath)) { | ||
Command = yield Promise.resolve().then(() => require(commandPath)); | ||
} | ||
else { | ||
Command = yield resolveCmd(name, commandDir); | ||
} | ||
return Command.default; | ||
}); | ||
} | ||
function setUp() { | ||
let Command; | ||
let iterative; | ||
let options; | ||
const operations = []; | ||
const parsed = nopt(process.argv); | ||
let remain = parsed.argv.remain; | ||
let cooked = parsed.argv.cooked; | ||
operations.push(callback => { | ||
base_1.checkVersion(); | ||
callback(); | ||
}); | ||
operations.push((callback) => __awaiter(this, void 0, void 0, function* () { | ||
var module = remain[0]; | ||
if (cooked[0] === '--version' || cooked[0] === '-v') { | ||
module = 'version'; | ||
} | ||
else if (!remain.length || cooked.indexOf('-h') >= 0 || cooked.indexOf('--help') >= 0) { | ||
module = 'help'; | ||
} | ||
try { | ||
Command = yield loadCommand(module); | ||
} | ||
catch (err) { | ||
throw new Error(`Cannot find module ${module}\n${err}`); | ||
} | ||
options = nopt(Command.DETAILS.options, Command.DETAILS.shorthands, process.argv, 2); | ||
iterative = Command.DETAILS.iterative; | ||
cooked = options.argv.cooked; | ||
remain = options.argv.remain; | ||
options.number = options.number || [remain[1]]; | ||
options.remote = options.remote || config.default_remote; | ||
if (module === 'help') { | ||
callback(); | ||
} | ||
else { | ||
user_1.default.login(callback); | ||
} | ||
})); | ||
async.series(operations, () => __awaiter(this, void 0, void 0, function* () { | ||
let iterativeValues; | ||
const remoteUrl = git.getRemoteUrl(options.remote); | ||
options.isTTY = {}; | ||
options.isTTY.in = Boolean(process.stdin.isTTY); | ||
options.isTTY.out = Boolean(process.stdout.isTTY); | ||
options.loggedUser = base_1.getUser(); | ||
options.remoteUser = git.getUserFromRemoteUrl(remoteUrl); | ||
if (!options.user) { | ||
if (options.repo || options.all) { | ||
options.user = options.loggedUser; | ||
} | ||
else { | ||
options.user = process.env.GH_USER || options.remoteUser || options.loggedUser; | ||
} | ||
} | ||
options.repo = options.repo || git.getRepoFromRemoteURL(remoteUrl); | ||
options.currentBranch = options.currentBranch || git.getCurrentBranch(); | ||
base_1.expandAliases(options); | ||
options.github_host = config.github_host; | ||
options.github_gist_host = config.github_gist_host; | ||
// Try to retrieve iterative values from iterative option key, | ||
// e.g. option['number'] === [1,2,3]. If iterative option key is not | ||
// present, assume [undefined] in order to initialize the loop. | ||
iterativeValues = options[iterative] || [undefined]; | ||
iterativeValues.forEach((value) => __awaiter(this, void 0, void 0, function* () { | ||
options = base_1.clone(options); | ||
// Value can be undefined when the command doesn't have a iterative | ||
// option. | ||
options[iterative] = value; | ||
invokePayload(options, Command, cooked, remain); | ||
if (process.env.NODE_ENV === 'testing') { | ||
const { prepareTestFixtures } = yield Promise.resolve().then(() => require('./utils')); | ||
yield new Command(options).run(prepareTestFixtures(Command.name, cooked)); | ||
} | ||
else { | ||
yield new Command(options).run(); | ||
} | ||
})); | ||
})); | ||
} | ||
exports.setUp = setUp; | ||
function run() { | ||
if (!fs.existsSync(configs.getUserHomePath())) { | ||
configs.createGlobalConfig(); | ||
} | ||
base_1.load(); | ||
configs.getConfig(); | ||
// If configs.PLUGINS_PATH_KEY is undefined, try to cache it before proceeding. | ||
if (configs.getConfig()[configs.PLUGINS_PATH_KEY] === undefined) { | ||
configs.getNodeModulesGlobalPath(); | ||
} | ||
try { | ||
process.env.GH_PATH = path.join(__dirname, '../'); | ||
this.setUp(); | ||
} | ||
catch (e) { | ||
console.error(e.stack || e); | ||
} | ||
} | ||
exports.run = run; |
Oops, something went wrong.