This MR adds linting and formatting to the CI pipeline for the repository for both the Golang and Lua code.
47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"net/http"
|
|
|
|
"github.com/xanzy/go-gitlab"
|
|
)
|
|
|
|
type RevisionsResponse struct {
|
|
SuccessResponse
|
|
Revisions []*gitlab.MergeRequestDiffVersion
|
|
}
|
|
|
|
func RevisionsHandler(w http.ResponseWriter, r *http.Request) {
|
|
c := r.Context().Value("client").(Client)
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
if r.Method != http.MethodGet {
|
|
w.Header().Set("Allow", http.MethodGet)
|
|
c.handleError(w, errors.New("Invalid request type"), "That request type is not allowed", http.StatusMethodNotAllowed)
|
|
w.WriteHeader(http.StatusMethodNotAllowed)
|
|
return
|
|
}
|
|
|
|
versionInfo, _, err := c.git.MergeRequests.GetMergeRequestDiffVersions(c.projectId, c.mergeId, &gitlab.GetMergeRequestDiffVersionsOptions{})
|
|
if err != nil {
|
|
c.handleError(w, err, "Could not get diff version info", http.StatusBadRequest)
|
|
}
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
response := RevisionsResponse{
|
|
SuccessResponse: SuccessResponse{
|
|
Message: "Revisions fetched successfully",
|
|
Status: http.StatusOK,
|
|
},
|
|
Revisions: versionInfo,
|
|
}
|
|
|
|
err = json.NewEncoder(w).Encode(response)
|
|
if err != nil {
|
|
c.handleError(w, err, "Could not encode response", http.StatusInternalServerError)
|
|
}
|
|
|
|
}
|