@@ -10,6 +10,8 @@ import (
1010 "strings"
1111 "text/template"
1212
13+ "strconv"
14+
1315 "github.com/spf13/cobra"
1416
1517 "magician/exec"
@@ -231,7 +233,7 @@ func execTestTerraformVCR(prNumber, mmCommitSha, buildID, projectID, buildStep,
231233 return fmt .Errorf ("error uploading replaying logs: %w" , err )
232234 }
233235
234- if hasPanics , err := handlePanics (prNumber , buildID , buildStatusTargetURL , mmCommitSha , replayingResult , vcr .Replaying , gh ); err != nil {
236+ if hasPanics , err := handlePanics (prNumber , buildID , buildStatusTargetURL , mmCommitSha , replayingResult , vcr .Replaying , gh , rnr ); err != nil {
235237 return fmt .Errorf ("error handling panics: %w" , err )
236238 } else if hasPanics {
237239 return nil
@@ -260,7 +262,7 @@ func execTestTerraformVCR(prNumber, mmCommitSha, buildID, projectID, buildStep,
260262 if err != nil {
261263 return fmt .Errorf ("error formatting post replay comment: %w" , err )
262264 }
263- if err := appendVCRResultToDiffComment (prNumber , comment , gh ); err != nil {
265+ if err := appendVCRResultToDiffComment (prNumber , comment , gh , rnr ); err != nil {
264266 return fmt .Errorf ("error appending comment: %w" , err )
265267 }
266268 if len (replayingResult .FailedTests ) > 0 {
@@ -291,7 +293,7 @@ func execTestTerraformVCR(prNumber, mmCommitSha, buildID, projectID, buildStep,
291293 return fmt .Errorf ("error uploading recording logs: %w" , err )
292294 }
293295
294- if hasPanics , err := handlePanics (prNumber , buildID , buildStatusTargetURL , mmCommitSha , recordingResult , vcr .Recording , gh ); err != nil {
296+ if hasPanics , err := handlePanics (prNumber , buildID , buildStatusTargetURL , mmCommitSha , recordingResult , vcr .Recording , gh , rnr ); err != nil {
295297 return fmt .Errorf ("error handling panics: %w" , err )
296298 } else if hasPanics {
297299 return nil
@@ -341,7 +343,7 @@ func execTestTerraformVCR(prNumber, mmCommitSha, buildID, projectID, buildStep,
341343 if err != nil {
342344 return fmt .Errorf ("error formatting record replay comment: %w" , err )
343345 }
344- if err := appendVCRResultToDiffComment (prNumber , recordReplayComment , gh ); err != nil {
346+ if err := appendVCRResultToDiffComment (prNumber , recordReplayComment , gh , rnr ); err != nil {
345347 return fmt .Errorf ("error appending comment: %w" , err )
346348 }
347349 }
@@ -492,12 +494,12 @@ func runReplaying(runFullVCR bool, version provider.Version, services map[string
492494 return result , testDirs , replayingErr
493495}
494496
495- func handlePanics (prNumber , buildID , buildStatusTargetURL , mmCommitSha string , result vcr.Result , mode vcr.Mode , gh GithubClient ) (bool , error ) {
497+ func handlePanics (prNumber , buildID , buildStatusTargetURL , mmCommitSha string , result vcr.Result , mode vcr.Mode , gh GithubClient , rnr ExecRunner ) (bool , error ) {
496498 if len (result .Panics ) > 0 {
497499 comment := color ("red" , fmt .Sprintf ("The provider crashed while running the VCR tests in %s mode\n " , mode .Upper ()))
498500 comment += fmt .Sprintf (`Please fix it to complete your PR.
499501View the [build log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/heads/auto-pr-%s/artifacts/%s/build-log/%s_test.log)` , prNumber , buildID , mode .Lower ())
500- if err := appendVCRResultToDiffComment (prNumber , comment , gh ); err != nil {
502+ if err := appendVCRResultToDiffComment (prNumber , comment , gh , rnr ); err != nil {
501503 return true , fmt .Errorf ("error appending comment: %v" , err )
502504 }
503505 if err := gh .PostBuildStatus (prNumber , "VCR-test" , "failure" , buildStatusTargetURL , mmCommitSha ); err != nil {
@@ -508,17 +510,23 @@ View the [build log](https://storage.cloud.google.com/ci-vcr-logs/beta/refs/head
508510 return false , nil
509511}
510512
511- func appendVCRResultToDiffComment (prNumber string , content string , gh GithubClient ) error {
513+ func appendVCRResultToDiffComment (prNumber string , content string , gh GithubClient , rnr ExecRunner ) error {
512514 comments , err := gh .GetPullRequestComments (prNumber )
513515 if err != nil {
514516 return fmt .Errorf ("error getting PR comments: %w" , err )
515517 }
516518
517519 var diffComment * github.PullRequestComment
518- for _ , c := range comments {
519- if strings .Contains (c .Body , "## Diff report" ) || strings .Contains (c .Body , "Hi there, I'm the Modular magician" ) {
520- diffComment = & c
521- break
520+
521+ // Try to find by ID from file
522+ if idStr , err := rnr .ReadFile ("diff_comment_id.txt" ); err == nil {
523+ if id , err := strconv .Atoi (strings .TrimSpace (idStr )); err == nil {
524+ for _ , c := range comments {
525+ if c .ID == id {
526+ diffComment = & c
527+ break
528+ }
529+ }
522530 }
523531 }
524532
0 commit comments