Bugfix: Fixed issue with JSON marshalling/unmarshalling
This commit is contained in:
25
cmd/info.go
25
cmd/info.go
@@ -1,14 +1,22 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/xanzy/go-gitlab"
|
||||||
)
|
)
|
||||||
|
|
||||||
const mrUrl = "%s/api/v4/projects/%s/merge_requests/%d"
|
const mrUrl = "%s/api/v4/projects/%s/merge_requests/%d"
|
||||||
|
|
||||||
|
type InfoResponse struct {
|
||||||
|
SuccessResponse
|
||||||
|
Info *gitlab.MergeRequest `json:"info"`
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Client) Info() ([]byte, error) {
|
func (c *Client) Info() ([]byte, error) {
|
||||||
|
|
||||||
url := fmt.Sprintf(mrUrl, c.gitlabInstance, c.projectId, c.mergeId)
|
url := fmt.Sprintf(mrUrl, c.gitlabInstance, c.projectId, c.mergeId)
|
||||||
@@ -58,6 +66,21 @@ func InfoHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var mergeRequest *gitlab.MergeRequest
|
||||||
|
err = json.Unmarshal(msg, &mergeRequest)
|
||||||
|
if err != nil {
|
||||||
|
c.handleError(w, err, "Could not unmarshal data from merge requests", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
w.Write(msg)
|
response := InfoResponse{
|
||||||
|
SuccessResponse: SuccessResponse{
|
||||||
|
Message: "Merge requests retrieved",
|
||||||
|
Status: http.StatusOK,
|
||||||
|
},
|
||||||
|
Info: mergeRequest,
|
||||||
|
}
|
||||||
|
|
||||||
|
json.NewEncoder(w).Encode(response)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ M.setup = function(args)
|
|||||||
return
|
return
|
||||||
else
|
else
|
||||||
job.run_job("info", "GET", nil, function(data)
|
job.run_job("info", "GET", nil, function(data)
|
||||||
state.INFO = data
|
state.INFO = data.info
|
||||||
keymaps.set_keymap_keys(args.keymaps)
|
keymaps.set_keymap_keys(args.keymaps)
|
||||||
keymaps.set_keymaps()
|
keymaps.set_keymaps()
|
||||||
end)
|
end)
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ M.run_job = function(endpoint, method, body, callback)
|
|||||||
vim.defer_fn(function()
|
vim.defer_fn(function()
|
||||||
local data_ok, data = pcall(vim.json.decode, output)
|
local data_ok, data = pcall(vim.json.decode, output)
|
||||||
if data_ok and data ~= nil then
|
if data_ok and data ~= nil then
|
||||||
local status = (data.status >= 200 and data.status < 300) and "success" or "error"
|
local status = (tonumber(data.status) >= 200 and tonumber(data.status) < 300) and "success" or "error"
|
||||||
if status == "success" and callback ~= nil then
|
if status == "success" and callback ~= nil then
|
||||||
callback(data)
|
callback(data)
|
||||||
elseif status == "success" then
|
elseif status == "success" then
|
||||||
|
|||||||
Reference in New Issue
Block a user