Change to HTTP Model (#5)

This commit is contained in:
Harrison (Harry) Cramer
2023-05-19 17:28:58 -07:00
committed by GitHub
parent fe0d09d582
commit 63fc025070
21 changed files with 689 additions and 430 deletions

View File

@@ -1,18 +1,47 @@
package main
import (
"encoding/json"
"fmt"
"net/http"
)
func (c *Client) Revoke() error {
func (c *Client) Revoke() (string, int, error) {
_, err := c.git.MergeRequestApprovals.UnapproveMergeRequest(c.projectId, c.mergeId, nil, nil)
res, err := c.git.MergeRequestApprovals.UnapproveMergeRequest(c.projectId, c.mergeId, nil, nil)
if err != nil {
return fmt.Errorf("Revoking approval failed: %w", err)
return "", res.Response.StatusCode, fmt.Errorf("Revoking approval failed: %w", err)
}
fmt.Println("Success! Revoked MR approval.")
return "Success! Revoked MR approval.", http.StatusOK, nil
return nil
}
func RevokeHandler(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
w.WriteHeader(http.StatusMethodNotAllowed)
return
}
w.Header().Set("Content-Type", "application/json")
client := r.Context().Value("client").(Client)
msg, status, err := client.Revoke()
w.WriteHeader(status)
if err != nil {
response := ErrorResponse{
Message: err.Error(),
Status: status,
}
json.NewEncoder(w).Encode(response)
return
}
response := SuccessResponse{
Message: msg,
Status: http.StatusOK,
}
json.NewEncoder(w).Encode(response)
}