feat: pull request generation
This commit is contained in:
46
internal/http/handler/webui/pullrequest/handler.go
Normal file
46
internal/http/handler/webui/pullrequest/handler.go
Normal file
@ -0,0 +1,46 @@
|
||||
package pullrequest
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"forge.cadoles.com/wpetit/clearcase/internal/core/service"
|
||||
httpCtx "forge.cadoles.com/wpetit/clearcase/internal/http/context"
|
||||
"forge.cadoles.com/wpetit/clearcase/internal/http/handler/webui/common"
|
||||
"forge.cadoles.com/wpetit/clearcase/internal/http/url"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type Handler struct {
|
||||
mux *http.ServeMux
|
||||
forge *service.ForgeManager
|
||||
}
|
||||
|
||||
// ServeHTTP implements http.Handler.
|
||||
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
h.mux.ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
func NewHandler(forge *service.ForgeManager) *Handler {
|
||||
h := &Handler{
|
||||
mux: http.NewServeMux(),
|
||||
forge: forge,
|
||||
}
|
||||
|
||||
h.mux.HandleFunc("GET /", h.getPullRequestPage)
|
||||
h.mux.HandleFunc("PUT /", h.handlePullRequestSummaryForm)
|
||||
h.mux.HandleFunc("POST /", h.handlePullRequestForm)
|
||||
|
||||
return h
|
||||
}
|
||||
|
||||
func (h *Handler) handleError(w http.ResponseWriter, r *http.Request, err error) {
|
||||
if errors.Is(err, service.ErrForgeNotAvailable) {
|
||||
baseURL := url.Mutate(httpCtx.BaseURL(r.Context()), url.WithPath("/auth/logout"))
|
||||
http.Redirect(w, r, baseURL.String(), http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
|
||||
common.HandleError(w, r, errors.WithStack(err))
|
||||
}
|
||||
|
||||
var _ http.Handler = &Handler{}
|
Reference in New Issue
Block a user