fix(private-org-sync): run git init and remote setup once per repo#5011
fix(private-org-sync): run git init and remote setup once per repo#5011petr-muller wants to merge 1 commit intoopenshift:mainfrom
Conversation
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>
|
Pipeline controller notification For optional jobs, comment This repository is configured in: automatic mode |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: openshift/coderabbit/.coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughThe changes refactor the Git repository synchronization tool by extracting repository initialization into a dedicated Changes
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Comment |
There was a problem hiding this comment.
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 rungit initand 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 dedicatedTestInitRepo.
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.
|
Pipeline controller notification No second-stage tests were triggered for this PR. This can happen when:
Use |
|
@petr-muller: The following test failed, say
Full PR test history. Your PR dashboard. DetailsInstructions 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. |
|
[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 DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
Thanks! /hold I'd like to test this better, I should have filed the PR as a draft |
Previously, mirror() called
git initandgit remote get-url/git remote addfor 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
Refactor