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

Function updateDocsVisitor

tools/metadata/metadata.go:273–354  ·  view source on GitHub ↗
(opsFile *operationsFile)

Source from the content-addressed store, hash-verified

271}
272
273func updateDocsVisitor(opsFile *operationsFile) nodeVisitor {
274 return func(serviceMethod string, fn *ast.FuncDecl, cmap ast.CommentMap) error {
275 linksMap := map[string]struct{}{}
276 undocMap := map[string]bool{}
277
278 ops, err := methodOps(opsFile, cmap, fn)
279 if err != nil {
280 return err
281 }
282 if len(ops) == 0 {
283 return fmt.Errorf("no operations defined for %v", serviceMethod)
284 }
285
286 for _, op := range ops {
287 if op.DocumentationURL == "" {
288 undocMap[op.Name] = true
289 continue
290 }
291 linksMap[op.DocumentationURL] = struct{}{}
292 }
293 undocumentedOps := slices.Sorted(maps.Keys(undocMap))
294
295 // Find the group that comes before the function
296 var group *ast.CommentGroup
297 for _, g := range cmap[fn] {
298 if g.End() == fn.Pos()-1 {
299 group = g
300 }
301 }
302
303 // If there is no group, create one
304 if group == nil {
305 group = &ast.CommentGroup{
306 List: []*ast.Comment{{Text: "//", Slash: fn.Pos() - 1}},
307 }
308 cmap[fn] = append(cmap[fn], group)
309 }
310
311 origList := group.List
312 group.List = nil
313 for _, comment := range origList {
314 if metaOpRe.MatchString(comment.Text) ||
315 docLineRE.MatchString(comment.Text) ||
316 undocRE.MatchString(comment.Text) {
317 continue
318 }
319 group.List = append(group.List, comment)
320 }
321
322 // add an empty line before adding doc links
323 group.List = append(group.List, &ast.Comment{Text: "//"})
324
325 docLinks := slices.Sorted(maps.Keys(linksMap))
326 for i, dl := range docLinks {
327 group.List = append(
328 group.List,
329 &ast.Comment{
330 Text: "// GitHub API docs: " + normalizeDocURL(dl),

Callers 1

updateDocsFunction · 0.85

Calls 2

methodOpsFunction · 0.85
normalizeDocURLFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…