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

Function formatRequest

script/ghmock/report.go:222–269  ·  view source on GitHub ↗
(e loggedRequest)

Source from the content-addressed store, hash-verified

220}
221
222func formatRequest(e loggedRequest) string {
223 var b strings.Builder
224 fmt.Fprintf(&b, "%d. %s", e.Seq, displayName(e))
225 if e.RawQuery != "" {
226 b.WriteString("?" + e.RawQuery)
227 }
228 if e.GraphQL != nil && len(e.GraphQL.Variables) > 0 {
229 b.WriteString(" " + truncate(compactJSON(e.GraphQL.Variables), maxShownBody))
230 }
231 if e.Body != "" {
232 b.WriteString(" body " + truncate(compactJSON([]byte(e.Body)), maxShownBody))
233 }
234 if e.RawBody != nil {
235 b.WriteString(" raw body " + rawBodySummary(*e.RawBody))
236 }
237 switch {
238 case e.Git != nil:
239 if e.Method == "SSH" {
240 fmt.Fprintf(&b, " -> %s, exit code %d", e.Git.Service, e.Git.ExitCode)
241 } else {
242 fmt.Fprintf(&b, " -> %d, %s", e.Status, e.Git.Service)
243 }
244 if e.Git.Error != "" {
245 b.WriteString(" [" + e.Git.Error + "]")
246 }
247 case e.Blocked:
248 b.WriteString(" -> blocked")
249 case e.TLSError != "":
250 b.WriteString(" -> TLS handshake failed")
251 case e.Matched:
252 fmt.Fprintf(&b, " -> %d, response %d of %d", e.Status, e.Response, e.Responses)
253 default:
254 fmt.Fprintf(&b, " -> %d, no response stored", e.Status)
255 }
256 if e.OffSchema {
257 b.WriteString(" [off-schema]")
258 }
259 if n := len(e.SchemaProblems); n > 0 {
260 fmt.Fprintf(&b, " [%s]", plural(n, "schema problem"))
261 }
262 if n := len(e.QueryProblems); n > 0 {
263 fmt.Fprintf(&b, " [query: %s]", plural(n, "schema problem"))
264 }
265 if e.SchemaNote != "" {
266 fmt.Fprintf(&b, " [not checked: %s]", e.SchemaNote)
267 }
268 return b.String()
269}
270
271func plural(n int, noun string) string {
272 if n == 1 {

Callers 2

printLogFunction · 0.85
printResultFunction · 0.85

Calls 6

truncateFunction · 0.85
rawBodySummaryFunction · 0.85
pluralFunction · 0.85
displayNameFunction · 0.70
compactJSONFunction · 0.70
StringMethod · 0.65

Tested by

no test coverage detected