local GhPrUtils = {} ---@param input_str string ---@return table GhPrUtils.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 lines end ---@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 GhPrUtils.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 string GhPrUtils.err_notify = function(err) vim.notify(err, vim.log.levels.ERROR, { title = "gh-pr-comments.nvim" }) end return GhPrUtils