Skip to content

Instantly share code, notes, and snippets.

@james-kelly
Created February 27, 2018 21:54
Embed
What would you like to do?
Exports a JQL expression as an Omniplan compatible CSV
import csv
import sys
from enum import Enum
from itertools import groupby
from jira import JIRA
class Omniplan:
class Fields(Enum):
WBS_NUMBER = 'WBS Number'
TITLE = 'Title'
START = 'Start'
END = 'End'
DURATION = 'Duration'
EFFORT = 'Effort'
COMPLETED = 'Completed'
TASK_COST = 'Task Cost'
ASSIGNED = 'Assigned'
PLANNED_START = 'Planned Start'
PLANNED_END = 'Planned End'
START_AFTER = 'Start After'
END_BEFORE = 'End Before'
PREREQUISITES = 'Prerequisites'
NOTES = 'Notes'
PRORITY = 'Priority'
def iter_issues(client, jql, start_at=0, expand=None):
while True:
issues = client.search_issues(jql, startAt=start_at, expand=expand)
yield from issues
start_at += len(issues)
if start_at >= issues.total:
break
def by_project(issue):
return issue.fields.project.key
def run(host, username, password, jql, filename='/tmp/out.csv'):
client = JIRA(host, basic_auth=(username, password))
with open(filename, 'w') as f:
writer = csv.writer(f)
writer.writerow([f.value for f in Omniplan.Fields])
all_issues = groupby(sorted(iter_issues(client, jql), key=by_project), key=by_project)
# Group everything under a 'JIRA IMPORT' task
values = {
Omniplan.Fields.WBS_NUMBER: f'1',
Omniplan.Fields.TITLE: 'JIRA IMPORT'
}
writer.writerow([values.get(f) for f in Omniplan.Fields])
for i, (k, g) in enumerate(all_issues, 1):
# Group tasks by project
values = {
Omniplan.Fields.WBS_NUMBER: f'1.{i}',
Omniplan.Fields.TITLE: k
}
writer.writerow([values.get(f) for f in Omniplan.Fields])
for j, issue in enumerate(g, 1):
values = {
Omniplan.Fields.WBS_NUMBER: f'1.{i}.{j}',
Omniplan.Fields.TITLE: f'{issue.fields.summary}',
Omniplan.Fields.NOTES: f'{host}/browse/{issue.key}'
}
writer.writerow([values.get(f) for f in Omniplan.Fields])
#
# Usage:
# jira_to_omniplan.py HOST USERNAME PASSWORD JQL
#
if __name__ == "__main__":
run(*sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment