Skip to content

Commit

Permalink
Merge branch 'master' into ldelossa/fix-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
wd60622 authored Feb 2, 2025
2 parents 3f6d22a + 3e7f335 commit b3a881f
Show file tree
Hide file tree
Showing 11 changed files with 211 additions and 63 deletions.
107 changes: 70 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -476,43 +476,76 @@ Octo provides a built-in omnifunc completion for issues, PRs and users that you

## 🎨 Colors

| Highlight Group | Defaults to |
| --------------------------- | --------------- |
| _OctoDirty_ | ErrorMsg |
| _OctoIssueTitle_ | PreProc |
| _OctoIssueId_ | Question |
| _OctoEmpty_ | Comment |
| _OctoFloat_ | NormalNC |
| _OctoDate_ | Comment |
| _OctoSymbol_ | Comment |
| _OctoTimelineItemHeading_ | Comment |
| _OctoDetailsLabel_ | Title |
| _OctoMissingDetails_ | Comment |
| _OctoDetailsValue_ | Identifier |
| _OctoDiffHunkPosition_ | NormalFloat |
| _OctoCommentLine_ | TabLineSel |
| _OctoEditable_ | NormalFloat bg |
| _OctoViewer_ | GitHub color |
| _OctoBubble_ | NormalFloat |
| _OctoBubbleGreen_ | GitHub color |
| _OctoBubbleRed_ | GitHub color |
| _OctoUser_ | OctoBubble |
| _OctoUserViewer_ | OctoViewer |
| _OctoReaction_ | OctoBubble |
| _OctoReactionViewer_ | OctoViewer |
| _OctoPassingTest_ | GitHub color |
| _OctoFailingTest_ | GitHub color |
| _OctoPullAdditions_ | GitHub color |
| _OctoPullDeletions_ | GitHub color |
| _OctoPullModifications_ | GitHub color |
| _OctoStateOpen_ | GitHub color |
| _OctoStateClosed_ | GitHub color |
| _OctoStateMerge_ | GitHub color |
| _OctoStatePending_ | GitHub color |
| _OctoStateApproved_ | OctoStateOpen |
| _OctoStateChangesRequested_ | OctoStateClosed |
| _OctoStateCommented_ | Normal |
| _OctoStateDismissed_ | OctoStateClosed |
| Highlight Group | Linked To |
|-----------------------------------|--------------------|
| _OctoNormal_ | Normal |
| _OctoCursorLine_ | CursorLine |
| _OctoVertSplit_ | VertSplit |
| _OctoSignColumn_ | Normal |
| _OctoStatusColumn_ | SignColumn |
| _OctoStatusLine_ | StatusLine |
| _OctoStatusLineNC_ | StatusLineNC |
| _OctoEndOfBuffer_ | EndOfBuffer |
| _OctoFilePanelFileName_ | NormalFront |
| _OctoFilePanelSelectedFile_ | Type |
| _OctoFilePanelPath_ | Comment |
| _OctoStatusAdded_ | OctoGreen |
| _OctoStatusUntracked_ | OctoGreen |
| _OctoStatusModified_ | OctoBlue |
| _OctoStatusRenamed_ | OctoBlue |
| _OctoStatusCopied_ | OctoBlue |
| _OctoStatusTypeChange_ | OctoBlue |
| _OctoStatusUnmerged_ | OctoBlue |
| _OctoStatusUnknown_ | OctoYellow |
| _OctoStatusDeleted_ | OctoRed |
| _OctoStatusBroken_ | OctoRed |
| _OctoDirty_ | OctoRed |
| _OctoIssueId_ | NormalFloat |
| _OctoIssueTitle_ | PreProc |
| _OctoFloat_ | NormalFloat |
| _OctoTimelineItemHeading_ | Comment |
| _OctoTimelineMarker_ | Identifier |
| _OctoSymbol_ | Comment |
| _OctoDate_ | Comment |
| _OctoDetailsLabel_ | Title |
| _OctoDetailsValue_ | Identifier |
| _OctoMissingDetails_ | Comment |
| _OctoEmpty_ | NormalFloat |
| _OctoBubble_ | NormalFloat |
| _OctoUser_ | OctoBubble |
| _OctoUserViewer_ | OctoViewer |
| _OctoReaction_ | OctoBubble |
| _OctoReactionViewer_ | OctoViewer |
| _OctoPassingTest_ | OctoGreen |
| _OctoFailingTest_ | OctoRed |
| _OctoPullAdditions_ | OctoGreen |
| _OctoPullDeletions_ | OctoRed |
| _OctoPullModifications_ | OctoGrey |
| _OctoStateOpen_ | OctoGreen |
| _OctoStateClosed_ | OctoRed |
| _OctoStateCompleted_ | OctoPurple |
| _OctoStateNotPlanned_ | OctoGrey |
| _OctoStateDraft_ | OctoGrey |
| _OctoStateMerge_ | OctoPurple |
| _OctoStatePending_ | OctoYellow |
| _OctoStateApproved_ | OctoGreen |
| _OctoStateChangesRequested_ | OctoRed |
| _OctoStateDismissed_ | OctoRed |
| _OctoStateCommented_ | OctoBlue |
| _OctoStateSubmitted_ | OctoGreen |
| _OctoStateOpenBubble_ | OctoBubbleGreen |
| _OctoStateClosedBubble_ | OctoBubbleRed |
| _OctoStateMergedBubble_ | OctoBubblePurple |
| _OctoStatePendingBubble_ | OctoBubbleYellow |
| _OctoStateApprovedBubble_ | OctoBubbleGreen |
| _OctoStateChangesRequestedBubble_ | OctoBubbleRed |
| _OctoStateDismissedBubble_ | OctoBubbleRed |
| _OctoStateCommentedBubble_ | OctoBubbleBlue |
| _OctoStateSubmittedBubble_ | OctoBubbleGreen |
| _OctoStateOpenFloat_ | OctoGreenFloat |
| _OctoStateClosedFloat_ | OctoRedFloat |
| _OctoStateMergedFloat_ | OctoPurpleFloat |
| _OctoStateDraftFloat_ | OctoGreyFloat |

