1
0
mirror of synced 2026-02-07 03:05:56 +00:00

Merge pull request #648 from SomtochiAma/validate-project-name

Validates project name for gitlab
This commit is contained in:
Stefan Prodan
2021-01-05 16:04:34 +02:00
committed by GitHub

View File

@@ -23,6 +23,7 @@ import (
"net/url" "net/url"
"os" "os"
"path" "path"
"regexp"
"time" "time"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@@ -67,6 +68,10 @@ the bootstrap command will perform an upgrade if needed.`,
RunE: bootstrapGitLabCmdRun, RunE: bootstrapGitLabCmdRun,
} }
const (
gitlabProjectRegex = `\A[[:alnum:]\x{00A9}-\x{1f9ff}_][[:alnum:]\p{Pd}\x{00A9}-\x{1f9ff}_\.]*\z`
)
var ( var (
glOwner string glOwner string
glRepository string glRepository string
@@ -97,6 +102,14 @@ func bootstrapGitLabCmdRun(cmd *cobra.Command, args []string) error {
return fmt.Errorf("%s environment variable not found", git.GitLabTokenName) return fmt.Errorf("%s environment variable not found", git.GitLabTokenName)
} }
projectNameIsValid, err := regexp.MatchString(gitlabProjectRegex, glRepository)
if err != nil {
return err
}
if !projectNameIsValid {
return fmt.Errorf("%s is an invalid project name for gitlab.\nIt can contain only letters, digits, emojis, '_', '.', dash, space. It must start with letter, digit, emoji or '_'.", glRepository)
}
if err := bootstrapValidate(); err != nil { if err := bootstrapValidate(); err != nil {
return err return err
} }