9
9
AUTOFIX_EXECUTION_SOFT_TIME_LIMIT_SECS ,
10
10
)
11
11
12
- # from seer.automation.codegen.retry_unit_test_coding_component import RetryUnitTestCodingComponent
13
12
from seer .automation .codebase .repo_client import RepoClientType
14
13
from seer .automation .codegen .models import CodeUnitTestRequest
15
14
from seer .automation .codegen .retry_unittest_coding_component import RetryUnitTestCodingComponent
19
18
from seer .automation .pipeline import PipelineStepTaskRequest
20
19
from seer .automation .state import DbStateRunTypes
21
20
from seer .automation .utils import determine_mapped_unit_test_run_id
21
+ from seer .db import DbPrContextToUnitTestGenerationRunIdMapping
22
22
23
23
24
24
class RetryUnittestStepRequest (PipelineStepTaskRequest ):
25
25
pr_id : int
26
26
repo_definition : RepoDefinition
27
- # codecov_status: dict
27
+ codecov_status : dict
28
28
29
29
30
30
@celery_app .task (
@@ -50,50 +50,50 @@ def _instantiate_request(request: dict[str, Any]) -> RetryUnittestStepRequest:
50
50
51
51
@staticmethod
52
52
def get_task ():
53
- x = retry_unittest_task
54
- return x
53
+ return retry_unittest_task
55
54
56
55
@observe (name = "Codegen - Retry Unittest Step" )
57
56
@ai_track (description = "Codegen - Retry Unittest Step" )
58
57
def _invoke (self , ** kwargs ):
59
58
self .logger .info ("Executing Codegen - Retry Unittest Step" )
60
59
self .context .event_manager .mark_running ()
61
- # TODO: IF STATUS CHECK HAS PASSED OR WE HAVE MORE THAN 3 COMMITS, SKIP UNIT TEST GENERATION:
62
-
63
- repo_client = self . context . get_repo_client ( type = RepoClientType . CODECOV_UNIT_TEST )
60
+ repo_client = self . context . get_repo_client (
61
+ type = RepoClientType . CODECOV_PR_REVIEW
62
+ ) # Codecov-ai GH app
64
63
pr = repo_client .repo .get_pull (self .request .pr_id )
65
- diff_content = repo_client . get_pr_diff_content ( pr . url )
64
+ codecov_status = self . request . codecov_status [ "check_run" ][ "conclusion" ]
66
65
67
- latest_commit_sha = repo_client .get_pr_head_sha (pr .url )
66
+ if codecov_status == "success" :
67
+ saved_memory = DbPrContextToUnitTestGenerationRunIdMapping .objects .filter (
68
+ owner = self .request .owner ,
69
+ repo = self .request .repo_definition .name ,
70
+ pr_id = self .request .pr_id ,
71
+ ).first ()
68
72
69
- codecov_client_params = {
70
- "repo_name" : self .request .repo_definition .name ,
71
- "pullid" : self .request .pr_id ,
72
- "owner_username" : self .request .repo_definition .owner ,
73
- "head_sha" : latest_commit_sha ,
74
- }
75
- try :
76
- unittest_output = RetryUnitTestCodingComponent (self .context ).invoke (
77
- CodeUnitTestRequest (
78
- diff = diff_content ,
79
- codecov_client_params = codecov_client_params ,
80
- ),
81
- generated_run_id = determine_mapped_unit_test_run_id (
82
- owner = self .request .repo_definition .owner ,
83
- repo_name = self .request .repo_definition .name ,
84
- pr_id = self .request .pr_id ,
85
- ),
73
+ repo_client .post_unit_test_reference_to_original_pr (
74
+ saved_memory .original_pr_url , pr .html_url
86
75
)
87
-
88
- if unittest_output :
89
- for file_change in unittest_output . diffs :
90
- self .context . event_manager . append_file_change ( file_change )
91
- generator = GeneratedTestsPullRequestCreator ( unittest_output . diffs , pr , repo_client )
92
- generator . create_github_pull_request ()
93
- else :
94
- repo_client . post_unit_test_not_generated_message_to_original_pr ( pr . html_url )
76
+ self . context . event_manager . mark_completed ()
77
+ else :
78
+ past_run = DbPrContextToUnitTestGenerationRunIdMapping . objects . filter (
79
+ owner = self .request . owner ,
80
+ repo = self . request . repo_definition . name ,
81
+ pr_id = self . request . pr_id ,
82
+ ). first ()
83
+ if not past_run :
95
84
return
85
+ if past_run .iterations == 3 :
86
+ # TODO: Fetch the "best" run and update the PR
87
+ return
88
+ else :
89
+ # TODO: Retry test generation
90
+ pass
91
+ self .context .event_manager .mark_completed ()
96
92
97
- except ValueError :
98
- repo_client .post_unit_test_not_generated_message_to_original_pr (pr .html_url )
99
- self .context .event_manager .mark_completed ()
93
+ def get_mapping (owner , repo , pr_id ):
94
+ try :
95
+ return DbPrContextToUnitTestGenerationRunIdMapping .objects .get (
96
+ owner = owner , repo = repo , pr_id = pr_id
97
+ )
98
+ except DbPrContextToUnitTestGenerationRunIdMapping .DoesNotExist :
99
+ return None
0 commit comments