The term `GitHub color` refers to the colors used in the WebUI.
The (addition) `viewer` means the user of the plugin or more precisely the user authenticated via the `gh` CLI tool used to retrieve the data from GitHub.
Expand Down
17 changes: 17 additions & 0 deletions lua/octo/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ local config = require "octo.config"
local colors = require "octo.ui.colors"
local vim = vim

-- a global variable where command handlers can access the details of the last
-- command ran.
--
-- this came into existence since some commands like "comment add" need to
-- understand the line range the comment should be created on.
-- this is problematic without the command options as you exit visual mode when
-- enterting the command line.
OctoLastCmdOpts = nil

local M = {}

local get_current_buffer = function()
Expand All @@ -32,7 +41,9 @@ end

function M.setup()
vim.api.nvim_create_user_command("Octo", function(opts)
OctoLastCmdOpts = opts
require("octo.commands").octo(unpack(opts.fargs))
OctoLastCmdOpts = nil
end, { complete = require("octo.completion").octo_command_complete, nargs = "*", range = true })
local conf = config.values

Expand Down Expand Up @@ -205,6 +216,11 @@ function M.setup()
local bufnr = vim.api.nvim_get_current_buf()
local buffer = octo_buffers[bufnr]
if not buffer or not buffer:isPullRequest() then
picker.prs {
cb = function(selected)
utils.checkout_pr(selected.obj.number)
end,
}
return
end
if not utils.in_pr_repo() then
Expand Down Expand Up @@ -536,6 +552,7 @@ function M.octo(object, action, ...)
utils.error(action and "Incorrect action: " .. action or "No action specified")
return
end

res = pcall(a, ...)
if not res then
utils.error(action and "Failed action: " .. action)
Expand Down
1 change: 1 addition & 0 deletions lua/octo/gh/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ local env_vars = {
http_proxy = vim.env["http_proxy"],
https_proxy = vim.env["https_proxy"],
no_proxy = vim.env["no_proxy"],
SSH_AUTH_SOCK = vim.env["SSH_AUTH_SOCK"],
}

local function get_env()
Expand Down
10 changes: 10 additions & 0 deletions lua/octo/pickers/fzf-lua/pickers/prs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,21 @@ local function checkout_pull_request(entry)
utils.checkout_pr(entry.obj.number)
end

