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

Function checkBeforeSave

script/ghmock/set.go:219–243  ·  view source on GitHub ↗

checkBeforeSave checks a changed response against GitHub's schema before it is saved. It returns a line saying what the check did, or an error listing the problems. A GraphQL response is checked against the query gh last sent for it, so it isn't checked until gh has sent one. With offSchema, the re

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

Source from the content-addressed store, hash-verified

217// so it's sent as stored. The line still says what the check found, because
218// callers report off-schema values and need to know whether they really are.
219func checkBeforeSave(st *state, chk *checker, name string, resp *response, offSchema bool) (string, error) {
220 // The checker skips responses marked off-schema, so mark it afterwards.
221 resp.OffSchema = false
222 problems, skipped, err := schemaCheck(st, chk, name, resp)
223 if err != nil {
224 return "", err
225 }
226 resp.OffSchema = offSchema
227
228 switch {
229 case offSchema && len(problems) > 0:
230 return "Schema check: failed, saved as off-schema:\n" + strings.TrimSuffix(indentProblems(problems, " ", 0), "\n"), nil
231 case offSchema && skipped != "":
232 return "Schema check: skipped, saved as off-schema", nil
233 case offSchema:
234 return "Schema check: passed, but saved as off-schema as asked. It matches GitHub's schema, so it doesn't need --off-schema", nil
235 case len(problems) > 0:
236 return "", fmt.Errorf("the response doesn't match GitHub's schema, so it wasn't saved:\n%sFix it, or pass --off-schema to save it anyway",
237 indentProblems(problems, " ", 0))
238 case skipped != "":
239 return skipped, nil
240 default:
241 return "Schema check: passed", nil
242 }
243}
244
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.

Callers 1

cmdSetFunction · 0.85

Calls 3

schemaCheckFunction · 0.85
indentProblemsFunction · 0.85
ErrorfMethod · 0.65

Tested by

no test coverage detected