-
Notifications
You must be signed in to change notification settings - Fork 8k
fix repo create in org with license/ignore #3924
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ import ( | |
| "encoding/json" | ||
| "fmt" | ||
| "net/http" | ||
| "strings" | ||
|
|
||
| "github.com/cli/cli/api" | ||
| ) | ||
|
|
@@ -38,6 +39,9 @@ type repoTemplateInput struct { | |
| func repoCreate(client *http.Client, hostname string, input repoCreateInput, templateRepositoryID string) (*api.Repository, error) { | ||
| apiClient := api.NewClientFromHTTP(client) | ||
|
|
||
| ownerName := input.OwnerID | ||
| isOrg := false | ||
|
|
||
| if input.TeamID != "" { | ||
| orgID, teamID, err := resolveOrganizationTeam(apiClient, hostname, input.OwnerID, input.TeamID) | ||
| if err != nil { | ||
|
|
@@ -46,7 +50,9 @@ func repoCreate(client *http.Client, hostname string, input repoCreateInput, tem | |
| input.TeamID = teamID | ||
| input.OwnerID = orgID | ||
| } else if input.OwnerID != "" { | ||
| orgID, err := resolveOrganization(apiClient, hostname, input.OwnerID) | ||
| var orgID string | ||
| var err error | ||
| orgID, isOrg, err = resolveOrganization(apiClient, hostname, input.OwnerID) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
@@ -109,12 +115,19 @@ func repoCreate(client *http.Client, hostname string, input repoCreateInput, tem | |
| } | ||
|
|
||
| if input.GitIgnoreTemplate != "" || input.LicenseTemplate != "" { | ||
| input.Visibility = strings.ToLower(input.Visibility) | ||
| body := &bytes.Buffer{} | ||
| enc := json.NewEncoder(body) | ||
| if err := enc.Encode(input); err != nil { | ||
| return nil, err | ||
| } | ||
| repo, err := api.CreateRepoTransformToV4(apiClient, hostname, "POST", "user/repos", body) | ||
|
|
||
| path := "user/repos" | ||
| if isOrg { | ||
| path = fmt.Sprintf("orgs/%s/repos", ownerName) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am pretty sure the answer is no, but can we just use the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, it's a graphql node ID.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but your confusion is warranted! it starts out life as an owner string and is then updated in place to be a node ID. |
||
| } | ||
|
|
||
| repo, err := api.CreateRepoTransformToV4(apiClient, hostname, "POST", path, body) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
@@ -141,12 +154,13 @@ func repoCreate(client *http.Client, hostname string, input repoCreateInput, tem | |
| } | ||
|
|
||
| // using API v3 here because the equivalent in GraphQL needs `read:org` scope | ||
| func resolveOrganization(client *api.Client, hostname, orgName string) (string, error) { | ||
| func resolveOrganization(client *api.Client, hostname, orgName string) (string, bool, error) { | ||
| var response struct { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whooooo |
||
| NodeID string `json:"node_id"` | ||
| Type string | ||
| } | ||
| err := client.REST(hostname, "GET", fmt.Sprintf("users/%s", orgName), nil, &response) | ||
| return response.NodeID, err | ||
| return response.NodeID, response.Type == "Organization", err | ||
| } | ||
|
|
||
| // using API v3 here because the equivalent in GraphQL needs `read:org` scope | ||
|
|
||
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.
🤦