local function not_implemented()
utils.error "Not implemented yet"
end

return function(opts)
opts = opts or {}
if not opts.states then
opts.states = "OPEN"
end

if opts.cb ~= nil then
not_implemented()
return
end

local filter = picker_utils.get_filter(opts, "pull_request")
if utils.is_blank(opts.repo) then
opts.repo = utils.get_remote_name()
Expand Down
24 changes: 18 additions & 6 deletions lua/octo/reviews/file-entry.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ M._null_buffer = {}
---@field right_binary boolean|nil
---@field left_bufid integer
---@field right_bufid integer
--- If this table is empty, the buffer is not ready to be displayed
--- If the file is actually empty for the revision, table will be filled with a single empty line
---@field left_lines string[]
--- If this table is empty, the buffer is not ready to be displayed
--- If the file is actually empty for the revision, table will be filled with a single empty line
---@field right_lines string[]
--- If either left_fetched or right_fetched is false,
--- the buffer is not ready to be displayed.
---@field left_fetched boolean
---@field right_fetched boolean
---@field left_winid number
---@field right_winid number
---@field left_comment_ranges table
Expand Down Expand Up @@ -78,6 +78,8 @@ function FileEntry:new(opt)
right_binary = opt.right_binary,
left_lines = {},
right_lines = {},
left_fetched = false,
right_fetched = false,
diffhunks = diffhunks,
associated_bufs = {},
viewed_state = pr.files[opt.path],
Expand Down Expand Up @@ -205,21 +207,25 @@ function FileEntry:fetch()
if self.pull_request.local_right then
utils.get_file_at_commit(right_path, right_sha, function(lines)
self.right_lines = lines
self.right_fetched = true
end)
else
utils.get_file_contents(self.pull_request.repo, right_abbrev, right_path, function(lines)
self.right_lines = lines
self.right_fetched = true
end)
end

-- fetch left version
if self.pull_request.local_left then
utils.get_file_at_commit(left_path, left_sha, function(lines)
self.left_lines = lines
self.left_fetched = true
end)
else
utils.get_file_contents(self.pull_request.repo, left_abbrev, left_path, function(lines)
self.left_lines = lines
self.left_fetched = true
end)
end

Expand All @@ -232,7 +238,7 @@ end
---Determines whether the file content has been loaded and the file is ready to render
---@return boolean
function FileEntry:is_ready_to_render()
return #self.left_lines > 0 and #self.right_lines > 0
return self.left_fetched and self.right_fetched
end

---Load the buffers.
Expand Down Expand Up @@ -445,9 +451,15 @@ function M._create_buffer(opts)
-- vim.fn.bufadd creates the buffer as unlisted by default
vim.api.nvim_buf_set_option(bufnr, "buflisted", true)
else
bufnr = vim.api.nvim_create_buf(false, false)
local bufname =
string.format("octo://%s/review/%s/file/%s/%s", opts.repo, current_review.id, string.upper(opts.split), opts.path)
local existing_bufnr = utils.find_named_buffer(bufname)
if existing_bufnr then
-- Buffer already exists, most likely because review is already opened
return existing_bufnr
end

