-
Notifications
You must be signed in to change notification settings - Fork 2
/
github_to_phab.py
executable file
·72 lines (61 loc) · 2.83 KB
/
github_to_phab.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/python
import sys
from github_issues import FetchGithubIssues
from wmfphablib import phabdb
from wmfphablib import phabapi
from wmfphablib import util
from wmfphablib import config
github_issues = FetchGithubIssues()
api = phabapi.phabapi()
project_phid = api.get_project_phid(config.project_name)
if project_phid is None:
print "Could not find the project '%s' in Phabricator" % config.project_name
sys.exit(-1)
if config.have_db_access is False and (config.delete_existing_issues or config.force_ids):
print "You cannot delete existing taks or force task IDs if you do not have DB access"
sys.exit(-1)
if config.delete_existing_issues:
tasks = api.get_task_list(project_phid)
for task in tasks:
print "Deleting %s" % task
util.destroy_issue(task)
if config.force_ids and len(phabdb.get_task_list()) > 0:
print "You should not force task ID if there are still existing tasks in maniphest"
sys.exit(-1)
for issue in github_issues:
print "Creating issue %d" % issue.id
author_phid = api.get_phid_by_username(issue.author)
assignee_phid = None if issue.assignee is None else api.get_phid_by_username(issue.assignee)
description = "= Task migrated from github issue #%d which was available at %s =\n\n%s" % (issue.id, issue.url, issue.description)
if config.have_db_access is False or author_phid is None:
description = "> Issue originally made by **%s** on //%s//\n\n%s" % (issue.author, issue.created_at, description)
new_task = api.task_create(issue.title, description, issue.id, 90, assignee_phid, [project_phid])
phid = new_task['phid']
if config.force_ids:
phabdb.set_task_id(issue.id, phid)
id = issue.id
else:
id = new_task['id']
if config.have_db_access:
if author_phid:
phabdb.set_task_author(author_phid, id)
phabdb.set_task_ctime(phid, issue.created_at.strftime("%s"))
phabdb.set_task_mtime(phid, issue.updated_at.strftime("%s"))
if issue.state != "open":
api.set_status(id, "resolved")
if config.have_db_access:
if issue.closed_at:
tphid = phabdb.last_state_change(phid)
phabdb.set_transaction_time(tphid, issue.closed_at.strftime("%s"))
for (author, date, comment) in issue.comments:
print "Adding comment from %s" % author
author_phid = api.get_phid_by_username(author)
if author_phid is None or config.have_db_access is False:
comment = "> Comment originally made by **%s** on //%s//\n\n%s" % (author, date, comment)
api.task_comment(id, comment)
if config.have_db_access:
tphid = phabdb.last_comment(phid)
phabdb.set_comment_time(tphid, date.strftime("%s"))
if author_phid:
phabdb.set_comment_author(tphid, author_phid)
util.purge_cache()