MCPcopy
hub / github.com/cli/cli / findEndCursor

Function findEndCursor

pkg/cmd/api/pagination.go:26–92  ·  view source on GitHub ↗
(r io.Reader)

Source from the content-addressed store, hash-verified

24}
25
26func findEndCursor(r io.Reader) string {
27 dec := json.NewDecoder(r)
28
29 var idx int
30 var stack []json.Delim
31 var lastKey string
32 var contextKey string
33
34 var endCursor string
35 var hasNextPage bool
36 var foundEndCursor bool
37 var foundNextPage bool
38
39loop:
40 for {
41 t, err := dec.Token()
42 if err == io.EOF {
43 break
44 }
45 if err != nil {
46 return ""
47 }
48
49 switch tt := t.(type) {
50 case json.Delim:
51 switch tt {
52 case '{', '[':
53 stack = append(stack, tt)
54 contextKey = lastKey
55 idx = 0
56 case '}', ']':
57 stack = stack[:len(stack)-1]
58 contextKey = ""
59 idx = 0
60 }
61 default:
62 isKey := len(stack) > 0 && stack[len(stack)-1] == '{' && idx%2 == 0
63 idx++
64
65 switch tt := t.(type) {
66 case string:
67 if isKey {
68 lastKey = tt
69 } else if contextKey == "pageInfo" && lastKey == "endCursor" {
70 endCursor = tt
71 foundEndCursor = true
72 if foundNextPage {
73 break loop
74 }
75 }
76 case bool:
77 if contextKey == "pageInfo" && lastKey == "hasNextPage" {
78 hasNextPage = tt
79 foundNextPage = true
80 if foundEndCursor {
81 break loop
82 }
83 }

Callers 2

processResponseFunction · 0.85
Test_findEndCursorFunction · 0.85

Calls

no outgoing calls

Tested by 1

Test_findEndCursorFunction · 0.68