Skip to content

Consolidate sync actions in route handlers - #240

Open
cmelone wants to merge 1 commit into
llnl:mainfrom
cmelone:add/consolidate-syncs
Open

Consolidate sync actions in route handlers#240
cmelone wants to merge 1 commit into
llnl:mainfrom
cmelone:add/consolidate-syncs

Conversation

@cmelone

@cmelone cmelone commented Mar 4, 2026

Copy link
Copy Markdown
Member

There was a lot of duplicated code/logic in the route handlers, especially for the sync/delete ref actions. I was a bit aggressive with the consolidation, so let me know if you'd like to keep something expanded.

@cmelone
cmelone requested a review from Copilot March 4, 2026 23:50

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR consolidates duplicated logic in GitHub route handlers by extracting common sync, delete, and pipeline context operations into shared helper functions. The RepoConfig class is also updated to compute fullname automatically.

Changes:

  • Extracted _sync_refs, _delete_ref, _get_dest_context, _get_pr_target_ref, and _get_pr_pipeline_context as shared helpers to eliminate duplicated code across push and pull request event handlers.
  • Simplified sync_pr signature by removing the src_repo_private parameter (now derived from the pull_request dict directly).
  • Changed RepoConfig.fullname to be auto-computed from dest_org and dest_name instead of being passed as a separate parameter.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/hubcast/web/github/routes.py Route handlers refactored to use new helper functions, removing significant code duplication
src/hubcast/repos/config.py RepoConfig.fullname now auto-computed from dest_org/dest_name

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/hubcast/web/github/routes.py
Comment thread src/hubcast/web/github/routes.py Outdated
Comment thread src/hubcast/repos/config.py Outdated
@cmelone cmelone mentioned this pull request Mar 5, 2026
2 tasks
cmelone added a commit to cmelone/hubcast that referenced this pull request Mar 5, 2026
Hubcast config settings for repos should only be fetched from the
default branch of the base repository. Previously, we were getting the
config from the head repo, which would lead to potential confusion for
users submitting PRs via forks.

This ensures that there is one source of settings for each repository.

I pulled this out of llnl#240 to make for a faster review.
alecbcs pushed a commit that referenced this pull request Mar 6, 2026
Hubcast config settings for repos should only be fetched from the
default branch of the base repository. Previously, we were getting the
config from the head repo, which would lead to potential confusion for
users submitting PRs via forks.

This ensures that there is one source of settings for each repository.

I pulled this out of #240 to make for a faster review.
@cmelone
cmelone force-pushed the add/consolidate-syncs branch 5 times, most recently from 9e8e2e5 to c9ac693 Compare March 11, 2026 21:15
@cmelone
cmelone marked this pull request as ready for review March 11, 2026 21:16
@cmelone
cmelone force-pushed the add/consolidate-syncs branch from c9ac693 to a26cc77 Compare March 11, 2026 23:01
@cmelone
cmelone requested a review from Copilot March 11, 2026 23:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/hubcast/web/github/routes.py Outdated
Comment thread src/hubcast/web/github/routes.py Outdated
Comment thread src/hubcast/web/github/routes.py Outdated
Comment thread src/hubcast/web/github/routes.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/hubcast/web/github/routes.py Outdated
Comment thread src/hubcast/web/github/routes.py
@cmelone
cmelone force-pushed the add/consolidate-syncs branch from dc3e0ce to 9f5ff47 Compare March 25, 2026 00:16
@cmelone
cmelone force-pushed the add/consolidate-syncs branch 4 times, most recently from e3e100d to 525b576 Compare April 10, 2026 23:00
There was a lot of duplicated code/logic in the route handlers,
especially for the sync/delete ref actions. I was a bit aggressive with
the consolidation, so let me know if you'd like to keep something
expanded.

address review

add guard when a ref to be deleted does not exist

unconsolidate _get_pr_pipeline_context and _get_dest_context

style
@cmelone
cmelone force-pushed the add/consolidate-syncs branch from 525b576 to b71c69c Compare April 13, 2026 20:37
alecbcs pushed a commit that referenced this pull request Jul 22, 2026
This PR adds support for sending messages back to users if their
intended action fails due to insufficient permissions.

Any requests to Gitlab can fail if the user account we're impersonating
is not set up properly.

1. with the `guest` role, the user can't read the repo
2. with the `reporter` role, the user can't write to the repo
3. with the `developer` role, the user can't read or write repo webhooks

If we hit (1) or (2) during a sync action, Hubcast will set a status to
the commit notifying the user of the issue and pointing to the
permissions requirements in the docs.

In the case of deletions, we have no way to set a GitHub check status so
the event will be logged and available to admins.

The way we go about catching exceptions is ugly, but modularization is
limited by the fact that most cases need unique handling, other than
actions like syncing/deleting refs (which should really be consolidated
like in #240). Please let me know if you have ideas about making this
all more readable.

Handling webhook setting:
- we now check if hubcast configuration files have been
added/edited/deleted in the push event to the default branch
- if the webhook set fails, we set a check with an error message saying
that a maintainer needs to push an update to the config or an empty
commit with the message `[hubcast config`]
--- 

TODO
- [x] once this is in a polished state, add tests
- [x] we'll need to cut a repligit release to handle the rejected push
exceptions

closes #355

---------

Signed-off-by: Caetano Melone <melone1@llnl.gov>
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