Skip to content

fix(private-org-sync): run git init and remote setup once per repo#5011

Open
petr-muller wants to merge 1 commit intoopenshift:mainfrom
petr-muller:git-sync-speedup-1
Open

fix(private-org-sync): run git init and remote setup once per repo#5011
petr-muller wants to merge 1 commit intoopenshift:mainfrom
petr-muller:git-sync-speedup-1

Conversation

@petr-muller
Copy link
Member

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

Previously, mirror() called git init and git remote get-url /git remote add for every (org, repo, branch) location.

Extract these steps into initRepo() and restructure the main loop to group locations by org/repo and init just once.

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

Summary by CodeRabbit

  • Tests

    • Added test coverage for repository initialization logic across multiple scenarios including cold/warm cache and failure cases.
  • Refactor

    • Modified repository processing to batch by organization and repository name.
    • Streamlined initialization workflow to reduce redundant operations.
    • Enhanced error reporting with per-source context on initialization failures.

Previously, mirror() called `git init` and `git remote get-url` /
`git remote add` for every (org, repo, branch) location.

Extract these steps into initRepo() and restructure the main loop to
group locations by org/repo and init just once.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@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

Copilot AI review requested due to automatic review settings March 13, 2026 00:07
@coderabbitai
Copy link

coderabbitai bot commented Mar 13, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0d778696-337c-4c54-81ed-d3bbd91b10a7

📥 Commits

Reviewing files that changed from the base of the PR and between 7693b73 and 1107417.

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

Walkthrough

The changes refactor the Git repository synchronization tool by extracting repository initialization into a dedicated initRepo method on gitSyncer, shifting the control flow from per-source handling to grouped-by-repository processing, and updating tests accordingly.

Changes

Cohort / File(s) Summary
Core Implementation
cmd/private-org-sync/main.go
Introduces initRepo method to handle repository initialization and source remote setup. Refactors main control flow to group locations by (org, repo) pair, initializing each repository once before per-source mirroring. Reduces mirror method scope to assume pre-initialized repos. Replaces per-source reconfiguration with per-group initialization followed by per-source destination computation and mirroring.
Test Updates
cmd/private-org-sync/main_test.go
Refactors TestMirror expectations to remove Git operations now handled by initRepo. Adds new TestInitRepo test covering cold cache initialization, warm cache scenarios, and failure cases for both init and remote add operations.

Sequence Diagram(s)

sequenceDiagram
    participant Main as Main Control Flow
    participant GS as gitSyncer
    participant GE as Git Executor

    Main->>Main: Group locations by (org, repo)
    
    loop Per repository group
        Main->>GS: initRepo(repoDir, org, repo)
        activate GS
        
        GS->>GE: git init
        activate GE
        GE-->>GS: success or error
        deactivate GE
        
        alt If init succeeded
            GS->>GE: git remote get-url source
            activate GE
            GE-->>GS: remote exists or not found
            deactivate GE
            
            alt Remote doesn't exist
                GS->>GE: git remote add source <url>
                activate GE
                GE-->>GS: success or error
                deactivate GE
            end
        end
        
        GS-->>Main: error (if any) with context
        deactivate GS
    end
    
    loop Per source in group
        Main->>GS: mirror(repoDir, source, destination)
        activate GS
        
        GS->>GE: git fetch source
        activate GE
        GE-->>GS: success or error
        deactivate GE
        
        GS->>GE: git push destination
        activate GE
        GE-->>GS: success or error
        deactivate GE
        
        GS-->>Main: error (if any)
        deactivate GS
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly describes the main change: extracting git init and remote setup into initRepo to run once per repository instead of per location, which aligns with the core refactoring in the changeset.
Stable And Deterministic Test Names ✅ Passed This pull request does not use the Ginkgo testing framework. The test file uses Go's standard testing package with static test names and no dynamic content.
Test Structure And Quality ✅ Passed Test file uses standard Go testing package, not Ginkgo framework, so check is not applicable.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

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

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

Refactors private-org-sync to avoid repeated local-repo initialization work by initializing each (org, repo) once, then mirroring multiple branches using the same prepared local checkout/cache.

Changes:

  • Added gitSyncer.initRepo() to run git init and ensure the source remote exists once per (org, repo).
  • Updated main() to group locations by (org, repo), initialize once, then mirror each branch.
  • Updated tests to remove per-mirror() init/remote expectations and added dedicated TestInitRepo.

Reviewed changes

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

File Description
cmd/private-org-sync/main.go Introduces initRepo() and restructures the main loop to initialize git repos/remotes once per repo before mirroring branches.
cmd/private-org-sync/main_test.go Adjusts TestMirror expectations to match the new initialization flow and adds TestInitRepo coverage.

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

You can also share your feedback on Copilot code review. Take the survey.

@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 13, 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 1107417 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 openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Mar 13, 2026
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 13, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: droslean, petr-muller

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

The pull request process is described 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

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 13, 2026
@petr-muller
Copy link
Member Author

Thanks!

/hold

I'd like to test this better, I should have filed the PR as a draft

@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 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants