Files
gitlab.nvim/cmd/info.go
Harrison (Harry) Cramer 4ae623cd65 Add Filtering, HealthCheck, Better Tests (#350)
feat: add filtering when choosing merge requests (#346)
feat: Add healthcheck (#345)
refactor: Move to gomock (#349)
feat: Makes the remote of the plugin configurable (#348)

This is a #MINOR release.
2024-08-23 14:01:59 -04:00

49 lines
1.3 KiB
Go

package main
import (
"encoding/json"
"net/http"
"github.com/xanzy/go-gitlab"
)
type InfoResponse struct {
SuccessResponse
Info *gitlab.MergeRequest `json:"info"`
}
/* infoHandler fetches infomation about the current git project. The data returned here is used in many other API calls */
func (a *Api) infoHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
if r.Method != http.MethodGet {
w.Header().Set("Access-Control-Allow-Methods", http.MethodGet)
handleError(w, InvalidRequestError{}, "Expected GET", http.StatusMethodNotAllowed)
return
}
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{endpoint: "/mr/info"}, "Could not get project info", res.StatusCode)
return
}
w.WriteHeader(http.StatusOK)
response := InfoResponse{
SuccessResponse: SuccessResponse{
Message: "Merge requests retrieved",
Status: http.StatusOK,
},
Info: mr,
}
err = json.NewEncoder(w).Encode(response)
if err != nil {
handleError(w, err, "Could not encode response", http.StatusInternalServerError)
}
}