Something went wrong. Try again.
Neovim plugin for working with Github pull request comments
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879local PrUtils = {}
---@param input_str string---@return table<string>PrUtils.split_newlines = function(input_str) local lines = {} -- add each split newline found in string for str in string.gmatch(input_str, '([^\n]+)') do table.insert(lines, str) end return linesend
PrUtils.format_diff_hunk = function(diff_hunk) local format_diff = {} table.insert(format_diff, '```diff') if string.find(diff_hunk, '\n') then for i, line in pairs(PrUtils.split_newlines(diff_hunk)) do if i == 1 then goto continue end table.insert(format_diff, line) ::continue:: end else -- or add the whole string if no newlines found table.insert(format_diff, diff_hunk) end table.insert(format_diff, '```') return format_diffend
PrUtils.format_comments = function(body) local comments = {} if string.find(body, '\n') then for _, line in pairs(PrUtils.split_newlines(body)) do table.insert(comments, line) end else -- or add the whole string if no newlines found table.insert(comments, body) end return commentsend
---@return string[]local function construct_headers() return { '-H', 'Accept: application/vnd.github+json', '-H', 'X-GitHub-Api-Version: 2022-11-28', '-H', 'Authorization: Bearer ' .. vim.env['GITHUB_TOKEN'], }end
PrUtils.http_get = function(url, cb) local cmd = { 'curl', '-sL' } vim.list_extend(cmd, construct_headers()) vim.list_extend(cmd, { url }) vim.system(cmd, { text = true }, function(res) vim.schedule(function() if res == '' or res.code ~= 0 then cb(nil, res.stderr) return end cb(res.stdout, nil) end) end)end
---@param err stringPrUtils.err_notify = function(err) vim.notify(err, vim.log.levels.ERROR, { title = 'gh-pr-comments.nvim' })end
return PrUtils