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

Function schemaCheck

script/ghmock/set.go:247–282  ·  view source on GitHub ↗

schemaCheck checks resp against GitHub's schema. It returns the problems it found, or, when it couldn't check, a line saying why.

(st *state, chk *checker, name string, resp *response)

Source from the content-addressed store, hash-verified

245// schemaCheck checks resp against GitHub's schema. It returns the problems it
246// found, or, when it couldn't check, a line saying why.
247func schemaCheck(st *state, chk *checker, name string, resp *response) (problems []string, skipped string, err error) {
248 method, target, _ := strings.Cut(name, " ")
249 e := loggedRequest{Name: name, Method: method, Host: dotcomAPIHost, Path: target}
250 if method == "graphql" {
251 if _, err := chk.graphQL(); err != nil {
252 return nil, fmt.Sprintf("Schema check: skipped, GraphQL checks are off: %v", err), nil
253 }
254 query, err := lastQuery(st, name)
255 if err != nil {
256 return nil, "", err
257 }
258 if query == "" {
259 return nil, fmt.Sprintf("Schema check: not yet, because gh hasn't sent %s; the next run checks it", name), nil
260 }
261 e = loggedRequest{Name: name, Method: http.MethodPost, Host: dotcomAPIHost, Path: "/graphql", GraphQL: &graphQLRequest{Query: query}}
262 } else {
263 if host, path, ok := strings.Cut(target, "/"); ok && host != "" {
264 e.Host, e.Path = host, "/"+path
265 }
266 if isAPIHost(e.Host) {
267 if _, err := chk.rest(); err != nil {
268 return nil, fmt.Sprintf("Schema check: skipped, REST checks are off: %v", err), nil
269 }
270 }
271 }
272
273 res := chk.checkResponse(e, resp)
274 switch {
275 case len(res.responseProblems) > 0:
276 return res.responseProblems, "", nil
277 case res.note != "":
278 return nil, "Schema check: skipped, " + res.note, nil
279 default:
280 return nil, "", nil
281 }
282}
283
284// lastQuery returns the query gh most recently sent for a GraphQL request
285// name, or "" if it hasn't sent one.

Callers 1

checkBeforeSaveFunction · 0.85

Calls 5

lastQueryFunction · 0.85
isAPIHostFunction · 0.85
graphQLMethod · 0.80
restMethod · 0.80
checkResponseMethod · 0.80

Tested by

no test coverage detected