Skip to content

Commit 27c0929

Browse files
authored
fix: gh check failing due to missing github organization (#462)
* fix: gh check failing due to missing github organization * fix: github organization validation conditions
1 parent 0f2eecc commit 27c0929

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

internal/constants/constants.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const (
1111
// prompt constants
1212

1313
MaxPnameLength = 16
14+
MaxOnameLength = 39
1415
RegexValidation = "regex"
1516
FunctionValidation = "function"
1617
ZeroReleaseURL = "https://github.com/commitdev/zero/releases"

internal/init/init.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ func getProjectPrompts(projectName string, modules map[string]moduleconfig.Modul
130130
"GithubRootOrg": {
131131
Parameter: moduleconfig.Parameter{
132132
Field: "GithubRootOrg",
133-
Label: "What's the root of the github org to create repositories in?",
133+
Label: "What's the root of the github organization that will own these repositories?",
134134
Info: "This should be github.com/<your-organization-name>",
135135
Default: "github.com/",
136136
},
137-
Condition: KeyMatchCondition("ShouldPushRepositories", "y"),
138-
Validate: NoValidation,
137+
Condition: NoCondition,
138+
Validate: ValidateOrganizationName,
139139
},
140140
}
141141

internal/init/prompts.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,21 @@ func ValidateProjectName(input string) error {
105105
return nil
106106
}
107107

108+
// ValidateOrganizationName validates Organization Name field user input.
109+
func ValidateOrganizationName(input string) error {
110+
// the first 62 char out of base64 and -
111+
var organizationName = strings.TrimLeft(input, "github.com/")
112+
var oName = regexp.MustCompile(`^[A-Za-z0-9-]{1,39}$`)
113+
// error if char len is greater than 39
114+
if len(organizationName) > constants.MaxOnameLength {
115+
return errors.New("Invalid, Organization Name: (cannot exceed a max length of 39)")
116+
}
117+
if !oName.MatchString(organizationName) {
118+
return errors.New("Invalid, Organization Name: (can only contain alphanumeric chars & '-')")
119+
}
120+
return nil
121+
}
122+
108123
const infoBoxHeight = 4
109124

110125
var currentLine int = infoBoxHeight

0 commit comments

Comments
 (0)