remotes icon indicating copy to clipboard operation
remotes copied to clipboard

Manage dependencies from GitHub Enterprise

Open hector-ps opened this issue 4 years ago • 13 comments

Dependencies from GitHub can be managed by including Remotes: [remote::]repo_spec in the DESCRIPTION file. Downloading packages from GitHub Enterprise requires the argument host on install_github, that cannot be defined in the DESCRIPTION file. While I understand that the general approach for packaging and sharing R code is using public repositories, company policies usually forces the developer to use private GitHub Enterprise. Are you considering to add a way for indicating inside the DESCRIPTION file the host to use?

hector-ps avatar Oct 17 '19 10:10 hector-ps

@ijlyttle How wonder how you do that with remotes and your 📦 ghentr ? Is this possible for you ?

cderv avatar Oct 17 '19 17:10 cderv

The package maintainers can speak on this with infinitely-greater authority than I can: I think that extensibility mechanisms are something they are thinking about across r-lib, e.g. usethis, remotes, etc.

To address @cderv's point, the I can't get the ghentr idea to work with remotes, which let me to ask about a way forward and workarounds. I can summarize the workaround they have suggested to me, which work for me while the larger issues are worked out.

The central idea is to use a url:: remote. For example, the standard GitHub remote:

r-lib/usethis

Can be expressed, roughly equivalently, as:

url::https://github.com/r-lib/usethis/archive/master.zip

Using a URL means that I don't have access to specific branches or releases, but I can point it at a repository on GitHub Enterprise. Update: I'm wrong - you can access specific branches or releases, see @jimhester's comment 👇

Hope this helps!

ijlyttle avatar Oct 17 '19 17:10 ijlyttle

The central idea is to use a url:: remote. For example, the standard GitHub remote:

This is what I thought. I got the same idea. I use that for gitlab on my side. Not the best way.

It would be nice to have an option to tell remotes : « now we mean for github this url not github.com ». I guess it means a way to change globally the default host used in ˋinstall_github` and implicitly in ˋgithub_remoteˋ when parsing DESCRIPTION.

Thanks @ijlyttle for you thoughts.

cderv avatar Oct 17 '19 17:10 cderv

Thanks @ijlyttle and @cderv for this workaround. I will use the url:: remote until an option to tell remotes : « now we mean for github this url not github.com ». is developed. This is a really useful approach.

hector-ps avatar Oct 24 '19 06:10 hector-ps

Just a small clarification, you can access releases and branches, e.g.

A specific release

https://github.com/r-lib/remotes/archive/v2.1.0.zip

A branch

https://github.com/r-lib/remotes/archive/always-install-uninstalled.zip

jimhester avatar Oct 24 '19 15:10 jimhester

Sorry for the inconvenience, Guys.

When I point the url:: remote to the zip url I get the following error:

Downloading package from url: https://github.example.com/organization/repo/archive/branch.zip
Error: Failed to install '******' from GitHub:
  Failed to install 'unknown package' from URL:
  zip file 'example_temp_zip_path.zip' cannot be opened
In addition: Warning message:
In utils::unzip(src, exdir = target) : error 1 in extracting from zip file

If I use install_url I get the same result, while install_github (passing the conveniend host) works as expected. How is install_url authenticating on the GitHub Enterprise? Do you think this authentication could be the source of the error?

hector-ps avatar Oct 25 '19 11:10 hector-ps

@hector-ps: I can think of a couple of possibilities:

  • Is this a private repository?
  • Perhaps something in the URL is mispelled? My go-to to get things working the first time is to "Copy Link Address":

image

ijlyttle avatar Oct 25 '19 12:10 ijlyttle

Hi, @ijlyttle.

It's public inside my company, but my Enterprise instance of GitHub is not public. To install the repositories using install_github I pass a personal token in the auth_token argument.

hector-ps avatar Oct 25 '19 13:10 hector-ps

Hi @hector-ps,

If it is public inside your company, you should be able to use the "Copy Link Address" value with install_url() - that works for me...

ijlyttle avatar Oct 25 '19 14:10 ijlyttle

Hi @hector-ps

I managed to do it for my package on Github Enterprise. For the installation please use:

Sys.setenv("GITHUB_PAT" = "<your PAT>")
remotes::install_github("<user>/<repo>", host = "https://github.<company>.com/api/v3")
Sys.unsetenv("GITHUB_PAT")

Then for the dependency I can confirm that url:: type of remote is working. My entries in the DESCRIPTION file are as follows: url::https://github.<company>.com/<user>/<repo>/archive/<version>.zip.

Please note that it's a link to a zip file for a given released version (in particular: it's not a git zip file for a branch that is presented above). In my case that's a significant limitation because I really want to use branch names, PR and also *release thing in specifying dependency. Basically it's not possible to use e.g. development version of a package (because it's not tagged and thus not zipped).

@jimhester Is there any plans for adding github:: type of dependency for packages on Github Enterprise?

pawelru avatar Oct 29 '19 13:10 pawelru

I am also looking into making remotes work from Github Enterprise.

So far, we have been using mostly SSH keys and works using the normal git protocol. I just need to specify this first: options("remotes.git_credentials" = git2r::cred_ssh_key())

However, the normal git protocol does not support branches or tags. I tried to use: git@github.<company>.com:<username>/<repo>.git#v2 or git@github.<company>.com:<username>/<repo>.git@v2

git2r then complains that the url is wrong, which is technically correct.

I then tried to use the url protocol, but that fails with the following message:

Error: Failed to install 'unknown package' from URL:
   length(file_list) > 0 is not TRUE

I tried downloading the file with download.file and I seem to be getting some login page html. :(

So, now I have found this thread. And using the code snippet from @pawelru it works, also for branches and tags. However, how can I then use this in a DESCRIPTION file?

Maybe we could have something like this: github::https://github..com//@tag

Or what would work for me as well is: git::git@github..com:/.git@tag

I am not sure which one is easiest to implement.

wligtenberg avatar Nov 26 '19 11:11 wligtenberg

If you're on windows and you're finding that:

# R
remotes::install_git("[email protected]:me/mypkg.git", git = "ext")

seems to fail, while

# bash
git clone [email protected]:me/mypkg.git

works, it's worth noting that, though both call the same ssh program, your shell usually looks for configs under /c/Users/username/.ssh, whilst R will look under /c/Users/username/Documents/.ssh.

This behavious confused me for a long while, and was the reason that using ssh keys to access my enterprise repos wasn't working on windows, but did work on other platforms.

strazto avatar Mar 08 '21 13:03 strazto

Is this resolved by #541? I was able to use Enterprise GitHub in DESCRIPTION with:

Remotes: [email protected]::<username>/<repo>[@ref]

jabenninghoff avatar Sep 20 '23 22:09 jabenninghoff