Commit aeac7eb0 authored by Rémy Coutable's avatar Rémy Coutable

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

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 06f1abe5
......@@ -411,8 +411,8 @@ module Issuable
changes = previous_changes
if old_associations
old_labels = old_associations.fetch(:labels, [])
old_assignees = old_associations.fetch(:assignees, [])
old_labels = old_associations.fetch(:labels, labels)
old_assignees = old_associations.fetch(:assignees, assignees)
if old_labels != labels
changes[:labels] = [old_labels.map(&:hook_attrs), labels.map(&:hook_attrs)]
......@@ -423,7 +423,7 @@ module Issuable
end
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
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
describe '#to_hook_data' do
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
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