r-hub/rhub

Unable to register secret with gh command

eitsupi opened this issue · 8 comments

I think this is strictly a bug in the gitcreds package, but rhub2 doesn't seem to recognize it even though I registered the secret in the GitHub CLI.

$ gh secret list
NAME   UPDATED            
RHUB2  about 3 minutes ago
> rhub2::rhub_doctor()
✔ Found R package at /workspaces/httpgd.Found git repository at /workspaces/httpgd.Do you have a GitHub personal access token (PAT)?

This hangs:

> gitcreds::gitcreds_get()

What OS and what credential helper?

What OS and what credential helper?

I haven't set any credential helpers on Ubuntu 22.04 on the container.
Maybe I need to do something with environment variables? It wasn't clear to me. (In other words, I don't need to worry about anything as long as I use the gh command)

AFAIR gh just stores your token in a plain text file, and I suspect that it installs its own credential helper that does not work well with gitcreds, apparently. Btw. does command line git work with https and the token that was installed in gh? I.e. can you do git push etc. without typing in your password?

What's the output of git config credential.helper?

Until this is fixed in gitcreds, a workaround is indeed to set the GITHUB_PAT env var.

Thanks, since I am working within VS Code Dev Containers, it appears that the credential helpers set up by VS Code Dev Containers are being used.

$ git config credential.helper
!f() { /home/user/.vscode-server/bin/1e790d77f81672c49be070e04474901747115651/node /tmp/vscode-remote-containers-dfcfcb41-7bf4-4916-bc63-9db9c9b00bfe.js git-credential-helper $*; }; f

(As a side note, I was wondering why installing packages on GitHub using pak::pak() causes a hang, perhaps this is the cause)

It turns out that gh has store credentials on ~/.config/gh/hosts.yml. (cli/cli#7023)

github.com:
    users:
        eitsupi:
            oauth_token: gho_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    git_protocol: https
    oauth_token: gho_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    user: eitsupi

Thanks! I'll investigate how to work with those helpers.

In the meanwhile, does seeing a GITHUB_PAT env var work?

Btw. what's the simplest way to spin up the dev container that you are using?

In the meanwhile, does seeing a GITHUB_PAT env var work?

I set with export GITHUB_PAT=gho_xxxxx, but it looks like I need to set up the host, etc.?

> gitcreds::gitcreds_get()
<gitcreds>
  protocol: NA
  host    : NA
  username: NA
  password: <-- hidden -->

In any case, it was enough for me to run the workflow manually from the GitHub.com UI, so I don't need to run it from R.

Btw. what's the simplest way to spin up the dev container that you are using?

I used devcontainer.json like this:

{
	"image": "ghcr.io/rocker-org/devcontainer/r-ver:4"
}

I believe it is the closed source VS Code Dev Container extension that set up the Git credential helper, so you probably need to create a container from VS Code. (Codespaces seems to set another credential helper)

I set with export GITHUB_PAT=gho_xxxxx, but it looks like I need to set up the host, etc.?

No, that's enough and it should work.