diff --git a/internal/constants/constants.go b/internal/constants/constants.go index f6f5e334..9abab1db 100644 --- a/internal/constants/constants.go +++ b/internal/constants/constants.go @@ -11,6 +11,7 @@ const ( // prompt constants MaxPnameLength = 16 + MaxOnameLength = 39 RegexValidation = "regex" FunctionValidation = "function" ZeroReleaseURL = "https://github.com/commitdev/zero/releases" diff --git a/internal/init/init.go b/internal/init/init.go index a0ddfc11..04520e49 100644 --- a/internal/init/init.go +++ b/internal/init/init.go @@ -130,12 +130,12 @@ func getProjectPrompts(projectName string, modules map[string]moduleconfig.Modul "GithubRootOrg": { Parameter: moduleconfig.Parameter{ Field: "GithubRootOrg", - Label: "What's the root of the github org to create repositories in?", + Label: "What's the root of the github organization that will own these repositories?", Info: "This should be github.com/", Default: "github.com/", }, - Condition: KeyMatchCondition("ShouldPushRepositories", "y"), - Validate: NoValidation, + Condition: NoCondition, + Validate: ValidateOrganizationName, }, } diff --git a/internal/init/prompts.go b/internal/init/prompts.go index fc33e0a8..b2c88078 100644 --- a/internal/init/prompts.go +++ b/internal/init/prompts.go @@ -105,6 +105,21 @@ func ValidateProjectName(input string) error { return nil } +// ValidateOrganizationName validates Organization Name field user input. +func ValidateOrganizationName(input string) error { + // the first 62 char out of base64 and - + var organizationName = strings.TrimLeft(input, "github.com/") + var oName = regexp.MustCompile(`^[A-Za-z0-9-]{1,39}$`) + // error if char len is greater than 39 + if len(organizationName) > constants.MaxOnameLength { + return errors.New("Invalid, Organization Name: (cannot exceed a max length of 39)") + } + if !oName.MatchString(organizationName) { + return errors.New("Invalid, Organization Name: (can only contain alphanumeric chars & '-')") + } + return nil +} + const infoBoxHeight = 4 var currentLine int = infoBoxHeight