mpadge / stellar

Search your github stars in R
MIT License
27 stars 3 forks source link

PAT details #9

Open jonocarroll opened 6 years ago

jonocarroll commented 6 years ago

The README instructions state "You'll need to check the box for accessing repository data via the github API v4." -- I suggest this should be clearer as the settings for a new PAT (mine at least) don't mention v4 at all... I read this as instructing to check the box 'repository data via the github API v4' rather than just repo (or a subset).

Is the token environment variable name GITHUB_GRAPHQL_TOKEN a standard for something? devtools looks for GITHUB_PAT which I -- and presumably many others -- already have set. Is this specifically a new token or will that one (especially with that name) do the job? In either case the value gets read into session, after which point the name isn't needed, but it would be nice to only have one of those environment variables. My existing GITHUB_PAT, saved as GITHUB_GRAPHQL_TOKEN, seems to work.

Does stellar require repo, or user authorization? I created a new token with just user and saved it as GITHUB_GRAPHQL_TOKEN and this appears to work. My original GITHUB_PAT is already authorized for user so it also works.

mpadge commented 6 years ago

Thanks for checking all that out - that naming as GITHUB_GRAPHQL_TOKEN was just copied directly from ghrecipes. I'm not (yet) sure of the details of what is necessary in terms of token access. The query is actually a user query, yet the properties are all repo properties. My token was generated by clicking repo only, @jonocarroll yours for user only, and they both work, so that's something we've learnt there. Do you wanna try to update the README and make it more informative? Current form was just a rush job.

@maelle I don't have admin for this repo, so would you please be so kind as to add all participant parties as collaborators?

maelle commented 6 years ago
jonocarroll commented 6 years ago

Upstream issue created: https://github.com/ropensci/ghql/issues/11

mpadge commented 6 years ago

Great point on the ghql issue - ROpenSci is the one institution that can really get some momentum here in terms of nomenclative consistency.

jonocarroll commented 6 years ago

I entirely overlooked that we're the ones enforcing GITHUB_GRAPHQL_TOKEN, not ghql. There's complete freedom to choose at the moment.

Proposal:

create_client could take an env_var parameter, passed from stars, default "", allowing a user to use an arbitrary environment variable as their token name. Otherwises searches GITHUB_GRAPHQL_TOKEN then GITHUB_PAT, taking the first it finds.

## use env_var with precedence, if present
## otherwise use GITHUB_GRAPHQL_TOKEN with precedence, if present
## otherwise use GITHUB_PAT, if present
## otherwise fail
get_token <- function(env_var = "") {
  token <- sapply(c(env_var, "GITHUB_GRAPHQL_TOKEN", "GITHUB_PAT"), Sys.getenv)
  token <- token[token != ""][1]
  if (is.na(token)) stop("NO TOKEN FOUND")
  token
}