Skip to content

Commit e4b9f8e

Browse files
authored
"jf setup" command improvaments (#294)
1 parent b32c70e commit e4b9f8e

File tree

4 files changed

+52
-16
lines changed

4 files changed

+52
-16
lines changed

general/envsetup/envsetup.go

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@ package envsetup
33
import (
44
"encoding/json"
55
"fmt"
6+
"github.com/pkg/browser"
67
"net/http"
78
"net/url"
89
"strings"
910
"time"
1011

11-
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
12-
"github.com/pkg/browser"
13-
1412
"github.com/google/uuid"
1513
"github.com/jfrog/jfrog-cli-core/v2/common/commands"
1614
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
15+
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
1716
"github.com/jfrog/jfrog-client-go/http/httpclient"
1817
clientutils "github.com/jfrog/jfrog-client-go/utils"
1918
"github.com/jfrog/jfrog-client-go/utils/errorutils"
@@ -25,7 +24,7 @@ import (
2524
const (
2625
myJfrogEndPoint = "https://myjfrog-api.jfrog.com/api/v1/activation/cloud/cli/getStatus/"
2726
syncSleepInterval = 5 * time.Second // 5 seconds
28-
maxWaitMinutes = 10 * time.Minute // 10 minutes
27+
maxWaitMinutes = 30 * time.Minute // 30 minutes
2928
)
3029

3130
type EnvSetupCommand struct {
@@ -66,12 +65,13 @@ func (ftc *EnvSetupCommand) Run() (err error) {
6665
return err
6766
}
6867
message :=
69-
coreutils.PrintBold("Your new JFrog environment is ready!") +
70-
"\n" +
68+
coreutils.PrintBold("Your new JFrog environment is ready!") + "\n" +
7169
"1. CD into your code project directory\n" +
7270
"2. Run \"jf project init\"\n" +
7371
"3. Read more about how to get started at -\n" +
74-
coreutils.PrintLink(coreutils.GettingStartedGuideUrl)
72+
coreutils.PrintLink(coreutils.GettingStartedGuideUrl) +
73+
"\n\n" +
74+
coreutils.GetFeedbackMessage()
7575

7676
err = coreutils.PrintTable("", "", message)
7777
return
@@ -96,31 +96,51 @@ func (ftc *EnvSetupCommand) getNewServerDetails() (serverDetails *config.ServerD
9696
if err != nil {
9797
return nil, err
9898
}
99-
message := fmt.Sprintf("Sync: Get MyJFrog status report. Request ID:%s...", ftc.id)
10099

100+
// Define the MyJFrog polling logic.
101+
pollingMessage := fmt.Sprintf("Sync: Get MyJFrog status report. Request ID:%s...", ftc.id)
102+
pollingErrorMessage := "Sync: Get MyJFrog status request failed. Attempt: %d. Error: %s"
103+
// The max consecutive polling errors allowed, before completely failing the setup action.
104+
const maxConsecutiveErrors = 6
105+
errorsCount := 0
101106
pollingAction := func() (shouldStop bool, responseBody []byte, err error) {
102-
log.Debug(message)
107+
log.Debug(pollingMessage)
108+
// Send request to MyJFrog.
103109
resp, body, err := client.SendPost(myJfrogEndPoint, requestContent, httpClientDetails, "")
110+
// If an HTTP error occured.
104111
if err != nil {
105-
return true, nil, err
112+
errorsCount++
113+
log.Debug(fmt.Sprintf(pollingErrorMessage, errorsCount, err.Error()))
114+
if errorsCount == maxConsecutiveErrors {
115+
return true, nil, err
116+
}
117+
return false, nil, nil
106118
}
119+
// If the response is not the expected 200 or 404.
107120
if err = errorutils.CheckResponseStatus(resp, http.StatusOK, http.StatusNotFound); err != nil {
108121
err = errorutils.CheckError(errorutils.GenerateResponseError(resp.Status, clientutils.IndentJson(body)))
109-
return true, nil, err
122+
errorsCount++
123+
log.Debug(fmt.Sprintf(pollingErrorMessage, errorsCount, err.Error()))
124+
if errorsCount == maxConsecutiveErrors {
125+
return true, nil, err
126+
}
127+
return false, nil, nil
110128
}
111-
log.Debug(message)
129+
errorsCount = 0
130+
112131
// Wait for 'ready=true' response from MyJFrog
113132
if resp.StatusCode == http.StatusOK {
114133
ftc.progress.SetHeadlineMsg("Ready for your DevOps journey? Please hang on while we create your environment")
115134
statusResponse := myJfrogGetStatusResponse{}
116135
if err = json.Unmarshal(body, &statusResponse); err != nil {
117136
return true, nil, err
118137
}
119-
// Got the new server deatiles
138+
// Got the new server details
120139
if statusResponse.Ready {
121140
return true, body, nil
122141
}
123142
}
143+
// The expected 404 response.
124144
return false, nil, nil
125145
}
126146

general/project/projectinit.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ func (pic *ProjectInitCommand) createSummarizeMessage(technologiesMap map[coreut
9595
pic.createBuildMessage(technologiesMap) +
9696
coreutils.PrintTitle("Read more using this link:") +
9797
"\n" +
98-
coreutils.PrintLink(coreutils.GettingStartedGuideUrl)
98+
coreutils.PrintLink(coreutils.GettingStartedGuideUrl) +
99+
"\n\n" +
100+
coreutils.GetFeedbackMessage()
99101
}
100102

101103
// Return a string message, which includes all the build and deployment commands, matching the technologiesMap sent.
@@ -109,7 +111,8 @@ func (pic *ProjectInitCommand) createBuildMessage(technologiesMap map[coreutils.
109111
case coreutils.Gradle:
110112
message += "jf gradle artifactoryP\n"
111113
case coreutils.Npm:
112-
message += "jf npm install publish\n"
114+
message += "jf npm install\n"
115+
message += "jf npm publish\n"
113116
case coreutils.Go:
114117
message +=
115118
"jf go build\n" +

go.sum

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgo
243243
github.com/klauspost/pgzip v1.2.5 h1:qnWYvvKqedOF2ulHpMG72XQol4ILEJ8k2wwRl/Km8oE=
244244
github.com/klauspost/pgzip v1.2.5/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs=
245245
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
246+
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
246247
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
247248
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
248249
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
@@ -277,6 +278,7 @@ github.com/mattn/go-tty v0.0.3 h1:5OfyWorkyO7xP52Mq7tB36ajHDG5OHrmBGIS/DtakQI=
277278
github.com/mattn/go-tty v0.0.3/go.mod h1:ihxohKRERHTVzN+aSVRwACLCeqIoZAWpoICkkvrWyR0=
278279
github.com/mholt/archiver/v3 v3.5.1-0.20210618180617-81fac4ba96e4 h1:S7ICJmgiEB5WbKXg3CPL/qmJKxxKf33yJSkxqbdiTQA=
279280
github.com/mholt/archiver/v3 v3.5.1-0.20210618180617-81fac4ba96e4/go.mod h1:e3dqJ7H78uzsRSEACH1joayhuSyhnonssnDhppzS1L4=
281+
github.com/miekg/dns v1.0.15/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
280282
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
281283
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
282284
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
@@ -306,6 +308,7 @@ github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
306308
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
307309
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
308310
github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA=
311+
github.com/pkg/sftp v1.11.0/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
309312
github.com/pkg/term v1.1.0 h1:xIAAdCMh3QIAy+5FrE8Ad8XoDhEU4ufwbaSozViP9kk=
310313
github.com/pkg/term v1.1.0/go.mod h1:E25nymQcrSllhX42Ok8MRm1+hyBdHY0dCeiKZ9jpNGw=
311314
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

utils/coreutils/utils.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ import (
1818
"github.com/pkg/errors"
1919
)
2020

21-
const GettingStartedGuideUrl = "https://github.com/jfrog/jfrog-cli/blob/v2/guides/getting-started-with-jfrog-using-the-cli.md"
21+
const (
22+
GettingStartedGuideUrl = "https://github.com/jfrog/jfrog-cli/blob/v2/guides/getting-started-with-jfrog-using-the-cli.md"
23+
GitHubIssuesUrl = "https://github.com/jfrog/jfrog-cli/issues"
24+
)
2225

2326
// Error modes (how should the application behave when the CheckError function is invoked):
2427
type OnError string
@@ -407,3 +410,10 @@ func SetCliExecutableName(executableName string) {
407410
func GetCliExecutableName() string {
408411
return cliExecutableName
409412
}
413+
414+
func GetFeedbackMessage() string {
415+
return PrintBold("Your feedback is important.") + "\n" +
416+
"We'd love to get your feedback and answer any questions you may have.\n" +
417+
"Communicate with us by opening a GitHub issue -\n" +
418+
PrintLink(GitHubIssuesUrl)
419+
}

0 commit comments

Comments
 (0)