forked from koansys/github-migrate-trac-tickets
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgithub_json.py
46 lines (40 loc) · 1.38 KB
/
github_json.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
import base64
import urllib2
import os
try:
import json
except ImportError:
import simplejson as json
class GitHubJson():
"""Dump json format suitable for import, See
https://gist.github.com/7f75ced1fa7576412901
http://developer.github.com/v3/
"""
def __init__(self, repo):
"""Username and password for auth; repo is like 'myorg/myapp'.
"""
self.repo = repo
os.makedirs(self.repo)
for subdir in ('issues', 'milestones'):
os.makedirs(os.path.join(self.repo, subdir))
def issues(self, id_, data=None):
"""Get issues or POST and issue with data.
Create a new one like: issues(data={'title': 'Plough', 'body': 'Plover'})
"""
with open(os.path.join(self.repo, 'issues', '%s.json' % id_), 'w') as outfile:
json.dump(data, outfile)
return data
def issue_comments(self, id_, data=None):
"""Get comments for a ticket by its number or POST a comment with data.
Example: issue_comments(5, data={'body': 'Is decapitated'})
"""
with open(os.path.join(self.repo, 'issues', '%s.comments.json' % id_), 'w') as outfile:
json.dump(data, outfile)
return data
def milestones(self, id_, data=None):
"""Set milestones
"""
data['number'] = id_
with open(os.path.join(self.repo, 'milestones', "%s.json" % id_), 'w') as outfile:
json.dump(data, outfile)
return data