Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.idea/*
__pycache__/*
*.py~
.env

# This is to prevent you from making the idiotic mistake of committing and uploading your
# config file that includes your password in plaintext into a publicly available repo!
Expand Down
16 changes: 14 additions & 2 deletions gh-issues-import.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3

import urllib.request, urllib.error, urllib.parse
import ssl
import json
import base64
import sys, os
Expand Down Expand Up @@ -31,6 +32,9 @@ class state:
http_error_messages[403] = http_error_messages[401]; # Basically the same problem. GitHub returns 403 instead to prevent abuse.
http_error_messages[404] = "ERROR: Unable to find the specified repository.\nDouble check the spelling for the source and target repositories. If either repository is private, make sure the specified user is allowed access to it."

skip_cert_validation_context = ssl.create_default_context()
skip_cert_validation_context.check_hostname = False
skip_cert_validation_context.verify_mode = ssl.CERT_NONE

def init_config():

Expand Down Expand Up @@ -59,6 +63,8 @@ def init_config():
arg_parser.add_argument('--comment-template', help="Specify a template file for use with comments.")
arg_parser.add_argument('--pull-request-template', help="Specify a template file for use with pull requests.")

arg_parser.add_argument('--skip-cert-validation', dest='skip_cert_validation', action='store_true', help="Ignore certificate validation")

include_group = arg_parser.add_mutually_exclusive_group(required=True)
include_group.add_argument("--all", dest='import_all', action='store_true', help="Import all issues, regardless of state.")
include_group.add_argument("--open", dest='import_open', action='store_true', help="Import only open issues.")
Expand Down Expand Up @@ -108,7 +114,8 @@ def load_config_file(config_file_name):

config.set('settings', 'import-open-issues', str(args.import_all or args.import_open));
config.set('settings', 'import-closed-issues', str(args.import_all or args.import_closed));


config.set('settings', 'skip-cert-validation', args.skip_cert_validation)

# Make sure no required config values are missing
if not config.has_option('source', 'repository') :
Expand Down Expand Up @@ -204,7 +211,7 @@ def send_request(which, url, post_data=None):
req.add_header("User-Agent", "IQAndreas/github-issues-import")

try:
response = urllib.request.urlopen(req)
response = urlopen(req)
json_data = response.read()
except urllib.error.HTTPError as error:

Expand All @@ -221,6 +228,11 @@ def send_request(which, url, post_data=None):

return json.loads(json_data.decode("utf-8"))

def urlopen(req):
if config.get('settings', 'skip-cert-validation'):
return urllib.request.urlopen(req, context=skip_cert_validation_context)
else: return urllib.request.urlopen(req)

def get_milestones(which):
return send_request(which, "milestones?state=open")

Expand Down