@@ -354,13 +354,67 @@ sub group_query {
354354 }
355355}
356356
357- sub _is_uplift_request_form_change {
358- # Return `true` if the story text is an uplift request change.
357+ sub get_last_uplift_hash {
358+ my ($revision_phid ) = @_ ;
359+ INFO(' Retrieving last uplift form hash for revision ' . $revision_phid );
360+
361+ return Bugzilla-> dbh-> selectrow_array(
362+ ' SELECT uplift_form_hash FROM phab_uplift_form_state WHERE revision_phid = ?' ,
363+ undef ,
364+ $revision_phid
365+ );
366+ }
367+
368+ sub update_last_uplift_hash {
369+ my ($revision_phid , $uplift_hash ) = @_ ;
370+ my $dbh = Bugzilla-> dbh;
371+
372+ INFO(
373+ ' Updating last uplift hash' . $uplift_hash . ' for revision' . $revision_phid
374+ );
375+
376+ $dbh -> do(
377+ ' DELETE FROM phab_uplift_form_state WHERE revision_phid = ?' ,
378+ undef ,
379+ $revision_phid
380+ );
381+ $dbh -> do(
382+ ' INSERT INTO phab_uplift_form_state (revision_phid, uplift_form_hash) VALUES (?, ?)' ,
383+ undef ,
384+ $revision_phid ,
385+ $uplift_hash
386+ );
387+ }
388+
389+ sub is_uplift_request_form_story_change {
390+ # Return `true` if the uplift request form has changed since last check.
359391 my ($story_text ) = @_ ;
360392
361393 return $story_text =~ / \s +uplift request field/ ;
362394}
363395
396+ sub has_uplift_request_form_changed {
397+ # Return `true` if the uplift request form has changed since last check.
398+ my ($revision ) = @_ ;
399+
400+ # Take no action if the form is empty.
401+ if (ref $revision -> uplift_request ne ' HASH'
402+ || !keys %{$revision -> uplift_request})
403+ {
404+ INFO(' Uplift request form field empty, ignoring.' );
405+ return ;
406+ }
407+
408+ my $previous_hash = get_last_uplift_hash($revision -> phid);
409+ if (!$previous_hash ) {
410+ # If the form is not empty and there is no previous hash,
411+ # the form has changed.
412+ return 1;
413+ }
414+
415+ return $revision -> uplift_hash ne $previous_hash ;
416+ }
417+
364418sub readable_answer {
365419 my ($answer ) = @_ ;
366420
@@ -414,14 +468,6 @@ sub process_uplift_request_form_change {
414468 my ($timestamp ) = Bugzilla-> dbh-> selectrow_array(' SELECT NOW()' );
415469 my $phab_bot_user = Bugzilla::User-> new({name => PHAB_AUTOMATION_USER});
416470
417- # Take no action if the form is empty.
418- if (ref $revision -> uplift_request ne ' HASH'
419- || !keys %{$revision -> uplift_request})
420- {
421- INFO(' Uplift request form field cleared, ignoring.' );
422- return ;
423- }
424-
425471 INFO(' Commenting the uplift form on the bug.' );
426472
427473 my $comment_content = format_uplift_request_as_markdown(
@@ -515,6 +561,7 @@ sub process_uplift_request_form_change {
515561 }
516562
517563 INFO(" Finished processing uplift request form change for $revision_phid ." );
564+ update_last_uplift_hash($revision -> phid, $revision -> uplift_hash);
518565}
519566
520567sub process_revision_change {
@@ -554,9 +601,13 @@ sub process_revision_change {
554601 my $restore_prev_user = set_phab_user();
555602 my $bug = $revision -> bug;
556603
557- # Change is a submission of the uplift request form.
558- if (_is_uplift_request_form_change($story_text )) {
559- return process_uplift_request_form_change($revision , $bug );
604+ # Process uplift request form changes if the hash has changed since phab-bot last
605+ # saw it.
606+ if (has_uplift_request_form_changed($revision )) {
607+ process_uplift_request_form_change($revision , $bug );
608+
609+ # Return early if updating from a story change.
610+ return if is_uplift_request_form_story_change($story_text );
560611 }
561612
562613 # Check to make sure bug id is valid and author can see it
0 commit comments