Skip to content

Commit

Permalink
update info configmap if webhook is configured before github apps
Browse files Browse the repository at this point in the history
  • Loading branch information
Shivam Mukhade committed Apr 20, 2022
1 parent d3f85be commit 3f60302
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
10 changes: 5 additions & 5 deletions pkg/cmd/tknpac/webhook/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ type gitHubWebhookConfig struct {
APIURL string
}

func (w Webhook) githubWebhook(ctx context.Context) error {
func (w Webhook) githubWebhook(ctx context.Context) (string, error) {
msg := "Would you like me to configure GitHub Webhook for your repository? "
var configureWebhook bool
if err := prompt.SurveyAskOne(&survey.Confirm{Message: msg, Default: true}, &configureWebhook); err != nil {
return err
return "", err
}
if !configureWebhook {
return nil
return "", nil
}

ghWebhook, err := askGHWebhookConfig(w.RepositoryURL, w.ControllerURL)
if err != nil {
return err
return "", err
}
ghWebhook.APIURL = w.ProviderAPIURL

return ghWebhook.create(ctx)
return ghWebhook.ControllerURL, ghWebhook.create(ctx)
}

func askGHWebhookConfig(repoURL, controllerURL string) (*gitHubWebhookConfig, error) {
Expand Down
11 changes: 10 additions & 1 deletion pkg/cmd/tknpac/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,14 @@ func (w Webhook) Install(ctx context.Context, run *params.Run) error {
w.ControllerURL = route
}

return w.githubWebhook(ctx)
controllerURL, err := w.githubWebhook(ctx)
if err != nil || controllerURL == "" {
return err
}

return info.UpdateInfoConfigMap(ctx, run, &info.Options{
TargetNamespace: installationNS,
ControllerURL: controllerURL,
Provider: provider.ProviderGitHubWebhook,
})
}
3 changes: 2 additions & 1 deletion pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ var (
)

const (
ProviderGitHubApp = "GitHub App"
ProviderGitHubApp = "GitHub App"
ProviderGitHubWebhook = "GitHub Webhook"
)

func Valid(value string, validValues []string) bool {
Expand Down

0 comments on commit 3f60302

Please sign in to comment.