Files
gitlab.nvim/cmd/app/info.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

48 lines
1.3 KiB
Go

package app
import (
"encoding/json"
"net/http"
gitlab "gitlab.com/gitlab-org/api/client-go"
)
type InfoResponse struct {
SuccessResponse
Info *gitlab.MergeRequest `json:"info"`
}
type MergeRequestGetter interface {
GetMergeRequest(pid interface{}, mergeRequest int64, opt *gitlab.GetMergeRequestsOptions, options ...gitlab.RequestOptionFunc) (*gitlab.MergeRequest, *gitlab.Response, error)
}
type infoService struct {
data
client MergeRequestGetter
}
/* infoHandler fetches infomation about the current git project. The data returned here is used in many other API calls */
func (a infoService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
mr, res, err := a.client.GetMergeRequest(a.projectInfo.ProjectId, a.projectInfo.MergeId, &gitlab.GetMergeRequestsOptions{})
if err != nil {
handleError(w, err, "Could not get project info", http.StatusInternalServerError)
return
}
if res.StatusCode >= 300 {
handleError(w, GenericError{r.URL.Path}, "Could not get project info", res.StatusCode)
return
}
w.WriteHeader(http.StatusOK)
response := InfoResponse{
SuccessResponse: SuccessResponse{Message: "Merge requests retrieved"},
Info: mr,
}
err = json.NewEncoder(w).Encode(response)
if err != nil {
handleError(w, err, "Could not encode response", http.StatusInternalServerError)
}
}