From 561f22942b5aff1be1b6e41e89f2128b4c2ab08d Mon Sep 17 00:00:00 2001 From: Calle Helmertz Date: Tue, 6 Aug 2024 23:45:35 +0200 Subject: [PATCH] Indent bury, in prep of more actions on a PR Specifically: golden testing for points, https://github.com/chelmertz/elly/issues/11 --- internal/server/server.go | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/internal/server/server.go b/internal/server/server.go index 61986b5..f639462 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -48,31 +48,32 @@ func ServeWeb(url, username string, store *storage.Storage, refreshingChannel ch if r.Method == http.MethodPost { wo := strings.TrimPrefix(r.URL.Path, "/api/v0/prs/") parts := strings.Split(wo, "/") - if len(parts) == 2 && (parts[1] == "bury" || parts[1] == "unbury") { + if len(parts) == 2 { prUrlBytes, err := base64.StdEncoding.DecodeString(parts[0]) if err != nil { _, _ = w.Write([]byte("invalid PR ID")) w.WriteHeader(http.StatusBadRequest) return } - - var buryFunc func(string) error - if parts[1] == "bury" { - buryFunc = store.Bury - } else { - buryFunc = store.Unbury - } - ghPrUrl := string(prUrlBytes) - if err := buryFunc(ghPrUrl); err != nil { - _, _ = w.Write([]byte(fmt.Sprintf("couldn't toggle bury for PR %s", ghPrUrl))) - w.WriteHeader(http.StatusInternalServerError) + if parts[1] == "bury" || parts[1] == "unbury" { + var buryFunc func(string) error + if parts[1] == "bury" { + buryFunc = store.Bury + } else { + buryFunc = store.Unbury + } + + if err := buryFunc(ghPrUrl); err != nil { + _, _ = w.Write([]byte(fmt.Sprintf("couldn't toggle bury for PR %s", ghPrUrl))) + w.WriteHeader(http.StatusInternalServerError) + return + } + + w.WriteHeader(http.StatusNoContent) return } - - w.WriteHeader(http.StatusNoContent) - return } }