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

Function InitRepository

pkg/cli/init.go:39–234  ·  view source on GitHub ↗

InitRepository initializes the repository for agentic workflows

(opts InitOptions)

Source from the content-addressed store, hash-verified

37
38// InitRepository initializes the repository for agentic workflows
39func InitRepository(opts InitOptions) error {
40 initLog.Print("Starting repository initialization for agentic workflows")
41
42 ctx := opts.Ctx
43 if ctx == nil {
44 ctx = context.Background()
45 }
46 copilotArtifactsEnabled := opts.Engine == "" || opts.Engine == "copilot"
47
48 // Show welcome banner for interactive mode
49 console.ShowWelcomeBanner("This tool will initialize your repository for GitHub Agentic Workflows.")
50
51 fmt.Fprintln(os.Stderr, console.FormatInfoMessage("Setting up repository..."))
52 fmt.Fprintln(os.Stderr, "")
53
54 // If --create-pull-request is enabled, run pre-flight checks before doing any work
55 if opts.CreatePR {
56 if err := PreflightCheckForCreatePR(opts.Verbose); err != nil {
57 return err
58 }
59 }
60
61 // Ensure we're in a git repository
62 if !isGitRepo() {
63 initLog.Print("Not in a git repository, initialization failed")
64 return errors.New("not in a git repository")
65 }
66 initLog.Print("Verified git repository")
67
68 // Auto-detect GHES deployment and configure aw.json ghes: true when needed.
69 if _, err := ensureGHESRepoConfig(opts.Verbose); err != nil {
70 initLog.Printf("Failed to configure GHES repo config: %v", err)
71 // Non-fatal: continue with the rest of init
72 fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("Failed to configure GHES repo config: %v", err)))
73 }
74
75 // Configure .gitattributes
76 initLog.Print("Configuring .gitattributes")
77 if updated, err := ensureGitAttributes(); err != nil {
78 initLog.Printf("Failed to configure .gitattributes: %v", err)
79 return fmt.Errorf("failed to configure .gitattributes: %w", err)
80 } else if updated && opts.Verbose {
81 fmt.Fprintln(os.Stderr, console.FormatSuccessMessage("Configured .gitattributes"))
82 }
83
84 // Write dispatcher skill for Copilot engine only
85 if copilotArtifactsEnabled {
86 if opts.Skill {
87 initLog.Print("Writing agentic workflows dispatcher skill")
88 if err := ensureAgenticWorkflowsDispatcher(opts.Verbose, false); err != nil {
89 initLog.Printf("Failed to write dispatcher skill: %v", err)
90 return fmt.Errorf("failed to write dispatcher skill: %w", err)
91 }
92 initLog.Print("Writing agentic workflow designer skill")
93 if err := ensureAgenticWorkflowDesignerSkill(opts.Verbose, false); err != nil {
94 initLog.Printf("Failed to write agentic workflow designer skill: %v", err)
95 return fmt.Errorf("failed to write agentic workflow designer skill: %w", err)
96 }

Calls 15

ShowWelcomeBannerFunction · 0.92
FormatInfoMessageFunction · 0.92
FormatWarningMessageFunction · 0.92
FormatSuccessMessageFunction · 0.92
DetectActionModeFunction · 0.92
isGitRepoFunction · 0.85
ensureGHESRepoConfigFunction · 0.85
ensureGitAttributesFunction · 0.85