Skip to content

Commit 03cd69b

Browse files
authored
Merge pull request #74 from aquasecurity/bugfix/invalid-scm-api-url
using the discovered scm api url instead of a simply parsed one
2 parents 06a5517 + 6298197 commit 03cd69b

File tree

2 files changed

+7
-25
lines changed

2 files changed

+7
-25
lines changed

pkg/commenter/jenkins/jenkins.go

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ package jenkins
22

33
import (
44
"fmt"
5+
"os"
6+
"strconv"
7+
"strings"
8+
59
"github.com/aquasecurity/go-git-pr-commenter/pkg/commenter/github"
610
"github.com/argonsecurity/go-environments/enums"
711
"github.com/argonsecurity/go-environments/environments/jenkins"
812
env_utils "github.com/argonsecurity/go-environments/environments/utils"
9-
"net/url"
10-
"os"
11-
"strconv"
12-
"strings"
1313

1414
"github.com/aquasecurity/go-git-pr-commenter/pkg/commenter"
1515
"github.com/aquasecurity/go-git-pr-commenter/pkg/commenter/bitbucket"
@@ -37,11 +37,7 @@ func NewJenkins(baseRef string) (commenter.Repository, error) {
3737
} else { // bitbucket server
3838
repoName := bitbucketutils.GetRepositoryName(cloneUrl)
3939
project, repo := bitbucketutils.GetProjectAndRepo(repoName)
40-
apiUrl, err := getBaseUrl(cloneUrl)
41-
if err != nil {
42-
return nil, err
43-
}
44-
return bitbucket_server.NewBitbucketServer(apiUrl, username, password, bitbucketutils.GetPrId(), project, repo, baseRef)
40+
return bitbucket_server.NewBitbucketServer(scmApiUrl, username, password, bitbucketutils.GetPrId(), project, repo, baseRef)
4541
}
4642
} else if scmSource == enums.GithubServer || scmSource == enums.Github {
4743
_, org, repoName, _, err := env_utils.ParseDataFromCloneUrl(cloneUrl, scmApiUrl, scmSource)
@@ -66,23 +62,9 @@ func NewJenkins(baseRef string) (commenter.Repository, error) {
6662
repoName,
6763
prNumberInt)
6864
} else { //github server
69-
apiUrl, err := getBaseUrl(cloneUrl)
70-
if err != nil {
71-
return nil, err
72-
}
73-
return github.NewGithubServer(apiUrl, token, org, repoName, prNumberInt)
65+
return github.NewGithubServer(scmApiUrl, token, org, repoName, prNumberInt)
7466
}
7567

7668
}
77-
7869
return nil, nil
7970
}
80-
81-
func getBaseUrl(fullUrl string) (string, error) {
82-
u, err := url.Parse(fullUrl)
83-
if err != nil {
84-
return "", fmt.Errorf("failed to parse url %s - %s", fullUrl, err.Error())
85-
}
86-
87-
return fmt.Sprintf("%s://%s", u.Scheme, u.Host), nil
88-
}

pkg/commenter/utils/comment_utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func GetRepositoryCloneURL() (string, error) {
6666
func getGitRemoteURL() (string, error) {
6767
repositoryPath, ok := os.LookupEnv("WORKSPACE")
6868
if !ok {
69-
return "", errors.New("colud not find remote url, no WORKSPACE env var")
69+
return "", errors.New("could not find remote url, no WORKSPACE env var")
7070
}
7171
remotes, err := getGitRemotes(repositoryPath)
7272
if err != nil {

0 commit comments

Comments
 (0)