MCPcopy Create free account
hub / github.com/cli/cli / repoCreate

Function repoCreate

pkg/cmd/repo/create/http.go:77–251  ·  view source on GitHub ↗

repoCreate creates a new GitHub repository

(client *http.Client, hostname string, input repoCreateInput)

Source from the content-addressed store, hash-verified

75
76// repoCreate creates a new GitHub repository
77func 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, `

Callers 4

createFromScratchFunction · 0.85
createFromTemplateFunction · 0.85
createFromLocalFunction · 0.85
Test_repoCreateFunction · 0.85

Calls 10

NewClientFromHTTPFunction · 0.92
CurrentUserIDFunction · 0.92
InitRepoHostnameFunction · 0.92
JoinPathFunction · 0.92
CreateRepoTransformToV4Function · 0.92
resolveOrganizationTeamFunction · 0.85
resolveOwnerFunction · 0.85
IsOrganizationMethod · 0.80
GraphQLMethod · 0.80
ErrorfMethod · 0.65

Tested by 1

Test_repoCreateFunction · 0.68