@@ -476,6 +476,40 @@ def handle(self):
476
476
return state_before_handle
477
477
478
478
# Implement handlers for ADD action
479
+ @log_function_entry_exit ()
480
+ def _create_symlink (self , source_path : str , target_path : str , branch : str = None ):
481
+ """Create a symlink in the given branch."""
482
+ try :
483
+ branch = self .git_repo .default_branch if branch is None else branch
484
+ ref = self .git_repo .get_git_ref (f"heads/{ branch } " )
485
+ commit = self .git_repo .get_git_commit (ref .object .sha )
486
+ base_tree = self .git_repo .get_git_tree (commit .tree .sha )
487
+
488
+ # Create blob for symlink target
489
+ blob = self .git_repo .create_git_blob (target_path , "utf-8" )
490
+
491
+ # Create tree element
492
+ tree_element = {
493
+ "path" : source_path ,
494
+ "mode" : "120000" ,
495
+ "type" : "blob" ,
496
+ "sha" : blob .sha
497
+ }
498
+
499
+ # Create new tree and commit
500
+ new_tree = self .git_repo .create_git_tree ([tree_element ], base_tree )
501
+ commit_message = f"Add symlink { source_path } -> { target_path } "
502
+ new_commit = self .git_repo .create_git_commit (commit_message , new_tree , [commit ])
503
+
504
+ # Update reference
505
+ ref .edit (new_commit .sha )
506
+
507
+ log_message (LoggingScope .TASK_OPS , 'INFO' , "Symlink created: %s -> %s" ,
508
+ source_path , target_path )
509
+
510
+ except Exception as err :
511
+ log_message (LoggingScope .TASK_OPS , 'ERROR' , "Error creating symlink: %s" , err )
512
+
479
513
@log_function_entry_exit ()
480
514
def _handle_add_undetermined (self ):
481
515
"""Handler for ADD action in UNDETERMINED state"""
@@ -487,7 +521,7 @@ def _handle_add_undetermined(self):
487
521
branch = self .git_repo .default_branch
488
522
repo_name = self .description .get_repo_name ()
489
523
pr_number = self .description .get_pr_number ()
490
- sequence_number = self ._get_fixed_sequence_number ()
524
+ sequence_number = self ._get_fixed_sequence_number () # corresponds to an open or yet to be created PR
491
525
task_file_name = self .description .get_task_file_name ()
492
526
target_dir = f"{ repo_name } /{ pr_number } /{ sequence_number } /{ task_file_name } "
493
527
task_description_file_path = f"{ target_dir } /TaskDescription"
@@ -498,8 +532,9 @@ def _handle_add_undetermined(self):
498
532
self .git_repo .create_file (task_state_file_path ,
499
533
f"new task state for { repo_name } PR { pr_number } seq { sequence_number } " ,
500
534
"" , branch = branch )
501
- # self.git_repo.create_symlink(self.description.task_object.remote_file_path,
502
- # target_dir, branch=branch)
535
+ self ._create_symlink (self .description .task_object .remote_file_path , target_dir , branch = branch )
536
+ # TODO: verify that the sequence number is still valid (PR corresponding to the sequence number is still open or
537
+ # yet to be created); if it is not valid, perform corrective actions
503
538
return TaskState .NEW_TASK
504
539
505
540
@log_function_entry_exit ()
0 commit comments