Skip to content

Commit

Permalink
Indent bury, in prep of more actions on a PR
Browse files Browse the repository at this point in the history
Specifically: golden testing for points, #11
  • Loading branch information
chelmertz committed Aug 6, 2024
1 parent 477eb2b commit 561f229
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down

0 comments on commit 561f229

Please sign in to comment.