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

GitHub connectivity #214

Closed
jennybc opened this Issue Jan 17, 2018 · 9 comments

Comments

Projects
None yet
3 participants
@jennybc
Copy link
Member

jennybc commented Jan 17, 2018

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

This comment has been minimized.

Copy link
Contributor

cboettig commented Jan 17, 2018

@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

This comment has been minimized.

Copy link
Member Author

jennybc commented Jan 17, 2018

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

This comment has been minimized.

Copy link
Contributor

cboettig commented Jan 17, 2018

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

This comment has been minimized.

Copy link
Member Author

jennybc commented Jan 17, 2018

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

This comment has been minimized.

Copy link
Contributor

cboettig commented Jan 17, 2018

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

This comment has been minimized.

Copy link
Member Author

jennybc commented Jan 17, 2018

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

This comment has been minimized.

Copy link
Contributor

cboettig commented Jan 17, 2018

Indeed it is! #214 (comment)

@jennybc

This comment has been minimized.

Copy link
Member Author

jennybc commented Jan 17, 2018

D'oh.

@mine-cetinkaya-rundel

This comment has been minimized.

Copy link
Contributor

mine-cetinkaya-rundel commented Jan 23, 2018

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.

@jennybc jennybc closed this in #253 Feb 15, 2018

jennybc added a commit that referenced this issue Feb 15, 2018

Better create_from_github() (#253)
* Strong, clear words about PAT; introduce new args

* Add rationalize_fork()

* Major upgrade of create_from_github()

Fixes #215, Fixes #214 

  * Clones from the ssh or https url (vs the git url), which stores the correct URL for origin remote
  * Better logic re: forking
  * Adds upstream remote in case of fork
  * Allows token, credentials, host to be specified

* Record some of my manual testing

* Fail early if repo_path exists and is not empty

In particular, do this before creating a fork

* Use pat vs. falling back to env vars

* Simplify logic when fork = NA

* Work on docs re: github
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.