diff --git a/bin/jira.js b/bin/jira.js index 66ac7af..7dd5dd7 100755 --- a/bin/jira.js +++ b/bin/jira.js @@ -1,5 +1,11 @@ #!/usr/bin/env node +// See: https://github.com/nodejs/node/issues/6456 +[process.stdout, process.stderr].forEach((s) => { + s && !s.isTTY && s._handle && s._handle.setBlocking && + s._handle.setBlocking(true) +}) + var requirejs = require('requirejs'); // https://docs.atlassian.com/jira/REST/server/?_ga=2.55654315.1871534859.1501779326-1034760119.1468908320#api/2/issueLink-linkIssues // https://developer.atlassian.com/jiradev/jira-apis/about-the-jira-rest-apis/jira-rest-api-tutorials/jira-rest-api-examples#JIRARESTAPIexamples-Creatinganissueusingcustomfields @@ -44,13 +50,14 @@ requirejs([ .description('List my issues') .option('-p, --project ', 'Filter by project', String) .option('-t, --type ', 'Filter by type', String) + .option('-j, --json ', 'Output in json', String, 0) .action(function (options) { auth.setConfig(function (auth) { if (auth) { if (options.project) { - ls.showByProject(options.project, options.type, finalCb); + ls.showByProject(options, finalCb); } else { - ls.showAll(options.type, finalCb); + ls.showAll(options, finalCb); } } }); diff --git a/lib/jira/ls.js b/lib/jira/ls.js index 446bde1..650c071 100644 --- a/lib/jira/ls.js +++ b/lib/jira/ls.js @@ -134,10 +134,10 @@ define([ (halfhours > 0 ? '' + (halfhours / 2) + 'h' : ''); }, - showAll: function (type, cb) { - this.type = (type) ? '+AND+type="' + type + '"' : ''; + showAll: function (options, cb) { + this.type = (options && options.type) ? '+AND+type="' + options.type + '"' : ''; this.query = 'rest/api/2/search?jql=' + 'assignee=currentUser()' + this.type + '+AND+status+in+("' + this.getAvailableStatuses() + '")' + '+order+by+priority+DESC,+key+ASC' + '&maxResults=500'; - return this.getIssues(cb); + return this.getIssues(options, cb); }, showInProgress: function (cb) { @@ -145,11 +145,10 @@ define([ return this.getIssues(cb); }, - showByProject: function (project, type, cb) { - this.type = (type) ? '+AND+type=' + type : ''; - - this.query = 'rest/api/2/search?jql=' + 'assignee=currentUser()' + this.type + '+AND+project=' + project + '+AND+status+in+("' + this.getAvailableStatuses() + '")' + '+order+by+priority+DESC,+key+ASC'; - return this.getIssues(cb); + showByProject: function (options, cb) { + this.type = (options && options.type) ? '+AND+type=' + options.type : ''; + this.query = 'rest/api/2/search?jql=' + 'assignee=currentUser()' + this.type + '+AND+project=' + options.project + '+AND+status+in+("' + this.getAvailableStatuses() + '")' + '+order+by+priority+DESC,+key+ASC'; + return this.getIssues(options, cb); }, search: function (query, cb) { @@ -175,12 +174,15 @@ define([ this.query = 'rest/api/2/search?jql=' + encodeURIComponent(query); return this.getIssues(options, cb); }, + getAvailableStatuses: function () { return config.options.available_issues_statuses.join('", "'); }, + getListIssuesColumns: function() { return config.options.list_issues_columns; }, + getWorkHoursInDay: function() { return config.options.work_hours_in_day },