Skip to content

fix(private-org-sync): batch ls-remote calls per repo instead of per branch#5027

Open
petr-muller wants to merge 2 commits intoopenshift:mainfrom
petr-muller:git-sync-speedup-4
Open

fix(private-org-sync): batch ls-remote calls per repo instead of per branch#5027
petr-muller wants to merge 2 commits intoopenshift:mainfrom
petr-muller:git-sync-speedup-4

Conversation

@petr-muller
Copy link
Member

@petr-muller petr-muller commented Mar 19, 2026

Previously, mirror() called ls-remote for both source and destination on every branch, resulting in 2×N network calls per repo where N is the number of branches. Since ls-remote --heads returns ALL branches at once, we can call it once per repo and pass the results to mirror().

This moves git init, remote setup, and ls-remote calls from mirror() into the main loop where repos are already grouped, reducing network calls from 2×N to 2 per repo.

Stacked on #5023 (merged).

@openshift-ci-robot
Copy link
Contributor

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: automatic mode

@coderabbitai
Copy link

coderabbitai bot commented Mar 19, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 92044a96-d7a9-4995-b56b-c05132ba8335

📥 Commits

Reviewing files that changed from the base of the PR and between 136df2b and a39befe.

📒 Files selected for processing (2)
  • cmd/private-org-sync/main.go
  • cmd/private-org-sync/main_test.go

Walkthrough

Introduces a two-stage git sync flow: syncRepo now does per-repo remote discovery and orchestration; mirror performs single-branch mirrors using pre-fetched RemoteBranchHeads and a constructed destination URL. Tests updated to reflect the new API and behaviors.

Changes

Cohort / File(s) Summary
Sync flow and mirror refactor
cmd/private-org-sync/main.go
Adds gitSyncer.syncRepo(org, repo, targetOrg, dstRepo, branches) that performs repo-level ls-remote discovery, initializes local repo dirs, computes dstRepo once, sets per-repo logger context, handles failOnNonexistentDst aggregation/warning, and iterates branches. Updates mirror to mirror(repoDir, src, dst, srcHeads, dstHeads, destUrl) to mirror a single branch using pre-fetched RemoteBranchHeads and pre-built destUrl. Branch loop no longer recomputes remote HEADs; location for destination is constructed inside syncRepo without mutating source.
Tests: Mirror and new SyncRepo tests
cmd/private-org-sync/main_test.go
TestMirror updated to pass srcHeads, dstHeads, and parsed destUrl to mirror; removed previous ls-remote mocking and patterns relying on failOnNonexistentDst. Adds TestSyncRepo to exercise syncRepo across multiple branches including destination/source ls-remote failure scenarios and per-branch error assertions. Test fixtures reworked to supply RemoteBranchHeads directly.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 19, 2026
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 19, 2026

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 19, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: petr-muller
Once this PR has been reviewed and has the lgtm label, please assign psalajova for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

…branch

Previously, mirror() called ls-remote for both source and destination
on every branch, resulting in 2*N network calls per repo where N is
the number of branches. Since ls-remote --heads returns ALL branches
at once, we can call it once per repo and pass the results to mirror().

This moves git init, remote setup, and ls-remote calls from mirror()
into the main loop where repos are already grouped, reducing network
calls from 2*N to 2 per repo.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@petr-muller petr-muller marked this pull request as ready for review March 19, 2026 19:09
Copilot AI review requested due to automatic review settings March 19, 2026 19:09
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 19, 2026
@petr-muller
Copy link
Member Author

/hold

Still need to review the code properly and address CodeRabbit reviews

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 19, 2026
@openshift-ci openshift-ci bot requested review from droslean and hector-vido March 19, 2026 19:10
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Reduces git ls-remote network calls in private-org-sync by batching branch head discovery once per repository (instead of per-branch), and passing those results into per-branch mirroring.

Changes:

  • Update gitSyncer.mirror() to accept pre-fetched source/destination branch heads and a pre-built destination URL.
  • Move destination/source ls-remote (and related URL construction) into the per-repo loop in main().
  • Refactor TestMirror to inject srcHeads/dstHeads and a destination URL rather than expecting ls-remote calls inside mirror().

Reviewed changes

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

File Description
cmd/private-org-sync/main.go Batches per-repo ls-remote calls and updates mirror() to consume pre-fetched heads/URL.
cmd/private-org-sync/main_test.go Adjusts TestMirror expectations to reflect the refactor (no ls-remote inside mirror()).

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

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
cmd/private-org-sync/main_test.go (1)

258-258: Minor: Error ignored in test setup.

The error from url.Parse is discarded. While this is fine for a hardcoded valid URL in tests, explicitly handling it would be more defensive.

