diff --git a/README.md b/README.md index f359c546..25348a47 100644 --- a/README.md +++ b/README.md @@ -143,6 +143,7 @@ require"octo".setup({ field = "CREATED_AT", -- either COMMENTS, CREATED_AT or UPDATED_AT (https://docs.github.com/en/graphql/reference/enums#issueorderfield) direction = "DESC" -- either DESC or ASC (https://docs.github.com/en/graphql/reference/enums#orderdirection) }, + limit = 100 -- maximum number of pull requests in `Octo pr list` results always_select_remote_on_create = false -- always give prompt to select base remote repo when creating PRs }, file_panel = { diff --git a/lua/octo/config.lua b/lua/octo/config.lua index 83828053..fd57d717 100644 --- a/lua/octo/config.lua +++ b/lua/octo/config.lua @@ -41,6 +41,7 @@ local M = {} ---@class OctoConfigPR ---@field order_by OctoConfigOrderBy ---@field always_select_remote_on_create boolean +---@field limit number ---@class OctoConfigOrderBy ---@field field string @@ -140,7 +141,7 @@ function M.get_default_values() field = "CREATED_AT", direction = "DESC", }, - limit = 50, + limit = 100, always_select_remote_on_create = false, }, file_panel = { @@ -402,7 +403,12 @@ function M.validate_config() validate_type(config.pull_requests.order_by.field, "pull_requests.order_by.field", "string") validate_type(config.pull_requests.order_by.direction, "pull_requests.order_by.direction", "string") end - validate_type(config.pull_requests.always_select_remote_on_create, "always_select_remote_on_create", "boolean") + validate_type( + config.pull_requests.always_select_remote_on_create, + "pull_requests.always_select_remote_on_create", + "boolean" + ) + validate_type(config.pull_requests.limit, "pull_requests.limit", "number") end local function validate_mappings() diff --git a/lua/octo/pickers/telescope/provider.lua b/lua/octo/pickers/telescope/provider.lua index bb99e8e1..1cc97960 100644 --- a/lua/octo/pickers/telescope/provider.lua +++ b/lua/octo/pickers/telescope/provider.lua @@ -296,16 +296,20 @@ function M.pull_requests(opts) utils.info "Fetching pull requests (this may take a while) ..." local args = { - "pr", "list", - "--limit", tostring(opts.limit), - "--json", "author,number,title,url,headRepository,headRepositoryOwner,headRefName,isDraft" + "pr", + "list", + "--limit", + tostring(opts.limit), + "--json", + "author,number,title,url,headRepository,headRepositoryOwner,headRefName,isDraft", } + if opts.repo then table.insert(args, "-R") table.insert(args, opts.repo) end - local keys = { "author", "assignee", "label", "state", "head", "base", "search" } + local keys = { "author", "assignee", "label", "state", "head", "base", "search" } for _, key in ipairs(keys) do if opts[key] then table.insert(args, "--" .. key) @@ -328,20 +332,29 @@ function M.pull_requests(opts) local max_number = -1 local username_col_len = 0 local branch_name_col_len = 0 - local authors = {} + local author_ids = {} local author_count = 0 for _, pull in ipairs(pull_requests) do -- modify result to be consistent with GraphQL output. pull["__typename"] = "pull_request" - pull.author.username = pull.author.login pull.repository = { nameWithOwner = pull.headRepositoryOwner.login .. "/" .. pull.headRepository.name } - authors[pull.author.id] = (authors[pull.author.id] or 0) + 1 + local author_id = "?" + local author_name = "?" + if pull.author ~= nil then + if pull.author.id ~= nil then + author_id = pull.author.id + end + if pull.author.login ~= nil then + author_name = pull.author.login + end + end + author_ids[author_id] = true + username_col_len = math.min(20, math.max(username_col_len, #tostring(author_name))) max_number = math.max(max_number, #tostring(pull.number)) - username_col_len = math.min(20, math.max(username_col_len, #tostring(pull.author.login))) branch_name_col_len = math.min(20, math.max(branch_name_col_len, #tostring(pull.headRefName))) end - for _ in pairs(authors) do + for _ in pairs(author_ids) do author_count = author_count + 1 end @@ -352,7 +365,12 @@ function M.pull_requests(opts) .new(opts, { finder = finders.new_table { results = pull_requests, - entry_maker = entry_maker.gen_from_pull_request(max_number, username_col_len, branch_name_col_len, author_count), + entry_maker = entry_maker.gen_from_pull_request( + max_number, + username_col_len, + branch_name_col_len, + author_count + ), }, sorter = conf.generic_sorter(opts), previewer = previewers.issue.new(opts),