-
-
Notifications
You must be signed in to change notification settings - Fork 14
Feature: Add ability to have custom mappings of repository name to a prefix #202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just need some formatting changes and a quick answer to a question on the switch statement in the environment deploy.
lib/helpers/prefix.go
Outdated
func (h *Helper) GetPrefixFromMapping(mapping map[string]string, repoName string) (string, error) { | ||
prefix, ok := mapping[repoName] | ||
if ok { | ||
return prefix, nil | ||
} else { | ||
return "", fmt.Errorf("Prefix not found in mapping for repo '%s'", repoName) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting issues. Use tabs instead of spaces here
lib/helpers/prefix.go
Outdated
@@ -1,6 +1,7 @@ | |||
package helpers | |||
|
|||
import ( | |||
"fmt" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting
lib/helpers/prefix_test.go
Outdated
func Test_GetPrefixFromMapping(t *testing.T) { | ||
h := Helper{} | ||
mapping := map[string]string{ | ||
"testrepo": "testprefix", | ||
"otherrepo": "", | ||
} | ||
|
||
prefix, err := h.GetPrefixFromMapping(mapping, "testrepo") | ||
assert.NilError(t, err) | ||
assert.Equal(t, "testprefix", prefix) | ||
|
||
prefix, err = h.GetPrefixFromMapping(mapping, "otherrepo") | ||
assert.NilError(t, err) | ||
assert.Equal(t, "", prefix) | ||
|
||
// Test with a repo not in the mapping | ||
prefix, err = h.GetPrefixFromMapping(mapping, "nonexistentrepo") | ||
assert.Error(t, err, "Prefix not found in mapping for repo 'nonexistentrepo'") | ||
assert.Equal(t, "", prefix) | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatting. Tabs instead of spaces.
Fixed the formatting of the code and removed a shadow declaration of the `err` variable
When using
webhook-go
in a large enterprise setup we have lots of Puppet control repositories all pointing to the same r10k setup. As part of this we want to prefix environments with short keys to differentiate them.This PR adds an extra config option that maps a repostiory name to a prefix. It requires setting the prefix to "mapping".