Add support for creating repos from template repos by shanempope · Pull Request #1236 · google/go-github · GitHub
Skip to content

Add support for creating repos from template repos#1236

Merged
gmlewis merged 1 commit into
google:masterfrom
shanempope:repo-template-support
Jul 25, 2019
Merged

Add support for creating repos from template repos#1236
gmlewis merged 1 commit into
google:masterfrom
shanempope:repo-template-support

Conversation

@shanempope

Copy link
Copy Markdown
Contributor

Add API for POST /repos/:template_owner/:template_repo/generate endpoint which creates a repository from a template repository.
Developer Blog: https://developer.github.com/changes/2019-07-16-repository-templates-api/
API Reference: https://developer.github.com/v3/repos/#create-repository-using-a-repository-template

Issue: #1235

@googlebot

Copy link
Copy Markdown

@shanempope

Copy link
Copy Markdown
Contributor Author

I signed it!

@googlebot

Copy link
Copy Markdown

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: yes Indication that the PR author has signed a Google Contributor License Agreement. and removed cla: no labels Jul 23, 2019
@shanempope shanempope force-pushed the repo-template-support branch from fc591e3 to 04ffdaf Compare July 23, 2019 05:08
@codecov

codecov Bot commented Jul 23, 2019

Copy link
Copy Markdown

Codecov Report

Merging #1236 into master will increase coverage by 0.06%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1236      +/-   ##
==========================================
+ Coverage   73.36%   73.42%   +0.06%     
==========================================
  Files          86       86              
  Lines        6026     6040      +14     
==========================================
+ Hits         4421     4435      +14     
  Misses        836      836              
  Partials      769      769
Impacted Files Coverage Δ
github/github.go 89.31% <ø> (ø) ⬆️
github/repos.go 75.16% <100%> (+0.79%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c756c32...cf71ae0. Read the comment docs.

@shanempope shanempope force-pushed the repo-template-support branch from 04ffdaf to bb3ceee Compare July 23, 2019 05:19
@shanempope

Copy link
Copy Markdown
Contributor Author

Note: Creating and using repository templates is currently available for developers to preview. To access this new endpoint during the preview period, you must provide a custom media type in the Accept header:

application/vnd.github.baptiste-preview+json

And

Warning: The API may change without advance notice during the preview period. Preview features are not supported for production use. If you experience any issues, contact GitHub Support.

@gmlewis gmlewis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @shanempope. This is a good start, but we need to make some changes.

Meanwhile, I'm going to ask @gauntface what he thinks about the new method name.

Comment thread github/repos.go Outdated
return r, resp, nil
}

// TemplateRepoRequest represents a request to create a repo from a template

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the auto-generated godocs, please end the comment in a period.

Comment thread github/repos.go Outdated
Private *bool `json:"private,omitempty"`
}

// Generate a repository using a repository template

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm... I see that GitHub named this endpoint generate, which seems odd to me.

@gauntface - what do you think about calling this endpoint repositories.CreateFromTemplate (or maybe just FromTemplate?) as that seems to more appropriate to me?

Either way, @shanempope, we will want to make this comment a complete sentence for the auto-generated godocs. Hopefully something like:

// CreateFromTemplate generates a repository from a template.

Comment thread github/repos.go Outdated
// Generate a repository using a repository template
//
// GitHub API docs: https://developer.github.com/v3/repos/#create-repository-using-a-repository-template
func (s *RepositoriesService) Generate(ctx context.Context, templateOwner string, templateRepo string, templateRepoReq *TemplateRepoRequest) (*Repository, *Response, error) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

templateOwner string, templateRepo string, should be templateOwner, templateRepo string,

Comment thread github/repos.go
if err != nil {
return nil, nil, err
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the required preview header here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!
The docs show the header required throughout the endpoints, in order to get the fields. (Create for example) https://developer.github.com/v3/repos/#create
I will add add it for all the required endpoints.

Comment thread github/repos_test.go
v := new(TemplateRepoRequest)
json.NewDecoder(r.Body).Decode(v)

testMethod(t, r, "POST")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please test for the required preview header here.

@gmlewis gmlewis requested a review from gauntface July 23, 2019 13:07
@shanempope shanempope force-pushed the repo-template-support branch from 17bce94 to ed90b7a Compare July 23, 2019 18:51
@shanempope

Copy link
Copy Markdown
Contributor Author

Alright, I manually tested all of the endpoints. It's ready for a second review. Thanks @gmlewis

@gmlewis gmlewis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @shanempope!
LGTM.

Let's see what @gauntface thinks about the questions I raised or if he wants to address anything else.

Add support for creating and using template repos preview feature: google#1236
Add API for `POST /repos/:template_owner/:template_repo/generate` endpoint which creates a repository from a template repository.

Developer Blog: https://developer.github.com/changes/2019-07-16-repository-templates-api/
API Reference: https://developer.github.com/v3/repos/#create-repository-using-a-repository-template
@shanempope shanempope force-pushed the repo-template-support branch from ed90b7a to cf71ae0 Compare July 25, 2019 02:44
@shanempope

Copy link
Copy Markdown
Contributor Author

Thanks @gauntface and @gmlewis. I've squashed the commits

@gmlewis

gmlewis commented Jul 25, 2019

Copy link
Copy Markdown
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes Indication that the PR author has signed a Google Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants