@@ -388,6 +388,52 @@ def test_add_labels_to_pr_success(self, mock_debug_log, mock_log, mock_run_comma
388388 mock_log .assert_any_call ("Adding labels to PR #123: ['contrast-vuln-id:VULN-12345', 'smartfix-id:remediation-67890']" )
389389 mock_log .assert_any_call ("Successfully added labels to PR #123: ['contrast-vuln-id:VULN-12345', 'smartfix-id:remediation-67890']" )
390390
391+ def test_extract_issue_number_from_branch_success (self ):
392+ """Test extracting issue number from valid copilot branch name"""
393+ # Test cases with valid branch names
394+ test_cases = [
395+ ("copilot/fix-123" , 123 ),
396+ ("copilot/fix-1" , 1 ),
397+ ("copilot/fix-999999" , 999999 ),
398+ ("copilot/fix-42" , 42 ),
399+ ]
400+
401+ for branch_name , expected_issue_number in test_cases :
402+ with self .subTest (branch_name = branch_name ):
403+ result = git_handler .extract_issue_number_from_branch (branch_name )
404+ self .assertEqual (result , expected_issue_number )
405+
406+ def test_extract_issue_number_from_branch_invalid (self ):
407+ """Test extracting issue number from invalid branch names"""
408+ # Test cases with invalid branch names
409+ invalid_branches = [
410+ "main" , # Wrong branch name
411+ "feature/new-feature" , # Wrong branch name
412+ "copilot/fix-" , # Missing issue number
413+ "copilot/fix-abc" , # Non-numeric issue number
414+ "copilot/fix-123abc" , # Invalid format
415+ "copilot/fix-123-extra" , # Extra parts
416+ "smartfix/remediation-123" , # Different prefix
417+ "" , # Empty string
418+ ]
419+
420+ for branch_name in invalid_branches :
421+ with self .subTest (branch_name = branch_name ):
422+ result = git_handler .extract_issue_number_from_branch (branch_name )
423+ self .assertIsNone (result )
424+
425+ def test_extract_issue_number_from_branch_edge_cases (self ):
426+ """Test edge cases for extracting issue number from branch name"""
427+ # Test edge cases
428+ edge_cases = [
429+ ("copilot/fix-2147483647" , 2147483647 ), # Large number (max 32-bit int)
430+ ]
431+
432+ for branch_name , expected_issue_number in edge_cases :
433+ with self .subTest (branch_name = branch_name ):
434+ result = git_handler .extract_issue_number_from_branch (branch_name )
435+ self .assertEqual (result , expected_issue_number )
436+
391437 @patch ('src.git_handler.ensure_label' )
392438 @patch ('src.git_handler.run_command' )
393439 @patch ('src.git_handler.log' )
0 commit comments