2
2
# -*- coding: utf-8 -*-
3
3
4
4
from __future__ import print_function , unicode_literals
5
+
6
+ import ssl
7
+ from functools import wraps
8
+ def sslwrap (func ):
9
+ @wraps (func )
10
+ def bar (* args , ** kw ):
11
+ kw ['ssl_version' ] = ssl .PROTOCOL_TLSv1
12
+ return func (* args , ** kw )
13
+ return bar
14
+
15
+ ssl .wrap_socket = sslwrap (ssl .wrap_socket )
16
+
5
17
import argparse
6
18
import json
7
19
import sys
@@ -123,9 +135,15 @@ def import_issue(bitbucket_data, argv):
123
135
# print("Github data")
124
136
# print("-----------")
125
137
# print(github_data)
126
-
127
- github_issue = argv .gh .issues .create (
128
- github_data , user = argv .username , repo = argv .repo )
138
+
139
+ github_issue = None
140
+ while (github_issue == None ):
141
+ try :
142
+ github_issue = argv .gh .issues .create (
143
+ github_data , user = argv .username , repo = argv .repo )
144
+ except :
145
+ print ('Exception' )
146
+ sleep (10 )
129
147
130
148
print ('Imported as {github_issue}' .format (github_issue = github_issue ))
131
149
@@ -140,16 +158,28 @@ def import_issue(bitbucket_data, argv):
140
158
'' .format (** bitbucket_data ))
141
159
142
160
github_data ['state' ] = GITHUB_CLOSED_STATE
143
- github_updated_issue = argv .gh .issues .update (
144
- github_issue .number , github_data ,
145
- user = argv .username , repo = argv .repo )
161
+ github_updated_issue = None
162
+ while (github_updated_issue == None ):
163
+ try :
164
+ github_updated_issue = argv .gh .issues .update (
165
+ github_issue .number , github_data ,
166
+ user = argv .username , repo = argv .repo )
167
+ except :
168
+ print ('Ex3ception' )
169
+ sleep (10 )
146
170
print ('Closed' )
147
171
148
172
if comment_message :
149
- argv .gh .issues .comments .create (
150
- number = github_issue .number ,
151
- message = '\n \n ' .join (comment_message ),
152
- user = argv .username , repo = argv .repo )
173
+ github_new_comment = None
174
+ while (github_new_comment == None ):
175
+ try :
176
+ github_new_comment = argv .gh .issues .comments .create (
177
+ number = github_issue .number ,
178
+ message = '\n \n ' .join (comment_message ),
179
+ user = argv .username , repo = argv .repo )
180
+ except :
181
+ print ('Ex4ception' )
182
+ sleep (10 )
153
183
154
184
return github_issue .number
155
185
@@ -161,13 +191,19 @@ def import_comment(github_issue_number, comment, argv):
161
191
# ignores status changing comments.
162
192
return
163
193
164
- ret = argv .gh .issues .comments .create (
165
- number = github_issue_number ,
166
- message = ('(Original comment by {user} on {created_on})\n \n '
167
- '{content}\n \n '
168
- '' .format (** comment )),
169
- user = argv .username ,
170
- repo = argv .repo )
194
+ ret = None
195
+ while (ret == None ):
196
+ try :
197
+ ret = argv .gh .issues .comments .create (
198
+ number = github_issue_number ,
199
+ message = ('(Original comment by {user} on {created_on})\n \n '
200
+ '{content}\n \n '
201
+ '' .format (** comment )),
202
+ user = argv .username ,
203
+ repo = argv .repo )
204
+ except :
205
+ print ('Ex2ception' )
206
+ sleep (10 )
171
207
172
208
173
209
def import_issues_and_comments (issues , comments , argv ):
@@ -192,7 +228,7 @@ def import_issues_and_comments(issues, comments, argv):
192
228
for bitbucket_comment in issue_comments :
193
229
comments_read += 1
194
230
# delay comment insertion to order comments properly.
195
- sleep (1 )
231
+ sleep (0.25 )
196
232
import_comment (
197
233
github_issue_number = github_issue_number ,
198
234
comment = bitbucket_comment ,
0 commit comments