Skip to content

Commit

Permalink
Merge branch 'master' into fix/use-user-command-line-ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
wd60622 authored Jan 28, 2025
2 parents ad33db5 + 1d2982f commit be9bda9
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lua/octo/model/pull-request.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ end

M.PullRequest = PullRequest

local function merge_pages(data)
local out = {}
for _, page in ipairs(data) do
for _, item in ipairs(page) do
table.insert(out, item)
end
end
return out
end

--- Fetch the diff of the PR
--- @param pr PullRequest
function PullRequest:get_diff(pr)
Expand All @@ -85,13 +95,14 @@ end
function PullRequest:get_changed_files(callback)
local url = string.format("repos/%s/pulls/%d/files", self.repo, self.number)
gh.run {
args = { "api", "--paginate", url, "--jq", "." },
args = { "api", "--paginate", url, "--slurp" },
cb = function(output, stderr)
if stderr and not utils.is_blank(stderr) then
utils.error(stderr)
elseif output then
local FileEntry = require("octo.reviews.file-entry").FileEntry
local results = vim.fn.json_decode(output)
results = merge_pages(results)
local files = {}
for _, result in ipairs(results) do
local entry = FileEntry:new {
Expand All @@ -118,13 +129,14 @@ end
function PullRequest:get_commit_changed_files(rev, callback)
local url = string.format("repos/%s/commits/%s", self.repo, rev.commit)
gh.run {
args = { "api", "--paginate", url, "--jq", "." },
args = { "api", "--paginate", url, "--slurp" },
cb = function(output, stderr)
if stderr and not utils.is_blank(stderr) then
utils.error(stderr)
elseif output then
local FileEntry = require("octo.reviews.file-entry").FileEntry
local results = vim.fn.json_decode(output)
results = merge_pages(results)
local files = {}
if results.files then
for _, result in ipairs(results.files) do
Expand Down

0 comments on commit be9bda9

Please sign in to comment.