Miscellaneous Bug Fixes (#423)

fix: Show non-resolvable notes in winbar (#417)
fix: add more emojis and make emoji picker configurable (#414)
fix: comment creation should not be possible for renamed and moved files (#416)
fix: color highlight groups are invalid (#421)
fix: plugin failing to build on Windows (#419)

---------

Co-authored-by: Jakub F. Bortlík <jakub.bortlik@proton.me>
This commit is contained in:
Harrison (Harry) Cramer
2024-11-12 11:01:28 -05:00
committed by GitHub
parent 30daecfb60
commit be027331e1
17 changed files with 221 additions and 11079 deletions

View File

@@ -23,6 +23,7 @@ type LineRange struct {
/* PositionData represents the position of a comment or note (relative to a file diff) */ /* PositionData represents the position of a comment or note (relative to a file diff) */
type PositionData struct { type PositionData struct {
FileName string `json:"file_name"` FileName string `json:"file_name"`
OldFileName string `json:"old_file_name"`
NewLine *int `json:"new_line,omitempty"` NewLine *int `json:"new_line,omitempty"`
OldLine *int `json:"old_line,omitempty"` OldLine *int `json:"old_line,omitempty"`
HeadCommitSHA string `json:"head_commit_sha"` HeadCommitSHA string `json:"head_commit_sha"`
@@ -41,13 +42,19 @@ type RequestWithPosition interface {
func buildCommentPosition(commentWithPositionData RequestWithPosition) *gitlab.PositionOptions { func buildCommentPosition(commentWithPositionData RequestWithPosition) *gitlab.PositionOptions {
positionData := commentWithPositionData.GetPositionData() positionData := commentWithPositionData.GetPositionData()
// If the file has been renamed, then this is a relevant part of the payload
oldFileName := positionData.OldFileName
if oldFileName == "" {
oldFileName = positionData.FileName
}
opt := &gitlab.PositionOptions{ opt := &gitlab.PositionOptions{
PositionType: &positionData.Type, PositionType: &positionData.Type,
StartSHA: &positionData.StartCommitSHA, StartSHA: &positionData.StartCommitSHA,
HeadSHA: &positionData.HeadCommitSHA, HeadSHA: &positionData.HeadCommitSHA,
BaseSHA: &positionData.BaseCommitSHA, BaseSHA: &positionData.BaseCommitSHA,
NewPath: &positionData.FileName, NewPath: &positionData.FileName,
OldPath: &positionData.FileName, OldPath: &oldFileName,
NewLine: positionData.NewLine, NewLine: positionData.NewLine,
OldLine: positionData.OldLine, OldLine: positionData.OldLine,
} }

View File

@@ -7,7 +7,7 @@ import (
"io" "io"
"net/http" "net/http"
"os" "os"
"path" "path/filepath"
"strconv" "strconv"
"strings" "strings"
@@ -157,8 +157,8 @@ func attachEmojis(a *data, fr FileReader) error {
return err return err
} }
binPath := path.Dir(e) binPath := filepath.Dir(e)
filePath := fmt.Sprintf("%s/config/emojis.json", binPath) filePath := filepath.Join(binPath, "config", "emojis.json")
reader, err := fr.ReadFile(filePath) reader, err := fr.ReadFile(filePath)

1
cmd/config/emojis.json Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@@ -266,6 +266,17 @@ you call this function with no values the defaults will be used:
winbar = nil -- Custom function to return winbar title, should return a string. Provided with WinbarTable (defined in annotations.lua) winbar = nil -- Custom function to return winbar title, should return a string. Provided with WinbarTable (defined in annotations.lua)
-- If using lualine, please add "gitlab" to disabled file types, otherwise you will not see the winbar. -- If using lualine, please add "gitlab" to disabled file types, otherwise you will not see the winbar.
}, },
emojis = {
-- Function for modifying how emojis are displayed in the picker. This does not affect the actual selected emoji.
-- The function is passed an emoji object as a paramter, e.g.,
-- {"unicode": "1F44D","name": "thumbs up sign", "shortname": ":thumbsup:", "moji": "👍"}
-- This is useful if your editor/terminal/font/tmux does not render some emojis properly,
-- e.g., you can remove skin tones and additionally show the shortname with
-- formatter = function(val)
-- return string.format("%s %s %s", val.moji:gsub("[\240][\159][\143][\187-\191]", ""), val.shortname, val.name)
-- end
formatter = nil,
},
choose_merge_request = { choose_merge_request = {
open_reviewer = true, -- Open the reviewer window automatically after switching merge requests open_reviewer = true, -- Open the reviewer window automatically after switching merge requests
}, },

View File

@@ -80,6 +80,7 @@ local confirm_create_comment = function(text, visual_range, unlinked, discussion
local revision = state.MR_REVISIONS[1] local revision = state.MR_REVISIONS[1]
local position_data = { local position_data = {
file_name = reviewer_data.file_name, file_name = reviewer_data.file_name,
old_file_name = reviewer_data.old_file_name,
base_commit_sha = revision.base_commit_sha, base_commit_sha = revision.base_commit_sha,
start_commit_sha = revision.start_commit_sha, start_commit_sha = revision.start_commit_sha,
head_commit_sha = revision.head_commit_sha, head_commit_sha = revision.head_commit_sha,
@@ -179,6 +180,12 @@ M.create_comment_layout = function(opts)
return return
end end
-- Check that the file has not been renamed
if reviewer.is_file_renamed() and not reviewer.does_file_have_changes() then
u.notify("Commenting on (unchanged) renamed or moved files is not supported", vim.log.levels.WARN)
return
end
-- Check that we are hovering over the code -- Check that we are hovering over the code
local filetype = vim.bo[0].filetype local filetype = vim.bo[0].filetype
if not opts.reply and (filetype == "DiffviewFiles" or filetype == "gitlab") then if not opts.reply and (filetype == "DiffviewFiles" or filetype == "gitlab") then
@@ -249,7 +256,6 @@ end
--- This function will open a comment popup in order to create a comment on the changed/updated --- This function will open a comment popup in order to create a comment on the changed/updated
--- line in the current MR --- line in the current MR
M.create_comment = function() M.create_comment = function()
vim.print("Creating comment...")
local has_clean_tree, err = git.has_clean_tree() local has_clean_tree, err = git.has_clean_tree()
if err ~= nil then if err ~= nil then
return return
@@ -293,7 +299,6 @@ end
--- This function will open a a popup to create a "note" (e.g. unlinked comment) --- This function will open a a popup to create a "note" (e.g. unlinked comment)
--- on the changed/updated line in the current MR --- on the changed/updated line in the current MR
M.create_note = function() M.create_note = function()
vim.print("Creating note...")
local layout = M.create_comment_layout({ ranged = false, unlinked = true }) local layout = M.create_comment_layout({ ranged = false, unlinked = true })
if layout ~= nil then if layout ~= nil then
layout:mount() layout:mount()
@@ -354,6 +359,8 @@ M.create_comment_suggestion = function()
local layout = M.create_comment_layout({ ranged = range_length > 0, unlinked = false }) local layout = M.create_comment_layout({ ranged = range_length > 0, unlinked = false })
if layout ~= nil then if layout ~= nil then
layout:mount() layout:mount()
else
return -- Failure in creating the comment layout
end end
vim.schedule(function() vim.schedule(function()
if suggestion_lines then if suggestion_lines then

View File

@@ -1,3 +1,4 @@
local u = require("gitlab.utils")
local List = require("gitlab.utils.list") local List = require("gitlab.utils.list")
local state = require("gitlab.state") local state = require("gitlab.state")
@@ -17,12 +18,13 @@ M.set_buffers = function(linked_bufnr, unlinked_bufnr)
end end
---@param nodes Discussion[]|UnlinkedDiscussion[]|nil ---@param nodes Discussion[]|UnlinkedDiscussion[]|nil
---@return number, number ---@return number, number, number
local get_data = function(nodes) local get_data = function(nodes)
local total_resolvable = 0 local total_resolvable = 0
local total_resolved = 0 local total_resolved = 0
local total_non_resolvable = 0
if nodes == nil or nodes == vim.NIL then if nodes == nil or nodes == vim.NIL then
return total_resolvable, total_resolved return total_resolvable, total_resolved, total_non_resolvable
end end
total_resolvable = List.new(nodes):reduce(function(agg, d) total_resolvable = List.new(nodes):reduce(function(agg, d)
@@ -33,6 +35,14 @@ local get_data = function(nodes)
return agg return agg
end, 0) end, 0)
total_non_resolvable = List.new(nodes):reduce(function(agg, d)
local first_child = d.notes[1]
if first_child and not first_child.resolvable then
agg = agg + 1
end
return agg
end, 0)
total_resolved = List.new(nodes):reduce(function(agg, d) total_resolved = List.new(nodes):reduce(function(agg, d)
local first_child = d.notes[1] local first_child = d.notes[1]
if first_child and first_child.resolved then if first_child and first_child.resolved then
@@ -41,12 +51,13 @@ local get_data = function(nodes)
return agg return agg
end, 0) end, 0)
return total_resolvable, total_resolved return total_resolvable, total_resolved, total_non_resolvable
end end
local function content() local function content()
local resolvable_discussions, resolved_discussions = get_data(state.DISCUSSION_DATA.discussions) local resolvable_discussions, resolved_discussions, non_resolvable_discussions =
local resolvable_notes, resolved_notes = get_data(state.DISCUSSION_DATA.unlinked_discussions) get_data(state.DISCUSSION_DATA.discussions)
local resolvable_notes, resolved_notes, non_resolvable_notes = get_data(state.DISCUSSION_DATA.unlinked_discussions)
local draft_notes = require("gitlab.actions.draft_notes") local draft_notes = require("gitlab.actions.draft_notes")
local inline_draft_notes, unlinked_draft_notes = List.new(state.DRAFT_NOTES):partition(function(note) local inline_draft_notes, unlinked_draft_notes = List.new(state.DRAFT_NOTES):partition(function(note)
@@ -64,10 +75,12 @@ local function content()
local t = { local t = {
resolvable_discussions = resolvable_discussions, resolvable_discussions = resolvable_discussions,
resolved_discussions = resolved_discussions, resolved_discussions = resolved_discussions,
non_resolvable_discussions = non_resolvable_discussions,
inline_draft_notes = #inline_draft_notes, inline_draft_notes = #inline_draft_notes,
unlinked_draft_notes = #unlinked_draft_notes, unlinked_draft_notes = #unlinked_draft_notes,
resolvable_notes = resolvable_notes, resolvable_notes = resolvable_notes,
resolved_notes = resolved_notes, resolved_notes = resolved_notes,
non_resolvable_notes = non_resolvable_notes,
help_keymap = state.settings.keymaps.help, help_keymap = state.settings.keymaps.help,
} }
@@ -94,34 +107,58 @@ M.update_winbar = function()
vim.api.nvim_set_option_value("winbar", c, { scope = "local", win = win_id }) vim.api.nvim_set_option_value("winbar", c, { scope = "local", win = win_id })
end end
local function get_connector(base_title)
return string.match(base_title, "%($") and "" or "; "
end
---Builds the title string for both sections, using the count of resolvable and draft nodes ---Builds the title string for both sections, using the count of resolvable and draft nodes
---@param base_title string ---@param base_title string
---@param resolvable_count integer ---@param resolvable_count integer
---@param resolved_count integer ---@param resolved_count integer
---@param drafts_count integer ---@param drafts_count integer
---@return string ---@return string
local add_drafts_and_resolvable = function(base_title, resolvable_count, resolved_count, drafts_count) local add_drafts_and_resolvable = function(
base_title,
resolvable_count,
resolved_count,
drafts_count,
non_resolvable_count
)
if resolvable_count == 0 and drafts_count == 0 and non_resolvable_count == 0 then
return base_title
end
base_title = base_title .. " ("
if non_resolvable_count ~= 0 then
base_title = base_title .. u.pluralize(non_resolvable_count, "comment")
end
if resolvable_count ~= 0 then if resolvable_count ~= 0 then
base_title = base_title .. string.format(" (%d/%d resolved", resolvable_count, resolved_count) base_title = base_title
.. get_connector(base_title)
.. string.format("%d/%s", resolved_count, u.pluralize(resolvable_count, "thread"))
end end
if drafts_count ~= 0 then if drafts_count ~= 0 then
if resolvable_count ~= 0 then base_title = base_title .. get_connector(base_title) .. u.pluralize(drafts_count, "draft")
base_title = base_title .. string.format("; %d drafts)", drafts_count)
else
base_title = base_title .. string.format(" (%d drafts)", drafts_count)
end end
elseif resolvable_count ~= 0 then
base_title = base_title .. ")" base_title = base_title .. ")"
end
return base_title return base_title
end end
---@param t WinbarTable ---@param t WinbarTable
M.make_winbar = function(t) M.make_winbar = function(t)
local discussion_title = local discussion_title = add_drafts_and_resolvable(
add_drafts_and_resolvable("Inline Comments", t.resolvable_discussions, t.resolved_discussions, t.inline_draft_notes) "Inline Comments",
local notes_title = add_drafts_and_resolvable("Notes", t.resolvable_notes, t.resolved_notes, t.unlinked_draft_notes) t.resolvable_discussions,
t.resolved_discussions,
t.inline_draft_notes,
t.non_resolvable_discussions
)
local notes_title = add_drafts_and_resolvable(
"Notes",
t.resolvable_notes,
t.resolved_notes,
t.unlinked_draft_notes,
t.non_resolvable_notes
)
-- Colorize the active tab -- Colorize the active tab
if M.current_view_type == "discussions" then if M.current_view_type == "discussions" then

View File

@@ -85,10 +85,12 @@
---@field view_type string ---@field view_type string
---@field resolvable_discussions number ---@field resolvable_discussions number
---@field resolved_discussions number ---@field resolved_discussions number
---@field non_resolvable_discussions number
---@field inline_draft_notes number ---@field inline_draft_notes number
---@field unlinked_draft_notes number ---@field unlinked_draft_notes number
---@field resolvable_notes number ---@field resolvable_notes number
---@field resolved_notes number ---@field resolved_notes number
---@field non_resolvable_notes number
---@field help_keymap string ---@field help_keymap string
--- ---
---@class SignTable ---@class SignTable
@@ -114,6 +116,8 @@
---@class DiffviewInfo ---@class DiffviewInfo
---@field modification_type string ---@field modification_type string
---@field file_name string ---@field file_name string
---Relevant for renamed files only, the name of the file in the previous commit
---@field old_file_name string
---@field current_bufnr integer ---@field current_bufnr integer
---@field new_sha_win_id integer ---@field new_sha_win_id integer
---@field old_sha_win_id integer ---@field old_sha_win_id integer

View File

@@ -1,5 +1,4 @@
local state = require("gitlab.state") local state = require("gitlab.state")
local u = require("gitlab.utils")
local colors = state.settings.colors local colors = state.settings.colors
@@ -12,13 +11,24 @@ vim.g.gitlab_discussion_tree_resolved = "✓"
vim.g.gitlab_discussion_tree_unresolved = "-" vim.g.gitlab_discussion_tree_unresolved = "-"
local discussion = colors.discussion_tree local discussion = colors.discussion_tree
vim.api.nvim_set_hl(0, "GitlabUsername", u.get_colors_for_group(discussion.username))
vim.api.nvim_set_hl(0, "GitlabMention", u.get_colors_for_group(discussion.mention)) local function get_colors_for_group(group)
vim.api.nvim_set_hl(0, "GitlabDate", u.get_colors_for_group(discussion.date)) local normal_fg = vim.fn.synIDattr(vim.fn.synIDtrans(vim.fn.hlID(group)), "fg")
vim.api.nvim_set_hl(0, "GitlabExpander", u.get_colors_for_group(discussion.expander)) local normal_bg = vim.fn.synIDattr(vim.fn.synIDtrans(vim.fn.hlID(group)), "bg")
vim.api.nvim_set_hl(0, "GitlabDirectory", u.get_colors_for_group(discussion.directory)) return { fg = normal_fg, bg = normal_bg }
vim.api.nvim_set_hl(0, "GitlabDirectoryIcon", u.get_colors_for_group(discussion.directory_icon)) end
vim.api.nvim_set_hl(0, "GitlabFileName", u.get_colors_for_group(discussion.file_name))
vim.api.nvim_set_hl(0, "GitlabResolved", u.get_colors_for_group(discussion.resolved)) vim.api.nvim_create_autocmd("VimEnter", {
vim.api.nvim_set_hl(0, "GitlabUnresolved", u.get_colors_for_group(discussion.unresolved)) callback = function()
vim.api.nvim_set_hl(0, "GitlabDraft", u.get_colors_for_group(discussion.draft)) vim.api.nvim_set_hl(0, "GitlabUsername", get_colors_for_group(discussion.username))
vim.api.nvim_set_hl(0, "GitlabMention", get_colors_for_group(discussion.mention))
vim.api.nvim_set_hl(0, "GitlabDate", get_colors_for_group(discussion.date))
vim.api.nvim_set_hl(0, "GitlabExpander", get_colors_for_group(discussion.expander))
vim.api.nvim_set_hl(0, "GitlabDirectory", get_colors_for_group(discussion.directory))
vim.api.nvim_set_hl(0, "GitlabDirectoryIcon", get_colors_for_group(discussion.directory_icon))
vim.api.nvim_set_hl(0, "GitlabFileName", get_colors_for_group(discussion.file_name))
vim.api.nvim_set_hl(0, "GitlabResolved", get_colors_for_group(discussion.resolved))
vim.api.nvim_set_hl(0, "GitlabUnresolved", get_colors_for_group(discussion.unresolved))
vim.api.nvim_set_hl(0, "GitlabDraft", get_colors_for_group(discussion.draft))
end,
})

View File

@@ -10,8 +10,10 @@ local M = {
} }
M.init = function() M.init = function()
local bin_path = state.settings.bin_path local root_path = state.settings.root_path
local emoji_path = bin_path local emoji_path = root_path
.. state.settings.file_separator
.. "cmd"
.. state.settings.file_separator .. state.settings.file_separator
.. "config" .. "config"
.. state.settings.file_separator .. state.settings.file_separator
@@ -132,6 +134,9 @@ M.pick_emoji = function(options, cb)
vim.ui.select(options, { vim.ui.select(options, {
prompt = "Choose emoji", prompt = "Choose emoji",
format_item = function(val) format_item = function(val)
if type(state.settings.emojis.formatter) == "function" then
return state.settings.emojis.formatter(val)
end
return string.format("%s %s", val.moji, val.name) return string.format("%s %s", val.moji, val.name)
end, end,
}, function(choice) }, function(choice)

View File

@@ -90,18 +90,28 @@ local line_was_added = function(linnr, hunk, all_diff_output)
end end
---Parse git diff hunks. ---Parse git diff hunks.
---@param file_path string Path to file.
---@param base_sha string Git base SHA of merge request. ---@param base_sha string Git base SHA of merge request.
---@return HunksAndDiff ---@return HunksAndDiff
local parse_hunks_and_diff = function(file_path, base_sha) local parse_hunks_and_diff = function(base_sha)
local hunks = {} local hunks = {}
local all_diff_output = {} local all_diff_output = {}
local Job = require("plenary.job") local reviewer = require("gitlab.reviewer")
local cmd = {
"diff",
"--minimal",
"--unified=0",
"--no-color",
base_sha,
"--",
reviewer.get_current_file_oldpath(),
reviewer.get_current_file_path(),
}
local Job = require("plenary.job")
local diff_job = Job:new({ local diff_job = Job:new({
command = "git", command = "git",
args = { "diff", "--minimal", "--unified=0", "--no-color", base_sha, "--", file_path }, args = cmd,
on_exit = function(j, return_code) on_exit = function(j, return_code)
if return_code == 0 then if return_code == 0 then
all_diff_output = j:result() all_diff_output = j:result()
@@ -139,8 +149,7 @@ end
--- Processes the number of changes until the target is reached. This returns --- Processes the number of changes until the target is reached. This returns
--- a negative or positive number indicating the number of lines in the hunk --- a negative or positive number indicating the number of lines in the hunk
--that have been added or removed prior to the target line --- that have been added or removed prior to the target line
---comment
---@param line_number number ---@param line_number number
---@param hunk Hunk ---@param hunk Hunk
---@param lines table ---@param lines table
@@ -221,11 +230,10 @@ end
---This is in order to build the payload for Gitlab correctly by setting the old line and new line. ---This is in order to build the payload for Gitlab correctly by setting the old line and new line.
---@param old_line number|nil ---@param old_line number|nil
---@param new_line number|nil ---@param new_line number|nil
---@param current_file string
---@param is_current_sha_focused boolean ---@param is_current_sha_focused boolean
---@return string|nil ---@return string|nil
function M.get_modification_type(old_line, new_line, current_file, is_current_sha_focused) function M.get_modification_type(old_line, new_line, is_current_sha_focused)
local hunk_and_diff_data = parse_hunks_and_diff(current_file, state.INFO.diff_refs.base_sha) local hunk_and_diff_data = parse_hunks_and_diff(state.INFO.diff_refs.base_sha)
if hunk_and_diff_data.hunks == nil then if hunk_and_diff_data.hunks == nil then
return return
end end
@@ -240,11 +248,19 @@ end
---@param old_sha string ---@param old_sha string
---@param new_sha string ---@param new_sha string
---@param file_path string ---@param file_path string
---@param old_file_path string
---@param line_number number ---@param line_number number
---@return number|nil ---@return number|nil
M.calculate_matching_line_new = function(old_sha, new_sha, file_path, line_number) M.calculate_matching_line_new = function(old_sha, new_sha, file_path, old_file_path, line_number)
local net_change = 0 local net_change = 0
local diff_cmd = string.format("git diff --minimal --unified=0 --no-color %s %s -- %s", old_sha, new_sha, file_path) local diff_cmd = string.format(
"git diff --minimal --unified=0 --no-color %s %s -- %s %s",
old_sha,
new_sha,
old_file_path,
file_path
)
local handle = io.popen(diff_cmd) local handle = io.popen(diff_cmd)
if handle == nil then if handle == nil then
u.notify(string.format("Error running git diff command for %s", file_path), vim.log.levels.ERROR) u.notify(string.format("Error running git diff command for %s", file_path), vim.log.levels.ERROR)

View File

@@ -41,7 +41,7 @@ M.filter_placeable_discussions = function()
draft_notes = {} draft_notes = {}
end end
local file = reviewer.get_current_file() local file = reviewer.get_current_file_path()
if not file then if not file then
return {} return {}
end end

View File

@@ -152,7 +152,7 @@ M.get_reviewer_data = function()
return return
end end
local current_file = M.get_current_file() local current_file = M.get_current_file_path()
if current_file == nil then if current_file == nil then
u.notify("Error getting current file from Diffview", vim.log.levels.ERROR) u.notify("Error getting current file from Diffview", vim.log.levels.ERROR)
return return
@@ -163,7 +163,7 @@ M.get_reviewer_data = function()
local is_current_sha_focused = M.is_current_sha_focused() local is_current_sha_focused = M.is_current_sha_focused()
local modification_type = hunks.get_modification_type(old_line, new_line, current_file, is_current_sha_focused) local modification_type = hunks.get_modification_type(old_line, new_line, is_current_sha_focused)
if modification_type == nil then if modification_type == nil then
u.notify("Error getting modification type", vim.log.levels.ERROR) u.notify("Error getting modification type", vim.log.levels.ERROR)
return return
@@ -180,6 +180,7 @@ M.get_reviewer_data = function()
return { return {
file_name = layout.a.file.path, file_name = layout.a.file.path,
old_file_name = M.is_file_renamed() and layout.b.file.path or "",
old_line_from_buf = old_line, old_line_from_buf = old_line,
new_line_from_buf = new_line, new_line_from_buf = new_line,
modification_type = modification_type, modification_type = modification_type,
@@ -205,14 +206,38 @@ M.is_current_sha_focused = function()
return current_win == b_win return current_win == b_win
end end
---Get currently shown file ---Get currently shown file data
---@return string|nil M.get_current_file_data = function()
M.get_current_file = function()
local view = diffview_lib.get_current_view() local view = diffview_lib.get_current_view()
if not view or not view.panel or not view.panel.cur_file then return view and view.panel and view.panel.cur_file
return
end end
return view.panel.cur_file.path
---Get currently shown file path
---@return string|nil
M.get_current_file_path = function()
local file_data = M.get_current_file_data()
return file_data and file_data.path
end
---Get currently shown file's old path
---@return string|nil
M.get_current_file_oldpath = function()
local file_data = M.get_current_file_data()
return file_data and file_data.oldpath
end
---Tell whether current file is renamed or not
---@return boolean|nil
M.is_file_renamed = function()
local file_data = M.get_current_file_data()
return file_data and file_data.status == "R"
end
---Tell whether current file has changes or not
---@return boolean|nil
M.does_file_have_changes = function()
local file_data = M.get_current_file_data()
return file_data.stats.additions > 0 or file_data.stats.deletions > 0
end end
---Diffview exposes events which can be used to setup autocommands. ---Diffview exposes events which can be used to setup autocommands.

View File

@@ -96,7 +96,13 @@ function Location:get_line_number_from_new_sha(line)
return line return line
end end
-- Otherwise we want to get the matching line in the opposite buffer -- Otherwise we want to get the matching line in the opposite buffer
return hunks.calculate_matching_line_new(self.base_sha, self.head_sha, self.reviewer_data.file_name, line) return hunks.calculate_matching_line_new(
self.base_sha,
self.head_sha,
self.reviewer_data.file_name,
self.reviewer_data.old_file_name,
line
)
end end
-- Returns the matching line from the old SHA. -- Returns the matching line from the old SHA.
@@ -112,7 +118,13 @@ function Location:get_line_number_from_old_sha(line)
end end
-- Otherwise we want to get the matching line in the opposite buffer -- Otherwise we want to get the matching line in the opposite buffer
return hunks.calculate_matching_line_new(self.head_sha, self.base_sha, self.reviewer_data.file_name, line) return hunks.calculate_matching_line_new(
self.head_sha,
self.base_sha,
self.reviewer_data.file_name,
self.reviewer_data.old_file_name,
line
)
end end
-- Returns the current line number from whatever SHA (new or old) -- Returns the current line number from whatever SHA (new or old)
@@ -135,7 +147,7 @@ end
---@param visual_range LineRange ---@param visual_range LineRange
---@return ReviewerLineInfo|nil ---@return ReviewerLineInfo|nil
function Location:set_start_range(visual_range) function Location:set_start_range(visual_range)
local current_file = require("gitlab.reviewer").get_current_file() local current_file = require("gitlab.reviewer").get_current_file_path()
if current_file == nil then if current_file == nil then
u.notify("Error getting current file from Diffview", vim.log.levels.ERROR) u.notify("Error getting current file from Diffview", vim.log.levels.ERROR)
return return
@@ -165,7 +177,7 @@ function Location:set_start_range(visual_range)
return return
end end
local modification_type = hunks.get_modification_type(old_line, new_line, current_file, is_current_sha_focused) local modification_type = hunks.get_modification_type(old_line, new_line, is_current_sha_focused)
if modification_type == nil then if modification_type == nil then
u.notify("Error getting modification type for start of range", vim.log.levels.ERROR) u.notify("Error getting modification type for start of range", vim.log.levels.ERROR)
return return
@@ -182,7 +194,7 @@ end
-- for the Gitlab payload -- for the Gitlab payload
---@param visual_range LineRange ---@param visual_range LineRange
function Location:set_end_range(visual_range) function Location:set_end_range(visual_range)
local current_file = require("gitlab.reviewer").get_current_file() local current_file = require("gitlab.reviewer").get_current_file_path()
if current_file == nil then if current_file == nil then
u.notify("Error getting current file from Diffview", vim.log.levels.ERROR) u.notify("Error getting current file from Diffview", vim.log.levels.ERROR)
return return
@@ -207,7 +219,7 @@ function Location:set_end_range(visual_range)
local reviewer = require("gitlab.reviewer") local reviewer = require("gitlab.reviewer")
local is_current_sha_focused = reviewer.is_current_sha_focused() local is_current_sha_focused = reviewer.is_current_sha_focused()
local modification_type = hunks.get_modification_type(old_line, new_line, current_file, is_current_sha_focused) local modification_type = hunks.get_modification_type(old_line, new_line, is_current_sha_focused)
if modification_type == nil then if modification_type == nil then
u.notify("Error getting modification type for end of range", vim.log.levels.ERROR) u.notify("Error getting modification type for end of range", vim.log.levels.ERROR)
return return

View File

@@ -80,8 +80,10 @@ end
M.build = function(override) M.build = function(override)
local file_path = u.current_file_path() local file_path = u.current_file_path()
local parent_dir = vim.fn.fnamemodify(file_path, ":h:h:h:h") local parent_dir = vim.fn.fnamemodify(file_path, ":h:h:h:h")
state.settings.bin_path = parent_dir
state.settings.bin = parent_dir .. (u.is_windows() and "\\bin.exe" or "/bin") local bin_name = u.is_windows() and "bin.exe" or "bin"
state.settings.root_path = parent_dir
state.settings.bin = parent_dir .. u.path_separator .. "cmd" .. u.path_separator .. bin_name
if not override then if not override then
local binary_exists = vim.loop.fs_stat(state.settings.bin) local binary_exists = vim.loop.fs_stat(state.settings.bin)
@@ -90,17 +92,15 @@ M.build = function(override)
end end
end end
local cmd = u.is_windows() and "cd %s\\cmd && go build -o bin.exe && move bin.exe ..\\" local res = vim
or "cd %s/cmd && go build -o bin && mv bin ../bin" .system({ "go", "build", "-o", bin_name }, { cwd = state.settings.root_path .. u.path_separator .. "cmd" })
:wait()
local command = string.format(cmd, state.settings.bin_path) if res.code ~= 0 then
local null = u.is_windows() and " >NUL" or " > /dev/null" u.notify(string.format("Failed to install with status code %d:\n%s", res.code, res.stderr), vim.log.levels.ERROR)
local installCode = os.execute(command .. null)
if installCode ~= 0 then
u.notify("Could not install gitlab.nvim!", vim.log.levels.ERROR)
return false return false
end end
u.notify("Gitlab.nvim installed successfully!", vim.log.levels.INFO) u.notify("Installed successfully!", vim.log.levels.INFO)
return true return true
end end

View File

@@ -162,6 +162,9 @@ M.settings = {
tree_type = "simple", tree_type = "simple",
draft_mode = false, draft_mode = false,
}, },
emojis = {
formatter = nil,
},
create_mr = { create_mr = {
target = nil, target = nil,
template_file = nil, template_file = nil,

View File

@@ -98,7 +98,7 @@ end
---@param num integer The count of the item/word ---@param num integer The count of the item/word
---@param word string The word to pluralize ---@param word string The word to pluralize
---@return string ---@return string
local function pluralize(num, word) M.pluralize = function(num, word)
return num .. string.format(" %s", word) .. ((num > 1 or num <= 0) and "s" or "") return num .. string.format(" %s", word) .. ((num > 1 or num <= 0) and "s" or "")
end end
@@ -122,13 +122,13 @@ M.time_since = function(date_string, current_date_table)
local time_diff = current_date - date local time_diff = current_date - date
if time_diff < 60 then if time_diff < 60 then
return pluralize(time_diff, "second") .. " ago" return M.pluralize(time_diff, "second") .. " ago"
elseif time_diff < 3600 then elseif time_diff < 3600 then
return pluralize(math.floor(time_diff / 60), "minute") .. " ago" return M.pluralize(math.floor(time_diff / 60), "minute") .. " ago"
elseif time_diff < 86400 then elseif time_diff < 86400 then
return pluralize(math.floor(time_diff / 3600), "hour") .. " ago" return M.pluralize(math.floor(time_diff / 3600), "hour") .. " ago"
elseif time_diff < 2592000 then elseif time_diff < 2592000 then
return pluralize(math.floor(time_diff / 86400), "day") .. " ago" return M.pluralize(math.floor(time_diff / 86400), "day") .. " ago"
else else
local formatted_date = os.date("%B %e, %Y", date) local formatted_date = os.date("%B %e, %Y", date)
return tostring(formatted_date) return tostring(formatted_date)
@@ -335,12 +335,6 @@ M.notify = function(msg, lvl)
vim.notify("gitlab.nvim: " .. msg, lvl) vim.notify("gitlab.nvim: " .. msg, lvl)
end end
M.get_colors_for_group = function(group)
local normal_fg = vim.fn.synIDattr(vim.fn.synIDtrans((vim.fn.hlID(group))), "fg")
local normal_bg = vim.fn.synIDattr(vim.fn.synIDtrans((vim.fn.hlID(group))), "bg")
return { fg = normal_fg, bg = normal_bg }
end
M.get_current_line_number = function() M.get_current_line_number = function()
return vim.api.nvim_call_function("line", { "." }) return vim.api.nvim_call_function("line", { "." })
end end
@@ -457,13 +451,13 @@ M.format_date = function(date_string)
local time_diff = current_date - date local time_diff = current_date - date
if time_diff < 60 then if time_diff < 60 then
return pluralize(time_diff, "second") return M.pluralize(time_diff, "second")
elseif time_diff < 3600 then elseif time_diff < 3600 then
return pluralize(math.floor(time_diff / 60), "minute") return M.pluralize(math.floor(time_diff / 60), "minute")
elseif time_diff < 86400 then elseif time_diff < 86400 then
return pluralize(math.floor(time_diff / 3600), "hour") return M.pluralize(math.floor(time_diff / 3600), "hour")
elseif time_diff < 2592000 then elseif time_diff < 2592000 then
return pluralize(math.floor(time_diff / 86400), "day") return M.pluralize(math.floor(time_diff / 86400), "day")
else else
local formatted_date = os.date("%A, %B %e", date) local formatted_date = os.date("%A, %B %e", date)
return formatted_date return formatted_date