Files
gitlab.nvim/cmd/app/summary.go
Harrison (Harry) Cramer 22bfd0c83e 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.
2024-09-14 16:53:00 -04:00

57 lines
1.3 KiB
Go

package app
import (
"encoding/json"
"net/http"
"github.com/xanzy/go-gitlab"
)
type SummaryUpdateRequest struct {
Title string `json:"title" validate:"required"`
Description string `json:"description"`
}
type SummaryUpdateResponse struct {
SuccessResponse
MergeRequest *gitlab.MergeRequest `json:"mr"`
}
type summaryService struct {
data
client MergeRequestUpdater
}
func (a summaryService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
payload := r.Context().Value(payload("payload")).(*SummaryUpdateRequest)
mr, res, err := a.client.UpdateMergeRequest(a.projectInfo.ProjectId, a.projectInfo.MergeId, &gitlab.UpdateMergeRequestOptions{
Description: &payload.Description,
Title: &payload.Title,
})
if err != nil {
handleError(w, err, "Could not edit merge request summary", http.StatusInternalServerError)
return
}
if res.StatusCode >= 300 {
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"},
MergeRequest: mr,
}
err = json.NewEncoder(w).Encode(response)
if err != nil {
handleError(w, err, "Could not encode response", http.StatusInternalServerError)
}
}