Skip to content

Commit

Permalink
Merge pull request #5 from brabbit10/add-priority-field
Browse files Browse the repository at this point in the history
Add priority field
  • Loading branch information
rotemreiss authored Jul 12, 2022
2 parents 2baf8a3 + fffe287 commit 777bd0f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ Short Form | Long Form | Description
-i | --identifier | A system identifier for the issue (unique key).
-s | --summary | Value for the summary field.
-d | --description | Value for the description field.
-pr | --priority | Value for the priority field.
-a | --attachment | One or more file paths seperated by comma to be attached
-l | --labels | Jira labels to add to new issues, separated by commas.
-j | --jira-closed-status | Jira statuses that are considered to be closed, defaults to 'Closed' and 'Resolved', separated by commas.
-t | --jira-type | Jira issue type for new tasks, deafults to 'Task'.
-se | --skip-existing | Do nothing if Jira already exists and open.
-q | --quiet | Do not print the banner.
-q | --quiet | Do not print the banner.

### Examples
- List all options\
Expand Down
30 changes: 19 additions & 11 deletions jtrack/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,30 +103,40 @@ def has_existing_task(identifier, jira_closed):


# Upsert a jira issue (wrapper for insert or update actions).
def upsert_jira(identifier, project, summary, skip_existing, jira_closed, attachments, type, description, labels):
def upsert_jira(identifier, project, summary, skip_existing, jira_closed, attachments, type, description, labels, priority):
if has_existing_task(identifier, jira_closed):
if skip_existing:
print('Issue already exists and open. Skipping.')
return False
jira_key = get_jira_key_by_identifier(identifier)
update_jira(jira_key, attachments)
else:
new_jira = create_new_jira(project, type, summary, description, labels, attachments)
new_jira = create_new_jira(project, type, summary, description, labels, attachments, priority)
jira_key = new_jira['key']
upsert_new_identifier(identifier, jira_key)
print(f'Created new Jira ticket: {jira_key}. jTrack id: {identifier}')


# Create a new Jira issue.
def create_new_jira(project, type, summary, description, labels, attachments):
new_task = jira.issue_create(fields={
def create_new_jira(project, type, summary, description, labels, attachments, priority):
fields = {
'project': {'key': project},
'issuetype': {
"name": type
},
'summary': summary,
'labels': labels
})
}

# Add priority
if priority is not None:
fields['priority'] = {'name': priority}

# Add description.
if description is not None:
fields['description'] = description

new_task = jira.issue_create(fields=fields)

jira_key = new_task['id']

Expand All @@ -135,11 +145,6 @@ def create_new_jira(project, type, summary, description, labels, attachments):
for attachment in attachments:
jira.add_attachment(jira_key, attachment)

# Add description.
if description is not None:
desc_field = {'description': description}
jira.update_issue_field(jira_key, desc_field)

return new_task


Expand Down Expand Up @@ -207,7 +212,8 @@ def main(identifier, project, summary, **kwargs):
itype = kwargs.get('type', JIRA_TYPE)
description = kwargs.get('desc', None)
labels = kwargs.get('labels', JIRA_LABELS)
upsert_jira(identifier, project, summary, skip_existing, jira_closed, attachments, itype, description, labels)
priority = kwargs.get('priority', None)
upsert_jira(identifier, project, summary, skip_existing, jira_closed, attachments, itype, description, labels, priority)

db.close()

Expand All @@ -222,6 +228,7 @@ def interactive():
required=True)
parser.add_argument('-s', '--summary', help='Value for the summary field.', dest='summary', required=True)
parser.add_argument('-d', '--description', help='Value for the description field.', dest='desc')
parser.add_argument('-pr', '--priority', help='Value for the priority field.', dest='priority')
parser.add_argument('-a', '--attachment', help='One or more file paths seperated by comma to be attached', type=attachment_arg,
dest='attach')
parser.add_argument('-l', '--labels', nargs='*', help='Jira labels to add to new issues.', dest='labels',
Expand All @@ -243,6 +250,7 @@ def interactive():
args.project,
args.summary,
desc=args.desc,
priority=args.priority,
attach=args.attach,
labels=args.labels,
jira_closed=args.jira_closed,
Expand Down

0 comments on commit 777bd0f

Please sign in to comment.