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

Method match

script/ghmock/restcheck.go:98–121  ·  view source on GitHub ↗

match finds the documented path template for a request. Literal segments beat parameters, so /repos/{owner}/{repo}/issues beats repos/{owner}/{repo}/{x} if both existed. Between templates that tie, such as /orgs/{org}/attestations/{attestation_id} and orgs/{org}/attestations/{subject_digest}, the on

(method, path string)

Source from the content-addressed store, hash-verified

96// /orgs/{org}/attestations/{subject_digest}, the one that documents the
97// method wins.
98func (idx *restIndex) match(method, path string) *restRoute {
99 parts := splitPath(path)
100 var best []*restRoute
101 bestScore := -1
102 for i := range idx.routes {
103 score, ok := idx.routes[i].score(parts)
104 switch {
105 case !ok || score < bestScore:
106 case score > bestScore:
107 best, bestScore = []*restRoute{&idx.routes[i]}, score
108 default:
109 best = append(best, &idx.routes[i])
110 }
111 }
112 for _, r := range best {
113 if r.item != nil && r.item.GetOperation(method) != nil {
114 return r
115 }
116 }
117 if len(best) == 0 {
118 return nil
119 }
120 return best[0]
121}
122
123func (r *restRoute) score(parts []string) (int, bool) {
124 segs := r.segments

Callers 11

TestRESTMatchFunction · 0.95
scaffoldMethod · 0.95
checkMethod · 0.95
describeRESTFunction · 0.80
graders.test.tsFile · 0.80
skills.test.tsFile · 0.80
replay.test.tsFile · 0.80
cleanup.test.tsFile · 0.80
github.test.tsFile · 0.80
harness.test.tsFile · 0.80

Calls 2

splitPathFunction · 0.85
scoreMethod · 0.80

Tested by 1

TestRESTMatchFunction · 0.76