Skip to content

Commit

Permalink
fix: sources.ref allow hyphen and underscore (#11775)
Browse files Browse the repository at this point in the history
Signed-off-by: toyamagu2021@gmail.com <toyamagu2021@gmail.com>

Signed-off-by: toyamagu2021@gmail.com <toyamagu2021@gmail.com>
  • Loading branch information
toyamagu-2021 authored and crenshaw-dev committed Dec 20, 2022
1 parent cdaf2b2 commit 3a8802f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions util/argo/argo.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,9 @@ func GetRefSources(ctx context.Context, spec argoappv1.ApplicationSpec, db db.Ar
refKeys := make(map[string]bool)
for _, source := range spec.Sources {
if source.Ref != "" {
isValidRefKey := regexp.MustCompile(`^[a-zA-Z0-9]+$`).MatchString
isValidRefKey := regexp.MustCompile(`^[a-zA-Z0-9_-]+$`).MatchString
if !isValidRefKey(source.Ref) {
return nil, fmt.Errorf("source.ref %s cannot contain any special characters except '_' and '-'", source.Ref)
return nil, fmt.Errorf("sources.ref %s cannot contain any special characters except '_' and '-'", source.Ref)
}
refKey := "$" + source.Ref
if _, ok := refKeys[refKey]; ok {
Expand Down
4 changes: 2 additions & 2 deletions util/argo/argo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1043,14 +1043,14 @@ func Test_GetRefSources(t *testing.T) {
repoDB.On("GetRepository", context.Background(), repo.Repo).Return(repo, nil)

argoSpec := getMultiSourceAppSpec(argoappv1.ApplicationSources{
{RepoURL: fmt.Sprintf("file://%s", repoPath), Ref: "source1"},
{RepoURL: fmt.Sprintf("file://%s", repoPath), Ref: "source-1_2"},
{RepoURL: fmt.Sprintf("file://%s", repoPath)},
})

refSources, err := GetRefSources(context.TODO(), *argoSpec, repoDB)

expectedRefSource := argoappv1.RefTargetRevisionMapping{
"$source1": &argoappv1.RefTarget{
"$source-1_2": &argoappv1.RefTarget{
Repo: *repo,
},
}
Expand Down

0 comments on commit 3a8802f

Please sign in to comment.