r-lib / usethis

Set up commonly used 📦 components
https://usethis.r-lib.org/
Other
861 stars 285 forks source link

GitHub connectivity #214

Closed jennybc closed 6 years ago

jennybc commented 6 years ago

Organizing various thoughts and issues around GitHub. Won't all be completed in v1.2.0 but this should make it easier to discuss and plan.

You = the usethis user Them = anyone else, but often an instructor, collaborator, other dev Here's the relevant universe of Git repos (them vs. you * GitHub vs. local):

them-you-github-local

How usethis functions help to make the necessary connections:

screen shot 2018-01-16 at 10 53 34 pm

create_from_github(repo = THEM_GITHUB, destdir = YOU_LOCAL_PARENT_DIR, fork = TRUE, ...) TODO: add THEM_GITHUB as remote fork-origin of YOU_LOCAL repo

screen shot 2018-01-16 at 10 56 09 pm

create_from_github(repo = THEM_GITHUB, destdir = YOU_LOCAL_PARENT_DIR, fork = FALSE, ...)

screen shot 2018-01-16 at 10 56 45 pm

create_from_github(repo = YOU_GITHUB, destdir = YOU_LOCAL_PARENT_DIR, fork = FALSE, ...)

screen shot 2018-01-16 at 10 57 32 pm

use_github(...)

cboettig commented 6 years ago

@jennybc Thanks for tackling this. Love the diagrams, but actually I think my use case isn't covered in these pictures. I don't think I'm crazy because my use-case is exactly what https://classroom.github.com does already, but maybe I'm missing something.

Essentially, I want to go from box 1 to box 1 (or equivalently, box 2 to box 2). The reason this doesn't fit into the diagram is that the diagram assumes that repository name is fixed; it let's you change where the repo lives, but it doesn't permit making copies of the repo with different names.

For instance, I have this repo called espm-157/climate-template. I want every student to end up with a repo called espm-157/studentName-climate that is based on this template (ideally private repos, though the template is public). This doesn't involve any personal github accounts and doesn't technically need any local copy, just go from box 1 to box 1 with a new name.

Does that make sense?

I think this would look something like:

studentName <- "Bob_Smith"
create_from_github("espm-157/climate-template", ".", fork=FALSE, open = FALSE)

## remove remote
r <- git2r::repository("climate-template")
git2r::remote_remove(r, "origin")

## rename file
file.rename("climate-template", "Bob_Smith-climate")

use_github("ds421", private=TRUE)

But this call to use_github throws the erroneous error that I need to do use_git() first. It looks like this has something to do with the RStudio project information still thinking the path is climate-template and not Bob_Smith-climate, I probably need a project rename function instead of just renaming the working directory?

In my ideal world, commands following create_from_github would be run automatically by giving a remote_destination. (Incidentally, I think a remote_destination argument would also be helpful for controlling where the fork goes if fork=TRUE).

jennybc commented 6 years ago

Essentially, I want to go from box 1 to box 1 (or equivalently, box 2 to box 2).

Is there even an existing way to do that in the browser or via the API? Create GitHub repo A from GitHub repo B without forking?

I do understand your goal btw.

cboettig commented 6 years ago

No, there's no way to do this in the GitHub API. My understanding is that was a major reason why GitHub Classroom was created in the first place, it provides a web API to do exactly this (and little else).

BTW, I just noticed usethis::use_course(), use_course() + use_github() is almost exactly what I'm looking for (I think). I'd just like to see use_course() handle repo names (or at least repo urls) directly instead of only zips; and perhaps the use of the term course is too narrow. (For instance, following the model suggested by GitHub Classroom, I've found it helps if I have a separate repo for each project, rather than one big course repo. Likewise I use this same workflow with my lab group, starting students off with a template repo that has travis set up to test that any .Rmd renders successfully. So I think of this more as use_template than use_course).

jennybc commented 6 years ago

OK I've really read this now. Yes, let's keep hammering it out ... but after today's release. You want a few things that are not trivial: the copy-that's-not-a-fork, repo name flexibility, and remote handling.

As for your use_git() glitch, yeah usethis has no way of knowing about the directory (and project) rename. You could raise this in a separate issue, but I'm not sure we'd "fix" it. You can just insert a proj_set() right after your file.rename(). Once we can use fs for file system stuff, you could imagine proj_set(file_move(..., ...)).

cboettig commented 6 years ago

Thanks, sounds like a plan!

Re use_git(), thanks for the proj_set() pointer; the behavior there was a little opaque to me. I had tried deleting the .Rproj after renaming the file, and couldn't think of where else it was able to get the old path from instead of the new path. A quick dig showed it was getting the path from proj_get() but looking at the R code for that function told me nothing about where it reads the path from. Reading the documentation as a last resort I see it was coming from the DESCRIPTION in my case, which I guess assumes package name should match the repo name). I follow the logic here but still feels a little ick that use_git() would tell me I'm not in a git repo when I am in a git repo but simply have a DESCRIPTION (or some hidden .here file) that has an outdated path...

jennybc commented 6 years ago

It occurs to me that use_course() might actually be useful to you, until the perfect functionality exists in usethis (or elsewhere). Because it allows you to grab the current contents of a template GitHub repo w/o making a fork, getting history, or acquiring remotes. Worth considering.

cboettig commented 6 years ago

Indeed it is! https://github.com/r-lib/usethis/issues/214#issuecomment-358394821

jennybc commented 6 years ago

D'oh.

mine-cetinkaya-rundel commented 6 years ago

Grabbing contents without the git history is nice, and a positive above GitHub Classroom. With GitHub Classroom students see history of the repo from before they created their copy, and I personally find that undesirable.