[Feature] Create repositories from a template repo#1590
Conversation
vilmibm
left a comment
There was a problem hiding this comment.
Thank you for taking this on! It's really close, just asking for some cosmetic and minor code structure changes.
pkg/cmd/repo/create/create.go
Outdated
| Visibility: visibility, | ||
| OwnerID: repoToCreate.RepoOwner(), | ||
| TeamID: opts.Team, | ||
| RepositoryID: opts.Template, |
There was a problem hiding this comment.
Since this type is intended to pass as input for the create repo mutation I'm not in love with using it to signal the desire to clone from a template.
I'd rather see:
- a new helper,
repoCreateFromTemplate - a change to
repoCreate's function signature to accept a potentially empty template argument
There was a problem hiding this comment.
Addressed in f465b07
@vilmibm I've refactored the changes so that repoCreate is a variadic function:
func repoCreate(client *http.Client, hostname string, input repoCreateInput, template ...string) (*api.Repository, error)
As a result, I was able to remove RepositoryID from the repoCreateInput block, and passed it as an argument instead whenever repoCreate was called 😄
This comment was marked as spam.
This comment was marked as spam.
957c31f to
f465b07
Compare
vilmibm
left a comment
There was a problem hiding this comment.
one last tiny nitpick then we're good!
10d25fc to
34c3718
Compare
34c3718 to
99372f0
Compare
Summary
Closes #1578
In this PR, I added functionality to use the following command to create a new repo from a template:
gh repo create <new-repo-name> --template="<link-to-template-repo> OR <owner/template-repo>"Changes
I used the
cloneTemplateRepositorymutation from the public GraphQL API to achieve this functionality. You can read more about it here: GraphQL DocsA limitation of using this mutation is that it does not fully support all of the inputs that the
createRepositorymutation does. Therefore, I had to add some ad-hoc input processing to warn the user about passing incompatible flags with--template.This seemed to be the most straightforward approach, as we do not want to modify the
createRepositorymutation to support this existing functionality.Example
Note:
--enable-wiki="true"or--enable-issues="true"will not throw an error, as those are repo defaults. However, if you passfalse, it will raise thisFlagError.Demo
Checklist