MCPcopy Index your code
hub / github.com/google/go-github / methodOps

Function methodOps

tools/metadata/metadata.go:438–479  ·  view source on GitHub ↗

methodOps parses a method's comments for //meta:operation lines and returns the corresponding operations.

(opsFile *operationsFile, cmap ast.CommentMap, fn *ast.FuncDecl)

Source from the content-addressed store, hash-verified

436
437// methodOps parses a method's comments for //meta:operation lines and returns the corresponding operations.
438func methodOps(opsFile *operationsFile, cmap ast.CommentMap, fn *ast.FuncDecl) ([]*operation, error) {
439 var ops []*operation
440 var err error
441 seen := map[string]bool{}
442 for _, g := range cmap[fn] {
443 for _, c := range g.List {
444 match := metaOpRe.FindStringSubmatch(c.Text)
445 if match == nil {
446 continue
447 }
448 opName := strings.TrimSpace(match[1])
449 opsFile.resolve()
450 var found []*operation
451 norm := normalizedOpName(opName)
452 for n := range opsFile.resolvedOps {
453 if normalizedOpName(n) == norm {
454 found = append(found, opsFile.resolvedOps[n])
455 }
456 }
457 switch len(found) {
458 case 0:
459 err = errors.Join(err, fmt.Errorf("could not find operation %q in openapi_operations.yaml", opName))
460 case 1:
461 name := found[0].Name
462 if seen[name] {
463 err = errors.Join(err, fmt.Errorf("duplicate operation: %v", name))
464 }
465 seen[name] = true
466 ops = append(ops, found[0])
467 default:
468 var foundNames []string
469 for _, op := range found {
470 foundNames = append(foundNames, op.Name)
471 }
472 slices.Sort(foundNames)
473 err = errors.Join(err, fmt.Errorf("ambiguous operation %q could match any of: %v", opName, foundNames))
474 }
475 }
476 }
477 sortOperations(ops)
478 return ops, err
479}
480
481// metadataDocsAPIVersion is appended to generated docs links.
482// Keep this in sync with defaultAPIVersion in github/github.go.

Callers 2

unusedOpsFunction · 0.85
updateDocsVisitorFunction · 0.85

Calls 3

normalizedOpNameFunction · 0.85
sortOperationsFunction · 0.85
resolveMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…