Skip to content

fix private repo creation in case of ignore templates & repo description bugs in case of template repos#3972

Merged
mislav merged 7 commits intocli:trunkfrom
g14a:fix/private-repo-create
Jul 20, 2021
Merged

fix private repo creation in case of ignore templates & repo description bugs in case of template repos#3972
mislav merged 7 commits intocli:trunkfrom
g14a:fix/private-repo-create

Conversation

@g14a
Copy link
Contributor

@g14a g14a commented Jul 10, 2021

Fixes #3969
Fixes #3931

Followup to #3746

Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

@g14a Thanks for this! As an exercise for myself, I'm going to attempt to add some tests and tweaks to this to further ensure that there are no incompatibilities between REST and GraphQL repo creation. 👍

@mislav mislav self-assigned this Jul 12, 2021
@g14a g14a changed the title fix private repo creation in case of ignore templates fix private repo creation in case of ignore templates & repo description bugs in case of template repos Jul 13, 2021
@g14a
Copy link
Contributor Author

g14a commented Jul 13, 2021

@mislav I tried fixing #3931 as well and pushed a commit because it is just a one line fix(and because it is similar to #3969). Hope its not a problem. Make sure to pull the latest commit for your tweaks :)

mislav added 2 commits July 15, 2021 12:56
This enforces strict separation between serialization structs used for
repository creation payload with respect to whether GraphQL or REST was
used. Before, a field added to a GraphQL payload would leak to REST
payload (and vice versa).
@mislav
Copy link
Contributor

mislav commented Jul 15, 2021

I've pushed a refactoring that creates strictly separate payload structs for REST vs GraphQL repository creation. Before, the same repoCreateInput struct was used for JSON serialization to both REST and GraphQL endpoints, which led to invalid JSON parameter names being sent in REST mode.

Summary of changes:

  • Fixes REST payload parameter names when gitignore or license are used
  • Fixes setting repository visibility when gitignore/license were used for org repos
  • Fixes setting team ID when gitignore/license were used for org repos
  • Fixes assertions in tests for create flow with gitignore and license
  • Adds extensive repoCreate() unit tests

Please review!

@mislav mislav requested review from samcoe and vilmibm July 15, 2021 11:10
Copy link
Contributor

@samcoe samcoe left a comment

Choose a reason for hiding this comment

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

Left a couple non-blocking suggestions. This looks great, much clearer when separating out the GraphQL and REST payloads.

var templateRepo ghrepo.Interface
apiClient := api.NewClientFromHTTP(httpClient)

cloneURL := opts.Template
Copy link
Contributor

Choose a reason for hiding this comment

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

I know that this was already in place but I think it would be clearer to rename this to templateRepoURL or something similar since toClone was renamed to remplateRepo.

Name string `json:"name"`
Visibility string `json:"visibility"`
OwnerID string `json:"ownerId,omitempty"`
type createRepositoryInput struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

It isn't immediately obvious from the name what the difference between repoCreateInput, createRepositoryInputV3, and createRepositoryInput is, I think comments about their purpose could help clear that up.

path := "user/repos"
if isOrg {
path = fmt.Sprintf("orgs/%s/repos", input.OwnerLogin)
inputv3.Visibility = strings.ToLower(input.Visibility)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not a CLI issue but the existence of private and visibility in this API endpoint is confusing.

input := repoCreateInput{
Description: "roasted chestnuts",
HomepageURL: "http://example.com",
func Test_repoCreate(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

These tests are great, just for completeness I think one case that is missing is creating a repo with a hostname that is not github.com.

}
}

func RESTPayload(responseStatus int, responseBody string, cb func(payload map[string]interface{})) Responder {
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes! 👍

@mislav mislav enabled auto-merge July 20, 2021 14:34
@mislav mislav merged commit 75c7fc1 into cli:trunk Jul 20, 2021
@mislav mislav mentioned this pull request Jul 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants