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,14 +2,14 @@ package app
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
)
|
||||
|
||||
type AssigneeUpdateRequest struct {
|
||||
Ids []int `json:"ids"`
|
||||
Ids []int `json:"ids" validate:"required"`
|
||||
}
|
||||
|
||||
type AssigneeUpdateResponse struct {
|
||||
@@ -17,37 +17,18 @@ type AssigneeUpdateResponse struct {
|
||||
Assignees []*gitlab.BasicUser `json:"assignees"`
|
||||
}
|
||||
|
||||
type AssigneesRequestResponse struct {
|
||||
SuccessResponse
|
||||
Assignees []int `json:"assignees"`
|
||||
}
|
||||
|
||||
type assigneesService struct {
|
||||
data
|
||||
client MergeRequestUpdater
|
||||
}
|
||||
|
||||
/* assigneesHandler adds or removes assignees from a merge request. */
|
||||
func (a assigneesService) handler(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
if r.Method != http.MethodPut {
|
||||
w.Header().Set("Access-Control-Allow-Methods", http.MethodPut)
|
||||
handleError(w, InvalidRequestError{}, "Expected PUT", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
func (a assigneesService) 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
|
||||
}
|
||||
assigneeUpdateRequest, ok := r.Context().Value(payload("payload")).(*AssigneeUpdateRequest)
|
||||
|
||||
defer r.Body.Close()
|
||||
var assigneeUpdateRequest AssigneeUpdateRequest
|
||||
err = json.Unmarshal(body, &assigneeUpdateRequest)
|
||||
|
||||
if err != nil {
|
||||
handleError(w, err, "Could not read JSON from request", http.StatusBadRequest)
|
||||
if !ok {
|
||||
handleError(w, errors.New("Could not get payload from context"), "Bad payload", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -61,17 +42,14 @@ func (a assigneesService) handler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if res.StatusCode >= 300 {
|
||||
handleError(w, GenericError{endpoint: "/mr/assignee"}, "Could not modify merge request assignees", res.StatusCode)
|
||||
handleError(w, GenericError{r.URL.Path}, "Could not modify merge request assignees", res.StatusCode)
|
||||
return
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
response := AssigneeUpdateResponse{
|
||||
SuccessResponse: SuccessResponse{
|
||||
Message: "Assignees updated",
|
||||
Status: http.StatusOK,
|
||||
},
|
||||
Assignees: mr.Assignees,
|
||||
SuccessResponse: SuccessResponse{Message: "Assignees updated"},
|
||||
Assignees: mr.Assignees,
|
||||
}
|
||||
|
||||
err = json.NewEncoder(w).Encode(response)
|
||||
|
||||
Reference in New Issue
Block a user