MCPcopy Create free account
hub / github.com/github/gh-aw / previewOrphanedIncludes

Function previewOrphanedIncludes

pkg/cli/remove_command.go:265–335  ·  view source on GitHub ↗

previewOrphanedIncludes returns a list of include files that would become orphaned if the specified files were removed

(filesToRemove []string, verbose bool)

Source from the content-addressed store, hash-verified

263
264// previewOrphanedIncludes returns a list of include files that would become orphaned if the specified files were removed
265func previewOrphanedIncludes(filesToRemove []string, verbose bool) ([]string, error) {
266 // Get all current markdown files
267 allMdFiles, err := getMarkdownWorkflowFiles("")
268 if err != nil {
269 return nil, err
270 }
271
272 // Create a map of files to remove for quick lookup
273 removeMap := make(map[string]struct {
274 })
275 for _, file := range filesToRemove {
276 removeMap[file] = struct {
277 }{}
278 }
279
280 // Get the files that would remain after removal
281 var remainingFiles []string
282 for _, file := range allMdFiles {
283 if !setutil.Contains(removeMap, file) {
284 remainingFiles = append(remainingFiles, file)
285 }
286 }
287
288 // If no files remain, all include files would be orphaned
289 if len(remainingFiles) == 0 {
290 return getAllIncludeFiles()
291 }
292
293 // Collect all include dependencies from remaining workflows
294 usedIncludes := make(map[string]struct {
295 })
296
297 for _, mdFile := range remainingFiles {
298 content, err := os.ReadFile(mdFile)
299 if err != nil {
300 if verbose {
301 fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("Could not read %s for include analysis: %v", mdFile, err)))
302 }
303 continue
304 }
305
306 // Find includes used by this workflow
307 includes, err := findIncludesInContent(string(content))
308 if err != nil {
309 if verbose {
310 fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("Could not analyze includes in %s: %v", mdFile, err)))
311 }
312 continue
313 }
314
315 for _, include := range includes {
316 usedIncludes[include] = struct {
317 }{}
318 }
319 }
320
321 // Find all include files and check which ones would be orphaned
322 allIncludes, err := getAllIncludeFiles()

Callers 3

RemoveWorkflowsFunction · 0.85

Calls 5

ContainsFunction · 0.92
FormatWarningMessageFunction · 0.92
getMarkdownWorkflowFilesFunction · 0.85
getAllIncludeFilesFunction · 0.85
findIncludesInContentFunction · 0.85

Tested by 2