Skip to content

Commit

Permalink
Merge pull request #1 from gabber12/feature/transition-issues
Browse files Browse the repository at this point in the history
Added Ability to transition issues by the move command
  • Loading branch information
gabber12 authored Feb 5, 2017
2 parents 7ef8bb2 + e1e4164 commit d511a2d
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 13 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# python-jira
A simple Atlassian jira cli client written in python

## Build
This is a little convoluted. The only option to install is installing by source.
```sh
$ pip install -r requirements.txt
$ python pjira # run directly through python
```

## QuickStart
Intial configuration include providing Jira details.
Expand Down Expand Up @@ -33,4 +39,14 @@ $ jira create JIRA -s "Suitable summary text"\
# Comment on an issue
$ jira comment JIRA-100 'Added jira comment'

# Transition issues to possible states.
$ jira move JIRA-100
101 On Hold
90 Start Development
Please enter the id of transition: 90
$ jira move JIRA-100
91 Send for code review
101 On Hold
Please enter the id of transition: 101

```
19 changes: 16 additions & 3 deletions pjira/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import click
from utils import ConfigManager, InvalidConfiguration, EditorMode, ask_for_confirmation
from utils import ConfigManager, InvalidConfiguration, EditorMode, ask_for_confirmation, prompt
from jira_service import Jira, IssueMapper
import editor

Expand Down Expand Up @@ -27,6 +27,17 @@ def issue(issue_key, full):
rep = mapper.get_long_rep() if full else mapper.get_short_rep()
print rep

@cli.command()
@click.argument("issue_key")
def move(issue_key):
"""Gets issue by issue key"""
jra = Jira.get_jira_service(); # Check for exception and ask user to configure
issue = jra.get_issue(issue_key)
possible_transitions = jra.get_transitions(issue)
print map(lambda x: printf(x['id']+" "+x['name']), possible_transitions)
res = prompt("Please enter the id of transition: ", map(lambda x: x['id'], possible_transitions))
print jra.transition_issue(issue, res)

@cli.command("ls")
@click.option("--project", "-p", help="Project name")
@click.option("--assignee", "-s", help ="Filter by assignee")
Expand All @@ -36,6 +47,8 @@ def list(project, assignee, all):
jra = Jira.get_jira_service();
issues = jra.get_issue_for_user(assignee, project, all) # shift list representation logic to IssueMapper
issue_reps = map(lambda x:IssueMapper(x).get_short_rep(), issues)
if len(issue_reps) == 0:
print "No issue found for you"
map(printf, issue_reps)

@cli.command("create")
Expand All @@ -51,12 +64,12 @@ def create(project, type,summary, desc, edit_mode):
interface.open()
data = interface.parse()
summary = data['summary']
description = data['description']
desc = data['description']
if not ask_for_confirmation('Are you sure you want to create issue(Y/N): '):
print 'Operation Aborted'
return None
jra = Jira.get_jira_service();
issue = jra.create_issue(project, summary, description, type)
issue = jra.create_issue(project, summary, desc, type)
print IssueMapper(issue).get_long_rep()

@cli.command("comment")
Expand Down
18 changes: 11 additions & 7 deletions pjira/jira_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ def get_issue(self, issue_key):
issue = self.jra.issue(issue_key)
return issue

def create_issue(self, project, title, desc, type ):
def create_issue(self, project, title, desc, issue_type ):
issue_detail = {
'project': {'key':project},
'summary': title,
'description': desc,
'issuetype':{'name':type}
'issuetype':{'name':issue_type}
}
return self.jra.create_issue(fields = issue_detail)

Expand All @@ -35,19 +35,23 @@ def get_issue_for_user(self, user, project, all):
jql = jql + " and resolution = Unresolved" if not all else jql
print jql
return self.jra.search_issues(jql)

def add_comment(self, issue_key, comment):
comment = self.jra.add_comment(issue_key, comment);


def get_transitions(self, issue):
return self.jra.transitions(issue)

def transition_issue(self, issue, transition_id):
return self.jra.transition_issue(issue, transition_id)
class IssueMapper(object):
def __init__(self, issue):
self.issue = issue

def get_short_rep(self):

return "[%s] - %s" % (self.issue.fields.issuetype, self.issue.fields.summary)
return "%s [%s] - %s" % (self.issue.key, self.issue.fields.issuetype, self.issue.fields.summary)

def get_long_rep(self):
desc = self.issue.fields.description
desc = desc.strip() if desc is not None else ""
return "[Type] - %s\n[Title] - %s\n[Assignee] - %s\t[Reporter] - %s\n[Description]\n%s" % (self.issue.fields.issuetype, self.issue.fields.summary.strip(), self.issue.fields.assignee, self.issue.fields.reporter, desc)
return "[%s - %s] %s\n[Assignee] - %s\t[Reporter] - %s\n[Description]\n%s" % (self.issue.key, self.issue.fields.issuetype, self.issue.fields.summary.strip(), self.issue.fields.assignee, self.issue.fields.reporter, desc)
9 changes: 6 additions & 3 deletions pjira/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,17 @@ def __str__(self):
return repr(self.value)

def ask_for_confirmation(text):
res = prompt(text, ['y', 'n'])
return res == 'y'

def prompt(text, input_values):
while True:
res = str(input(text))
if res.lower() not in ['y', 'n']:
if res.lower() not in input_values:
print 'Please try with a valid response'
continue
else:
return res.lower() == 'y'

return res


def save_json_to_file(json_obj, file):
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
jira
click

0 comments on commit d511a2d

Please sign in to comment.