Add repo sync
Change-Id: I6b61873c97e9ff46a699151fc52aa937248bcf81
diff --git a/server/cmd/commands/webhook.go b/server/cmd/commands/webhook.go
index e62d1ce..da75284 100644
--- a/server/cmd/commands/webhook.go
+++ b/server/cmd/commands/webhook.go
@@ -52,14 +52,14 @@
webhookConfigureCmd.Flags().StringVar(&webhookURL, "webhook-url", "", "Webhook URL (if not provided, will prompt)")
webhookConfigureCmd.Flags().BoolVar(&dryRun, "dry-run", false, "Show what would be done without executing")
webhookConfigureCmd.Flags().BoolVar(&force, "force", false, "Force re-registration even if webhook exists")
-
+
webhookCmd.AddCommand(webhookConfigureCmd)
rootCmd.AddCommand(webhookCmd)
}
func runWebhookConfigure(cmd *cobra.Command, args []string) error {
ctx := context.Background()
-
+
// Validate GitHub configuration
if !cfg.HasGitHubConfig() {
return fmt.Errorf("GitHub configuration is required. Please configure github.token, github.owner, and github.repo in config.yaml")
@@ -125,13 +125,13 @@
if !force {
return fmt.Errorf("webhook already exists with URL %s (ID: %d). Use --force to update it", webhookURL, existingWebhook.ID)
}
-
+
fmt.Printf("Updating existing webhook (ID: %d)...\n", existingWebhook.ID)
updatedWebhook, err := gitInterface.UpdateWebhook(ctx, existingWebhook.ID, webhookURL, secret)
if err != nil {
return fmt.Errorf("failed to update webhook: %w", err)
}
-
+
fmt.Printf("Successfully updated webhook!\n")
fmt.Printf("- Webhook ID: %d\n", updatedWebhook.ID)
fmt.Printf("- URL: %s\n", updatedWebhook.Config.URL)
@@ -143,7 +143,7 @@
if err != nil {
return fmt.Errorf("failed to create webhook: %w", err)
}
-
+
fmt.Printf("Successfully created webhook!\n")
fmt.Printf("- Webhook ID: %d\n", newWebhook.ID)
fmt.Printf("- URL: %s\n", newWebhook.Config.URL)
@@ -164,26 +164,26 @@
fmt.Printf("\nWebhook Secret: %s\n", secret)
fmt.Printf("Please save this secret for your webhook endpoint configuration.\n")
fmt.Printf("\nYour Staff system will now automatically detect merged PRs and complete tasks.\n")
-
+
return nil
}
func promptWebhookURL() (string, error) {
reader := bufio.NewReader(os.Stdin)
-
+
// Show server listen address if configured
if cfg.Server.ListenAddress != "" {
fmt.Printf("Detected server listen address: %s\n", cfg.Server.ListenAddress)
fmt.Printf("Suggested webhook URL: http://%s/webhooks/github\n", cfg.Server.ListenAddress)
fmt.Printf("(Note: Use https:// and a public domain for production)\n")
}
-
+
fmt.Printf("Enter webhook URL (e.g., https://your-domain.com/webhooks/github): ")
url, err := reader.ReadString('\n')
if err != nil {
return "", err
}
-
+
return strings.TrimSpace(url), nil
}
@@ -192,15 +192,15 @@
if err != nil {
return fmt.Errorf("invalid URL format: %w", err)
}
-
+
if parsedURL.Scheme != "http" && parsedURL.Scheme != "https" {
return fmt.Errorf("URL must use http or https scheme")
}
-
+
if parsedURL.Host == "" {
return fmt.Errorf("URL must include a host")
}
-
+
return nil
}
@@ -210,7 +210,7 @@
if _, err := rand.Read(bytes); err != nil {
return "", fmt.Errorf("failed to generate random bytes: %w", err)
}
-
+
// Encode as hex string
return hex.EncodeToString(bytes), nil
}
@@ -221,13 +221,13 @@
if err != nil {
return fmt.Errorf("failed to read config file: %w", err)
}
-
+
// Parse YAML
var configMap map[string]interface{}
if err := yaml.Unmarshal(configData, &configMap); err != nil {
return fmt.Errorf("failed to parse config YAML: %w", err)
}
-
+
// Update webhook secret
github, ok := configMap["github"].(map[string]interface{})
if !ok {
@@ -235,17 +235,17 @@
configMap["github"] = github
}
github["webhook_secret"] = secret
-
+
// Marshal back to YAML
updatedData, err := yaml.Marshal(configMap)
if err != nil {
return fmt.Errorf("failed to marshal config YAML: %w", err)
}
-
+
// Write back to file
if err := os.WriteFile("config.yaml", updatedData, 0644); err != nil {
return fmt.Errorf("failed to write config file: %w", err)
}
-
+
return nil
-}
\ No newline at end of file
+}