Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add detailed info about feature; enable transition by name; enable r… #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 7 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jira.init().then(function(){
.command('search [search terms]')
.description('Search issues')
.alias('s')
.option("-j, --jql <jql search string>", "Search issues with raw jql")
.action((c, o) => {
jira.cmdSearch(c, o);
});
Expand Down Expand Up @@ -71,11 +72,13 @@ jira.init().then(function(){
.command('issue [command]')
.description('Issue commands')
.alias('i')
.option("-d, --details", "Print issue detailed info")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexadept where are you passing this option to the findIssue method? I can't find it, are you currently able to trigger the detailed condition?

I think we'll need to pass the detail option (if it's present) here:

jira-cli/src/jira.js

Lines 286 to 289 in 704defd

} else {
// If none of the above options is passed then search for specific issue
this.issues.findIssue( args );
}

What do you think?

.option("-r, --release <version>", "Get the given release issues")
.option("-p, --project <projectKey>", "Set the current project")
.option("-u, --user <username>", "Set the user name")
.option("-a, --assign <username>", "Assign issue to a user")
.option("-t, --transition [transitionName]", "Make issue transition")
.option("--trs, --transitions", "Get list of issue possible transitions")
.option("-h, --help", "")
.action((c, o) => {
jira.cmdIssue(c, o);
Expand Down
93 changes: 87 additions & 6 deletions src/issues.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,26 @@ export default class JiraIssues {
});
}

/**
* search issue viq raw jql
*/

jqlSearch ( jql_string ) {
const _this = this;
jira.api.searchJira( jql_string ).then(function( r ){
if( r.total ){
_this.showIssues( r.issues );
console.log( color.bold( " Total issues found: " + color.green( r.total ) ) );
console.log('');
} else {
jira.showError( "No issues found with search terms: '" + args + "'" );
}
}).catch(function( res ){
jira.showErrors( res );
process.exit();
});
}

/**
* Open issue in default browser
*/
Expand Down Expand Up @@ -236,7 +256,7 @@ export default class JiraIssues {
/**
* Show issue detail in pretty format
*/
showIssue( issue ) {
showIssue( issue, detailed ) {
const table = new Table({ chars: jira.tableChars });
const detailTable = new Table({ chars: jira.tableChars });
let status;
Expand All @@ -260,12 +280,18 @@ export default class JiraIssues {
break;
}

table.push({ 'Summary': issue.fields.summary.trim() });
if ( detailed ) {
table.push({ 'Desc': issue.fields.description })
};
table.push(
{ 'Summary': issue.fields.summary.trim() }
, { 'Status': status }
{ 'Status': status }
, { 'Type': issue.fields.issuetype.name }
, { 'Project': issue.fields.project.name + ' (' + issue.fields.project.key + ')' }
, { 'Reporter': issue.fields.reporter.name });
if ( detailed ) {
table.push({ 'Attachnemt count': issue.fields.attachment.length })
};

// If issue has assignee
if( issue.fields.assignee != null ) {
Expand Down Expand Up @@ -300,6 +326,17 @@ export default class JiraIssues {
}

console.log( table.toString() );
if ( detailed ) {
console.log('Comments:')
issue.fields.comment.comments.map((comment) => {
console.log(color.yellow('--------------------'));
console.log(color.italic(comment.body));
console.log();
console.log('Created: ' + moment(comment.created).format('MMMM Do YYYY, h:mm:ss a'))
console.log('Author: ' + comment.author.name);
console.log();
})
}
}

/**
Expand Down Expand Up @@ -347,11 +384,11 @@ export default class JiraIssues {
/**
* Find specific issue
*/
findIssue( issue ) {
findIssue( issue, detailed ) {
const _this = this;

jira.api.findIssue( issue ).then(function( r ){
_this.showIssue( r );
_this.showIssue( r, detailed );
}).catch(function( res ){
jira.showErrors( res );
process.exit();
Expand Down Expand Up @@ -432,14 +469,48 @@ export default class JiraIssues {
});
}

/**
* list of issue transitions
*/
async listTransitions( issueId ) {
const transitions = await this.getIssueTransitions(issueId);
const table = new Table({ chars: jira.tableChars, head: ['id', 'name', 'to'] });
transitions.map(function(tr) {
table.push(
[
color.green(tr['id']),
tr['name'],
tr['to']
]
)
});
console.log(color.bold.blue( issueId.toUpperCase() ) + ' available transitions:');
console.log(table.toString());
return transitions
}

/**
* Make issue transition
*/
async makeTransition( issueId ){
async makeTransition( issueId, transitionValue ){

const transitions = await this.getIssueTransitions(issueId);
const _this = this;

const passedTransition = transitions.find(function(tr) {
if ( tr.id == transitionValue || tr.name == transitionValue ) {
return tr;
}
});
if ( transitionValue && typeof(transitionValue) != typeof(true) && !passedTransition ) {
const listOfPossible = transitions.map((tr) => { return(`id: ${tr.id}, name: ${tr.name}`) })
const listOfPossibleForPrint = JSON.stringify(listOfPossible, null, 2)
jira.showErrors(
`Transition '${transitionValue}' does not found. list of possible transition:\n${listOfPossibleForPrint}`
);
return
}

if ( transitions.length == 1 ) {

const obj = {
Expand All @@ -451,6 +522,16 @@ export default class JiraIssues {

return this.transitionIssue( issueId, obj );

} else if (passedTransition) {

const obj = {
transition: {
id: passedTransition.id
},
to: passedTransition.to
}
return this.transitionIssue( issueId, obj );

} else {

var question = [
Expand Down
13 changes: 10 additions & 3 deletions src/jira.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,12 @@ class JiraCLI {
/**
* Search
*/
cmdSearch( args ){
this.issues.search( args );
cmdSearch( args, options ){
if ( options.jql ) {
this.issues.jqlSearch( options.jql );
} else {
this.issues.search( args );
}
}

/**
Expand Down Expand Up @@ -281,8 +285,11 @@ class JiraCLI {
// Assign issue to a user
this.issues.assignIssue( args, options.assign );
} else if ( options.transition ) {
//Make issue transition
// Make issue transition
this.issues.makeTransition( args, options.transition);
} else if ( options.transitions ) {
// Show all posible issue transitions
this.issues.listTransitions( args );
} else {
// If none of the above options is passed then search for specific issue
this.issues.findIssue( args );
Expand Down