Skip to content

Commit

Permalink
Fix working dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
sverdlov93 committed Aug 8, 2023
1 parent d039c43 commit 257d090
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 22 deletions.
20 changes: 10 additions & 10 deletions commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ func GetCommands() []*clitool.Command {
}
}

func Exec(command FrogbotCommand, name string) (err error) {
// Get frogbotUtils that contains the config, server, and VCS client
func Exec(command FrogbotCommand, commandName string) (err error) {
// Get frogbotDetails that contains the config, server, and VCS client
log.Info("Frogbot version:", utils.FrogbotVersion)
frogbotUtils, err := utils.GetFrogbotDetails()
frogbotDetails, err := utils.GetFrogbotDetails()
if err != nil {
return err
}

// Build the server configuration file
originalJfrogHomeDir, tempJFrogHomeDir, err := utils.BuildServerConfigFile(frogbotUtils.ServerDetails)
originalJfrogHomeDir, tempJFrogHomeDir, err := utils.BuildServerConfigFile(frogbotDetails.ServerDetails)
if err != nil {
return err
}
Expand All @@ -79,8 +79,8 @@ func Exec(command FrogbotCommand, name string) (err error) {

// Set releases remote repository env if needed
previousReleasesRepoEnv := os.Getenv(coreutils.ReleasesRemoteEnv)
if frogbotUtils.ReleasesRepo != "" {
if err = os.Setenv(coreutils.ReleasesRemoteEnv, fmt.Sprintf("frogbot/%s", frogbotUtils.ReleasesRepo)); err != nil {
if frogbotDetails.ReleasesRepo != "" {
if err = os.Setenv(coreutils.ReleasesRemoteEnv, fmt.Sprintf("frogbot/%s", frogbotDetails.ReleasesRepo)); err != nil {
return
}
defer func() {
Expand All @@ -90,17 +90,17 @@ func Exec(command FrogbotCommand, name string) (err error) {

// Send a usage report
usageReportSent := make(chan error)
go utils.ReportUsage(name, frogbotUtils.ServerDetails, usageReportSent)
go utils.ReportUsage(commandName, frogbotDetails.ServerDetails, usageReportSent)

// Invoke the command interface
log.Info(fmt.Sprintf("Running Frogbot %q command", name))
err = command.Run(frogbotUtils.Repositories, frogbotUtils.Client)
log.Info(fmt.Sprintf("Running Frogbot %q command", commandName))
err = command.Run(frogbotDetails.Repositories, frogbotDetails.Client)

// Wait for a signal, letting us know that the usage reporting is done.
<-usageReportSent

if err == nil {
log.Info(fmt.Sprintf("Frogbot %q command finished successfully", name))
log.Info(fmt.Sprintf("Frogbot %q command finished successfully", commandName))
}
return err
}
6 changes: 2 additions & 4 deletions commands/scanrepository/scanrepository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ var testPackagesData = []struct {
func TestScanRepositoryCmd_Run(t *testing.T) {
tests := []struct {
testName string
testDir string
configPath string
expectedDiff []string
expectedBranches []string
Expand Down Expand Up @@ -163,7 +162,7 @@ func TestScanRepositoryCmd_Run(t *testing.T) {
gitTestParams.Branches = []string{"main"}
}

envPath, cleanUp := utils.PrepareTestEnvironment(t, "", path.Join(rootTestDir, test.testDir))
envPath, cleanUp := utils.PrepareTestEnvironment(t, "", path.Join(rootTestDir, test.testName))
defer cleanUp()
configAggregator, err := utils.BuildRepoAggregator(configData, &gitTestParams, &serverParams)
assert.NoError(t, err)
Expand Down Expand Up @@ -195,7 +194,6 @@ func TestAggregatePullRequestLifecycle(t *testing.T) {
mockPrId := int64(1)
tests := []struct {
testName string
testDir string
expectedUpdate bool
mockPullRequestResponse []vcsclient.PullRequestInfo
}{
Expand Down Expand Up @@ -256,7 +254,7 @@ pr body
var configData []byte
// Manual set of "JF_GIT_BASE_BRANCH"
gitTestParams.Branches = []string{"main"}
envPath, cleanUp := utils.PrepareTestEnvironment(t, "", path.Join(rootTestDir, test.testDir))
envPath, cleanUp := utils.PrepareTestEnvironment(t, "", path.Join(rootTestDir, test.testName))
defer cleanUp()
configAggregator, err := utils.BuildRepoAggregator(configData, gitTestParams, &serverParams)
assert.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions commands/utils/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func GetFrogbotDetails() (frogbotUtils *FrogbotDetails, err error) {
if err != nil {
return
}
gitClientInfo, err := extractGitInfoFromEnvs()
gitClientInfo, err := extractGitParamsFromEnvs()
if err != nil {
return
}
Expand Down Expand Up @@ -378,7 +378,7 @@ func extractJFrogCredentialsFromEnvs() (*coreconfig.ServerDetails, error) {
return &server, nil
}

func extractGitInfoFromEnvs() (*GitClientInfo, error) {
func extractGitParamsFromEnvs() (*GitClientInfo, error) {
e := &ErrMissingEnv{}
var err error
clientInfo := &GitClientInfo{}
Expand Down
12 changes: 6 additions & 6 deletions commands/utils/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ func TestExtractClientInfo(t *testing.T) {
assert.NoError(t, SanitizeEnv())
}()

_, err := extractGitInfoFromEnvs()
_, err := extractGitParamsFromEnvs()
assert.EqualError(t, err, "JF_GIT_PROVIDER should be one of: 'github', 'gitlab', 'bitbucketServer' or 'azureRepos'")

SetEnvAndAssert(t, map[string]string{GitProvider: "github"})
_, err = extractGitInfoFromEnvs()
_, err = extractGitParamsFromEnvs()
assert.EqualError(t, err, "'JF_GIT_OWNER' environment variable is missing")

SetEnvAndAssert(t, map[string]string{GitRepoOwnerEnv: "jfrog"})
_, err = extractGitInfoFromEnvs()
_, err = extractGitParamsFromEnvs()
assert.EqualError(t, err, "'JF_GIT_TOKEN' environment variable is missing")
}

Expand All @@ -147,7 +147,7 @@ func TestExtractAndAssertRepoParams(t *testing.T) {

server, err := extractJFrogCredentialsFromEnvs()
assert.NoError(t, err)
gitParams, err := extractGitInfoFromEnvs()
gitParams, err := extractGitParamsFromEnvs()
assert.NoError(t, err)
configFileContent, err := ReadConfigFromFileSystem(configParamsTestFile)
assert.NoError(t, err)
Expand Down Expand Up @@ -190,7 +190,7 @@ func TestBuildRepoAggregatorWithEmptyScan(t *testing.T) {
}()
server, err := extractJFrogCredentialsFromEnvs()
assert.NoError(t, err)
gitParams, err := extractGitInfoFromEnvs()
gitParams, err := extractGitParamsFromEnvs()
assert.NoError(t, err)
configFileContent, err := ReadConfigFromFileSystem(configEmptyScanParamsTestFile)
assert.NoError(t, err)
Expand Down Expand Up @@ -225,7 +225,7 @@ func testExtractAndAssertProjectParams(t *testing.T, project Project) {
func extractAndAssertParamsFromEnv(t *testing.T, platformUrl, basicAuth bool) {
server, err := extractJFrogCredentialsFromEnvs()
assert.NoError(t, err)
gitParams, err := extractGitInfoFromEnvs()
gitParams, err := extractGitParamsFromEnvs()
assert.NoError(t, err)
configFile, err := BuildRepoAggregator(nil, gitParams, server)
assert.NoError(t, err)
Expand Down

0 comments on commit 257d090

Please sign in to comment.