Skip to content

Adds additional support for Github enterprise usecases #548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

daniel-anya
Copy link
Contributor

@daniel-anya daniel-anya commented May 15, 2025

5764cba: Adds support for figuring out a Github host from the GITHUB_BASE_URL config, and using this value in generated coverage artifacts. The usecase here is that, when this action is used in the enterprise environment, coverage artifacts like html files and README docs point to github.com/... which is not what we'd want.

07a88e1: Adds support for saving coverage artifacts on PR merged to default branch events which is functionally equivalent to the currently supported path of saving coverage artifacts on commit pushed to default branch events.

78a7324: Adds support for generating Github Pages based coverage report links.

Tested all changes in a Github enterprise environment and they've been working fine for a while now.

daniel-anya and others added 4 commits May 15, 2025 11:51
…st merge to the default branch.

This is functionally equivalent to the currently supported pattern of pushing to the default branch.
Adds support for figuring out a github host from the `GITHUB_BASE_URL` config and using this value in generated coverage artifacts rather than hardcoding them to "github.com"
Copy link

End-to-end public repo

Admin commands cheatsheet:

  • /e2e (in approved PR review body): Trigger end-to-end tests on external contributions
  • /invite (in comment): Invite the author & admins to the end-to-end private repo

Copy link

github-actions bot commented May 15, 2025

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  coverage_comment
  activity.py
  github.py
  main.py 77-81
  settings.py
  storage.py
  template.py
Project Total  

This report was generated by python-coverage-comment-action

Copy link
Member

@ewjoachim ewjoachim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a stellar contribution 🤩

I'm sorry it took so long to find the time to review it.
I think what it mainly needs is documentation in README. In particular:

  • That you can use the pull_request merged event
  • How to setup GH pages
  • Maybe add some details on how it works for GHE ?

Comment on lines 77 to 78
with open(event_path, "r") as event_file:
event_payload = json.load(event_file)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use Pathlib everywhere else in the project, and event_path is already a path

Suggested change
with open(event_path, "r") as event_file:
event_payload = json.load(event_file)
event_payload = json.loads(event_path.read_text())

) -> str:
"""Find the activity to perform based on the event type and payload."""
if event_name == "workflow_run":
return "post_comment"

if (event_name == "push" and is_default_branch) or event_name == "schedule":
if (event_name == "push" and is_default_branch) or (event_name == "pull_request" and event_action == "merged" and is_default_branch) or event_name == "schedule":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there should be a mention of this in the README too?

@@ -47,7 +47,7 @@ function create-repo(){
repo_dirname=$(basename ${GITHUB_REPOSITORY})
mv "${repo_dirname}/"{*,.*} .
rmdir "${repo_dirname}"
git pull --ff-only origin master
git pull --ff-only origin main
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch !

Comment on lines +66 to +72
# Special case for GitHub.com API
if netloc == "api.github.com":
host_domain = "github.com"
# Special case for GitHub.com with port (less common but good practice)
elif netloc.startswith("api.github.com:"):
# Remove 'api.' prefix but keep the port
host_domain = netloc.replace("api.", "", 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Special case for GitHub.com API
if netloc == "api.github.com":
host_domain = "github.com"
# Special case for GitHub.com with port (less common but good practice)
elif netloc.startswith("api.github.com:"):
# Remove 'api.' prefix but keep the port
host_domain = netloc.replace("api.", "", 1)
# Special case for GitHub.com API (including possible port)
if re.match(r"api\.github\.com(:|$)", netloc):
# Remove 'api.' prefix but keep the port
host_domain = netloc.removeprefix("api.")

@ewjoachim
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants