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

Function toggleWorkflowsByNames

pkg/cli/enable.go:37–276  ·  view source on GitHub ↗

toggleWorkflowsByNames toggles workflows by specific names, or all if no names provided

(ctx context.Context, workflowNames []string, enable bool, repoOverride string)

Source from the content-addressed store, hash-verified

35
36// toggleWorkflowsByNames toggles workflows by specific names, or all if no names provided
37func toggleWorkflowsByNames(ctx context.Context, workflowNames []string, enable bool, repoOverride string) error {
38 action := "enable"
39 if !enable {
40 action = "disable"
41 }
42
43 enableLog.Printf("Toggle workflows: action=%s, count=%d, repo=%s", action, len(workflowNames), repoOverride)
44
45 // If no specific workflow names provided, enable/disable all workflows
46 if len(workflowNames) == 0 {
47 enableLog.Print("No specific workflows provided, processing all workflows")
48 fmt.Fprintf(os.Stderr, "No specific workflows provided. %sing all workflows...\n", strings.ToUpper(action[:1])+action[1:])
49 // Get all workflow names and process them
50 mdFiles, err := getMarkdownWorkflowFiles("")
51 if err != nil {
52 return fmt.Errorf("no workflow files found to %s: %w", action, err)
53 }
54
55 if len(mdFiles) == 0 {
56 return fmt.Errorf("no markdown workflow files found to %s", action)
57 }
58
59 // Extract all workflow names
60 var allWorkflowNames []string
61 for _, file := range mdFiles {
62 base := filepath.Base(file)
63 name := normalizeWorkflowID(base)
64 allWorkflowNames = append(allWorkflowNames, name)
65 }
66
67 // Recursively call with all workflow names
68 return toggleWorkflowsByNames(ctx, allWorkflowNames, enable, repoOverride)
69 }
70
71 // Check if gh CLI is available
72 if !isGHCLIAvailable() {
73 return errors.New("GitHub CLI (gh) is required but not available")
74 }
75
76 // Get the core set of workflows from markdown files in .github/workflows
77 mdFiles, err := getMarkdownWorkflowFiles("")
78 if err != nil {
79 return fmt.Errorf("no workflow files found to %s: %w", action, err)
80 }
81
82 // Get GitHub workflows status for comparison; warn but continue if unavailable
83 enableLog.Print("Fetching GitHub workflows status for comparison")
84 githubWorkflows, err := fetchGitHubWorkflows(repoOverride, false)
85 if err != nil {
86 enableLog.Printf("Failed to fetch GitHub workflows: %v", err)
87 fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("Unable to fetch GitHub workflows (gh CLI may not be authenticated): %v", err)))
88 githubWorkflows = make(map[string]*GitHubWorkflow)
89 }
90 enableLog.Printf("Retrieved %d GitHub workflows from remote", len(githubWorkflows))
91
92 // Internal target model to support enabling by ID or lock filename
93 type workflowTarget struct {
94 Name string

Callers 2

EnableWorkflowsByNamesFunction · 0.85
DisableWorkflowsByNamesFunction · 0.85

Calls 15

FormatWarningMessageFunction · 0.92
MarkdownToLockFileFunction · 0.92
ExecGHFunction · 0.92
FormatErrorMessageFunction · 0.92
FormatInfoMessageFunction · 0.92
getMarkdownWorkflowFilesFunction · 0.85
normalizeWorkflowIDFunction · 0.85
isGHCLIAvailableFunction · 0.85
fetchGitHubWorkflowsFunction · 0.85
suggestWorkflowNamesFunction · 0.85
cancelWorkflowRunsFunction · 0.85

Tested by

no test coverage detected