Repository: ansible-collections/community.general

Issue:
Can't create github repo
### Summary

When I try to create a github repo with community general 2.4.0 github_repo module, I got an assertion error related to port.

### Issue Type

Bug Report

### Component Name

github_repo

### Ansible Version

ansible 2.10.7
community.general 2.4.0
PyGithub 1.54.1

### Configuration

_No response_

### OS / Environment

MacOS Mojave 10.14.6

### Steps to Reproduce

This is the task I've used
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- name: Create a Github repository
      github_repo:
        access_token: "{{ lookup('env', 'GITHUB_ACESS_TOKEN') }}"
        organization: xxx
        name: xxx
        description: "xxx"
        private: yes
```


### Expected Results

it should create a new Github Repo without error

### Actual Results

```console (paste below)
The full traceback is:
  File "/var/folders/kx/5h602b9s6fq3r5h7lxpxy8sr0000gn/T/ansible_github_repo_payload_8ng_7p6h/ansible_github_repo_payload.zip/ansible_collections/community/general/plugins/modules/github_repo.py", line 233, in main
  File "/var/folders/kx/5h602b9s6fq3r5h7lxpxy8sr0000gn/T/ansible_github_repo_payload_8ng_7p6h/ansible_github_repo_payload.zip/ansible_collections/community/general/plugins/modules/github_repo.py", line 197, in run_module
  File "/var/folders/kx/5h602b9s6fq3r5h7lxpxy8sr0000gn/T/ansible_github_repo_payload_8ng_7p6h/ansible_github_repo_payload.zip/ansible_collections/community/general/plugins/modules/github_repo.py", line 144, in create_repo
  File "/Users/kakarukeys/.local/share/virtualenvs/infra_setup-AVEq_0GX/lib/python3.9/site-packages/github/Organization.py", line 578, in create_repo
    headers, data = self._requester.requestJsonAndCheck(
  File "/Users/kakarukeys/.local/share/virtualenvs/infra_setup-AVEq_0GX/lib/python3.9/site-packages/github/Requester.py", line 316, in requestJsonAndCheck
    *self.requestJson(
  File "/Users/kakarukeys/.local/share/virtualenvs/infra_setup-AVEq_0GX/lib/python3.9/site-packages/github/Requester.py", line 408, in requestJson
    return self.__requestEncode(cnx, verb, url, parameters, headers, input, encode)
  File "/Users/kakarukeys/.local/share/virtualenvs/infra_setup-AVEq_0GX/lib/python3.9/site-packages/github/Requester.py", line 475, in __requestEncode
    url = self.__makeAbsoluteUrl(url)
  File "/Users/kakarukeys/.local/share/virtualenvs/infra_setup-AVEq_0GX/lib/python3.9/site-packages/github/Requester.py", line 557, in __makeAbsoluteUrl
    assert o.port == self.__port
fatal: [localhost]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "access_token": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "description": "xxx",
            "name": "xxx",
            "organization": "xxx",
            "password": null,
            "private": true,
            "state": "present",
            "username": null
        }
    },
    "msg": "Unexpected error. AssertionError()"
}
```


### Code of Conduct

I agree to follow the Ansible Code of Conduct


Discussion:
Files identified in the description:
None

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
Files identified in the description:
* [`plugins/modules/source_control/github/github_repo.py`](https://github.com/ansible-collections/community.general/blob/master/plugins/modules/source_control/github/github_repo.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @atorrescogollo @stpierre
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
I realized after removing `base_url="https://api.github.com:443` from `github_repo.py` the bug is gone. hope this helps.

Resolving patch:
diff --git a/plugins/modules/source_control/github/github_repo.py b/plugins/modules/source_control/github/github_repo.py
--- a/plugins/modules/source_control/github/github_repo.py
+++ b/plugins/modules/source_control/github/github_repo.py
@@ -121,9 +121,9 @@
 
 def authenticate(username=None, password=None, access_token=None):
     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:
-        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):


Test patch:
diff --git a/tests/unit/plugins/modules/source_control/github/test_github_repo.py b/tests/unit/plugins/modules/source_control/github/test_github_repo.py
--- a/tests/unit/plugins/modules/source_control/github/test_github_repo.py
+++ b/tests/unit/plugins/modules/source_control/github/test_github_repo.py
@@ -17,42 +17,42 @@ def debug_mock(url, request):
     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):
-    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")
 
     # https://docs.github.com/en/rest/reference/orgs#get-an-organization
     headers = {'content-type': 'application/json'}
     content = {
         "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")
     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):
     # https://docs.github.com/en/rest/reference/users#get-the-authenticated-user
     headers = {'content-type': 'application/json'}
     content = {
         "login": "octocat",
-        "url": "https://api.github.com:443/users/octocat"
+        "url": "https://api.github.com/users/octocat"
     }
     content = json.dumps(content).encode("utf-8")
     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):
     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):
     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")
     repo = match.group("repo")
 
@@ -61,7 +61,7 @@ def get_repo_mock(url, request):
     content = {
         "name": 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,
         "description": "This your first repo!",
         "default_branch": "master",
@@ -71,10 +71,10 @@ def get_repo_mock(url, 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):
     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")
     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)
 
 
-@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):
     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)
 
 
-@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):
     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")
     repo = match.group("repo")
 
@@ -119,7 +119,7 @@ def patch_repo_mock(url, request):
     content = {
         "name": 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'],
         "description": body['description'],
         "default_branch": "master",
@@ -129,13 +129,13 @@ def patch_repo_mock(url, 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):
     # https://docs.github.com/en/rest/reference/repos#delete-a-repository
     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):
     # https://docs.github.com/en/rest/reference/repos#delete-a-repository
     return response(404, "{\"message\": \"Not Found\"}", "", "Not Found", 5, request)