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