Commit 37bd477b authored by Markus Koller's avatar Markus Koller

Merge branch 'dont-include-changes-in-webhook-payload-when-old-associations-is-empty' into 'master'

Don't include changes in webhook payload when old associations are empty

See merge request gitlab-org/gitlab!35158
parents 33a594e8 aeac7eb0
...@@ -411,8 +411,8 @@ module Issuable ...@@ -411,8 +411,8 @@ module Issuable
changes = previous_changes changes = previous_changes
if old_associations if old_associations
old_labels = old_associations.fetch(:labels, []) old_labels = old_associations.fetch(:labels, labels)
old_assignees = old_associations.fetch(:assignees, []) old_assignees = old_associations.fetch(:assignees, assignees)
if old_labels != labels if old_labels != labels
changes[:labels] = [old_labels.map(&:hook_attrs), labels.map(&:hook_attrs)] changes[:labels] = [old_labels.map(&:hook_attrs), labels.map(&:hook_attrs)]
...@@ -423,7 +423,7 @@ module Issuable ...@@ -423,7 +423,7 @@ module Issuable
end end
if self.respond_to?(:total_time_spent) if self.respond_to?(:total_time_spent)
old_total_time_spent = old_associations.fetch(:total_time_spent, nil) old_total_time_spent = old_associations.fetch(:total_time_spent, total_time_spent)
if old_total_time_spent != total_time_spent if old_total_time_spent != total_time_spent
changes[:total_time_spent] = [old_total_time_spent, total_time_spent] changes[:total_time_spent] = [old_total_time_spent, total_time_spent]
......
---
title: Don't include changes in webhook payload when old associations are empty
merge_request: 35158
author:
type: fixed
...@@ -416,6 +416,27 @@ RSpec.describe Issuable do ...@@ -416,6 +416,27 @@ RSpec.describe Issuable do
describe '#to_hook_data' do describe '#to_hook_data' do
let(:builder) { double } let(:builder) { double }
context 'when old_associations is empty' do
let(:label) { create(:label) }
before do
issue.update!(labels: [label])
issue.assignees << user
issue.spend_time(duration: 2, user_id: user.id, spent_at: Time.current)
expect(Gitlab::HookData::IssuableBuilder)
.to receive(:new).with(issue).and_return(builder)
end
it 'delegates to Gitlab::HookData::IssuableBuilder#build and does not set labels, assignees, nor total_time_spent' do
expect(builder).to receive(:build).with(
user: user,
changes: {})
# In some cases, old_associations is empty, e.g. on a close event
issue.to_hook_data(user)
end
end
context 'labels are updated' do context 'labels are updated' do
let(:labels) { create_list(:label, 2) } let(:labels) { create_list(:label, 2) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment