fix: date fixes; go middleware refactors; regex fixes; etc (#368)
fix: format of date when MR was closed or merged (#367) refactor: Add Payload Validators + Middleware In Go Code (#366) fix: Add better checks for leaving comments (#369) fix: regex support for http credentials embedded in remote url (#372) fix: Comment on single line selects two lines (#371) This is a #PATCH release.
This commit is contained in:
committed by
GitHub
parent
f1faf603b0
commit
22bfd0c83e
@@ -2,21 +2,19 @@ package app
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
)
|
||||
|
||||
type CreateMrRequest struct {
|
||||
Title string `json:"title"`
|
||||
Title string `json:"title" validate:"required"`
|
||||
TargetBranch string `json:"target_branch" validate:"required"`
|
||||
Description string `json:"description"`
|
||||
TargetBranch string `json:"target_branch"`
|
||||
TargetProjectID int `json:"forked_project_id,omitempty"`
|
||||
DeleteBranch bool `json:"delete_branch"`
|
||||
Squash bool `json:"squash"`
|
||||
TargetProjectID int `json:"forked_project_id,omitempty"`
|
||||
}
|
||||
|
||||
type MergeRequestCreator interface {
|
||||
@@ -29,36 +27,9 @@ type mergeRequestCreatorService struct {
|
||||
}
|
||||
|
||||
/* createMr creates a merge request */
|
||||
func (a mergeRequestCreatorService) handler(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Header().Set("Access-Control-Allow-Methods", http.MethodGet)
|
||||
if r.Method != http.MethodPost {
|
||||
handleError(w, InvalidRequestError{}, "Expected POST", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
func (a mergeRequestCreatorService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
body, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
handleError(w, err, "Could not read request body", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
var createMrRequest CreateMrRequest
|
||||
err = json.Unmarshal(body, &createMrRequest)
|
||||
if err != nil {
|
||||
handleError(w, err, "Could not unmarshal request body", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if createMrRequest.Title == "" {
|
||||
handleError(w, errors.New("Title cannot be empty"), "Could not create MR", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if createMrRequest.TargetBranch == "" {
|
||||
handleError(w, errors.New("Target branch cannot be empty"), "Could not create MR", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
createMrRequest := r.Context().Value(payload("payload")).(*CreateMrRequest)
|
||||
|
||||
opts := gitlab.CreateMergeRequestOptions{
|
||||
Title: &createMrRequest.Title,
|
||||
@@ -81,14 +52,11 @@ func (a mergeRequestCreatorService) handler(w http.ResponseWriter, r *http.Reque
|
||||
}
|
||||
|
||||
if res.StatusCode >= 300 {
|
||||
handleError(w, GenericError{endpoint: "/create_mr"}, "Could not create MR", res.StatusCode)
|
||||
handleError(w, GenericError{r.URL.Path}, "Could not create MR", res.StatusCode)
|
||||
return
|
||||
}
|
||||
|
||||
response := SuccessResponse{
|
||||
Status: http.StatusOK,
|
||||
Message: fmt.Sprintf("MR '%s' created", createMrRequest.Title),
|
||||
}
|
||||
response := SuccessResponse{Message: fmt.Sprintf("MR '%s' created", createMrRequest.Title)}
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user