Skip to content

Commit

Permalink
resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
pwntester committed Sep 13, 2022
2 parents 820ee98 + bc20d4f commit 1cff3ae
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 29 deletions.
2 changes: 1 addition & 1 deletion lua/octo/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ function M.save_issue(opts)
)
if choice == 1 then
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, true)
body = utils.escape_char(vim.fn.trim(table.concat(lines, "\n")))
body = utils.escape_char(utils.trim(table.concat(lines, "\n")))
else
body = constants.NO_BODY_MSG
end
Expand Down
14 changes: 7 additions & 7 deletions lua/octo/model/octo-buffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ function OctoBuffer:do_add_issue_comment(comment_metadata)
local resp = vim.fn.json_decode(output)
local respBody = resp.data.addComment.commentEdge.node.body
local respId = resp.data.addComment.commentEdge.node.id
if vim.fn.trim(comment_metadata.body) == vim.fn.trim(respBody) then
if utils.trim(comment_metadata.body) == utils.trim(respBody) then
local comments = self.commentsMetadata
for i, c in ipairs(comments) do
if tonumber(c.id) == -1 then
Expand Down Expand Up @@ -442,7 +442,7 @@ function OctoBuffer:do_add_thread_comment(comment_metadata)
local resp = vim.fn.json_decode(output)
local resp_comment = resp.data.addPullRequestReviewComment.comment
local comment_end
if vim.fn.trim(comment_metadata.body) == vim.fn.trim(resp_comment.body) then
if utils.trim(comment_metadata.body) == utils.trim(resp_comment.body) then
local comments = self.commentsMetadata
for i, c in ipairs(comments) do
if tonumber(c.id) == -1 then
Expand Down Expand Up @@ -550,7 +550,7 @@ function OctoBuffer:do_add_new_thread(comment_metadata)
local resp = vim.fn.json_decode(output).data.addPullRequestReviewThread
if not utils.is_blank(resp.thread) then
local new_comment = resp.thread.comments.nodes[1]
if vim.fn.trim(comment_metadata.body) == vim.fn.trim(new_comment.body) then
if utils.trim(comment_metadata.body) == utils.trim(new_comment.body) then
local comments = self.commentsMetadata
for i, c in ipairs(comments) do
if tonumber(c.id) == -1 then
Expand Down Expand Up @@ -647,7 +647,7 @@ function OctoBuffer:do_add_new_thread(comment_metadata)
local r = vim.fn.json_decode(output)
local resp = r.data.addPullRequestReviewComment
if not utils.is_blank(resp.comment) then
if vim.fn.trim(comment_metadata.body) == vim.fn.trim(resp.comment.body) then
if utils.trim(comment_metadata.body) == utils.trim(resp.comment.body) then
local comments = self.commentsMetadata
for i, c in ipairs(comments) do
if tonumber(c.id) == -1 then
Expand Down Expand Up @@ -699,7 +699,7 @@ function OctoBuffer:do_add_pull_request_comment(comment_metadata)
elseif output then
local resp = vim.fn.json_decode(output)
if not utils.is_blank(resp) then
if vim.fn.trim(comment_metadata.body) == vim.fn.trim(resp.body) then
if utils.trim(comment_metadata.body) == utils.trim(resp.body) then
local comments = self.commentsMetadata
for i, c in ipairs(comments) do
if tonumber(c.id) == -1 then
Expand Down Expand Up @@ -752,7 +752,7 @@ function OctoBuffer:do_update_comment(comment_metadata)
elseif comment_metadata.kind == "PullRequestReview" then
resp_comment = resp.data.updatePullRequestReview.pullRequestReview
end
if resp_comment and vim.fn.trim(comment_metadata.body) == vim.fn.trim(resp_comment.body) then
if resp_comment and utils.trim(comment_metadata.body) == utils.trim(resp_comment.body) then
local comments = self.commentsMetadata
for i, c in ipairs(comments) do
if c.id == comment_metadata.id then
Expand Down Expand Up @@ -789,7 +789,7 @@ function OctoBuffer:update_metadata()
metadata.body = text
metadata.startLine = start_line
metadata.endLine = end_line
metadata.dirty = vim.fn.trim(metadata.body) ~= vim.fn.trim(metadata.savedBody) and true or false
metadata.dirty = utils.trim(metadata.body) ~= utils.trim(metadata.savedBody) and true or false
end
end

