Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Enterprise GitHub #15

Open
David-Kunz opened this issue May 17, 2022 · 20 comments
Open

Support for Enterprise GitHub #15

David-Kunz opened this issue May 17, 2022 · 20 comments

Comments

@David-Kunz
Copy link
Contributor

David-Kunz commented May 17, 2022

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)
@ldelossa
Copy link
Owner

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

@David-Kunz
Copy link
Contributor Author

Yes, with gh I can perform

gh pr list

and

gh pr view xxx

@ldelossa
Copy link
Owner

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

local cmd = [[gh api /repos/{owner}/{repo}/pulls/]] .. number

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.

@David-Kunz
Copy link
Contributor Author

David-Kunz commented May 17, 2022

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
Copy link
Contributor Author

Screen Shot 2022-05-17 at 14 38 54

@ldelossa
Copy link
Owner

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
Copy link
Owner

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.

@David-Kunz
Copy link
Contributor Author

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.

@ldelossa
Copy link
Owner

@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 :.

@David-Kunz
Copy link
Contributor Author

David-Kunz commented May 18, 2022

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

@ldelossa
Copy link
Owner

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

if not ok then

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.

@David-Kunz
Copy link
Contributor Author

David-Kunz commented May 18, 2022

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.

@ldelossa
Copy link
Owner

Can you discern why the git fetch is failing?

@ldelossa
Copy link
Owner

The easiest thing to do is probably log the "cmd" variable here:

local cmd = string.format([[git fetch %s %s]], remote, branch)
and then run the same exact command in your terminal at the root of the repo.

@David-Kunz
Copy link
Contributor Author

David-Kunz commented May 18, 2022

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)

@ldelossa
Copy link
Owner

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.

@David-Kunz
Copy link
Contributor Author

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?

@ldelossa
Copy link
Owner

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

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

@David-Kunz
Copy link
Contributor Author

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

@ldelossa
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants