MCPcopy Index your code
hub / github.com/github/gh-aw / DisableAllWorkflowsExcept

Function DisableAllWorkflowsExcept

pkg/cli/enable.go:280–384  ·  view source on GitHub ↗

DisableAllWorkflowsExcept disables all workflows except the specified ones Typically used to disable all workflows except the one being trialled

(repoSlug string, exceptWorkflows []string, verbose bool)

Source from the content-addressed store, hash-verified

278// DisableAllWorkflowsExcept disables all workflows except the specified ones
279// Typically used to disable all workflows except the one being trialled
280func DisableAllWorkflowsExcept(repoSlug string, exceptWorkflows []string, verbose bool) error {
281 enableLog.Printf("Disabling all workflows except: count=%d, repo=%s", len(exceptWorkflows), repoSlug)
282 workflowsDir := constants.GetWorkflowDir()
283
284 // Check if workflows directory exists
285 if _, err := os.Stat(workflowsDir); os.IsNotExist(err) {
286 if verbose {
287 fmt.Fprintln(os.Stderr, console.FormatInfoMessage("No .github/workflows directory found, nothing to disable"))
288 }
289 return nil
290 }
291
292 // Get all .yml and .yaml files
293 ymlFiles, _ := filepath.Glob(filepath.Join(workflowsDir, "*.yml"))
294 yamlFiles, _ := filepath.Glob(filepath.Join(workflowsDir, "*.yaml"))
295 allYAMLFiles := append(ymlFiles, yamlFiles...)
296
297 enableLog.Printf("Found %d YAML workflow files", len(allYAMLFiles))
298 if len(allYAMLFiles) == 0 {
299 if verbose {
300 fmt.Fprintln(os.Stderr, console.FormatInfoMessage("No YAML workflow files found"))
301 }
302 return nil
303 }
304
305 // Create a set of workflows to keep enabled
306 keepEnabled := make(map[string]struct {
307 })
308 for _, workflowName := range exceptWorkflows {
309 // Add both .md and .lock.yml variants
310 keepEnabled[workflowName+".md"] = struct {
311 }{}
312 keepEnabled[workflowName+".lock.yml"] = struct {
313 }{}
314 keepEnabled[workflowName] = struct { // In case the full filename is provided
315 }{}
316 }
317
318 // Filter to find workflows to disable
319 var workflowsToDisable []string
320
321 for _, yamlFile := range allYAMLFiles {
322 base := filepath.Base(yamlFile)
323
324 // Skip if it's in the keep-enabled set
325 if setutil.Contains(keepEnabled, base) {
326 if verbose {
327 fmt.Fprintf(os.Stderr, "Keeping enabled: %s\n", base)
328 }
329 continue
330 }
331
332 // Check if the base name without extension matches
333 nameWithoutExt := strings.TrimSuffix(base, filepath.Ext(base))
334 if setutil.Contains(keepEnabled, nameWithoutExt) {
335 if verbose {
336 fmt.Fprintf(os.Stderr, "Keeping enabled: %s\n", base)
337 }

Callers 1

RunWorkflowTrialsFunction · 0.85

Calls 8

GetWorkflowDirFunction · 0.92
FormatInfoMessageFunction · 0.92
ContainsFunction · 0.92
ExecGHFunction · 0.92
FormatWarningMessageFunction · 0.92
FormatSuccessMessageFunction · 0.92
PrintfMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected