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:
Harrison (Harry) Cramer
2024-09-14 16:53:00 -04:00
committed by GitHub
parent f1faf603b0
commit 22bfd0c83e
61 changed files with 1527 additions and 1284 deletions

View File

@@ -2,15 +2,14 @@ package app
import (
"encoding/json"
"io"
"net/http"
"github.com/xanzy/go-gitlab"
)
type SummaryUpdateRequest struct {
Title string `json:"title" validate:"required"`
Description string `json:"description"`
Title string `json:"title"`
}
type SummaryUpdateResponse struct {
@@ -23,33 +22,13 @@ type summaryService struct {
client MergeRequestUpdater
}
func (a summaryService) handler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
func (a summaryService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPut {
w.Header().Set("Access-Control-Allow-Methods", http.MethodPut)
handleError(w, InvalidRequestError{}, "Expected PUT", http.StatusMethodNotAllowed)
return
}
body, err := io.ReadAll(r.Body)
if err != nil {
handleError(w, err, "Could not read request body", http.StatusBadRequest)
return
}
defer r.Body.Close()
var SummaryUpdateRequest SummaryUpdateRequest
err = json.Unmarshal(body, &SummaryUpdateRequest)
if err != nil {
handleError(w, err, "Could not read JSON from request", http.StatusBadRequest)
return
}
payload := r.Context().Value(payload("payload")).(*SummaryUpdateRequest)
mr, res, err := a.client.UpdateMergeRequest(a.projectInfo.ProjectId, a.projectInfo.MergeId, &gitlab.UpdateMergeRequestOptions{
Description: &SummaryUpdateRequest.Description,
Title: &SummaryUpdateRequest.Title,
Description: &payload.Description,
Title: &payload.Title,
})
if err != nil {
@@ -58,18 +37,15 @@ func (a summaryService) handler(w http.ResponseWriter, r *http.Request) {
}
if res.StatusCode >= 300 {
handleError(w, GenericError{endpoint: "/summary"}, "Could not edit merge request summary", res.StatusCode)
handleError(w, GenericError{r.URL.Path}, "Could not edit merge request summary", res.StatusCode)
return
}
w.WriteHeader(http.StatusOK)
response := SummaryUpdateResponse{
SuccessResponse: SuccessResponse{
Message: "Summary updated",
Status: http.StatusOK,
},
MergeRequest: mr,
SuccessResponse: SuccessResponse{Message: "Summary updated"},
MergeRequest: mr,
}
err = json.NewEncoder(w).Encode(response)