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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missingness and API Calls #3

Open
coatless opened this issue May 10, 2018 · 2 comments
Open

Missingness and API Calls #3

coatless opened this issue May 10, 2018 · 2 comments

Comments

@coatless
Copy link
Collaborator

Consider:

repo_transfer = function(owner, repo, new_owner, team_id = NA) {
  if( is.na(team_id) ) {
    gh("POST /repos/:owner/:repo/transfer",
       owner = owner,
       repo = repo,
       new_owner = new_owner)
  } else {
    gh("POST /repos/:owner/:repo/transfer",
       owner = owner,
       repo = repo,
       new_owner = new_owner,
       team_id = team_id)
  }
}

There is a lot of code duplication.

Perhaps a variant of do.call with the parameters being added into a list() is better suited to this endeavor. Unless, there is something I'm overlooking in terms of evoking gh.

@lwjohnst86
Copy link

I created a similar package (githubr) mostly targeted to making and editing issues. I dealt with that here:

add_request_parameters <- function(...) {
    params <- list(...)
    Filter(Negate(is.null), params)
}

And I had each param's default being NULL. So then all NULL params are dropped, so that I could then pass the params to:

do.call(gh::gh, params)

@coatless
Copy link
Collaborator Author

coatless commented Mar 3, 2019

@lwjohnst86 thanks for the comment. This looks like what I was proposing in r-lib/gh#84.

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