Files
gitlab.nvim/cmd/app/draft_note_publisher.go
Harrison Cramer 3d2828a950 feat!: MAJOR release. Update go to 1.25, and add migration path (#520)
BREAKING CHANGE: This bumps Go and external packages to later versions.
2026-01-30 21:54:00 -05:00

53 lines
1.4 KiB
Go

package app
import (
"encoding/json"
"net/http"
gitlab "gitlab.com/gitlab-org/api/client-go"
)
type DraftNotePublisher interface {
PublishAllDraftNotes(pid interface{}, mergeRequest int64, options ...gitlab.RequestOptionFunc) (*gitlab.Response, error)
PublishDraftNote(pid interface{}, mergeRequest int64, note int64, options ...gitlab.RequestOptionFunc) (*gitlab.Response, error)
}
type draftNotePublisherService struct {
data
client DraftNotePublisher
}
type DraftNotePublishRequest struct {
Note int64 `json:"note,omitempty"`
}
func (a draftNotePublisherService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
payload := r.Context().Value(payload("payload")).(*DraftNotePublishRequest)
var res *gitlab.Response
var err error
if payload.Note != 0 {
res, err = a.client.PublishDraftNote(a.projectInfo.ProjectId, a.projectInfo.MergeId, payload.Note)
} else {
res, err = a.client.PublishAllDraftNotes(a.projectInfo.ProjectId, a.projectInfo.MergeId)
}
if err != nil {
handleError(w, err, "Could not publish draft note(s)", http.StatusInternalServerError)
return
}
if res.StatusCode >= 300 {
handleError(w, GenericError{r.URL.Path}, "Could not publish dfaft note", res.StatusCode)
return
}
w.WriteHeader(http.StatusOK)
response := SuccessResponse{Message: "Draft note(s) published"}
err = json.NewEncoder(w).Encode(response)
if err != nil {
handleError(w, err, "Could not encode response", http.StatusInternalServerError)
}
}