♻️ Optional improvement
-	destUrl, _ := url.Parse(fmt.Sprintf("https://%s@github.com/%s/%s", token, destOrg, repo))
+	destUrl, err := url.Parse(fmt.Sprintf("https://%s@github.com/%s/%s", token, destOrg, repo))
+	if err != nil {
+		t.Fatalf("failed to parse destUrl: %v", err)
+	}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/private-org-sync/main_test.go` at line 258, The test currently ignores
the error returned by url.Parse when building destUrl; update the test to
capture the returned error (e.g., destUrl, err := url.Parse(...)) and assert or
fail on it (using t.Fatalf/require.NoError) so any unexpected parse failure for
the constructed URL using token, destOrg, and repo is handled instead of
silently ignored.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@cmd/private-org-sync/main_test.go`:
- Line 258: The test currently ignores the error returned by url.Parse when
building destUrl; update the test to capture the returned error (e.g., destUrl,
err := url.Parse(...)) and assert or fail on it (using t.Fatalf/require.NoError)
so any unexpected parse failure for the constructed URL using token, destOrg,
and repo is handled instead of silently ignored.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e6ae7923-e687-4285-9e9d-d93e163d9f02

📥 Commits

Reviewing files that changed from the base of the PR and between 7c4fa01 and 136df2b.

📒 Files selected for processing (2)
  • cmd/private-org-sync/main.go
  • cmd/private-org-sync/main_test.go

@petr-muller
Copy link
Member Author

/test images

@openshift-ci-robot
Copy link
Contributor

Pipeline controller notification

No second-stage tests were triggered for this PR.

This can happen when:

  • The changed files don't match any pipeline_run_if_changed patterns
  • All files match pipeline_skip_if_only_changed patterns
  • No pipeline-controlled jobs are defined for the main branch

Use /test ? to see all available tests.

Extract the per-repo sync logic from main() into a syncRepo method on
gitSyncer. This makes the repo initialization, ls-remote batching, and
branch mirroring flow independently testable.

Add TestSyncRepo with 6 test cases covering: branches in sync, one
branch needing sync, dst/src ls-remote failures (with and without
failOnNonexistentDst), and init failure.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@petr-muller
Copy link
Member Author

/test ci/prow/codegen ci/prow/format

@petr-muller
Copy link
Member Author

/test codegen format

@petr-muller
Copy link
Member Author

/test images

@petr-muller
Copy link
Member Author

@CodeRabbit help

@coderabbitai
Copy link

coderabbitai bot commented Mar 20, 2026

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

CodeRabbit commands

These commands are invoked using PR/Issue comments.

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai evaluate custom pre-merge check --instructions <custom-checks-instructions> --name <custom-checks-title> [--mode <error|warning>] to validate the custom pre-merge checks instructions. Defaults to error when --mode is omitted.
    • @coderabbitai ignore pre-merge checks to override pre-merge checks and get an approval on PR.
    • @coderabbitai run pre-merge checks to run pre-merge checks on the pull request.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve merge conflict to automatically resolve merge conflicts.
  • @coderabbitai autofix to automatically fix issues identified in unresolved review comments.
  • @coderabbitai resolve to resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai generate configuration to create a PR that adds the current resolved configuration as .coderabbit.yaml (or show it if already present).
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit configuration file (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, support, documentation and community

  • Visit our status page to check the current availability of CodeRabbit.
  • Create a ticket on our support page for assistance with any issues or questions.
  • Visit our documentation site for detailed information on how to use CodeRabbit.
  • Join our Discord community to connect with other users and get help from the community.
  • Follow us on X/Twitter for updates and announcements.

@petr-muller
Copy link
Member Author

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Mar 20, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@openshift-ci-robot
Copy link
Contributor

Pipeline controller notification

No second-stage tests were triggered for this PR.

This can happen when:

  • The changed files don't match any pipeline_run_if_changed patterns
  • All files match pipeline_skip_if_only_changed patterns
  • No pipeline-controlled jobs are defined for the main branch

Use /test ? to see all available tests.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 20, 2026

@petr-muller: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/breaking-changes a39befe link false /test breaking-changes

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@openshift-ci-robot
Copy link
Contributor

Pipeline controller notification

No second-stage tests were triggered for this PR.

This can happen when:

  • The changed files don't match any pipeline_run_if_changed patterns
  • All files match pipeline_skip_if_only_changed patterns
  • No pipeline-controlled jobs are defined for the main branch

Use /test ? to see all available tests.

1 similar comment
@openshift-ci-robot
Copy link
Contributor

Pipeline controller notification

No second-stage tests were triggered for this PR.

This can happen when:

  • The changed files don't match any pipeline_run_if_changed patterns
  • All files match pipeline_skip_if_only_changed patterns
  • No pipeline-controlled jobs are defined for the main branch

Use /test ? to see all available tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants