gh.nvim icon indicating copy to clipboard operation
gh.nvim copied to clipboard

Support for Enterprise GitHub

Open David-Kunz opened this issue 3 years ago • 21 comments

Hi 👋 ,

I was trying to use this plugin with our internal Enterprise GitHub server (not github.com).

When running :GHOpenPR I successfully retrieve a list of pull requests, but when selecting one I get

Failed to fetch pull request: Not Found

Are Enterprise GitHub servers supported?

Thanks a lot and best regards, David

gh version 2.10.1 (2022-05-10)

David-Kunz avatar May 17 '22 11:05 David-Kunz

Does the "gh" tool work with enterprise? Ive only interfaced with the public site and API. Maybe we can determine if this will work.

ldelossa avatar May 17 '22 12:05 ldelossa

Yes, with gh I can perform

gh pr list

and

gh pr view xxx

David-Kunz avatar May 17 '22 12:05 David-Kunz

Its interesting you can list the pull requests, but the API call for it indicates it does not exist on your enterprise github server.

https://github.com/ldelossa/gh.nvim/blob/f766943a229d3c8b42f2a53954f78e3a07f449b5/lua/litee/gh/ghcli/init.lua#L142

This is essentially the command thats failing. If you were to run something similar with the gh tool manually, what happens?

"gh api /repos/{owner}/{repo}/pulls/1" for example.

ldelossa avatar May 17 '22 12:05 ldelossa

Yes, that was the problem, gh api always sends requests to github.com, but one can change that with the environment variable GH_HOST.

After setting GH_HOST,

gh api /repos/{owner}/{repo}/pulls/1

works.

When performing :GHOpenPR, it seems to retrieve the data but it hangs at fetching checks.

David-Kunz avatar May 17 '22 12:05 David-Kunz

Screen Shot 2022-05-17 at 14 38 54

David-Kunz avatar May 17 '22 12:05 David-Kunz

Hm, its most likely not hanging there, thats just the last log message when we fetch data. So either theres a silent error in checks, or something didnt load and we couldn't spawn the UI.

If you issue ":LTPanel" command, what happens?

ldelossa avatar May 17 '22 14:05 ldelossa

Yes, that was the problem, gh api always sends requests to github.com, but one can change that with the environment variable GH_HOST.

After setting GH_HOST,

gh api /repos/{owner}/{repo}/pulls/1

works.

When performing :GHOpenPR, it seems to retrieve the data but it hangs at fetching checks.

This gives me an idea. If we can somehow tell from the git repo and we are using GitHub Enterprise server, we could set that ENV var for all CLI requests so the user doesnt need. Or we can just make a config value which maps remotes to enterprise hosts.

ldelossa avatar May 17 '22 15:05 ldelossa

If you issue ":LTPanel" command, what happens?

Then I get the error

Must open a litee component before toggling the panel.

This gives me an idea. If we can somehow tell from the git repo and we are using GitHub Enterprise server, we could set that ENV var for all CLI requests so the user doesnt need. Or we can just make a config value which maps remotes to enterprise hosts.

Yes, these would be good options. Or we can add to the documentation that users need to set GH_HOST.

David-Kunz avatar May 17 '22 15:05 David-Kunz

@David-Kunz https://github.com/ldelossa/gh.nvim/tree/debug

Can you switch gh.nvim to the above branch and lets see where we log out to. Somewhere we fail, this is annoying because since the ui is loaded in a callback, errors happen silently :.

ldelossa avatar May 17 '22 15:05 ldelossa

Using the debug branch I get the following output when performing :GHOpenPR:

!!DEBUG: obtained current win and tabpage
!!DEBUG: passed repo dirty check
!!DEBUG: returned from remote exists check

David-Kunz avatar May 18 '22 06:05 David-Kunz

Wow that is not what I would have expected. If that's the case, your gh.nvim is dying somewhere around here:

https://github.com/ldelossa/gh.nvim/blob/7fe8f5bc859a4651c6fb738e3dfc7bc67d843b70/lua/litee/gh/pr/handlers.lua#L65

If you follow the lines, it seems like you never get past the "fetch" of the local code using the Git tool.

Are you familiar with lua and your neovim directories to place a few more logs around that "gitcli.fetch" command? You can go to its definition and print the command its issuing, then try it on your repo and see what happens.

ldelossa avatar May 18 '22 09:05 ldelossa

Okay so

        local out = gitcli.fetch(remote_name, head_branch)

is called with

remote_name = "litee-gh_{owner}/{repo}" -- {owner} and {repo} are replaced by the actual values of my repository
head_branch = "foo/bar" -- that's how the branch is called

where the return value

out == nil

And indeed I get a notification failed to fetch remote branch.

BUT: In order to get the notification, I have to press CTRL+C because it hangs.

David-Kunz avatar May 18 '22 10:05 David-Kunz

Can you discern why the git fetch is failing?

ldelossa avatar May 18 '22 11:05 ldelossa

The easiest thing to do is probably log the "cmd" variable here: https://github.com/ldelossa/gh.nvim/blob/7fe8f5bc859a4651c6fb738e3dfc7bc67d843b70/lua/litee/gh/gitcli/init.lua#L35 and then run the same exact command in your terminal at the root of the repo.

ldelossa avatar May 18 '22 11:05 ldelossa

Yes, the command

 git fetch litee-gh_{owner}/{repo} {branchname}

will timeout:

ssh: connect to host xxx port 22: Operation timed out

({owner}, {repo} and {branchname} replaced)

David-Kunz avatar May 18 '22 11:05 David-Kunz

Okay, you'll have to do a bit of debugging on your end why that's occurring. If the git remote looks OK, and the fetch command looks OK, you have a different issue here where connectivity is not working.

ldelossa avatar May 18 '22 12:05 ldelossa

Okay, I now know the problem. Access via git: is not supported, only via https.

So if I'd change the entry it would work:

[remote "litee-gh_xxx/yyy"]
-	url = git@HOST:xxx/yyy.git
+	url = https://HOST/xxx/yyy.git
	fetch = +refs/heads/*:refs/remotes/litee-gh_xxx/yyy/*

Any chance to change it to HTTPS?

David-Kunz avatar May 18 '22 12:05 David-Kunz

https://github.com/ldelossa/gh.nvim/blob/main/doc/gh-nvm.txt#L356

You'll want to flip this flag in your config.

ldelossa avatar May 18 '22 12:05 ldelossa

Hurray, it works 👍

Thanks a lot for your quick help!

If you want, I can open a PR to document the necessity for GH_HOST or alternatively provide a config option to set it inside gh.nvim.

Best regards, David

David-Kunz avatar May 18 '22 12:05 David-Kunz

PR to document for now would be a good idea.

I want to make that a "per git repo" option, so that you dont need to flick it on and off for every repository you open.

My thinking is, in the config have an option to map "remote_name => GH_HOST value", then if we see the remote in that map, make sure to set that ENV variable during init. I think any "gh" or "git" processes forked from Neovim will inherit the env var.

ldelossa avatar May 18 '22 12:05 ldelossa