#!/usr/bin/python3 import json import requests import sys # TODO: Append comments! def main(input_path, hostname, project_path, username, password): issues = json.load(open(input_path))['issues'] # Reverse issues so they're actually ordered by ID. for issue in reversed(issues): headers = { 'Accept': 'application/json', 'Content-Type': 'application/json', } payload = { 'body': issue['description'] + '\n\n---\nImported from Taiga issue {taiga_id}: {status} {type}. Created on {created_date} by {author}.'.format( taiga_id=issue['ref'], status=issue['status'].lower(), type=issue['type'].lower(), created_date=issue['created_date'], author=issue['history'][0]['user'][1], ), 'closed': bool(issue['status'] in ('Done', 'Won\'t fix')), 'title': issue['subject'], } response = requests.post( 'https://{}/api/v1/repos/{}/issues'.format(hostname, project_path), auth=(username, password), headers=headers, data=json.dumps(payload), ) return # TODO if __name__ == '__main__': main(*sys.argv[1:])