-
Couldn't load subscription status.
- Fork 7.3k
[Feature] Create repositories from a template repo #1590
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 😄
|
Thank you for this improvement |
957c31f to
f465b07
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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