From 4e06ebaba33f1ac43c10f9b3afdc0a5491731604 Mon Sep 17 00:00:00 2001 From: Harold Wanyama Date: Tue, 18 Jul 2023 18:23:51 +0300 Subject: [PATCH] [#4006] Bug/Approval List handles - Updated validation for github and gitlab handles allowing . Signed-off-by: Harold Wanyama --- cla-backend-go/github/github_repository.go | 21 ++++++++++++++++----- cla-backend-go/utils/validators.go | 4 ++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/cla-backend-go/github/github_repository.go b/cla-backend-go/github/github_repository.go index a7f1bcc4d..b88f12f96 100644 --- a/cla-backend-go/github/github_repository.go +++ b/cla-backend-go/github/github_repository.go @@ -140,21 +140,32 @@ func (u UserCommitSummary) GetDisplayText(tagUser bool) string { } func (u UserCommitSummary) getUserInfo(tagUser bool) string { + + f := logrus.Fields{ + "functionName": "github.github_repository.getUserInfo", + "tagUser": tagUser, + } + userInfo := "" tagValue := "" var sb strings.Builder sb.WriteString(userInfo) + log.WithFields(f).Debugf("author: %+v", u.CommitAuthor) + if tagUser { tagValue = "@" } - if *u.CommitAuthor.Login != "" { - sb.WriteString(fmt.Sprintf("login: %s%s / ", tagValue, *u.CommitAuthor.Login)) - } + if u.CommitAuthor != nil { + if *u.CommitAuthor.Login != "" { + sb.WriteString(fmt.Sprintf("login: %s%s / ", tagValue, *u.CommitAuthor.Login)) + } - if u.CommitAuthor.Name != nil { - sb.WriteString(fmt.Sprintf("%sname: %s / ", userInfo, utils.StringValue(u.CommitAuthor.Name))) + if u.CommitAuthor.Name != nil { + sb.WriteString(fmt.Sprintf("%sname: %s / ", userInfo, utils.StringValue(u.CommitAuthor.Name))) + } } + return strings.Replace(sb.String(), "/ $", "", -1) } diff --git a/cla-backend-go/utils/validators.go b/cla-backend-go/utils/validators.go index d43334780..bb3cc8954 100644 --- a/cla-backend-go/utils/validators.go +++ b/cla-backend-go/utils/validators.go @@ -96,7 +96,7 @@ func ValidGitHubUsername(githubUsername string) (string, bool) { } // For now, we only allow alphanumeric values - re := regexp.MustCompile("^[a-zA-Z0-9_-]*$") + re := regexp.MustCompile("^[a-zA-Z0-9._-]*$") valid := re.MatchString(strings.TrimSpace(githubUsername)) if !valid { return fmt.Sprintf("invalid GitHub username: %s", githubUsername), false @@ -113,7 +113,7 @@ func ValidGitlabUsername(gitlabUsername string) (string, bool) { } // For now, we only allow alphanumeric values - re := regexp.MustCompile("^[a-zA-Z0-9_-]*$") + re := regexp.MustCompile("^[a-zA-Z0-9._-]*$") valid := re.MatchString(strings.TrimSpace(gitlabUsername)) if !valid { return fmt.Sprintf("invalid Gitlab username: %s", gitlabUsername), false