Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
ldelossa committed May 17, 2022
1 parent 44e016c commit 7fe8f5b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
19 changes: 19 additions & 0 deletions lua/litee/gh/pr/handlers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function M.ui_handler(refresh, on_load_ui)
local cur_win = vim.api.nvim_get_current_win()
local cur_tabpage = vim.api.nvim_win_get_tabpage(cur_win)
local state_was_nil = false
print("!!DEBUG: obtained current win and tabpage")

-- refresh var from closure.
if not refresh then
Expand All @@ -54,13 +55,16 @@ function M.ui_handler(refresh, on_load_ui)
lib_notify.notify_popup_with_timeout("Cannot open pull request because repository has changes. Stash changes and try again.", 7500, "error")
return
end
print("!!DEBUG: passed repo dirty check")
-- if we don't have the remote HEAD then add it and fetch the branch by ref
-- name.
--
-- if it exists the remote name is returned turned.
local ok, remote = gitcli.remote_exists(remote_url)
print("!!DEBUG: returned from remote exists check")
if not ok then
local out = gitcli.add_remote(remote_name, remote_url)
print("!!DEBUG: returned from adding remote")
if out == nil then
lib_notify.notify_popup_with_timeout("Failed to add remote git repository.", 7500, "error")
return
Expand All @@ -74,10 +78,12 @@ function M.ui_handler(refresh, on_load_ui)
lib_notify.notify_popup_with_timeout("Failed to fetch remote branch.", 7500, "error")
return
end
print("!!DEBUG: returned from fetching remote branch locally")
end

-- setup state for the pr component
local state = lib_state.get_component_state(cur_tabpage, "pr")
print("!!DEBUG: returned from getting global component state")
if state == nil then
state = {}
-- if state.tree ~= nil then
Expand All @@ -90,6 +96,7 @@ function M.ui_handler(refresh, on_load_ui)
s.pull_state.tab = state.tab

local prev_tree = lib_tree.get_tree(state.tree)
print("!!DEBUG: returned getting tree")

-- dynamic set of subtrees to create
local subtrees = {}
Expand All @@ -107,44 +114,53 @@ function M.ui_handler(refresh, on_load_ui)
-- build root's details sub-tree
local details_subtree = details.build_details_tree(s.pull_state.pr_raw, 1, prev_tree)
table.insert(subtrees, details_subtree)
print("!!DEBUG: created details subtree")

-- build commits subtree
local commits_subtree = commits.build_commits_tree(s.pull_state.commits, 1, prev_tree)
table.insert(subtrees, commits_subtree)
print("!!DEBUG: created commits subtree")

-- build reviews subtree
local reviews_subtree = reviews.build_reviews_subtree(1, prev_tree)
if #reviews_subtree.children > 0 then
table.insert(subtrees, reviews_subtree)
end
print("!!DEBUG: created reviews subtree")

-- build converstation subtree
local conversations_subtree = conversations.build_conversations_tree(s.pull_state.review_threads_raw, 1, prev_tree)
if #conversations_subtree.children > 0 then
table.insert(subtrees, conversations_subtree)
end
print("!!DEBUG: created conversations")

local files_changed_subtree = files_changed.build_files_changed_tree(s.pull_state.files_by_name, 1, prev_tree)
table.insert(subtrees, files_changed_subtree)
print("!!DEBUG: created files changed subtree")

-- build checks subtree
local checks_subtree = checks.build_checks_tree(s.pull_state.check_runs, 1, prev_tree)
if #checks_subtree.children > 0 then
table.insert(subtrees, checks_subtree)
end
print("!!DEBUG: created checks subtree")

-- register our pr_root as the root of our new tree.
lib_tree.add_node(state.tree, pr_root, "", true)
print("!!DEBUG: returned from adding root pr node")

-- update component state and grab the global since we need it to toggle
-- the panel open.
local global_state = lib_state.put_component_state(cur_tabpage, "pr", state)
print("!!DEBUG: returned from getting global state")

local cursor = nil
if global_state["pr"].win ~= nil and
vim.api.nvim_win_is_valid(global_state["pr"].win) then
cursor = vim.api.nvim_win_get_cursor(global_state["pr"].win)
end
print("!!DEBUG: returned from getting cursor")

-- state was not nil, can we reuse the existing win
-- and buffer?
Expand All @@ -161,6 +177,7 @@ function M.ui_handler(refresh, on_load_ui)
state.tree,
marshaller.marshal_pr_commit_node
)
print("!!DEBUG: returned from writing out tree")
else
-- we have no state, so open up the panel or popout to create
-- a window and buffer.
Expand All @@ -169,10 +186,12 @@ function M.ui_handler(refresh, on_load_ui)
else
lib_panel.toggle_panel(global_state, true, false)
end
print("!!DEBUG: returned from toggling panel")
end
if not refresh then
local buf = pr_buffer.render_comments()
vim.api.nvim_win_set_buf(0, buf)
print("!!DEBUG: returned from rendering pr buffer")
end

if cursor ~= nil then
Expand Down
4 changes: 3 additions & 1 deletion lua/litee/gh/pr/state.lua
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,9 @@ function M.load_state_async(pull_number, on_load)
M.get_collaborators_async(function ()
M.get_repo_issues_async(function ()
M.get_check_runs(
function () vim.schedule(on_load) end
function ()
vim.schedule(function() vim.api.nvim_echo({{spinner() .. " successfully fetched PR data", "LTInfo"}}, false, {}) end)
vim.schedule(on_load) end
)
end)
end)
Expand Down

0 comments on commit 7fe8f5b

Please sign in to comment.