diff --git a/README.md b/README.md index 615f109..5c05904 100644 --- a/README.md +++ b/README.md @@ -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\ diff --git a/jtrack/main.py b/jtrack/main.py index 2a16d71..be3a738 100644 --- a/jtrack/main.py +++ b/jtrack/main.py @@ -103,7 +103,7 @@ 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.') @@ -111,22 +111,32 @@ def upsert_jira(identifier, project, summary, skip_existing, jira_closed, attach 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'] @@ -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 @@ -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() @@ -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', @@ -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,