Skip to content

Commit

Permalink
chore(tibuild): add checks for method `GitHubClient#GetBranchesForCom…
Browse files Browse the repository at this point in the history
…mit`

Signed-off-by: wuhuizuo <[email protected]>
  • Loading branch information
wuhuizuo committed Dec 31, 2024
1 parent 3ecf1f8 commit 9045866
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tibuild/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/PingCAP-QE/ee-apps/tibuild

go 1.23
go 1.23.4

require (
github.com/DATA-DOG/go-sqlmock v1.5.2
Expand Down
13 changes: 13 additions & 0 deletions tibuild/pkg/rest/service/gh_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ type branchesForCommitResponse struct {

// GetBranchesForCommit implements GHClient.
func (c GitHubClient) GetBranchesForCommit(ctx context.Context, owner string, repo string, commit string) ([]string, error) {
// check for github owner format with regexp, only support [a-zA-Z0-9_-]
if !regexp.MustCompile(`^[a-zA-Z0-9_-]+$`).MatchString(owner) {
return nil, fmt.Errorf("owner %s is not a valid github owner", owner)
}
// check for github repo name format with regexp, only support [a-zA-Z0-9_-]
if !regexp.MustCompile(`^[a-zA-Z0-9_-]+$`).MatchString(repo) {
return nil, fmt.Errorf("repo %s is not a valid github repo name", repo)
}
// check for commit format
if !sha1regex.MatchString(commit) {
return nil, fmt.Errorf("commit %s is not a valid sha1", commit)
}

rawURL, err := url.JoinPath("https://github.com", owner, repo, "branch_commits", commit)
if err != nil {
return nil, err
Expand Down

0 comments on commit 9045866

Please sign in to comment.