Skip to content

Commit a55fece

Browse files
savitaashturechmouel
authored andcommitted
Added a check to watch on secret pipelines-as-code-secret to decide GithubApp or Webhook
1 parent efab6ed commit a55fece

File tree

3 files changed

+11
-19
lines changed

3 files changed

+11
-19
lines changed

pkg/cli/info/configmap.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55

66
"github.com/openshift-pipelines/pipelines-as-code/pkg/params"
7+
"github.com/openshift-pipelines/pipelines-as-code/pkg/pipelineascode"
78
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
89
)
910

@@ -15,6 +16,13 @@ type Options struct {
1516
Provider string
1617
}
1718

19+
func IsGithubAppInstalled(ctx context.Context, run *params.Run, targetNamespace string) bool {
20+
if _, err := run.Clients.Kube.CoreV1().Secrets(targetNamespace).Get(ctx, pipelineascode.DefaultPipelinesAscodeSecretName, metav1.GetOptions{}); err != nil {
21+
return false
22+
}
23+
return true
24+
}
25+
1826
func GetPACInfo(ctx context.Context, run *params.Run, targetNamespace string) (*Options, error) {
1927
cm, err := run.Clients.Kube.CoreV1().ConfigMaps(targetNamespace).Get(ctx, infoConfigMap, metav1.GetOptions{})
2028
if err != nil {

pkg/cmd/tknpac/bootstrap/bootstrap.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/openshift-pipelines/pipelines-as-code/pkg/cli/info"
1111
"github.com/openshift-pipelines/pipelines-as-code/pkg/params"
1212
"github.com/openshift-pipelines/pipelines-as-code/pkg/params/settings"
13-
"github.com/openshift-pipelines/pipelines-as-code/pkg/provider"
1413
"github.com/spf13/cobra"
1514
kapierror "k8s.io/apimachinery/pkg/api/errors"
1615
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -151,13 +150,8 @@ func Command(run *params.Run, ioStreams *cli.IOStreams) *cobra.Command {
151150
}
152151
}
153152

154-
pacInfo, err := info.GetPACInfo(ctx, run, opts.targetNamespace)
155-
if err != nil {
156-
return err
157-
}
158-
159153
if !opts.forceGitHubApp {
160-
if pacInfo.Provider == provider.ProviderGitHubApp {
154+
if info.IsGithubAppInstalled(ctx, run, opts.targetNamespace) {
161155
fmt.Fprintln(opts.ioStreams.Out, "👌 Skips bootstrapping GitHub App, as one is already configured. Please pass --force-configure to override existing")
162156
return nil
163157
}
@@ -214,13 +208,8 @@ func GithubApp(run *params.Run, ioStreams *cli.IOStreams) *cobra.Command {
214208
return err
215209
}
216210

217-
pacInfo, err := info.GetPACInfo(ctx, run, opts.targetNamespace)
218-
if err != nil {
219-
return err
220-
}
221-
222211
if !opts.forceGitHubApp {
223-
if pacInfo.Provider == provider.ProviderGitHubApp {
212+
if info.IsGithubAppInstalled(ctx, run, opts.targetNamespace) {
224213
fmt.Fprintln(opts.ioStreams.Out, "👌 Skips bootstrapping GitHub App, as one is already configured. Please pass --force-configure to override existing")
225214
return nil
226215
}

pkg/cmd/tknpac/create/repository.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"github.com/openshift-pipelines/pipelines-as-code/pkg/git"
2121
"github.com/openshift-pipelines/pipelines-as-code/pkg/params"
2222
"github.com/openshift-pipelines/pipelines-as-code/pkg/params/info"
23-
"github.com/openshift-pipelines/pipelines-as-code/pkg/provider"
2423
"github.com/spf13/cobra"
2524
v1 "k8s.io/api/core/v1"
2625
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -81,12 +80,8 @@ func repositoryCommand(run *params.Run, ioStreams *cli.IOStreams) *cobra.Command
8180
if err != nil {
8281
return err
8382
}
84-
pacCMInfo, err := pacInfo.GetPACInfo(ctx, run, installationNS)
85-
if err != nil {
86-
return err
87-
}
8883

89-
if pacCMInfo.Provider == provider.ProviderGitHubApp {
84+
if pacInfo.IsGithubAppInstalled(ctx, run, installationNS) {
9085
if strings.Contains(createOpts.Event.URL, "github") {
9186
if err := createOpts.generateTemplate(nil); err != nil {
9287
return err

0 commit comments

Comments
 (0)