diff --git a/.gitignore b/.gitignore index 95d0cfed..5e8ed586 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ dev-env-vars .coverage* __pycache__ +.idea/ diff --git a/README.md b/README.md index 028929fc..2fcbfc43 100644 --- a/README.md +++ b/README.md @@ -313,6 +313,9 @@ jobs: with: GITHUB_TOKEN: ${{ github.token }} + # Change this in case you use GitHub Entreprise with a different API endpoint + GITHUB_BASE_URL: https://api.github.com + # Only necessary in the "workflow_run" workflow. GITHUB_PR_RUN_ID: ${{ inputs.GITHUB_PR_RUN_ID }} @@ -594,6 +597,10 @@ source = This action is supposedly compatible with private repository. Just make sure to use the svg badge directly, and not the `shields.io` URL. +## Github Enterprise (GHE) Support + +This action should be compatible with GitHub Enterprise. Just make sure to set the `GITHUB_BASE_URL` input to your GHE URL. + ## Upgrading from v2 to v3 When upgrading, we change the location and format where the coverage diff --git a/action.yml b/action.yml index 362dfebf..9a6c2c70 100644 --- a/action.yml +++ b/action.yml @@ -6,6 +6,13 @@ description: > Publish diff coverage report as PR comment, and create a coverage badge to display on the readme. inputs: + GITHUB_BASE_URL: + description: > + The base URL for the GitHub API, typically used to specify custom endpoints + for GitHub Enterprise Server (e.g., `https://github.mycompany.com/api/v3`). + Defaults to `https://api.github.com` for GitHub.com. + default: "https://api.github.com" + required: false GITHUB_TOKEN: description: > A GitHub token to write comments and write the badge & coverage data diff --git a/coverage_comment/main.py b/coverage_comment/main.py index 71c5bedc..8da1c792 100644 --- a/coverage_comment/main.py +++ b/coverage_comment/main.py @@ -34,7 +34,7 @@ def main(): config = settings.Config.from_environ(environ=os.environ) github_session = httpx.Client( - base_url="https://api.github.com", + base_url=config.GITHUB_BASE_URL, follow_redirects=True, headers={"Authorization": f"token {config.GITHUB_TOKEN}"}, ) diff --git a/coverage_comment/settings.py b/coverage_comment/settings.py index 5d4360b7..12473c7d 100644 --- a/coverage_comment/settings.py +++ b/coverage_comment/settings.py @@ -37,6 +37,7 @@ class Config: # A branch name, not a fully-formed ref. For example, `main`. GITHUB_BASE_REF: str + GITHUB_BASE_URL: str = "https://api.github.com" GITHUB_TOKEN: str = dataclasses.field(repr=False) GITHUB_REPOSITORY: str # > The ref given is fully-formed, meaning that for branches the format is