This MR makes several major tweaks to the codebase. Primarily it adjusts the setup steps for the application so that rather than providing just the project ID in the `.gitlab.nvim` file, users can also provide a vareity of other settings, such as auth_token, base_branch, and so forth. This is to make the project more extensible in the future. This MR also fixes a variety of issues with error handling in the code, primarily in the request/response model between the Lua jobs and the Golang server. BREAKING CHANGE: Modifies `.gitlab.nvim` and setup steps
47 lines
1.0 KiB
Go
47 lines
1.0 KiB
Go
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")
|
|
|
|
if r.Method != http.MethodPost {
|
|
c.handleError(w, errors.New("Invalid request type"), "That request type is not allowed", http.StatusMethodNotAllowed)
|
|
w.WriteHeader(http.StatusMethodNotAllowed)
|
|
return
|
|
}
|
|
|
|
msg, status, err := c.Revoke()
|
|
|
|
if err != nil {
|
|
c.handleError(w, err, "Could not revoke approval", http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
w.WriteHeader(status)
|
|
response := SuccessResponse{
|
|
Message: msg,
|
|
Status: http.StatusOK,
|
|
}
|
|
|
|
json.NewEncoder(w).Encode(response)
|
|
}
|