MCPcopy Index your code
hub / github.com/cli/cli / repoCreate

Function repoCreate

pkg/cmd/repo/create/http.go:76–244  ·  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

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

Callers 4

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

Calls 9

NewClientFromHTTPFunction · 0.92
CurrentUserIDFunction · 0.92
InitRepoHostnameFunction · 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