Skip to content

Commit 341f407

Browse files
committed
Multiple other fixes for bootstrap
- Fix install on public Github where the URL wasn't set. - Don't ask for the Github App URL anymore set it to the one from the Route and let user configure it in the github app page. - Set proper defaults to ask yes or not questions. Signed-off-by: Chmouel Boudjnah <[email protected]>
1 parent c4657ec commit 341f407

File tree

5 files changed

+30
-20
lines changed

5 files changed

+30
-20
lines changed

β€Žpkg/cmd/bootstrap/bootstrap.goβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ func createSecret(ctx context.Context, run *params.Run, opts *bootstrapOpts) err
8686
return err
8787
}
8888
}
89-
9089
jeez, err := generateManifest(opts)
9190
if err != nil {
9291
return err

β€Žpkg/cmd/bootstrap/github.goβ€Ž

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ func generateManifest(opts *bootstrapOpts) ([]byte, error) {
4040

4141
// getGHClient get github client
4242
func getGHClient(opts *bootstrapOpts) (*github.Client, error) {
43-
if opts.GithubAPIURL == "" {
44-
opts.GithubAPIURL = "https://github.com"
43+
if opts.GithubAPIURL == defaultPublicGithub {
4544
return github.NewClient(nil), nil
4645
}
4746

β€Žpkg/cmd/bootstrap/install.goβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func installPac(ctx context.Context, opts *bootstrapOpts) error {
5656
}
5757
}
5858

59-
doinstall, err := askYN(opts, "πŸ•΅οΈ Pipelines as Code doesn't seem installed", fmt.Sprintf("Do you want me to install Pipelines as Code %s?", latestversion))
59+
doinstall, err := askYN(opts, true, "πŸ•΅οΈ Pipelines as Code doesn't seem installed", fmt.Sprintf("Do you want me to install Pipelines as Code %s?", latestversion))
6060
if err != nil {
6161
return err
6262
}
@@ -69,6 +69,6 @@ func installPac(ctx context.Context, opts *bootstrapOpts) error {
6969
}
7070

7171
// nolint:forbidigo
72-
fmt.Printf("βœ… Pipelines-as-Code %s has been installed\n", latestversion)
72+
fmt.Printf("βœ“ Pipelines-as-Code %s has been installed\n", latestversion)
7373
return nil
7474
}

β€Žpkg/cmd/bootstrap/questions.goβ€Ž

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,22 @@ package bootstrap
22

33
import (
44
"fmt"
5+
"strings"
56

67
"github.com/AlecAivazis/survey/v2"
78
)
89

9-
func askYN(opts *bootstrapOpts, title, question string) (bool, error) {
10+
const defaultPublicGithub = "https://github.com"
11+
12+
func askYN(opts *bootstrapOpts, deflt bool, title, question string) (bool, error) {
1013
var answer bool
1114
// nolint:forbidigo
1215
fmt.Printf("%s\n", title)
1316
err := opts.cliOpts.Ask([]*survey.Question{
1417
{
1518
Prompt: &survey.Confirm{
1619
Message: question,
20+
Default: deflt,
1721
},
1822
},
1923
}, &answer)
@@ -29,7 +33,7 @@ func askQuestions(opts *bootstrapOpts) error {
2933
var qs []*survey.Question
3034

3135
if opts.recreateSecret {
32-
answer, err := askYN(opts,
36+
answer, err := askYN(opts, false,
3337
fmt.Sprintf("πŸ‘€ A secret named %s in %s namespace has been detected.", secretName, opts.targetNamespace),
3438
"Do you want me to override the secret?")
3539
if err != nil {
@@ -43,23 +47,22 @@ func askQuestions(opts *bootstrapOpts) error {
4347
if opts.vcsType == "github-enteprise-app" {
4448
prompt := "Enter your Github enteprise API URL: "
4549
qs = append(qs, &survey.Question{
46-
Name: "GithubAPIURL",
47-
Prompt: &survey.Input{Message: prompt},
50+
Name: "GithubAPIURL",
51+
Prompt: &survey.Input{
52+
Message: prompt,
53+
},
54+
Validate: survey.Required,
4855
})
56+
} else {
57+
opts.GithubAPIURL = defaultPublicGithub
4958
}
5059

5160
prompt := "Enter the name of your GitHub application: "
5261
if opts.GithubApplicationName == "" {
5362
qs = append(qs, &survey.Question{
54-
Name: "GithubApplicationName",
55-
Prompt: &survey.Input{Message: prompt},
56-
})
57-
}
58-
if opts.GithubApplicationURL == "" {
59-
prompt = "Enter an URL for your GitHub application"
60-
qs = append(qs, &survey.Question{
61-
Name: "GithubApplicationURL",
62-
Prompt: &survey.Input{Message: prompt},
63+
Name: "GithubApplicationName",
64+
Prompt: &survey.Input{Message: prompt},
65+
Validate: survey.Required,
6366
})
6467
}
6568

@@ -68,8 +71,12 @@ func askQuestions(opts *bootstrapOpts) error {
6871
return err
6972
}
7073

74+
if !strings.HasPrefix(opts.GithubAPIURL, "https") {
75+
opts.GithubAPIURL = "https://" + strings.Trim(opts.GithubAPIURL, "/")
76+
}
77+
7178
if opts.RouteName != "" {
72-
answer, err := askYN(opts,
79+
answer, err := askYN(opts, true,
7380
fmt.Sprintf("πŸ‘€ We have detected an OpenShift Route on: %s", opts.RouteName),
7481
"Do you want me to use it?")
7582
if err != nil {
@@ -86,12 +93,17 @@ func askQuestions(opts *bootstrapOpts) error {
8693
Prompt: &survey.Input{
8794
Message: "Enter your public route URL: ",
8895
},
96+
Validate: survey.Required,
8997
},
9098
}, &opts.RouteName)
9199
if err != nil {
92100
return err
93101
}
94102
}
95103

104+
if opts.GithubApplicationURL == "" {
105+
opts.GithubApplicationURL = opts.RouteName
106+
}
107+
96108
return nil
97109
}

β€Žpkg/cmd/bootstrap/web.goβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func startWebServer(ctx context.Context, opts *bootstrapOpts, run *params.Run, j
7878
}
7979

8080
// nolint:forbidigo
81-
fmt.Printf("πŸš€ You can now add your newly created application on your repository by going to this URL:\n%s\n", *manifest.HTMLURL)
81+
fmt.Printf("πŸš€ You can now add your newly created application on your repository by going to this URL:\n%s\n\n", *manifest.HTMLURL)
8282

8383
// nolint:forbidigo
8484
fmt.Println("πŸ’‘ Don't forget to run the \"tkn pac repo create\" to create a new Repository CRD on your cluster.")

0 commit comments

Comments
Β (0)