Skip to content

Commit

Permalink
fix: gh check failing due to missing github organization (#462)
Browse files Browse the repository at this point in the history
* fix: gh check failing due to missing github organization

* fix: github organization validation conditions
  • Loading branch information
sachinsmc committed Mar 2, 2022
1 parent 0f2eecc commit 27c0929
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions internal/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const (
// prompt constants

MaxPnameLength = 16
MaxOnameLength = 39
RegexValidation = "regex"
FunctionValidation = "function"
ZeroReleaseURL = "https://github.com/commitdev/zero/releases"
Expand Down
6 changes: 3 additions & 3 deletions internal/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/<your-organization-name>",
Default: "github.com/",
},
Condition: KeyMatchCondition("ShouldPushRepositories", "y"),
Validate: NoValidation,
Condition: NoCondition,
Validate: ValidateOrganizationName,
},
}

Expand Down
15 changes: 15 additions & 0 deletions internal/init/prompts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 27c0929

Please sign in to comment.