MCPcopy Create free account
hub / github.com/openclaw/gogcli / findDocsWriteMarkdownOrphans

Function findDocsWriteMarkdownOrphans

internal/cmd/docs_write_orphans.go:32–101  ·  view source on GitHub ↗
(
	ctx context.Context,
	driveSvc *drive.Service,
	docsSvc *docs.Service,
	docID string,
	markdown preparedMarkdown,
	tabQuery string,
	wholeDocument bool,
)

Source from the content-addressed store, hash-verified

30}
31
32func findDocsWriteMarkdownOrphans(
33 ctx context.Context,
34 driveSvc *drive.Service,
35 docsSvc *docs.Service,
36 docID string,
37 markdown preparedMarkdown,
38 tabQuery string,
39 wholeDocument bool,
40) ([]docsWriteOrphanComment, string, error) {
41 doc, err := docsSvc.Documents.Get(docID).Context(ctx).IncludeTabsContent(true).Do()
42 if err != nil {
43 if isDocsNotFound(err) {
44 return nil, "", fmt.Errorf("doc not found or not a Google Doc (id=%s)", docID)
45 }
46 return nil, "", err
47 }
48 doc, err = requireRawResponse(doc, "doc not found")
49 if err != nil {
50 return nil, "", err
51 }
52
53 targetTabID, err := docsWriteOrphanTargetTabID(doc, tabQuery, wholeDocument)
54 if err != nil {
55 return nil, "", err
56 }
57 comments, _, err := listDriveComments(ctx, driveSvc, docID, driveCommentListOptions{
58 includeQuoted: true,
59 all: true,
60 max: 100,
61 mode: driveCommentListModeExpanded,
62 })
63 if err != nil {
64 return nil, "", fmt.Errorf("list document comments: %w", err)
65 }
66
67 outgoing := docsWriteMarkdownDocument(markdown)
68 locator := DocsCommentsLocateCmd{NormalizeWhitespace: true}
69 var orphans []docsWriteOrphanComment
70 for _, comment := range comments {
71 quote := strings.TrimSpace(docsCommentQuote(comment))
72 if quote == "" {
73 continue
74 }
75
76 currentMatches := locator.findQuoteMatchesAcrossDocument(doc, quote)
77 if len(currentMatches) == 0 || !docsWriteCommentTouchesTarget(currentMatches, targetTabID, wholeDocument) {
78 continue
79 }
80 if len(locator.findQuoteMatchesInDoc(outgoing, quote, targetTabID)) > 0 {
81 continue
82 }
83
84 orphan := docsWriteOrphanComment{
85 CommentID: comment.Id,
86 Content: comment.Content,
87 Quote: docsCommentQuote(comment),
88 }
89 if comment.Author != nil {

Calls 12

findQuoteMatchesInDocMethod · 0.95
isDocsNotFoundFunction · 0.85
requireRawResponseFunction · 0.85
listDriveCommentsFunction · 0.85
docsCommentQuoteFunction · 0.85
ErrorfMethod · 0.80
DoMethod · 0.65
GetMethod · 0.65