@@ -136,18 +136,8 @@ sub webhook_before_send {
136136
137137 INFO(" Processing webhook for bug $bug_id to Jira host $hostname " );
138138
139- # Check if there's a Jira mapping for this bug
140- if (my $jira_map
141- = Bugzilla::Extension::JiraWebhookSync::JiraBugMap-> get_by_bug_id($bug_id ))
142- {
143- INFO(' Adding Jira see_also to webhook payload: ' . $jira_map -> jira_url);
144-
145- # Add the Jira URL to the see_also array in the payload if not already present
146- $payload -> {bug }-> {see_also } ||= [];
147- if (none { $_ eq $jira_map -> jira_url } @{$payload -> {bug }-> {see_also }}) {
148- push @{$payload -> {bug }-> {see_also }}, $jira_map -> jira_url;
149- }
150- }
139+ # Check if there's a Jira mapping for this bug and add to see also
140+ $payload -> {bug }-> {see_also } = _populate_jira_see_also($bug_id , $payload -> {bug }-> {see_also });
151141
152142 # Make copy of the current whiteboard value
153143 my $whiteboard = $payload -> {bug }-> {whiteboard };
@@ -167,6 +157,26 @@ sub webhook_before_send {
167157 $payload -> {bug }-> {whiteboard } = _add_whiteboard_tags($whiteboard , \@new_tags );
168158}
169159
160+ sub webservice_bug_get {
161+ my ($self , $args ) = @_ ;
162+ my $bug_data = $args -> {bug_data };
163+ my $user = $args -> {user };
164+ my $params = Bugzilla-> params;
165+
166+ # Only add see also values for the Jira webhook sync user
167+ if (!$params -> {jira_webhook_sync_user } || $user -> login ne $params -> {jira_webhook_sync_user }) {
168+ INFO(' Not the jira_webhook_sync_user so skipping see also population' );
169+ return ;
170+ }
171+
172+ INFO(' Jira sync user is accessing REST get bug. Looking for see also values' );
173+
174+ foreach my $bug (@{$bug_data }) {
175+ INFO(' Processing bug id ' . $bug -> {id } . ' for Jira see also population' );
176+ $bug -> {see_also } = _populate_jira_see_also($bug -> {id }, $bug -> {see_also });
177+ }
178+ }
179+
170180# Adds a whiteboard tag to the whiteboard string if it doesn't already exist.
171181# Returns the whiteboard value with the tag in [brackets] format.
172182# If the tag already exists, returns the whiteboard unchanged.
@@ -203,4 +213,22 @@ sub _bug_matches_rule {
203213 return 0;
204214}
205215
216+ # Adds the Jira issue URL associated with the given Bugzilla bug ID to the see_also list,
217+ # ensuring no duplicates. Returns the updated list.
218+ sub _populate_jira_see_also {
219+ my ($bug_id , $see_also_list ) = @_ ;
220+
221+ $see_also_list ||= [];
222+
223+ if (my $jira_map
224+ = Bugzilla::Extension::JiraWebhookSync::JiraBugMap-> get_by_bug_id($bug_id ))
225+ {
226+ INFO(' Adding Jira see_also to webhook payload: ' . $jira_map -> jira_url);
227+ push @{$see_also_list }, $jira_map -> jira_url
228+ if none { $_ eq $jira_map -> jira_url } @{$see_also_list };
229+ }
230+
231+ return $see_also_list ;
232+ }
233+
206234__PACKAGE__ -> NAME;
0 commit comments