Skip to content

Commit

Permalink
remove formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Dolev Hadar authored and ldelossa committed May 24, 2022
1 parent 7ce678b commit 5382e92
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 48 deletions.
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,6 @@ require('litee.gh').setup({
jump_mode = "invoking",
-- remap the arrow keys to resize any litee.nvim windows.
map_resize_keys = false,
-- by default gh.nvim adds the remote of the pull request's HEAD as an
-- ssh_url. If you do not have ssh keys configured in GitHub this flag will
-- use the https clone address instead.
--
-- be aware, for gh.nvim to work correctly with private repositories, you
-- should configure ssh keys and use the default settings. gh.nvim will not
-- prompt for https authentication.
prefer_https_remote = false,
-- do not map any keys inside any gh.nvim buffers.
disable_keymaps = false,
-- defines keymaps in gh.nvim buffers.
Expand Down
16 changes: 2 additions & 14 deletions doc/gh-nvm.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,8 @@ Code Review Environment:

Additionally, you must be aware of how git will fetch a repository.

By default gh.nvm will use the ssh url when it adds a remote.

You must have ssh keys configured in GitHub for this to work correctly.

Alternatively you can use the "prefer_https_remote" config flag to utilize
the https clone address.
gh.nvim will use the git_protocol defined in your gh config.
Run `gh config get git_protocol` to see the current protocol.

Configuration:
A simplest possible configuration, using all the defaults, will look like
Expand Down Expand Up @@ -352,14 +348,6 @@ M.config = {
jump_mode = "invoking",
-- remap the arrow keys to resize any litee.nvim windows.
map_resize_keys = false,
-- by default gh.nvim adds the remote of the pull request's HEAD as an
-- ssh_url. If you do not have ssh keys configured in GitHub this flag will
-- use the https clone address instead.
--
-- be aware, for gh.nvim to work correctly with private repositories, you
-- should configure ssh keys and use the default settings. gh.nvim will not
-- prompt for https authentication.
prefer_https_remote = false,
-- do not map any keys inside any gh.nvim buffers.
disable_keymaps = false,
-- defines keymaps in gh.nvim buffers.
Expand Down
8 changes: 0 additions & 8 deletions lua/litee/gh/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@ M.config = {
jump_mode = "invoking",
-- remap the arrow keys to resize any litee.nvim windows.
map_resize_keys = false,
-- by default gh.nvim adds the remote of the pull request's HEAD as an
-- ssh_url. If you do not have ssh keys configured in GitHub this flag will
-- use the https clone address instead.
--
-- be aware, for gh.nvim to work correctly with private repositories, you
-- should configure ssh keys and use the default settings. gh.nvim will not
-- prompt for https authentication.
prefer_https_remote = false,
-- do not map any keys inside any gh.nvim buffers.
disable_keymaps = false,
-- defines keymaps in gh.nvim buffers.
Expand Down
5 changes: 5 additions & 0 deletions lua/litee/gh/ghcli/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -680,4 +680,9 @@ function M.get_check_runs_by_suite(suite_id, on_read)
async_request(args, on_read, true)
end

function M.get_git_protocol()
local cmd = [[gh config get git_protocol]]
return gh_exec(cmd)
end

return M
7 changes: 1 addition & 6 deletions lua/litee/gh/pr/handlers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ function M.ui_handler(refresh, on_load_ui)

-- refresh var from closure.
if not refresh then
local remote_url = ""
if config.prefer_https_remote then
remote_url = s.pull_state.pr_raw["head"]["repo"]["clone_url"]
else
remote_url = s.pull_state.pr_raw["head"]["repo"]["ssh_url"]
end
local remote_url = s.get_pr_remote_url()
local remote_name = "litee-gh_" .. s.pull_state.pr_raw["head"]["repo"]["full_name"]
local head_branch = s.pull_state.pr_raw["head"]["ref"]

Expand Down
27 changes: 15 additions & 12 deletions lua/litee/gh/pr/state.lua
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,7 @@ local function should_fetch(old_commits, new_commits)
end

local function git_fetch()
local remote_url = ""
if config.prefer_https_remote then
remote_url = M.pull_state.pr_raw["head"]["repo"]["clone_url"]
else
remote_url = M.pull_state.pr_raw["head"]["repo"]["ssh_url"]
end
local remote_url = M.get_pr_remote_url()
local ok, remote = gitcli.remote_exists(remote_url)
if not ok then
-- really shouldn't happen
Expand All @@ -286,12 +281,7 @@ local function git_reset()
lib_notify.notify_popup_with_timeout("Git history has changed, want to reset to remote but repo is dirty. Please stash changes and run GHRefreshPR", 7500, "error")
return false
end
local remote_url = ""
if config.prefer_https_remote then
remote_url = M.pull_state.pr_raw["head"]["repo"]["clone_url"]
else
remote_url = M.pull_state.pr_raw["head"]["repo"]["ssh_url"]
end
local remote_url = M.get_pr_remote_url()
local ok, remote = gitcli.remote_exists(remote_url)
if not ok then
-- really shouldn't happen
Expand Down Expand Up @@ -550,6 +540,19 @@ function M.get_pr_data_async(pull_number, cb)
end)
end

function M.get_pr_remote_url()
local remote_url = ''

local protocol = ghcli.get_git_protocol()
if protocol == 'https' then
remote_url = M.pull_state.pr_raw['head']['repo']['clone_url']
else
remote_url = M.pull_state.pr_raw['head']['repo']['ssh_url']
end

return remote_url
end

M.reset_pull_state()

-- WELCOME TO CALLBACK HELL.
Expand Down

0 comments on commit 5382e92

Please sign in to comment.