Feat | Add --repo-regex option and made --repo stricter #436
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a new repository matching abstraction to make --repo matching stricter (avoiding prefix/substring false-positives) and adds an advanced --repo-regex option to support templated Argo CD repoURL values. It also updates the repo-server rendering path to correctly fall back to remote RPC when any $ref source repo does not match the selected repo, addressing issue #426.
Changes:
- Add
pkg/repository.Selectorwith strict repo identity matching (MatchesRepo) and optional regex matching (--repo-regex). - Update Application patching and repo-server rendering logic to use the selector (including external
$refdetection and prefix-safe matching). - Extend CLI/options/docs and add/adjust unit tests for strict matching and regex behavior.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/repository/match.go | New repo selector + strict repo identity matcher implementation. |
| pkg/repository/match_test.go | Unit tests for strict matching and regex selector behavior. |
| pkg/reposerverextract/repocreds.go | Switch repo comparison for PR repo matching to strict identity match. |
| pkg/reposerverextract/extract.go | Use repository.Selector for PR repo matching; remote-RPC fallback when ref sources are external. |
| pkg/reposerverextract/extract_test.go | Update tests to use selectors; add regression coverage for prefix-sharing external ref repos. |
| pkg/reposerverextract/appofapps.go | Thread repository.Selector through app-of-apps traversal rendering and patching. |
| pkg/argoapplication/patching.go | Use selector for redirect logic (sources/generators) instead of substring matching. |
| pkg/argoapplication/patching_test.go | Add coverage for prefix-safe matching and --repo-regex redirect behavior. |
| pkg/argoapplication/applications.go | Pass selector through application loading/patching flow. |
| pkg/argoapplication/application_sets.go | Pass selector through ApplicationSet conversion flow. |
| pkg/argoapplication/app_status.go | Inline case-insensitive “error” check (removes old helper). |
| docs/options.md | Document --repo-regex and updated usage. |
| cmd/options.go | Add --repo-regex, enforce mutual exclusivity, store selector in config, and log it. |
| cmd/main.go | Pass selector into downstream application/rendering flows. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -303,6 +305,7 @@ func Parse() *Config { | |||
| rootCmd.Flags().StringP("base-branch", "b", DefaultBaseBranch, "Base branch name") | |||
| rootCmd.Flags().StringP("target-branch", "t", "", "Target branch name (required)") | |||
| rootCmd.Flags().String("repo", "", "Git Repository. Format: OWNER/REPO (required)") | |||
Comment on lines
+535
to
+539
| func (o *RawOptions) parseRepositorySelector() (repository.Selector, error) { | ||
| repoSelector, err := repository.NewSelector(o.Repo, o.RepoRegex) | ||
| if err != nil { | ||
| return repository.Selector{}, fmt.Errorf("invalid repo-regex: %w", err) | ||
| } |
Comment on lines
+676
to
+679
| log.Info().Msgf("✨ - repo: %s", o.RepoSelector.Repo) | ||
| if o.RepoSelector.Regex != nil { | ||
| log.Info().Msgf("✨ - repo-regex: %s", o.RepoSelector.Regex.String()) | ||
| } |
| @@ -65,6 +65,7 @@ argocd-diff-preview [FLAGS] [OPTIONS] --repo <repo> --target-branch <target-bran | |||
| | `--output-folder <folder>`, `-o` | `OUTPUT_FOLDER` | `./output` | Output folder where the diff will be saved | | |||
| | `--redirect-target-revisions <revs>` | `REDIRECT_TARGET_REVISIONS` | - | List of target revisions to redirect | | |||
Comment on lines
+54
to
+58
| func MatchesRepo(repoURL, repo string) bool { | ||
| normalizedURL := normalizeRepoMatchInput(repoURL) | ||
| normalizedRepo := normalizeRepoMatchInput(repo) | ||
| if normalizedURL == "" || normalizedRepo == "" { | ||
| return false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
related to #426