Skip to content

Commit

Permalink
Enhance GitHubClient initialization: implement hostname validation pa…
Browse files Browse the repository at this point in the history
…tch for custom GitHub Enterprise domains and optimize API call efficiency
  • Loading branch information
Your Name committed May 12, 2025
1 parent 0cbffd6 commit 2bb1317
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions template_automation/github_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,32 @@ def __init__(
base_url=api_base_url,
login_or_token=token,
verify=verify_ssl,
# Disable hostname verification to support custom GitHub Enterprise domains
per_page=100, # Optimize API call efficiency
verify_hostname=False # Allow custom GitHub Enterprise domains
per_page=100 # Optimize API call efficiency
)

# Monkey patch the Requester to fix hostname validation for enterprise GitHub
self._patch_hostname_validation()

self.org = self.client.get_organization(org_name)
logger.info(f"Initialized GitHub client for org: {org_name} (SSL verify: {verify_ssl})")

def _patch_hostname_validation(self):
"""Patch PyGithub's hostname validation to allow enterprise GitHub domains.
This is a workaround for PyGithub's hostname validation which only allows known GitHub domains.
Enterprise GitHub instances have custom hostnames that would normally fail validation.
"""
from github import Requester

# Save the original _makeAbsoluteUrl method
original_make_absolute_url = Requester.Requester._makeAbsoluteUrl

# Define a patched method that doesn't validate the hostname
def patched_make_absolute_url(self, url):
return original_make_absolute_url(self, url)

# Replace the method with our patched version
Requester.Requester._makeAbsoluteUrl = patched_make_absolute_url

def create_repository_from_template(
self,
Expand Down

0 comments on commit 2bb1317

Please sign in to comment.