11import configparser
2+ import json
23import logging
34import subprocess
45from pathlib import Path
@@ -172,15 +173,27 @@ def run_job(self, job: LandingJob) -> bool:
172173
173174 return True
174175
176+ def add_try_task_config (self , scm : AbstractSCM ):
177+ with (Path (scm .path ) / "try_task_config.json" ).open ("x" ) as f :
178+ data = {
179+ "parameters" : {
180+ "optimize_target_tasks" : True ,
181+ "target_tasks_method" : "codereview" ,
182+ },
183+ "version" : 2 ,
184+ }
185+ content = json .dumps (data )
186+ f .write (content )
187+
175188 def convert_patches_to_diff (self , scm : AbstractSCM , job : LandingJob ):
176189 """Generate a unified diff from multiple patches stored in a revision."""
177190 # NOTE: this only applies to git patches that are downloaded from GitHub
178191 # at this time. In theory this would work for any provided patches in a
179192 # standard format.
180193
181- def get_diff_from_patches (revision : Revision ) -> str :
194+ def add_diff_from_patches (revision : Revision ) -> str :
182195 logger .debug (f"Converting paches to single diff for { revision } ..." )
183- return scm .get_diff_from_patches (revision .patches )
196+ return scm .add_diff_from_patches (revision .patches )
184197
185198 # NOTE: this is only supported for jobs with a single revision at this time.
186199 # See bug 2001185.
@@ -197,7 +210,7 @@ def get_diff_from_patches(revision: Revision) -> str:
197210 raise ValueError ("Revision is missing patches." )
198211
199212 diff = self .handle_new_commit_failures (
200- get_diff_from_patches ,
213+ add_diff_from_patches ,
201214 job .target_repo ,
202215 job ,
203216 scm ,
@@ -230,6 +243,19 @@ def apply_patch(revision: Revision):
230243
231244 self .update_repo (repo , job , scm , job .target_commit_hash )
232245
246+ if job .is_pull_request_job and job .handover_repo :
247+ if not job .handover_repo .is_try :
248+ raise ValueError (
249+ f"{ job } handover to non-try repo ({ job .handover_repos } ) is not supported"
250+ )
251+
252+ self .add_try_task_config (scm )
253+ self .convert_patches_to_diff (scm , job )
254+ job .handover ()
255+ message = "Job deferred to try repo."
256+ job .transition_status (JobAction .DEFER , message = message )
257+ raise TemporaryFailureException (message )
258+
233259 if job .is_pull_request_job :
234260 self .convert_patches_to_diff (scm , job )
235261 self .update_repo (repo , job , scm , job .target_commit_hash )
0 commit comments