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

View File

@@ -3,22 +3,9 @@ package main
import (
"encoding/json"
"errors"
"fmt"
"net/http"
)
func (c *Client) Revoke() (string, int, error) {
res, err := c.git.MergeRequestApprovals.UnapproveMergeRequest(c.projectId, c.mergeId, nil, nil)
if err != nil {
return "", res.Response.StatusCode, fmt.Errorf("Revoking approval failed: %w", err)
}
return "Success! Revoked MR approval.", http.StatusOK, nil
}
func RevokeHandler(w http.ResponseWriter, r *http.Request) {
c := r.Context().Value("client").(Client)
w.Header().Set("Content-Type", "application/json")
@@ -29,16 +16,17 @@ func RevokeHandler(w http.ResponseWriter, r *http.Request) {
return
}
msg, status, err := c.Revoke()
res, err := c.git.MergeRequestApprovals.UnapproveMergeRequest(c.projectId, c.mergeId, nil, nil)
if err != nil {
c.handleError(w, err, "Could not revoke approval", http.StatusBadRequest)
return
}
w.WriteHeader(status)
/* TODO: Check for non-200 status codes */
w.WriteHeader(res.StatusCode)
response := SuccessResponse{
Message: msg,
Message: "Success! Revoked MR approval.",
Status: http.StatusOK,
}