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

48 lines
1.3 KiB
Go

package app
import (
"encoding/json"
"net/http"
"github.com/xanzy/go-gitlab"
)
type InfoResponse struct {
SuccessResponse
Info *gitlab.MergeRequest `json:"info"`
}
type MergeRequestGetter interface {
GetMergeRequest(pid interface{}, mergeRequest int, 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)
}
}