Cleanup of comment creation (#42)

Refactor of comment creation code
This commit is contained in:
Harrison (Harry) Cramer
2023-08-19 00:27:11 -04:00
committed by GitHub
parent ce5dd1aaa2
commit 27c54b4739
8 changed files with 124 additions and 195 deletions

42
cmd/revisions.go Normal file
View File

@@ -0,0 +1,42 @@
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 {
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,
}
json.NewEncoder(w).Encode(response)
}