Home > Software design >  Use GitHub API to create a repository from a private template
Use GitHub API to create a repository from a private template

Time:06-29

I'm trying to automate my Rmarkdown workflow by creating a package that will contain some helpful functions. I'd like to be able to call a function (say, new_manuscript()) that would create a new project from a private template repository that I have.

Using the gh package, I can easily create a new repository:

gh::gh("POST /user/repos", name = "test", private = "true")

However, there is no argument that can be passed in this API call to specify a template repository. I have found this Github App called createstructure that seems like it may do what I need to do, but the documentation is not entirely clear to me.

CodePudding user response:

The r-lib/gh does not seem to include the API call "Create a repository using a template"

The normal workaround is to use gh api call (which gh() should be able to do):

gh api \
  --method POST \
  -H "Accept: application/vnd.github.v3 json" \
  /repos/TEMPLATE_OWNER/TEMPLATE_REPO/generate \
  -f owner='octocat'
 -f name='Hello-World'
 -f description='This is your first repository'
 -F include_all_branches=false
 -F private=false
  • Related