Something went wrong. Try again.
Neovim plugin for working with Github pull request comments
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970local M = {}
---@return stringlocal function construct_gh_comments_url() local comment_url = { "https://api.github.com/repos/", M.pr_data.repo_owner, "/", M.pr_data.repo_name, "/pulls/", M.pr_data.number, "/comments", } return table.concat(comment_url, "")end
---@return stringlocal function construct_headers() local headers = { '-H "Accept: application/vnd.github+json" ', '-H "X-GitHub-Api-Version: 2022-11-28" ', '-H "Authorization: Bearer ', vim.env["GITHUB_TOKEN"], '" '
} return table.concat(headers, "")end
M.get_pr_data = function() local cmd = "gh pr view --json number,url,headRepositoryOwner,headRepository,state" local res = vim.fn.system(cmd) local pr_result = vim.json.decode(res) M.pr_data = {} M.pr_data.number = pr_result['number'] M.pr_data.repo_name = pr_result['headRepository']['name'] M.pr_data.repo_owner = pr_result['headRepositoryOwner']['login'] M.pr_data.state = pr_result['state'] M.pr_data.url = pr_result['url'] M.pr_data.comments_url = construct_gh_comments_url()end
M.get_pr_comments = function() if M.pr_data == nil then M.get_pr_data() end
local cmd = "curl -sL " .. construct_headers() .. M.pr_data.comments_url local res = vim.fn.system(cmd) -- TODO: handle errors here...pcall local res_json = vim.json.decode(res) local comments_data = {} for _, comment in pairs(res_json) do local fp = comment['path'] local c_data = {} c_data.body = comment['body'] c_data.line = comment['line'] c_data.original_line = comment['original_line'] if comments_data[fp] ~= nil then comments_data[fp][#comments_data[fp]+1] = c_data else comments_data[fp] = { c_data } end end
return comments_dataend
return M