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

Function applyEngineAndPermissionModifications

pkg/cli/add_command.go:522–558  ·  view source on GitHub ↗
(content string, opts AddOptions)

Source from the content-addressed store, hash-verified

520}
521
522func applyEngineAndPermissionModifications(content string, opts AddOptions) (string, error) {
523 // Handle engine override - add/update the engine field in frontmatter before source so
524 // the engine declaration appears above the source field in the final file.
525 // The default engine is omitted to avoid unnecessary noise and prevent conflicts during
526 // later workflow updates.
527 if opts.EngineOverride != "" && opts.EngineOverride != string(constants.DefaultEngine) {
528 updatedContent, err := addEngineToWorkflow(content, opts.EngineOverride)
529 if err != nil {
530 if opts.Verbose {
531 fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("Failed to set engine field: %v", err)))
532 }
533 } else {
534 content = updatedContent
535 if opts.Verbose {
536 fmt.Fprintln(os.Stderr, console.FormatInfoMessage("Set engine field to: "+opts.EngineOverride))
537 }
538 }
539 }
540
541 // Inject permissions.copilot-requests: write when the user chose org-billing auth.
542 // Only inject for Copilot workflows — guard against the flag being inadvertently set
543 // when multiple workflows with different engines are processed in the same batch.
544 if opts.AddCopilotRequestsPermission && isCopilotWorkflowContent(content) {
545 updatedContent, err := addCopilotRequestsPermissionToContent(content)
546 if err != nil {
547 // Always warn: user explicitly chose copilot-requests auth; a silent failure
548 // means the deployed workflow will lack the required permission.
549 fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("Failed to add copilot-requests permission: %v", err)))
550 } else {
551 content = updatedContent
552 if opts.Verbose {
553 fmt.Fprintln(os.Stderr, console.FormatInfoMessage("Added permissions.copilot-requests: write to workflow"))
554 }
555 }
556 }
557 return content, nil
558}
559
560func applySourceAndIncludeModifications(content string, workflowSpec *WorkflowSpec, sourceInfo *FetchedWorkflow, githubWorkflowsDir string, opts AddOptions) (string, error) {
561 // Add source field to frontmatter

Callers 1

Calls 5

FormatWarningMessageFunction · 0.92
FormatInfoMessageFunction · 0.92
addEngineToWorkflowFunction · 0.85
isCopilotWorkflowContentFunction · 0.85

Tested by

no test coverage detected