|
1 | 1 | package cli |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "encoding/json" |
5 | 4 | "fmt" |
6 | 5 | "math/rand" |
7 | 6 | "os" |
8 | | - "os/exec" |
9 | 7 | "path/filepath" |
10 | 8 | "strings" |
11 | 9 |
|
@@ -815,164 +813,6 @@ func compileWorkflowWithTracking(filePath string, verbose bool, engineOverride s |
815 | 813 | return nil |
816 | 814 | } |
817 | 815 |
|
818 | | -// ensureCopilotInstructions ensures that .github/instructions/github-agentic-workflows.md contains the copilot instructions |
819 | | -func ensureCopilotInstructions(verbose bool, skipInstructions bool) error { |
820 | | - if skipInstructions { |
821 | | - return nil // Skip writing instructions if flag is set |
822 | | - } |
823 | | - |
824 | | - gitRoot, err := findGitRoot() |
825 | | - if err != nil { |
826 | | - return err // Not in a git repository, skip |
827 | | - } |
828 | | - |
829 | | - copilotDir := filepath.Join(gitRoot, ".github", "instructions") |
830 | | - copilotInstructionsPath := filepath.Join(copilotDir, "github-agentic-workflows.instructions.md") |
831 | | - |
832 | | - // Ensure the .github/instructions directory exists |
833 | | - if err := os.MkdirAll(copilotDir, 0755); err != nil { |
834 | | - return fmt.Errorf("failed to create .github/instructions directory: %w", err) |
835 | | - } |
836 | | - |
837 | | - // Check if the instructions file already exists and matches the template |
838 | | - existingContent := "" |
839 | | - if content, err := os.ReadFile(copilotInstructionsPath); err == nil { |
840 | | - existingContent = string(content) |
841 | | - } |
842 | | - |
843 | | - // Check if content matches our expected template |
844 | | - expectedContent := strings.TrimSpace(copilotInstructionsTemplate) |
845 | | - if strings.TrimSpace(existingContent) == expectedContent { |
846 | | - if verbose { |
847 | | - fmt.Printf("Copilot instructions are up-to-date: %s\n", copilotInstructionsPath) |
848 | | - } |
849 | | - return nil |
850 | | - } |
851 | | - |
852 | | - // Write the copilot instructions file |
853 | | - if err := os.WriteFile(copilotInstructionsPath, []byte(copilotInstructionsTemplate), 0644); err != nil { |
854 | | - return fmt.Errorf("failed to write copilot instructions: %w", err) |
855 | | - } |
856 | | - |
857 | | - if verbose { |
858 | | - if existingContent == "" { |
859 | | - fmt.Printf("Created copilot instructions: %s\n", copilotInstructionsPath) |
860 | | - } else { |
861 | | - fmt.Printf("Updated copilot instructions: %s\n", copilotInstructionsPath) |
862 | | - } |
863 | | - } |
864 | | - |
865 | | - return nil |
866 | | -} |
867 | | - |
868 | | -// ensureAgenticWorkflowPrompt removes the old agentic workflow prompt file if it exists |
869 | | -func ensureAgenticWorkflowPrompt(verbose bool, skipInstructions bool) error { |
870 | | - // This function now removes the old prompt file since we've migrated to agent format |
871 | | - if skipInstructions { |
872 | | - return nil |
873 | | - } |
874 | | - |
875 | | - gitRoot, err := findGitRoot() |
876 | | - if err != nil { |
877 | | - return err // Not in a git repository, skip |
878 | | - } |
879 | | - |
880 | | - promptsDir := filepath.Join(gitRoot, ".github", "prompts") |
881 | | - oldPromptPath := filepath.Join(promptsDir, "create-agentic-workflow.prompt.md") |
882 | | - |
883 | | - // Check if the old prompt file exists and remove it |
884 | | - if _, err := os.Stat(oldPromptPath); err == nil { |
885 | | - if err := os.Remove(oldPromptPath); err != nil { |
886 | | - return fmt.Errorf("failed to remove old prompt file: %w", err) |
887 | | - } |
888 | | - if verbose { |
889 | | - fmt.Printf("Removed old prompt file: %s\n", oldPromptPath) |
890 | | - } |
891 | | - } |
892 | | - |
893 | | - return nil |
894 | | -} |
895 | | - |
896 | | -// ensureAgenticWorkflowAgent ensures that .github/agents/create-agentic-workflow.md contains the agentic workflow creation agent |
897 | | -func ensureAgenticWorkflowAgent(verbose bool, skipInstructions bool) error { |
898 | | - return ensureAgentFromTemplate("create-agentic-workflow.md", agenticWorkflowAgentTemplate, verbose, skipInstructions) |
899 | | -} |
900 | | - |
901 | | -// ensureSharedAgenticWorkflowAgent ensures that .github/agents/create-shared-agentic-workflow.md contains the shared workflow creation agent |
902 | | -func ensureSharedAgenticWorkflowAgent(verbose bool, skipInstructions bool) error { |
903 | | - return ensureAgentFromTemplate("create-shared-agentic-workflow.md", sharedAgenticWorkflowAgentTemplate, verbose, skipInstructions) |
904 | | -} |
905 | | - |
906 | | -// ensureSetupAgenticWorkflowsAgent ensures that .github/agents/setup-agentic-workflows.md contains the setup guide agent |
907 | | -func ensureSetupAgenticWorkflowsAgent(verbose bool, skipInstructions bool) error { |
908 | | - return ensureAgentFromTemplate("setup-agentic-workflows.md", setupAgenticWorkflowsAgentTemplate, verbose, skipInstructions) |
909 | | -} |
910 | | - |
911 | | -// checkCleanWorkingDirectory checks if there are uncommitted changes |
912 | | -func checkCleanWorkingDirectory(verbose bool) error { |
913 | | - if verbose { |
914 | | - fmt.Printf("Checking for uncommitted changes...\n") |
915 | | - } |
916 | | - |
917 | | - cmd := exec.Command("git", "status", "--porcelain") |
918 | | - output, err := cmd.Output() |
919 | | - if err != nil { |
920 | | - return fmt.Errorf("failed to check git status: %w", err) |
921 | | - } |
922 | | - |
923 | | - if len(strings.TrimSpace(string(output))) > 0 { |
924 | | - return fmt.Errorf("working directory has uncommitted changes, please commit or stash them first") |
925 | | - } |
926 | | - |
927 | | - if verbose { |
928 | | - fmt.Printf("Working directory is clean\n") |
929 | | - } |
930 | | - return nil |
931 | | -} |
932 | | - |
933 | | -// createPR creates a pull request using GitHub CLI |
934 | | -func createPR(branchName, title, body string, verbose bool) error { |
935 | | - if verbose { |
936 | | - fmt.Printf("Creating PR: %s\n", title) |
937 | | - } |
938 | | - |
939 | | - // Get the current repository info to ensure PR is created in the correct repo |
940 | | - cmd := exec.Command("gh", "repo", "view", "--json", "owner,name") |
941 | | - repoOutput, err := cmd.Output() |
942 | | - if err != nil { |
943 | | - return fmt.Errorf("failed to get current repository info: %w", err) |
944 | | - } |
945 | | - |
946 | | - var repoInfo struct { |
947 | | - Owner struct { |
948 | | - Login string `json:"login"` |
949 | | - } `json:"owner"` |
950 | | - Name string `json:"name"` |
951 | | - } |
952 | | - |
953 | | - if err := json.Unmarshal(repoOutput, &repoInfo); err != nil { |
954 | | - return fmt.Errorf("failed to parse repository info: %w", err) |
955 | | - } |
956 | | - |
957 | | - repoSpec := fmt.Sprintf("%s/%s", repoInfo.Owner.Login, repoInfo.Name) |
958 | | - |
959 | | - // Explicitly specify the repository to ensure PR is created in the current repo (not upstream) |
960 | | - cmd = exec.Command("gh", "pr", "create", "--repo", repoSpec, "--title", title, "--body", body, "--head", branchName) |
961 | | - output, err := cmd.Output() |
962 | | - if err != nil { |
963 | | - // Try to get stderr for better error reporting |
964 | | - if exitError, ok := err.(*exec.ExitError); ok { |
965 | | - return fmt.Errorf("failed to create PR: %w\nOutput: %s\nError: %s", err, string(output), string(exitError.Stderr)) |
966 | | - } |
967 | | - return fmt.Errorf("failed to create PR: %w", err) |
968 | | - } |
969 | | - |
970 | | - prURL := strings.TrimSpace(string(output)) |
971 | | - fmt.Printf("📢 Pull Request created: %s\n", prURL) |
972 | | - |
973 | | - return nil |
974 | | -} |
975 | | - |
976 | 816 | // addSourceToWorkflow adds the source field to the workflow's frontmatter |
977 | 817 | func addSourceToWorkflow(content, source string) (string, error) { |
978 | 818 | // Use shared frontmatter logic that preserves formatting |
|
0 commit comments