MCPcopy Create free account
hub / github.com/castai/openwebui-content-sync / processContent

Method processContent

internal/adapter/github.go:120–176  ·  view source on GitHub ↗

processContent processes a GitHub content item recursively

(ctx context.Context, owner, repo string, content *github.RepositoryContent, path string, knowledgeID string)

Source from the content-addressed store, hash-verified

118
119// processContent processes a GitHub content item recursively
120func (g *GitHubAdapter) processContent(ctx context.Context, owner, repo string, content *github.RepositoryContent, path string, knowledgeID string) ([]*File, error) {
121 if content == nil {
122 return nil, nil
123 }
124
125 currentPath := filepath.Join(path, content.GetName())
126
127 // Skip binary files and non-text files
128 if content.GetType() == "file" {
129 // Check if it's a text file
130 if !isTextFile(content.GetName()) {
131 return nil, nil
132 }
133
134 // Get file content
135 fileContent, err := g.getFileContent(ctx, owner, repo, content)
136 if err != nil {
137 return nil, fmt.Errorf("failed to get file content: %w", err)
138 }
139
140 // Calculate hash
141 hash := fmt.Sprintf("%x", sha256.Sum256(fileContent))
142
143 return []*File{{
144 Path: currentPath,
145 Content: fileContent,
146 Hash: hash,
147 Modified: time.Now(), // GitHub API doesn't provide modification time for content
148 Size: int64(len(fileContent)),
149 Source: fmt.Sprintf("%s/%s", owner, repo),
150 KnowledgeID: knowledgeID,
151 }}, nil
152 }
153
154 // If it's a directory, recurse
155 if content.GetType() == "dir" {
156 _, contents, _, err := g.client.Repositories.GetContents(ctx, owner, repo, content.GetPath(), nil)
157 if err != nil {
158 return nil, fmt.Errorf("failed to get directory contents: %w", err)
159 }
160
161 var allFiles []*File
162 for _, subContent := range contents {
163 files, err := g.processContent(ctx, owner, repo, subContent, currentPath, knowledgeID)
164 if err != nil {
165 continue
166 }
167 if files != nil {
168 allFiles = append(allFiles, files...)
169 }
170 }
171
172 return allFiles, nil
173 }
174
175 return nil, nil
176}
177

Callers 1

fetchRepositoryFilesMethod · 0.95

Calls 2

getFileContentMethod · 0.95
isTextFileFunction · 0.85

Tested by

no test coverage detected