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

Function RemoveWorkflows

pkg/cli/remove_command.go:21–172  ·  view source on GitHub ↗

RemoveWorkflows removes workflows matching a pattern

(pattern string, keepOrphans bool, workflowDir string)

Source from the content-addressed store, hash-verified

19
20// RemoveWorkflows removes workflows matching a pattern
21func RemoveWorkflows(pattern string, keepOrphans bool, workflowDir string) error {
22 removeLog.Printf("Removing workflows: pattern=%q, keepOrphans=%v, workflowDir=%q", pattern, keepOrphans, workflowDir)
23 workflowsDir := workflowDir
24 if workflowsDir == "" {
25 workflowsDir = getWorkflowsDir()
26 }
27
28 if _, err := os.Stat(workflowsDir); os.IsNotExist(err) {
29 fmt.Fprintln(os.Stderr, console.FormatInfoMessage("No .github/workflows directory found."))
30 return nil
31 }
32
33 // Find all markdown files in .github/workflows
34 mdFiles, err := filepath.Glob(filepath.Join(workflowsDir, "*.md"))
35 if err != nil {
36 return fmt.Errorf("failed to find workflow files: %w", err)
37 }
38
39 // Filter out README.md files
40 mdFiles = filterWorkflowFiles(mdFiles)
41
42 removeLog.Printf("Found %d workflow files", len(mdFiles))
43 if len(mdFiles) == 0 {
44 fmt.Fprintln(os.Stderr, console.FormatInfoMessage("No workflow files found to remove."))
45 return nil
46 }
47
48 var filesToRemove []string
49
50 // If no pattern specified, list all files for user to see
51 if pattern == "" {
52 fmt.Fprintln(os.Stderr, console.FormatInfoMessage("Available workflows to remove:"))
53 for _, file := range mdFiles {
54 workflowName, _ := extractWorkflowNameFromFile(file)
55 base := filepath.Base(file)
56 name := normalizeWorkflowID(base)
57 if workflowName != "" {
58 fmt.Fprintf(os.Stderr, " %-20s - %s\n", name, workflowName)
59 } else {
60 fmt.Fprintf(os.Stderr, " %s\n", name)
61 }
62 }
63 fmt.Fprintln(os.Stderr, console.FormatInfoMessage(fmt.Sprintf("\nUsage: %s remove <filter>", string(constants.CLIExtensionPrefix))))
64 return nil
65 }
66
67 // Find matching files by workflow name or filename
68 for _, file := range mdFiles {
69 base := filepath.Base(file)
70 filename := normalizeWorkflowID(base)
71 workflowName, _ := extractWorkflowNameFromFile(file)
72
73 // Check if pattern matches filename or workflow name
74 if strings.Contains(strings.ToLower(filename), strings.ToLower(pattern)) ||
75 strings.Contains(strings.ToLower(workflowName), strings.ToLower(pattern)) {
76 filesToRemove = append(filesToRemove, file)
77 }
78 }

Callers 3

main.goFile · 0.92
TestRemoveWorkflowsFunction · 0.85
TestAllCommandsExistFunction · 0.85

Calls 15

FormatInfoMessageFunction · 0.92
FormatWarningMessageFunction · 0.92
MarkdownToLockFileFunction · 0.92
FileExistsFunction · 0.92
ConfirmActionFunction · 0.92
FormatSuccessMessageFunction · 0.92
getWorkflowsDirFunction · 0.85
filterWorkflowFilesFunction · 0.85
normalizeWorkflowIDFunction · 0.85
previewOrphanedIncludesFunction · 0.85
cleanupOrphanedIncludesFunction · 0.85

Tested by 2

TestRemoveWorkflowsFunction · 0.68
TestAllCommandsExistFunction · 0.68