Skip to content

Commit

Permalink
Merge pull request #74 from aquasecurity/bugfix/invalid-scm-api-url
Browse files Browse the repository at this point in the history
using the discovered scm api url instead of a simply parsed one
  • Loading branch information
orizerah authored Oct 4, 2023
2 parents 06a5517 + 6298197 commit 03cd69b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 25 deletions.
30 changes: 6 additions & 24 deletions pkg/commenter/jenkins/jenkins.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package jenkins

import (
"fmt"
"os"
"strconv"
"strings"

"github.com/aquasecurity/go-git-pr-commenter/pkg/commenter/github"
"github.com/argonsecurity/go-environments/enums"
"github.com/argonsecurity/go-environments/environments/jenkins"
env_utils "github.com/argonsecurity/go-environments/environments/utils"
"net/url"
"os"
"strconv"
"strings"

"github.com/aquasecurity/go-git-pr-commenter/pkg/commenter"
"github.com/aquasecurity/go-git-pr-commenter/pkg/commenter/bitbucket"
Expand Down Expand Up @@ -37,11 +37,7 @@ func NewJenkins(baseRef string) (commenter.Repository, error) {
} else { // bitbucket server
repoName := bitbucketutils.GetRepositoryName(cloneUrl)
project, repo := bitbucketutils.GetProjectAndRepo(repoName)
apiUrl, err := getBaseUrl(cloneUrl)
if err != nil {
return nil, err
}
return bitbucket_server.NewBitbucketServer(apiUrl, username, password, bitbucketutils.GetPrId(), project, repo, baseRef)
return bitbucket_server.NewBitbucketServer(scmApiUrl, username, password, bitbucketutils.GetPrId(), project, repo, baseRef)
}
} else if scmSource == enums.GithubServer || scmSource == enums.Github {
_, org, repoName, _, err := env_utils.ParseDataFromCloneUrl(cloneUrl, scmApiUrl, scmSource)
Expand All @@ -66,23 +62,9 @@ func NewJenkins(baseRef string) (commenter.Repository, error) {
repoName,
prNumberInt)
} else { //github server
apiUrl, err := getBaseUrl(cloneUrl)
if err != nil {
return nil, err
}
return github.NewGithubServer(apiUrl, token, org, repoName, prNumberInt)
return github.NewGithubServer(scmApiUrl, token, org, repoName, prNumberInt)
}

}

return nil, nil
}

func getBaseUrl(fullUrl string) (string, error) {
u, err := url.Parse(fullUrl)
if err != nil {
return "", fmt.Errorf("failed to parse url %s - %s", fullUrl, err.Error())
}

return fmt.Sprintf("%s://%s", u.Scheme, u.Host), nil
}
2 changes: 1 addition & 1 deletion pkg/commenter/utils/comment_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func GetRepositoryCloneURL() (string, error) {
func getGitRemoteURL() (string, error) {
repositoryPath, ok := os.LookupEnv("WORKSPACE")
if !ok {
return "", errors.New("colud not find remote url, no WORKSPACE env var")
return "", errors.New("could not find remote url, no WORKSPACE env var")
}
remotes, err := getGitRemotes(repositoryPath)
if err != nil {
Expand Down

0 comments on commit 03cd69b

Please sign in to comment.