|
Lines 406-413
sub attach_patches {
Link Here
|
| 406 |
# Apply updates with spinner |
406 |
# Apply updates with spinner |
| 407 |
if (%bug_updates) { |
407 |
if (%bug_updates) { |
| 408 |
my $spinner = GitBz::Progress::start_spinner("Updating bug fields"); |
408 |
my $spinner = GitBz::Progress::start_spinner("Updating bug fields"); |
| 409 |
$bug->apply_updates(); |
409 |
|
| 410 |
GitBz::Progress::stop_spinner( $spinner, 'success', "Bug fields updated" ); |
410 |
my $update_success = eval { |
|
|
411 |
$bug->apply_updates(); |
| 412 |
1; |
| 413 |
}; |
| 414 |
|
| 415 |
if ($@) { |
| 416 |
my $error = $@; |
| 417 |
GitBz::Progress::stop_spinner( $spinner, 'error' ); |
| 418 |
|
| 419 |
# Check if it's a 404 error related to QA contact |
| 420 |
if ( exists $bug_updates{qa_contact} && $error =~ /404|not found/i ) { |
| 421 |
print "\n"; |
| 422 |
GitBz::Progress::print_error("QA contact '$bug_updates{qa_contact}' not found"); |
| 423 |
|
| 424 |
# Iteratively search and retry until success or user cancels |
| 425 |
my $attempted_email = $bug_updates{qa_contact}; |
| 426 |
my $retry_success = 0; |
| 427 |
|
| 428 |
while ( !$retry_success ) { |
| 429 |
# Offer to search for similar users |
| 430 |
my $selected_email = $self->select_qa_contact( $client, $attempted_email ); |
| 431 |
|
| 432 |
if ( !$selected_email ) { |
| 433 |
die "Update cancelled by user\n"; |
| 434 |
} |
| 435 |
|
| 436 |
# Retry with the selected user |
| 437 |
$bug->set_field( 'qa_contact', $selected_email ); |
| 438 |
print "\nRetrying with QA contact: $selected_email\n"; |
| 439 |
$spinner = GitBz::Progress::start_spinner("Updating bug fields"); |
| 440 |
|
| 441 |
my $retry_eval = eval { |
| 442 |
$bug->apply_updates(); |
| 443 |
1; |
| 444 |
}; |
| 445 |
|
| 446 |
if ($@) { |
| 447 |
my $retry_error = $@; |
| 448 |
GitBz::Progress::stop_spinner( $spinner, 'error' ); |
| 449 |
|
| 450 |
# Check if it's another 404 error |
| 451 |
if ( $retry_error =~ /404|not found/i ) { |
| 452 |
GitBz::Progress::print_error("QA contact '$selected_email' not found"); |
| 453 |
$attempted_email = $selected_email; # Use this as the next search term |
| 454 |
# Loop continues |
| 455 |
} else { |
| 456 |
# Different error, rethrow |
| 457 |
die $retry_error; |
| 458 |
} |
| 459 |
} else { |
| 460 |
# Success! |
| 461 |
GitBz::Progress::stop_spinner( $spinner, 'success', "Bug fields updated" ); |
| 462 |
$retry_success = 1; |
| 463 |
} |
| 464 |
} |
| 465 |
} else { |
| 466 |
die $error; |
| 467 |
} |
| 468 |
} else { |
| 469 |
GitBz::Progress::stop_spinner( $spinner, 'success', "Bug fields updated" ); |
| 470 |
} |
| 411 |
} |
471 |
} |
| 412 |
|
472 |
|
| 413 |
# Perform obsoletes with real-time feedback |
473 |
# Perform obsoletes with real-time feedback |
|
Lines 659-662
sub parse_bug_updates {
Link Here
|
| 659 |
return ( $bug_comment, \@obsoletes, $bug_updates ); |
719 |
return ( $bug_comment, \@obsoletes, $bug_updates ); |
| 660 |
} |
720 |
} |
| 661 |
|
721 |
|
|
|
722 |
=head2 select_qa_contact |
| 723 |
|
| 724 |
my $email = $attach->select_qa_contact($client, $invalid_email); |
| 725 |
|
| 726 |
Searches for users matching the invalid email and presents a selection menu. |
| 727 |
Returns the selected email, or undef if cancelled. |
| 728 |
|
| 729 |
=cut |
| 730 |
|
| 731 |
sub select_qa_contact { |
| 732 |
my ( $self, $client, $invalid_email ) = @_; |
| 733 |
|
| 734 |
# Extract the local part (before @) from the invalid email |
| 735 |
my $search_term; |
| 736 |
if ( $invalid_email =~ /^([^@]+)@/ ) { |
| 737 |
$search_term = $1; |
| 738 |
} else { |
| 739 |
$search_term = $invalid_email; |
| 740 |
} |
| 741 |
|
| 742 |
# Search for users whose email begins with the local part |
| 743 |
print "\nSearching for similar users (begins with '$search_term')...\n"; |
| 744 |
my $users = GitBz::Progress::with_spinner( |
| 745 |
"Searching users", |
| 746 |
sub { |
| 747 |
return $client->search_users($search_term); |
| 748 |
}, |
| 749 |
1 |
| 750 |
); |
| 751 |
|
| 752 |
if ( !@$users ) { |
| 753 |
print "No similar users found.\n"; |
| 754 |
print "Would you like to enter a different QA contact? [y/N]: "; |
| 755 |
my $response = <STDIN>; |
| 756 |
chomp $response; |
| 757 |
|
| 758 |
if ( $response =~ /^[yY]/ ) { |
| 759 |
print "Enter QA contact email: "; |
| 760 |
my $new_email = <STDIN>; |
| 761 |
chomp $new_email; |
| 762 |
$new_email =~ s/^\s+|\s+$//g; |
| 763 |
return $new_email if $new_email; |
| 764 |
} |
| 765 |
|
| 766 |
return; |
| 767 |
} |
| 768 |
|
| 769 |
# Present users for selection |
| 770 |
print "\nFound " . scalar(@$users) . " similar user(s):\n\n"; |
| 771 |
|
| 772 |
for my $i ( 0 .. $#$users ) { |
| 773 |
my $user = $users->[$i]; |
| 774 |
my $display_name = $user->{real_name} ? "$user->{real_name} <$user->{email}>" : $user->{email}; |
| 775 |
print " [$i] $display_name\n"; |
| 776 |
} |
| 777 |
|
| 778 |
print "\nSelect a user by number, or press Enter to cancel: "; |
| 779 |
my $selection = <STDIN>; |
| 780 |
chomp $selection; |
| 781 |
|
| 782 |
if ( $selection =~ /^\d+$/ && $selection >= 0 && $selection <= $#$users ) { |
| 783 |
return $users->[$selection]{email}; |
| 784 |
} |
| 785 |
|
| 786 |
return; |
| 787 |
} |
| 788 |
|
| 662 |
1; |
789 |
1; |