From e727a1c1677142817402c2b57a947f3e63f0eeab Mon Sep 17 00:00:00 2001 From: Dan Date: Wed, 3 Jan 2018 22:23:05 -0800 Subject: [PATCH] Initial import. --- README.md | 20 ++++++++++++++++++++ import_issues.py | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 README.md create mode 100755 import_issues.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..755ad81 --- /dev/null +++ b/README.md @@ -0,0 +1,20 @@ +## Overview + +Simple Python script that takes a JSON file for an exported Taiga projects and +imports its issue into it a Gitea project via API. + +It doesn't have much in the way of error handling. Caveat usor. + +The script relies on the requests library. + +## Usage + +``` +./import_issues.py [input-path] [hostname] [project-path] [username] [password] +``` + +Example: + +``` +./import_issues.py taiga_export.json gitea.example.org bob/cool-project bob password +``` diff --git a/import_issues.py b/import_issues.py new file mode 100755 index 0000000..8ee7611 --- /dev/null +++ b/import_issues.py @@ -0,0 +1,41 @@ +#!/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:])