repoCreate creates a new GitHub repository
(client *http.Client, hostname string, input repoCreateInput)
| 75 | |
| 76 | // repoCreate creates a new GitHub repository |
| 77 | func repoCreate(client *http.Client, hostname string, input repoCreateInput) (*api.Repository, error) { |
| 78 | isOrg := false |
| 79 | var ownerID string |
| 80 | var teamID string |
| 81 | var teamIDv3 uint64 |
| 82 | |
| 83 | apiClient := api.NewClientFromHTTP(client) |
| 84 | |
| 85 | if input.TeamSlug != "" { |
| 86 | team, err := resolveOrganizationTeam(apiClient, hostname, input.OwnerLogin, input.TeamSlug) |
| 87 | if err != nil { |
| 88 | return nil, err |
| 89 | } |
| 90 | teamIDv3 = team.ID |
| 91 | teamID = team.NodeID |
| 92 | ownerID = team.Organization.NodeID |
| 93 | isOrg = true |
| 94 | } else if input.OwnerLogin != "" { |
| 95 | owner, err := resolveOwner(apiClient, hostname, input.OwnerLogin) |
| 96 | if err != nil { |
| 97 | return nil, err |
| 98 | } |
| 99 | ownerID = owner.NodeID |
| 100 | isOrg = owner.IsOrganization() |
| 101 | } |
| 102 | |
| 103 | isInternal := strings.ToLower(input.Visibility) == "internal" |
| 104 | if isInternal && !isOrg { |
| 105 | return nil, fmt.Errorf("internal repositories can only be created within an organization") |
| 106 | } |
| 107 | |
| 108 | if input.TemplateRepositoryID != "" { |
| 109 | var response struct { |
| 110 | CloneTemplateRepository struct { |
| 111 | Repository api.Repository |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | if ownerID == "" { |
| 116 | var err error |
| 117 | ownerID, err = api.CurrentUserID(apiClient, hostname) |
| 118 | if err != nil { |
| 119 | return nil, err |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | variables := map[string]interface{}{ |
| 124 | "input": cloneTemplateRepositoryInput{ |
| 125 | Name: input.Name, |
| 126 | Description: input.Description, |
| 127 | Visibility: strings.ToUpper(input.Visibility), |
| 128 | OwnerID: ownerID, |
| 129 | RepositoryID: input.TemplateRepositoryID, |
| 130 | IncludeAllBranches: input.IncludeAllBranches, |
| 131 | }, |
| 132 | } |
| 133 | |
| 134 | err := apiClient.GraphQL(hostname, ` |