@@ -20,29 +20,15 @@ import (
2020 "github.com/smartcontractkit/chainlink-testing-framework/tools/flakeguard/localdb"
2121)
2222
23- const (
24- openAIKeyEnvVar = "OPENAI_API_KEY"
25- openAIKeyFlag = "openai-key"
26- )
27-
2823var (
2924 repoPath string
3025 localDBPath string
31- openAIKey string
3226)
3327
3428var MakePRCmd = & cobra.Command {
3529 Use : "make-pr" ,
3630 Short : "Make a PR to skip identified flaky tests" ,
37- PersistentPreRun : func (cmd * cobra.Command , args []string ) {
38- if ! cmd .Flag (openAIKeyFlag ).Changed {
39- openAIKey = os .Getenv (openAIKeyEnvVar )
40- }
41- if openAIKey == "" {
42- fmt .Printf ("Warning: OpenAI API key is not provided by flag '%s' or env var '%s', cannot use LLM to skip or fix flaky tests\n " , openAIKeyFlag , openAIKeyEnvVar )
43- }
44- },
45- RunE : makePR ,
31+ RunE : makePR ,
4632}
4733
4834func makePR (cmd * cobra.Command , args []string ) error {
@@ -103,29 +89,28 @@ func makePR(cmd *cobra.Command, args []string) error {
10389 return fmt .Errorf ("failed to checkout new branch: %w" , err )
10490 }
10591
106- // DEBUG: Maybe this shouldn't be used ever? Debugging is harder without the branch around.
107- // cleanUpBranch := true
108- // defer func() {
109- // if cleanUpBranch {
110- // fmt.Printf("Cleaning up branch %s...", branchName)
111- // // First checkout default branch
112- // err = targetRepoWorktree.Checkout(&git.CheckoutOptions{
113- // Branch: plumbing.NewBranchReferenceName(defaultBranch),
114- // Force: true, // Force checkout to discard any changes for a clean default branch
115- // })
116- // if err != nil {
117- // fmt.Printf("Failed to checkout default branch: %v\n", err)
118- // return
119- // }
120- // // Then delete the local branch
121- // err = repo.Storer.RemoveReference(plumbing.NewBranchReferenceName(branchName))
122- // if err != nil {
123- // fmt.Printf("Failed to remove local branch: %v\n", err)
124- // return
125- // }
126- // fmt.Println(" ✅")
127- // }
128- // }()
92+ cleanUpBranch := true
93+ defer func () {
94+ if cleanUpBranch {
95+ fmt .Printf ("Cleaning up branch %s..." , branchName )
96+ // First checkout default branch
97+ err = targetRepoWorktree .Checkout (& git.CheckoutOptions {
98+ Branch : plumbing .NewBranchReferenceName (defaultBranch ),
99+ Force : true , // Force checkout to discard any changes for a clean default branch
100+ })
101+ if err != nil {
102+ fmt .Printf ("Failed to checkout default branch: %v\n " , err )
103+ return
104+ }
105+ // Then delete the local branch
106+ err = repo .Storer .RemoveReference (plumbing .NewBranchReferenceName (branchName ))
107+ if err != nil {
108+ fmt .Printf ("Failed to remove local branch: %v\n " , err )
109+ return
110+ }
111+ fmt .Println (" ✅" )
112+ }
113+ }()
129114
130115 if len (currentlyFlakyEntries ) == 0 {
131116 fmt .Println ("No flaky tests found!" )
@@ -143,7 +128,7 @@ func makePR(cmd *cobra.Command, args []string) error {
143128 jiraTickets = append (jiraTickets , entry .JiraTicket )
144129 }
145130
146- err = golang .SkipTests (repoPath , openAIKey , testsToSkip )
131+ err = golang .SkipTests (repoPath , testsToSkip )
147132 if err != nil {
148133 return fmt .Errorf ("failed to modify code to skip tests: %w" , err )
149134 }
@@ -178,7 +163,6 @@ func makePR(cmd *cobra.Command, args []string) error {
178163 skippedTestsPRBody strings.Builder
179164 alreadySkippedTestsPRBody strings.Builder
180165 errorSkippingTestsPRBody strings.Builder
181- llmSkippedTestsPRBody strings.Builder
182166 )
183167
184168 for _ , test := range testsToSkip {
@@ -196,11 +180,6 @@ func makePR(cmd *cobra.Command, args []string) error {
196180 alreadySkippedTestsPRBody .WriteString (fmt .Sprintf ("- Package: `%s`\n " , test .Package ))
197181 alreadySkippedTestsPRBody .WriteString (fmt .Sprintf (" Test: `%s`\n " , test .Name ))
198182 alreadySkippedTestsPRBody .WriteString (fmt .Sprintf (" Ticket: [%s](https://%s/browse/%s)\n " , test .JiraTicket , os .Getenv ("JIRA_DOMAIN" ), test .JiraTicket ))
199- } else if test .LLMSkipped {
200- llmSkippedTestsPRBody .WriteString (fmt .Sprintf ("- Package: `%s`\n " , test .Package ))
201- llmSkippedTestsPRBody .WriteString (fmt .Sprintf (" Test: `%s`\n " , test .Name ))
202- llmSkippedTestsPRBody .WriteString (fmt .Sprintf (" Ticket: [%s](https://%s/browse/%s)\n " , test .JiraTicket , os .Getenv ("JIRA_DOMAIN" ), test .JiraTicket ))
203- llmSkippedTestsPRBody .WriteString (fmt .Sprintf (" [View skip in PR](https://github.com/%s/%s/pull/%s/files#diff-%sL%d)\n \n " , owner , repoName , branchName , commitHash , test .Line ))
204183 }
205184 }
206185 body := fmt .Sprintf (`## Tests That I Failed to Skip, Need Manual Intervention
@@ -211,13 +190,9 @@ func makePR(cmd *cobra.Command, args []string) error {
211190
212191%s
213192
214- ## Tests Skipped Using LLM Assistance
215-
216- %s
217-
218193## Tests That Were Already Skipped
219194
220- %s` , errorSkippingTestsPRBody .String (), skippedTestsPRBody .String (), llmSkippedTestsPRBody . String (), alreadySkippedTestsPRBody .String ())
195+ %s` , errorSkippingTestsPRBody .String (), skippedTestsPRBody .String (), alreadySkippedTestsPRBody .String ())
221196
222197 pr := & github.NewPullRequest {
223198 Title : github .Ptr (fmt .Sprintf ("[%s] Flakeguard: Skip flaky tests" , strings .Join (jiraTickets , "] [" ))),
@@ -227,13 +202,15 @@ func makePR(cmd *cobra.Command, args []string) error {
227202 MaintainerCanModify : github .Ptr (true ),
228203 }
229204
230- fmt .Println ("PR Preview:" )
231- fmt .Println ("================================================" )
232- fmt .Println (pr .Title )
205+ fmt .Println ()
206+ fmt .Println ("*** PR Preview ***" )
207+ fmt .Println ()
208+ fmt .Println (pr .GetTitle ())
233209 fmt .Println ("--------------------------------" )
234210 fmt .Printf ("Merging '%s' into '%s'\n " , branchName , defaultBranch )
235- fmt .Println (pr .Body )
211+ fmt .Println (pr .GetBody () )
236212 fmt .Println ("================================================" )
213+ fmt .Println ()
237214
238215 fmt .Printf ("To preview the code changes in the GitHub UI, visit: https://github.com/%s/%s/compare/%s...%s\n " , owner , repoName , defaultBranch , branchName )
239216 fmt .Print ("Would you like to create the PR automatically from the CLI? (y/N): " )
@@ -261,11 +238,11 @@ func makePR(cmd *cobra.Command, args []string) error {
261238 return fmt .Errorf ("failed to create PR, got bad status: %s\n %s" , resp .Status , string (body ))
262239 }
263240
241+ cleanUpBranch = false
264242 fmt .Printf ("PR created! https://github.com/%s/%s/pull/%d\n " , owner , repoName , createdPR .GetNumber ())
265243 return nil
266244}
267245
268246func init () {
269247 MakePRCmd .Flags ().StringVarP (& repoPath , "repoPath" , "r" , "." , "Local path to the repository to make the PR for" )
270- MakePRCmd .Flags ().StringVarP (& openAIKey , openAIKeyFlag , "k" , "" , fmt .Sprintf ("OpenAI API key for using an LLM to help create the PR (can be set via %s environment variable)" , openAIKeyEnvVar ))
271248}
0 commit comments