bufnr = vim.api.nvim_create_buf(false, false)
vim.api.nvim_buf_set_name(bufnr, bufname)
if opts.binary then
vim.api.nvim_buf_set_option(bufnr, "modifiable", true)
Expand Down
16 changes: 9 additions & 7 deletions lua/octo/reviews/file-panel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ FilePanel.winopts = {
foldenable = false,
spell = false,
wrap = false,
cursorline = false,
cursorline = true,
signcolumn = "yes",
foldmethod = "manual",
foldcolumn = "0",
Expand All @@ -38,7 +38,6 @@ FilePanel.winopts = {
winhl = table.concat({
"EndOfBuffer:OctoEndOfBuffer",
"Normal:OctoNormal",
--'CursorLine:OctoCursorLine',
"VertSplit:OctoVertSplit",
"SignColumn:OctoNormal",
"StatusLine:OctoStatusLine",
Expand Down Expand Up @@ -183,7 +182,14 @@ function FilePanel:highlight_file(file)
if f == file then
pcall(vim.api.nvim_win_set_cursor, self.winid, { i + header_size, 0 })
vim.api.nvim_buf_clear_namespace(self.bufid, constants.OCTO_FILE_PANEL_NS, 0, -1)
vim.api.nvim_buf_add_highlight(self.bufid, constants.OCTO_FILE_PANEL_NS, "CursorLine", i + header_size - 1, 0, -1)
vim.api.nvim_buf_add_highlight(
self.bufid,
constants.OCTO_FILE_PANEL_NS,
"OctoFilePanelSelectedFile",
i + header_size - 1,
0,
-1
)
end
end
end
Expand All @@ -198,8 +204,6 @@ function FilePanel:highlight_prev_file()
if f == cur then
local line = utils.clamp(i + header_size - 1, header_size + 1, #self.files + header_size)
pcall(vim.api.nvim_win_set_cursor, self.winid, { line, 0 })
vim.api.nvim_buf_clear_namespace(self.bufid, constants.OCTO_FILE_PANEL_NS, 0, -1)
vim.api.nvim_buf_add_highlight(self.bufid, constants.OCTO_FILE_PANEL_NS, "CursorLine", line - 1, 0, -1)
end
end
end
Expand All @@ -214,8 +218,6 @@ function FilePanel:highlight_next_file()
if f == cur then
local line = utils.clamp(i + header_size + 1, header_size, #self.files + header_size)
pcall(vim.api.nvim_win_set_cursor, self.winid, { line, 0 })
vim.api.nvim_buf_clear_namespace(self.bufid, constants.OCTO_FILE_PANEL_NS, 0, -1)
vim.api.nvim_buf_add_highlight(self.bufid, constants.OCTO_FILE_PANEL_NS, "CursorLine", line - 1, 0, -1)
end
end
end
Expand Down
11 changes: 9 additions & 2 deletions lua/octo/reviews/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ function Review:initiate(opts)
if conf.use_local_fs and not utils.in_pr_branch(pr) then
local choice = vim.fn.confirm("Currently not in PR branch, would you like to checkout?", "&Yes\n&No", 2)
if choice == 1 then
utils.checkout_pr_sync { pr_number = pr.number, timeout = conf.timeout }
utils.checkout_pr_sync { repo = pr.repo, pr_number = pr.number, timeout = conf.timeout }
end
end

Expand Down Expand Up @@ -329,8 +329,15 @@ function Review:add_comment(isSuggestion)
return
end

-- get visual selected line range
-- get visual selected line range, used if coming from a keymap where current
-- mode can be evaluated.
local line1, line2 = utils.get_lines_from_context "visual"
-- if we came from the command line the command options will provide line
-- range
if OctoLastCmdOpts ~= nil then
line1 = OctoLastCmdOpts.line1
line2 = OctoLastCmdOpts.line2
end

local comment_ranges, current_bufnr
if split == "RIGHT" then
Expand Down
5 changes: 4 additions & 1 deletion lua/octo/ui/colors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ local function get_hl_links()
StatusLineNC = "StatusLineNC",
EndOfBuffer = "EndOfBuffer",
FilePanelFileName = "NormalFront",
FilePanelSelectedFile = "Type",
FilePanelPath = "Comment",
StatusAdded = "OctoGreen",
StatusUntracked = "OctoGreen",
Expand Down Expand Up @@ -153,7 +154,9 @@ function M.setup()
end

for from, to in pairs(get_hl_links()) do
vim.cmd("hi def link Octo" .. from .. " " .. to)
if vim.fn.hlexists("Octo" .. from) == 0 then
vim.cmd("hi def link Octo" .. from .. " " .. to)
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion lua/octo/ui/writers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1347,7 +1347,7 @@ function M.write_commit_event(bufnr, item)
item.commit.committer.user.login,
item.commit.committer.user.login == vim.g.octo_viewer and "OctoUserViewer" or "OctoUser",
})
elseif item.commit.author ~= vim.NIL then
elseif item.commit.author ~= vim.NIL and item.commit.author.user ~= vim.NIL then
table.insert(vt, {
item.commit.author.user.login,
item.commit.author.user.login == vim.g.octo_viewer and "OctoUserViewer" or "OctoUser",
Expand Down
Loading

0 comments on commit b3a881f

Please sign in to comment.