Skip to content

Commit 9ba81e1

Browse files
committed
Add hacks for working around PyTLS bug & GitHub ratelimiting.
1 parent 2a5870b commit 9ba81e1

File tree

1 file changed

+54
-18
lines changed

1 file changed

+54
-18
lines changed

bb2gh_issues.py

+54-18
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22
# -*- coding: utf-8 -*-
33

44
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+
517
import argparse
618
import json
719
import sys
@@ -123,9 +135,15 @@ def import_issue(bitbucket_data, argv):
123135
# print("Github data")
124136
# print("-----------")
125137
# 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)
129147

130148
print('Imported as {github_issue}'.format(github_issue=github_issue))
131149

@@ -140,16 +158,28 @@ def import_issue(bitbucket_data, argv):
140158
''.format(**bitbucket_data))
141159

142160
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)
146170
print('Closed')
147171

148172
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)
153183

154184
return github_issue.number
155185

@@ -161,13 +191,19 @@ def import_comment(github_issue_number, comment, argv):
161191
# ignores status changing comments.
162192
return
163193

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)
171207

172208

173209
def import_issues_and_comments(issues, comments, argv):
@@ -192,7 +228,7 @@ def import_issues_and_comments(issues, comments, argv):
192228
for bitbucket_comment in issue_comments:
193229
comments_read += 1
194230
# delay comment insertion to order comments properly.
195-
sleep(1)
231+
sleep(0.25)
196232
import_comment(
197233
github_issue_number=github_issue_number,
198234
comment=bitbucket_comment,

0 commit comments

Comments
 (0)