Skip to content

Commit

Permalink
fix: don't require credentials when not configuring webhook (#1743)
Browse files Browse the repository at this point in the history
Signed-off-by: Zbynek Roubalik <zroubalik@gmail.com>
  • Loading branch information
zroubalik committed May 18, 2023
1 parent 530ea4f commit a0b9a86
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions cmd/config_git_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ type configGitSetConfig struct {
GitRevision string
GitContextDir string

WebhookTrigger bool
WebhookTriggerSet bool // whether WebhookTrigger value has been set
ConfigureRemoteResourcesSet bool // whether ConfigureRemoteResources value has been set

metadata pipelines.PacMetadata
}
Expand All @@ -115,10 +114,15 @@ func newConfigGitSetConfig(cmd *cobra.Command) (c configGitSetConfig) {
configLocal := true
configCluster := true
configRemote := true

configRemoteSet := false

if viper.HasChanged("config-local") || viper.HasChanged("config-cluster") || viper.HasChanged("config-remote") {
configLocal = viper.GetBool("config-local")
configCluster = viper.GetBool("config-cluster")
configRemote = viper.GetBool("config-remote")

configRemoteSet = true
}

c = configGitSetConfig{
Expand All @@ -129,6 +133,8 @@ func newConfigGitSetConfig(cmd *cobra.Command) (c configGitSetConfig) {
GitRevision: viper.GetString("git-branch"),
GitContextDir: viper.GetString("git-dir"),

ConfigureRemoteResourcesSet: configRemoteSet,

metadata: pipelines.PacMetadata{
GitProvider: viper.GetString("git-provider"),
PersonalAccessToken: viper.GetString("gh-access-token"),
Expand Down Expand Up @@ -197,7 +203,7 @@ func (c configGitSetConfig) Prompt(f fn.Function) (configGitSetConfig, error) {
}

// prompt if webhook trigger setting hasn't been set previously
if !c.WebhookTriggerSet {
if !c.ConfigureRemoteResourcesSet {
trigger := true
if err := survey.AskOne(&survey.Confirm{
Message: "Do you want to configure webhook trigger?",
Expand All @@ -206,11 +212,11 @@ func (c configGitSetConfig) Prompt(f fn.Function) (configGitSetConfig, error) {
}, &trigger, survey.WithValidator(survey.Required)); err != nil {
return c, err
}
c.WebhookTrigger = trigger
c.WebhookTriggerSet = true
c.metadata.ConfigureRemoteResources = trigger
c.ConfigureRemoteResourcesSet = true
}

if c.WebhookTrigger {
if c.metadata.ConfigureRemoteResources {
// Configure Git provider
if c.metadata.GitProvider == "" {
provider, err := git.GitProviderName(c.GitURL)
Expand Down

0 comments on commit a0b9a86

Please sign in to comment.