1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Bugfix: PyGithub does not support explicit port in base_url (#2204) (#2215)

* Bugfix: PyGithub does not support explicit port in base_url

* Fix unit tests

* Fix unit tests

* Added changelog

* Update changelogs/fragments/2204-github_repo-fix-baseurl_port.yml

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
(cherry picked from commit 8eb2331aea)

Co-authored-by: Álvaro Torres Cogollo <atorrescogollo@gmail.com>
This commit is contained in:
patchback[bot] 2021-04-09 12:16:29 +02:00 committed by GitHub
parent ec78558559
commit 9d93760564
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 19 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- github_repo - PyGithub bug does not allow explicit port in ``base_url``. Specifying port is not required (https://github.com/PyGithub/PyGithub/issues/1913).

View file

@ -121,9 +121,9 @@ except Exception:
def authenticate(username=None, password=None, access_token=None): def authenticate(username=None, password=None, access_token=None):
if access_token: if access_token:
return Github(base_url="https://api.github.com:443", login_or_token=access_token) return Github(base_url="https://api.github.com", login_or_token=access_token)
else: else:
return Github(base_url="https://api.github.com:443", login_or_token=username, password=password) return Github(base_url="https://api.github.com", login_or_token=username, password=password)
def create_repo(gh, name, organization=None, private=False, description='', check_mode=False): def create_repo(gh, name, organization=None, private=False, description='', check_mode=False):

View file

@ -17,42 +17,42 @@ def debug_mock(url, request):
print(request.original.__dict__) print(request.original.__dict__)
@urlmatch(netloc=r'api\.github\.com:443$', path=r'/orgs/.*', method="get") @urlmatch(netloc=r'api\.github\.com(:[0-9]+)?$', path=r'/orgs/.*', method="get")
def get_orgs_mock(url, request): def get_orgs_mock(url, request):
match = re.search(r"api\.github\.com:443/orgs/(?P<org>[^/]+)", request.url) match = re.search(r"api\.github\.com(:[0-9]+)?/orgs/(?P<org>[^/]+)", request.url)
org = match.group("org") org = match.group("org")
# https://docs.github.com/en/rest/reference/orgs#get-an-organization # https://docs.github.com/en/rest/reference/orgs#get-an-organization
headers = {'content-type': 'application/json'} headers = {'content-type': 'application/json'}
content = { content = {
"login": org, "login": org,
"url": "https://api.github.com:443/orgs/{0}".format(org) "url": "https://api.github.com/orgs/{0}".format(org)
} }
content = json.dumps(content).encode("utf-8") content = json.dumps(content).encode("utf-8")
return response(200, content, headers, None, 5, request) return response(200, content, headers, None, 5, request)
@urlmatch(netloc=r'api\.github\.com:443$', path=r'/user', method="get") @urlmatch(netloc=r'api\.github\.com(:[0-9]+)?$', path=r'/user', method="get")
def get_user_mock(url, request): def get_user_mock(url, request):
# https://docs.github.com/en/rest/reference/users#get-the-authenticated-user # https://docs.github.com/en/rest/reference/users#get-the-authenticated-user
headers = {'content-type': 'application/json'} headers = {'content-type': 'application/json'}
content = { content = {
"login": "octocat", "login": "octocat",
"url": "https://api.github.com:443/users/octocat" "url": "https://api.github.com/users/octocat"
} }
content = json.dumps(content).encode("utf-8") content = json.dumps(content).encode("utf-8")
return response(200, content, headers, None, 5, request) return response(200, content, headers, None, 5, request)
@urlmatch(netloc=r'api\.github\.com:443$', path=r'/repos/.*/.*', method="get") @urlmatch(netloc=r'api\.github\.com(:[0-9]+)?$', path=r'/repos/.*/.*', method="get")
def get_repo_notfound_mock(url, request): def get_repo_notfound_mock(url, request):
return response(404, "{\"message\": \"Not Found\"}", "", "Not Found", 5, request) return response(404, "{\"message\": \"Not Found\"}", "", "Not Found", 5, request)
@urlmatch(netloc=r'api\.github\.com:443$', path=r'/repos/.*/.*', method="get") @urlmatch(netloc=r'api\.github\.com(:[0-9]+)?$', path=r'/repos/.*/.*', method="get")
def get_repo_mock(url, request): def get_repo_mock(url, request):
match = re.search( match = re.search(
r"api\.github\.com:443/repos/(?P<org>[^/]+)/(?P<repo>[^/]+)", request.url) r"api\.github\.com(:[0-9]+)?/repos/(?P<org>[^/]+)/(?P<repo>[^/]+)", request.url)
org = match.group("org") org = match.group("org")
repo = match.group("repo") repo = match.group("repo")
@ -61,7 +61,7 @@ def get_repo_mock(url, request):
content = { content = {
"name": repo, "name": repo,
"full_name": "{0}/{1}".format(org, repo), "full_name": "{0}/{1}".format(org, repo),
"url": "https://api.github.com:443/repos/{0}/{1}".format(org, repo), "url": "https://api.github.com/repos/{0}/{1}".format(org, repo),
"private": False, "private": False,
"description": "This your first repo!", "description": "This your first repo!",
"default_branch": "master", "default_branch": "master",
@ -71,10 +71,10 @@ def get_repo_mock(url, request):
return response(200, content, headers, None, 5, request) return response(200, content, headers, None, 5, request)
@urlmatch(netloc=r'api\.github\.com:443$', path=r'/orgs/.*/repos', method="post") @urlmatch(netloc=r'api\.github\.com(:[0-9]+)?$', path=r'/orgs/.*/repos', method="post")
def create_new_org_repo_mock(url, request): def create_new_org_repo_mock(url, request):
match = re.search( match = re.search(
r"api\.github\.com:443/orgs/(?P<org>[^/]+)/repos", request.url) r"api\.github\.com(:[0-9]+)?/orgs/(?P<org>[^/]+)/repos", request.url)
org = match.group("org") org = match.group("org")
repo = json.loads(request.body) repo = json.loads(request.body)
@ -90,7 +90,7 @@ def create_new_org_repo_mock(url, request):
return response(201, content, headers, None, 5, request) return response(201, content, headers, None, 5, request)
@urlmatch(netloc=r'api\.github\.com:443$', path=r'/user/repos', method="post") @urlmatch(netloc=r'api\.github\.com(:[0-9]+)?$', path=r'/user/repos', method="post")
def create_new_user_repo_mock(url, request): def create_new_user_repo_mock(url, request):
repo = json.loads(request.body) repo = json.loads(request.body)
@ -106,10 +106,10 @@ def create_new_user_repo_mock(url, request):
return response(201, content, headers, None, 5, request) return response(201, content, headers, None, 5, request)
@urlmatch(netloc=r'api\.github\.com:443$', path=r'/repos/.*/.*', method="patch") @urlmatch(netloc=r'api\.github\.com(:[0-9]+)?$', path=r'/repos/.*/.*', method="patch")
def patch_repo_mock(url, request): def patch_repo_mock(url, request):
match = re.search( match = re.search(
r"api\.github\.com:443/repos/(?P<org>[^/]+)/(?P<repo>[^/]+)", request.url) r"api\.github\.com(:[0-9]+)?/repos/(?P<org>[^/]+)/(?P<repo>[^/]+)", request.url)
org = match.group("org") org = match.group("org")
repo = match.group("repo") repo = match.group("repo")
@ -119,7 +119,7 @@ def patch_repo_mock(url, request):
content = { content = {
"name": repo, "name": repo,
"full_name": "{0}/{1}".format(org, repo), "full_name": "{0}/{1}".format(org, repo),
"url": "https://api.github.com:443/repos/{0}/{1}".format(org, repo), "url": "https://api.github.com/repos/{0}/{1}".format(org, repo),
"private": body['private'], "private": body['private'],
"description": body['description'], "description": body['description'],
"default_branch": "master", "default_branch": "master",
@ -129,13 +129,13 @@ def patch_repo_mock(url, request):
return response(200, content, headers, None, 5, request) return response(200, content, headers, None, 5, request)
@urlmatch(netloc=r'api\.github\.com:443$', path=r'/repos/.*/.*', method="delete") @urlmatch(netloc=r'api\.github\.com(:[0-9]+)?$', path=r'/repos/.*/.*', method="delete")
def delete_repo_mock(url, request): def delete_repo_mock(url, request):
# https://docs.github.com/en/rest/reference/repos#delete-a-repository # https://docs.github.com/en/rest/reference/repos#delete-a-repository
return response(204, None, None, None, 5, request) return response(204, None, None, None, 5, request)
@urlmatch(netloc=r'api\.github\.com:443$', path=r'/repos/.*/.*', method="delete") @urlmatch(netloc=r'api\.github\.com(:[0-9]+)?$', path=r'/repos/.*/.*', method="delete")
def delete_repo_notfound_mock(url, request): def delete_repo_notfound_mock(url, request):
# https://docs.github.com/en/rest/reference/repos#delete-a-repository # https://docs.github.com/en/rest/reference/repos#delete-a-repository
return response(404, "{\"message\": \"Not Found\"}", "", "Not Found", 5, request) return response(404, "{\"message\": \"Not Found\"}", "", "Not Found", 5, request)