Expand Down
2 changes: 1 addition & 1 deletion lua/octo/reviews/file-panel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ function M.thread_counts(path)
end
for _, comment in ipairs(thread.comments.nodes) do
local review = comment.pullRequestReview
if not utils.is_blank(review) and review.state == "PENDING" and not utils.is_blank(vim.fn.trim(comment.body)) then
if not utils.is_blank(review) and review.state == "PENDING" and not utils.is_blank(utils.trim(comment.body)) then
pending = pending + 1
end
end
Expand Down
4 changes: 2 additions & 2 deletions lua/octo/reviews/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ function Review:submit(event)
local bufnr = vim.api.nvim_get_current_buf()
local winid = vim.api.nvim_get_current_win()
local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
local body = utils.escape_char(vim.fn.trim(table.concat(lines, "\n")))
local body = utils.escape_char(utils.trim(table.concat(lines, "\n")))
local query = graphql("submit_pull_request_review_mutation", self.id, event, body, { escape = false })
gh.run {
args = { "api", "graphql", "-f", string.format("query=%s", query) },
Expand All @@ -256,7 +256,7 @@ function Review:show_pending_comments()
local pending_threads = {}
for _, thread in ipairs(vim.tbl_values(self.threads)) do
for _, comment in ipairs(thread.comments.nodes) do
if comment.pullRequestReview.state == "PENDING" and not utils.is_blank(vim.fn.trim(comment.body)) then
if comment.pullRequestReview.state == "PENDING" and not utils.is_blank(utils.trim(comment.body)) then
table.insert(pending_threads, thread)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lua/octo/reviews/thread-panel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function M.create_thread_buffer(threads, repo, number, side, path)
if not vim.startswith(path, "/") then
path = "/" .. path
end
local line = threads[1].originalStartLine
local line = threads[1].originalStartLine ~= vim.NIL and threads[1].originalStartLine or threads[1].originalLine
local bufname = string.format("octo://%s/review/%s/threads/%s%s:%d", repo, current_review.id, side, path, line)
local bufnr = vim.fn.bufnr(bufname)
local buffer
Expand Down
4 changes: 2 additions & 2 deletions lua/octo/ui/writers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ function M.write_state(bufnr, state, number)
end

function M.write_body(bufnr, issue, line)
local body = vim.fn.trim(issue.body)
local body = utils.trim(issue.body)
if vim.startswith(body, constants.NO_BODY_MSG) or utils.is_blank(body) then
body = " "
end
Expand Down Expand Up @@ -539,7 +539,7 @@ function M.write_comment(bufnr, comment, kind, line)

-- body
line = line + 2
local comment_body = vim.fn.trim(string.gsub(comment.body, "\r\n", "\n"))
local comment_body = utils.trim(string.gsub(comment.body, "\r\n", "\n"))
if vim.startswith(comment_body, constants.NO_BODY_MSG) or utils.is_blank(comment_body) then
comment_body = " "
end
Expand Down
39 changes: 24 additions & 15 deletions lua/octo/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ M.file_status_map = {
renamed = "R",
}

function M.trim(str)
if type(vim.fn.trim) == "function" then
return vim.fn.trim(str)
elseif type(vim.trim) == "function" then
return vim.trim(str)
else
return str:gsub("^%s*(.-)%s*$", "%1")
end
end

function M.calculate_strongest_review_state(states)
if vim.tbl_contains(states, "APPROVED") then
return "APPROVED"
Expand Down Expand Up @@ -121,11 +131,11 @@ end

function M.is_blank(s)
return (
s == nil
or s == vim.NIL
or (type(s) == "string" and string.match(s, "%S") == nil)
or (type(s) == "table" and next(s) == nil)
)
s == nil
or s == vim.NIL
or (type(s) == "string" and string.match(s, "%S") == nil)
or (type(s) == "table" and next(s) == nil)
)
end

function M.parse_remote_url(url, aliases)
Expand Down Expand Up @@ -198,7 +208,7 @@ function M.commit_exists(commit, cb)
command = "git",
args = { "cat-file", "-t", commit },
on_exit = vim.schedule_wrap(function(j_self, _, _)
if "commit" == vim.fn.trim(table.concat(j_self:result(), "\n")) then
if "commit" == M.trim(table.concat(j_self:result(), "\n")) then
cb(true)
else
cb(false)
Expand Down Expand Up @@ -887,7 +897,7 @@ function M.process_patch(patch)
for _, hunk in ipairs(hunk_strings) do
local header = vim.split(hunk, "\n")[1]
local found, _, left_start, left_length, right_start, right_length =
string.find(header, "^%s*%-(%d+),(%d+)%s+%+(%d+),(%d+)%s*@@")
string.find(header, "^%s*%-(%d+),(%d+)%s+%+(%d+),(%d+)%s*@@")
if found then
table.insert(hunks, hunk)
table.insert(left_ranges, { tonumber(left_start), math.max(left_start + left_length - 1, 0) })
Expand Down Expand Up @@ -988,7 +998,7 @@ function M.get_pull_request_for_current_branch(cb)
vim.api.nvim_err_writeln(stderr)
elseif output then
local resp =
M.aggregate_pages(output, string.format("data.repository.%s.timelineItems.nodes", "pullRequest"))
M.aggregate_pages(output, string.format("data.repository.%s.timelineItems.nodes", "pullRequest"))
local obj = resp.data.repository.pullRequest
local Rev = require("octo.reviews.rev").Rev
local PullRequest = require("octo.model.pull-request").PullRequest
Expand Down Expand Up @@ -1026,7 +1036,7 @@ function M.close_preview_autocmd(events, winnr, bufnrs)
autocmd!
autocmd BufEnter * lua vim.lsp.util._close_preview_window(%d, {%s})
augroup end
]],
]] ,
augroup,
winnr,
table.concat(bufnrs, ",")
Expand All @@ -1038,7 +1048,7 @@ function M.close_preview_autocmd(events, winnr, bufnrs)
augroup %s
autocmd %s <buffer> lua vim.lsp.util._close_preview_window(%d)
augroup end
]],
]] ,
augroup,
table.concat(events, ","),
winnr
Expand Down Expand Up @@ -1154,11 +1164,10 @@ function M.apply_mappings(kind, bufnr)
local mappings = require "octo.mappings"
local conf = config.get_config()
for action, value in pairs(conf.mappings[kind]) do
if
not M.is_blank(value)
and not M.is_blank(action)
and not M.is_blank(value.lhs)
and not M.is_blank(mappings[action])
if not M.is_blank(value)
and not M.is_blank(action)
and not M.is_blank(value.lhs)
and not M.is_blank(mappings[action])
then
if M.is_blank(value.desc) then
value.desc = ""
Expand Down

0 comments on commit 1cff3ae

Please sign in to comment.