Skip to content

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

Merged
merged 6 commits into from
Jul 16, 2025

Conversation

chriscn
Copy link
Contributor

@chriscn chriscn commented Jun 12, 2025

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".

@bastelfreak bastelfreak added the enhancement New feature or request label Jun 12, 2025
Copy link
Member

@dhollinger dhollinger left a 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.

Comment on lines 23 to 30
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)
}
}
Copy link
Member

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

@@ -1,6 +1,7 @@
package helpers

import (
"fmt"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting

Comment on lines 32 to 52
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)

}
Copy link
Member

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.

dhollinger and others added 2 commits July 16, 2025 09:31
Fixed the formatting of the code and removed a shadow declaration of the
`err` variable
@dhollinger dhollinger merged commit f6dce68 into voxpupuli:master Jul 16, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants