Skip to content
This repository has been archived by the owner on Jul 15, 2024. It is now read-only.

add a organizationNormalized template value for SCM provider #641

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/Generators-SCM-Provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ spec:
```

* `organization`: The name of the organization the repository is in.
* `organizationNormalized`: The `name` of the organization the repository is in *but normalized to contain only lowercase alphanumeric characters, '-' or '.'*.
* `repository`: The name of the repository.
* `url`: The clone URL for the repository.
* `branch`: The default branch of the repository.
Expand Down
13 changes: 7 additions & 6 deletions pkg/generators/scm_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,13 @@ func (g *SCMProviderGenerator) GenerateParams(appSetGenerator *argoprojiov1alpha
params := make([]map[string]string, 0, len(repos))
for _, repo := range repos {
params = append(params, map[string]string{
"organization": repo.Organization,
"repository": repo.Repository,
"url": repo.URL,
"branch": repo.Branch,
"sha": repo.SHA,
"labels": strings.Join(repo.Labels, ","),
"organization": repo.Organization,
"organizationNormalized": sanitizeName(repo.Organization),
"repository": repo.Repository,
"url": repo.URL,
"branch": repo.Branch,
"sha": repo.SHA,
"labels": strings.Join(repo.Labels, ","),
})
}
return params, nil
Expand Down
9 changes: 9 additions & 0 deletions pkg/generators/scm_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ func TestSCMProviderGenerateParams(t *testing.T) {
Branch: "main",
SHA: "00000000",
},
{
Organization: "myorg/myteam",
Repository: "repo3",
URL: "git@github.com:myorg/myteam/repo2.git",
Branch: "main",
SHA: "00000000",
},
},
}
gen := &SCMProviderGenerator{overrideProvider: mockProvider}
Expand All @@ -106,6 +113,8 @@ func TestSCMProviderGenerateParams(t *testing.T) {
assert.Nil(t, err)
assert.Len(t, params, 2)
assert.Equal(t, "myorg", params[0]["organization"])
assert.Equal(t, "myorg", params[0]["organizationNormalized"])
assert.Equal(t, "myorg/myteam", params[2]["organizationNormalized"])
assert.Equal(t, "repo1", params[0]["repository"])
assert.Equal(t, "git@github.com:myorg/repo1.git", params[0]["url"])
assert.Equal(t, "main", params[0]["branch"])
Expand Down