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
@@ -3,7 +3,6 @@ package app
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/xanzy/go-gitlab"
|
||||
@@ -23,37 +22,20 @@ type mergeRequestListerService struct {
|
||||
client MergeRequestLister
|
||||
}
|
||||
|
||||
func (a mergeRequestListerService) handler(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
if r.Method != http.MethodPost {
|
||||
w.Header().Set("Access-Control-Allow-Methods", http.MethodPost)
|
||||
handleError(w, InvalidRequestError{}, "Expected POST", http.StatusMethodNotAllowed)
|
||||
return
|
||||
// Lists all merge requests in Gitlab according to the provided filters
|
||||
func (a mergeRequestListerService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
payload := r.Context().Value(payload("payload")).(*gitlab.ListProjectMergeRequestsOptions)
|
||||
|
||||
if payload.State == nil {
|
||||
payload.State = gitlab.Ptr("opened")
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
handleError(w, err, "Could not read request body", http.StatusBadRequest)
|
||||
return
|
||||
if payload.Scope == nil {
|
||||
payload.Scope = gitlab.Ptr("all")
|
||||
}
|
||||
|
||||
defer r.Body.Close()
|
||||
var listMergeRequestRequest gitlab.ListProjectMergeRequestsOptions
|
||||
err = json.Unmarshal(body, &listMergeRequestRequest)
|
||||
if err != nil {
|
||||
handleError(w, err, "Could not read JSON from request", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if listMergeRequestRequest.State == nil {
|
||||
listMergeRequestRequest.State = gitlab.Ptr("opened")
|
||||
}
|
||||
|
||||
if listMergeRequestRequest.Scope == nil {
|
||||
listMergeRequestRequest.Scope = gitlab.Ptr("all")
|
||||
}
|
||||
|
||||
mergeRequests, res, err := a.client.ListProjectMergeRequests(a.projectInfo.ProjectId, &listMergeRequestRequest)
|
||||
mergeRequests, res, err := a.client.ListProjectMergeRequests(a.projectInfo.ProjectId, payload)
|
||||
|
||||
if err != nil {
|
||||
handleError(w, err, "Failed to list merge requests", http.StatusInternalServerError)
|
||||
@@ -61,7 +43,7 @@ func (a mergeRequestListerService) handler(w http.ResponseWriter, r *http.Reques
|
||||
}
|
||||
|
||||
if res.StatusCode >= 300 {
|
||||
handleError(w, GenericError{endpoint: "/merge_requests"}, "Failed to list merge requests", res.StatusCode)
|
||||
handleError(w, GenericError{r.URL.Path}, "Failed to list merge requests", res.StatusCode)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -72,11 +54,8 @@ func (a mergeRequestListerService) handler(w http.ResponseWriter, r *http.Reques
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
response := ListMergeRequestResponse{
|
||||
SuccessResponse: SuccessResponse{
|
||||
Message: "Merge requests fetched successfully",
|
||||
Status: http.StatusOK,
|
||||
},
|
||||
MergeRequests: mergeRequests,
|
||||
SuccessResponse: SuccessResponse{Message: "Merge requests fetched successfully"},
|
||||
MergeRequests: mergeRequests,
|
||||
}
|
||||
|
||||
err = json.NewEncoder(w).Encode(response)
|
||||
|
||||
Reference in New Issue
Block a user