MCPcopy
hub / github.com/mislav/hub / apiCommand

Function apiCommand

commands/api.go:149–325  ·  view source on GitHub ↗
(_ *Command, args *Args)

Source from the content-addressed store, hash-verified

147}
148
149func apiCommand(_ *Command, args *Args) {
150 path := ""
151 if !args.IsParamsEmpty() {
152 path = args.GetParam(0)
153 }
154
155 method := "GET"
156 if args.Flag.HasReceived("--method") {
157 method = args.Flag.Value("--method")
158 } else if args.Flag.HasReceived("--field") || args.Flag.HasReceived("--raw-field") || args.Flag.HasReceived("--input") {
159 method = "POST"
160 }
161 cacheTTL := args.Flag.Int("--cache")
162
163 params := make(map[string]interface{})
164 for _, val := range args.Flag.AllValues("--field") {
165 parts := strings.SplitN(val, "=", 2)
166 if len(parts) >= 2 {
167 params[parts[0]] = magicValue(parts[1])
168 }
169 }
170 for _, val := range args.Flag.AllValues("--raw-field") {
171 parts := strings.SplitN(val, "=", 2)
172 if len(parts) >= 2 {
173 params[parts[0]] = parts[1]
174 }
175 }
176
177 headers := make(map[string]string)
178 for _, val := range args.Flag.AllValues("--header") {
179 parts := strings.SplitN(val, ":", 2)
180 if len(parts) >= 2 {
181 headers[parts[0]] = strings.TrimLeft(parts[1], " ")
182 }
183 }
184
185 host := ""
186 owner := ""
187 repo := ""
188 localRepo, localRepoErr := github.LocalRepo()
189 if localRepoErr == nil {
190 var project *github.Project
191 if project, localRepoErr = localRepo.MainProject(); localRepoErr == nil {
192 host = project.Host
193 owner = project.Owner
194 repo = project.Name
195 }
196 }
197 if host == "" {
198 defHost, err := github.CurrentConfig().DefaultHostNoPrompt()
199 utils.Check(err)
200 host = defHost.Host
201 }
202
203 isGraphQL := path == "graphql"
204 if isGraphQL && params["query"] != nil {
205 query := params["query"].(string)
206 query = strings.Replace(query, "{owner}", owner, -1)

Callers

nothing calls this directly

Calls 15

GenericAPIRequestMethod · 0.95
LocalRepoFunction · 0.92
CurrentConfigFunction · 0.92
CheckFunction · 0.92
NewClientFunction · 0.92
JSONPathFunction · 0.92
ValidateGitHubSSOFunction · 0.92
ErrorlnFunction · 0.92
magicValueFunction · 0.85
colorizeOutputFunction · 0.85
pauseUntilFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…