Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ import (
"github.com/jfrog/frogbot/v2/scanpullrequest"
"github.com/jfrog/frogbot/v2/scanrepository"
"github.com/jfrog/frogbot/v2/utils"
"github.com/jfrog/frogbot/v2/utils/outputwriter"

"github.com/jfrog/jfrog-cli-security/utils/xsc"
clitool "github.com/urfave/cli/v2"
)

type FrogbotCommand interface {
// Run the command
Run(config utils.Repository, client vcsclient.VcsClient, frogbotRepoConnection *utils.UrlAccessChecker) error
Run(config utils.Repository, client vcsclient.VcsClient) error
}

func GetCommands() []*clitool.Command {
Expand Down Expand Up @@ -54,8 +52,6 @@ func Exec(command FrogbotCommand, commandName string) (err error) {
if err != nil {
return err
}
// Check if the user has access to the frogbot repository (to access the resources needed)
frogbotRepoConnection := utils.CheckConnection(outputwriter.FrogbotRepoUrl)

// Build the server configuration file
originalJfrogHomeDir, tempJFrogHomeDir, err := utils.BuildServerConfigFile(frogbotDetails.ServerDetails)
Expand All @@ -79,7 +75,7 @@ func Exec(command FrogbotCommand, commandName string) (err error) {

// Invoke the command interface
log.Info(fmt.Sprintf("Running Frogbot %q command", commandName))
err = command.Run(frogbotDetails.Repository, frogbotDetails.GitClient, frogbotRepoConnection)
err = command.Run(frogbotDetails.Repository, frogbotDetails.GitClient)

if err != nil {
if reportError := xsc.ReportError(frogbotDetails.XrayVersion, frogbotDetails.XscVersion, frogbotDetails.ServerDetails, err, "frogbot", frogbotDetails.Repository.JFrogProjectKey); reportError != nil {
Expand Down
8 changes: 3 additions & 5 deletions scanpullrequest/scanpullrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@ type targetPair struct {

type ScanPullRequestCmd struct{}

func (pr *ScanPullRequestCmd) Run(repository utils.Repository, client vcsclient.VcsClient, frogbotRepoConnection *utils.UrlAccessChecker) (err error) {
repoConfig := &repository
repoConfig.OutputWriter.SetHasInternetConnection(frogbotRepoConnection.IsConnected())
if repoConfig.Params.Git.PullRequestDetails, err = client.GetPullRequestByID(context.Background(),
repoConfig.Params.Git.RepoOwner, repoConfig.Params.Git.RepoName, int(repoConfig.Params.Git.PullRequestDetails.ID)); err != nil {
func (pr *ScanPullRequestCmd) Run(repository utils.Repository, client vcsclient.VcsClient) (err error) {
if repository.Params.Git.PullRequestDetails, err = client.GetPullRequestByID(context.Background(),
repository.Params.Git.RepoOwner, repository.Params.Git.RepoName, int(repository.Params.Git.PullRequestDetails.ID)); err != nil {
return
}
pullRequestDetails := &repository.Params.Git.PullRequestDetails
Expand Down
2 changes: 1 addition & 1 deletion scanpullrequest/scanpullrequest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func testScanPullRequest(t *testing.T, projectName string) {

// Run "frogbot scan pull request"
var scanPullRequest ScanPullRequestCmd
err := scanPullRequest.Run(config, client, utils.MockHasConnection())
err := scanPullRequest.Run(config, client)
assert.NoError(t, err)

// Check env sanitize
Expand Down
6 changes: 2 additions & 4 deletions scanrepository/scanrepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ type ScanRepositoryCmd struct {
XscVersion string
}

func (sr *ScanRepositoryCmd) Run(repository utils.Repository, client vcsclient.VcsClient, frogbotRepoConnection *utils.UrlAccessChecker) (err error) {
repository.OutputWriter.SetHasInternetConnection(frogbotRepoConnection.IsConnected())
func (sr *ScanRepositoryCmd) Run(repository utils.Repository, client vcsclient.VcsClient) (err error) {
sr.XrayVersion = repository.Params.XrayVersion
sr.XscVersion = repository.Params.XscVersion
if err = sr.setCommandPrerequisites(&repository, client); err != nil {
Expand Down Expand Up @@ -106,8 +105,7 @@ func (sr *ScanRepositoryCmd) setCommandPrerequisites(repository *utils.Repositor
SetResultsContext(repositoryCloneUrl, repository.Params.JFrogPlatform.JFrogProjectKey, false).
SetConfigProfile(repository.Params.ConfigProfile)

// Set the outputwriter interface for the relevant vcs git provider
sr.OutputWriter = outputwriter.GetCompatibleOutputWriter(repository.Params.Git.GitProvider)
sr.OutputWriter = repository.OutputWriter
sr.OutputWriter.SetSizeLimit(client)
// Set the git client to perform git operations
sr.gitManager, err = utils.NewGitManager().
Expand Down
4 changes: 2 additions & 2 deletions scanrepository/scanrepository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func TestScanRepositoryCmd_Run(t *testing.T) {

// Run
var cmd = ScanRepositoryCmd{XrayVersion: xrayVersion, XscVersion: xscVersion, dryRun: true, dryRunRepoPath: testDir}
err = cmd.Run(repository, client, utils.MockHasConnection())
err = cmd.Run(repository, client)
defer func() {
assert.NoError(t, os.Chdir(baseDir))
}()
Expand Down Expand Up @@ -334,7 +334,7 @@ pr body

// Run
var cmd = ScanRepositoryCmd{dryRun: true, dryRunRepoPath: testDir}
err = cmd.Run(repository, client, utils.MockHasConnection())
err = cmd.Run(repository, client)
defer func() {
assert.NoError(t, os.Chdir(baseDir))
}()
Expand Down
4 changes: 3 additions & 1 deletion utils/getconfiguration.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ type Repository struct {
}

func (r *Repository) setOutputWriterDetails() {
r.OutputWriter = outputwriter.GetCompatibleOutputWriter(r.Params.Git.GitProvider)
// Check if the user has access to the frogbot repository (to access the resources needed)
frogbotRepoConnection := CheckConnection(outputwriter.FrogbotRepoUrl)
r.OutputWriter = outputwriter.GetCompatibleOutputWriter(r.Params.Git.GitProvider, frogbotRepoConnection.IsConnected())
}

type Params struct {
Expand Down
10 changes: 4 additions & 6 deletions utils/outputwriter/outputwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,11 @@ func (mo *MarkdownOutput) SetSizeLimit(client vcsclient.VcsClient) {
mo.descriptionSizeLimit = client.GetPullRequestDetailsSizeLimit()
}

func GetCompatibleOutputWriter(provider vcsutils.VcsProvider) OutputWriter {
switch provider {
case vcsutils.BitbucketServer:
return &SimplifiedOutput{MarkdownOutput{vcsProvider: provider, hasInternetConnection: true}}
default:
return &StandardOutput{MarkdownOutput{vcsProvider: provider, hasInternetConnection: true}}
func GetCompatibleOutputWriter(provider vcsutils.VcsProvider, hasInternetConnection bool) OutputWriter {
if provider == vcsutils.BitbucketServer {
return &SimplifiedOutput{MarkdownOutput{vcsProvider: provider, hasInternetConnection: hasInternetConnection}}
}
return &StandardOutput{MarkdownOutput{vcsProvider: provider, hasInternetConnection: hasInternetConnection}}
}

func MarkdownComment(text string) string {
Expand Down
4 changes: 0 additions & 4 deletions utils/testsutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ func SetEnvsAndAssertWithCallback(t *testing.T, envs map[string]string) func() {
}
}

func MockHasConnection() *UrlAccessChecker {
return &UrlAccessChecker{url: "url", connected: true}
}

// Create a temporary directory and copy the content of "testdata/testDir" into it
func CopyTestdataProjectsToTemp(t *testing.T, testDir string) (tmpDir string, restoreFunc func()) {
// Copy project to a temporary directory
Expand Down
Loading