From afb36ec8ad3ef7c36f83266dff0afc1427fa4f0a Mon Sep 17 00:00:00 2001 From: Sachin Chavan Date: Sun, 27 Feb 2022 23:17:46 +0400 Subject: [PATCH 1/2] fix: gh check failing due to missing github organization --- internal/init/init.go | 6 +++--- internal/init/prompts.go | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) 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..7bfd901e 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}$`) + if !oName.MatchString(organizationName) { + // error if char len is greater than 39 + if len(organizationName) > constants.MaxPnameLength { + return errors.New("Invalid, Organization Name: (cannot exceed a max length of 39)") + } + return errors.New("Invalid, Organization Name: (can only contain alphanumeric chars & '-')") + } + return nil +} + const infoBoxHeight = 4 var currentLine int = infoBoxHeight From 4786671ae6a96c7168f150568e67f935b247ed60 Mon Sep 17 00:00:00 2001 From: Sachin Chavan Date: Tue, 1 Mar 2022 09:57:53 +0400 Subject: [PATCH 2/2] fix: github organization validation conditions --- internal/constants/constants.go | 1 + internal/init/prompts.go | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) 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/prompts.go b/internal/init/prompts.go index 7bfd901e..b2c88078 100644 --- a/internal/init/prompts.go +++ b/internal/init/prompts.go @@ -110,11 +110,11 @@ 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) { - // error if char len is greater than 39 - if len(organizationName) > constants.MaxPnameLength { - return errors.New("Invalid, Organization Name: (cannot exceed a max length of 39)") - } return errors.New("Invalid, Organization Name: (can only contain alphanumeric chars & '-')") } return nil