From ef51f0d3ece14ee5e009d3ef52998a526e6118b1 Mon Sep 17 00:00:00 2001 From: Daniel Togey Date: Sun, 25 Jan 2026 13:18:13 +0300 Subject: [PATCH] refactor(github): Simplify GitHub API routes for post-installation and webhook - Moved GitHub post-installation and webhook routes to a more consistent path structure. - Updated the setup URL in the manifest to reflect the new routing. - Enhanced code clarity by consolidating GitHub route definitions under a single path. --- internal/api/handlers/github.go | 4 ++-- internal/api/server.go | 10 +++------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/internal/api/handlers/github.go b/internal/api/handlers/github.go index 4d11a6e..f0785c7 100644 --- a/internal/api/handlers/github.go +++ b/internal/api/handlers/github.go @@ -144,7 +144,7 @@ func (h *GitHubHandler) ManifestStart(w http.ResponseWriter, r *http.Request) { apiURL + "/github/callback", // Needed for manifest redirect apiURL + "/github/oauth/callback", }, - "setup_url": apiURL + "/v1/github/post-install", + "setup_url": apiURL + "/github/post-install", "public": false, "default_permissions": map[string]string{ "contents": "read", @@ -158,7 +158,7 @@ func (h *GitHubHandler) ManifestStart(w http.ResponseWriter, r *http.Request) { // 3. Handle Webhook URL (GitHub rejects 'localhost' in manifest flow) webhookURL := os.Getenv("GITHUB_WEBHOOK_URL") if webhookURL == "" { - webhookURL = apiURL + "/v1/github/webhook" + webhookURL = apiURL + "/github/webhook" } // Only include hook_attributes and events if the URL appears publicly reachable diff --git a/internal/api/server.go b/internal/api/server.go index dfa4d36..a7e9e19 100644 --- a/internal/api/server.go +++ b/internal/api/server.go @@ -117,12 +117,8 @@ func (s *Server) setupRouter() { githubHandler := handlers.NewGitHubHandler(s.store, s.logger) r.Get("/github/callback", githubHandler.ManifestCallback) r.Get("/github/oauth/callback", githubHandler.OAuthCallback) - - // GitHub post-installation (public - called by GitHub after app install) - r.Route("/v1/github", func(r chi.Router) { - r.Get("/post-install", githubHandler.PostInstallation) - r.Get("/webhook", githubHandler.Webhook) - }) + r.Get("/github/post-install", githubHandler.PostInstallation) + r.Post("/github/webhook", githubHandler.Webhook) // API v1 routes r.Route("/v1", func(r chi.Router) { @@ -272,7 +268,7 @@ func (s *Server) setupRouter() { }) }) - // GitHub routes + // GitHub routes (under /v1 for consistency) r.Route("/github", func(r chi.Router) { r.Get("/setup", githubHandler.ManifestStart) r.Post("/config", githubHandler.SaveConfigManual)