Skip to content

Feat | Add --repo-regex option and made --repo stricter #436

Merged
dag-andersen merged 4 commits into
mainfrom
add-repo-regex-option
May 23, 2026
Merged

Feat | Add --repo-regex option and made --repo stricter #436
dag-andersen merged 4 commits into
mainfrom
add-repo-regex-option

Conversation

@dag-andersen

Copy link
Copy Markdown
Owner

related to #426

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 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.Selector with 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 $ref detection 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.

Comment thread cmd/options.go Outdated
@@ -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 thread cmd/options.go
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 thread cmd/options.go Outdated
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())
}
Comment thread docs/options.md Outdated
@@ -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 thread pkg/repository/match.go Outdated
Comment on lines +54 to +58
func MatchesRepo(repoURL, repo string) bool {
normalizedURL := normalizeRepoMatchInput(repoURL)
normalizedRepo := normalizeRepoMatchInput(repo)
if normalizedURL == "" || normalizedRepo == "" {
return false
@dag-andersen dag-andersen merged commit 90d4c0d into main May 23, 2026
3 checks passed
@dag-andersen dag-andersen deleted the add-repo-regex-option branch May 23, 2026 14:38
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