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

Clean up install_github parameters pull and branch #509

Merged
merged 8 commits into from
Jun 30, 2014
Merged

Clean up install_github parameters pull and branch #509

merged 8 commits into from
Jun 30, 2014

Conversation

krlmlr
Copy link
Member

@krlmlr krlmlr commented Jun 26, 2014

The ref and pull parameters are mutually exclusive, and the branch parameter has been deprecated. The latter two should be removed, and the ref parameter should now also accept functions.

If ref is a function, it will be called with a named list that contains all other parameters (after parsing with github_parse_path and obtaining access tokens), and return an updated version of this list. Implementation and usage examples:

github_pull_request <- function(pull) {
  force(pull)
  function(param) {
    pullinfo <- github_pull_info(param$repo, param$username, param$pull)
    param$username <- pullinfo$username
    param$ref <- pullinfo$ref
    param
  }
}

install_github("devtools", ref = github_pull_request(475))

github_pull_request <- function(pull) {
  force(pull)
  function(param) {
    pullinfo <- github_pull_info(param$repo, param$username, param$pull)
    param$username <- pullinfo$username
    param$ref <- pullinfo$ref
    param
  }
}

github_release <- function(pos = 1, pre_release = TRUE) {
  force(pos)
  force(pre_release)
  function(param) {
    param$ref <- ...
    param
  }
}

install_github("devtools", github_release())

This would allow for a cleaner implementation of #350.

Usage of the deprecated parameters pull and branch can be detected by looking at ....

Thoughts?

@hadley
Copy link
Member

hadley commented Jun 26, 2014

I'd prefer to use some simple S3 dispatch.

@krlmlr
Copy link
Member Author

krlmlr commented Jun 26, 2014

Do you mean something like this:

github_ref <- function(x) UseMethod("github_ref")
github_ref.default <- function(x) list(ref=x)
github_ref.pull <- function(x) {
  list(repo=xxx, username=yyy, ref=zzz)
}
github_pull <- function(pull) structure(pull, class="pull")

# in github_get_conn:
ref_params <- github_ref(ref)
params[names(ref_params)] <- ref_params

?

@hadley
Copy link
Member

hadley commented Jun 26, 2014

Yes, exactly, except I'd write the last bit as ref_params <- modifyList(params, github_ref(ref))

Kirill Müller added 3 commits June 27, 2014 01:48
- New exported function github_pull() to be used as value for ref parameter
- Implemented using a simple S3 dispatch mechanism
- Tests with improved mocking
    - new function with_mock
- Tests for warning when using deprecated parameters branch and pull
@krlmlr
Copy link
Member Author

krlmlr commented Jun 26, 2014

This implementation seems to work for me.

@@ -69,26 +67,18 @@ github_get_conn <- function(repo, username = getOption("github.user"),
ref <- branch
}

if (!is.null(pull)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this always be false?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not if an explicit pull = xxx is passed to install_github -- it will be captured by ... and assigned to pull in the call to install_github_single.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see - missed the separation of the functions in the diff.

@krlmlr
Copy link
Member Author

krlmlr commented Jun 27, 2014

Should be okay now.

hadley added a commit that referenced this pull request Jun 30, 2014
Clean up install_github parameters pull and branch
@hadley hadley merged commit 68d37d0 into r-lib:master Jun 30, 2014
@hadley
Copy link
Member

hadley commented Jun 30, 2014

Thanks!

@krlmlr krlmlr deleted the 509-install_github-s3-ref branch June 30, 2014 20:58
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

Successfully merging this pull request may close these issues.

2 participants