5
5
import sys
6
6
7
7
import py .path
8
+ import requests
8
9
9
10
LOG_LEVELS = {logging .getLevelName (level ): level for level in (
10
11
logging .DEBUG ,
@@ -42,6 +43,9 @@ def __call__(self, parser, namespace, value, option_string=None):
42
43
43
44
parser .add_argument ("--statedir" , action = PyPathLocalAction ,
44
45
help = "Directory to store change state" )
46
+ parser .add_argument ("--githubroot" ,
47
+ default = "https://api.github.com" ,
48
+ help = "Root for the GitHub API" )
45
49
46
50
parser .add_argument ("trello_json" , action = PyPathLocalAction ,
47
51
help = "JSON file exported from Trello" )
@@ -50,6 +54,11 @@ def __call__(self, parser, namespace, value, option_string=None):
50
54
parser .add_argument ("github_repo" ,
51
55
help = "Repo in GitHub" )
52
56
57
+ parser .add_argument ("github_user" ,
58
+ help = "Your GitHub username" )
59
+ parser .add_argument ("github_password" ,
60
+ help = "Your GitHub password" )
61
+
53
62
54
63
class Card (object ):
55
64
def __init__ (self , card_data , statedir = None ):
@@ -69,6 +78,22 @@ def state(self):
69
78
return None
70
79
71
80
81
+ def gh_request (path , args ):
82
+ req = requests .get ('%s/%s' % (args .githubroot , path ),
83
+ auth = (args .github_user , args .github_password ))
84
+
85
+ if not req .ok :
86
+ data = req .json ()
87
+ message = data .get (
88
+ 'message' ,
89
+ "HTTP error %d: %s" % (req .status_code , req .reason )
90
+ )
91
+ logging .getLogger ('github' ).error (message )
92
+ return False
93
+
94
+ return req
95
+
96
+
72
97
def main ():
73
98
args = parser .parse_args ()
74
99
@@ -92,6 +117,15 @@ def main():
92
117
cards_log = logging .getLogger ("cards import" )
93
118
cards_log .info ("Importing %d cards" , len (trello_data ['cards' ]))
94
119
120
+ req = gh_request ('user' , args )
121
+ if not req :
122
+ sys .exit (1 )
123
+
124
+ logging .info (
125
+ "Importing as GitHub user %s" ,
126
+ req .json ().get ('name' , "unknown user name" )
127
+ )
128
+
95
129
for card_data in trello_data ['cards' ]:
96
130
cards_log .debug ("Card %s" , card_data ['name' ])
97
131
card = Card (card_data , args .statedir )
0 commit comments