diff options
author | Jan Provaznik <jprovaznik@gitlab.com> | 2019-06-24 11:51:34 +0200 |
---|---|---|
committer | Jan Provaznik <jprovaznik@gitlab.com> | 2019-06-24 11:51:34 +0200 |
commit | 4189ffe2142e0a0969a3f28ec55e069c3b5abb9f (patch) | |
tree | abb30e42e8317a53dfe72c5cfaa7ddfd28ce47ae | |
parent | da4702493d046e6de24c0a071b0162818e9d990c (diff) | |
download | gitlab-ce-4189ffe2142e0a0969a3f28ec55e069c3b5abb9f.tar.gz |
Added labels_hook_attrs methodfix-labels-in-hooks
Based on review comment fetching labels hook_attrs is now
wrapped in an issue's model method.
-rw-r--r-- | app/models/issue.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/data_builder/note.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/hook_data/issue_builder.rb | 2 | ||||
-rw-r--r-- | spec/models/issue_spec.rb | 9 |
4 files changed, 15 insertions, 2 deletions
diff --git a/app/models/issue.rb b/app/models/issue.rb index 6da6fbe55cb..30e29911758 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -254,6 +254,10 @@ class Issue < ApplicationRecord merge_requests_closing_issues.count end + def labels_hook_attrs + labels.map(&:hook_attrs) + end + private def ensure_metrics diff --git a/lib/gitlab/data_builder/note.rb b/lib/gitlab/data_builder/note.rb index 9a2fe4e9abf..2c4ef73a688 100644 --- a/lib/gitlab/data_builder/note.rb +++ b/lib/gitlab/data_builder/note.rb @@ -44,7 +44,7 @@ module Gitlab data[:commit] = build_data_for_commit(project, user, note) elsif note.for_issue? data[:issue] = note.noteable.hook_attrs - data[:issue][:labels] = note.noteable.labels.map(&:hook_attrs) + data[:issue][:labels] = note.noteable.labels_hook_attrs elsif note.for_merge_request? data[:merge_request] = note.noteable.hook_attrs elsif note.for_snippet? diff --git a/lib/gitlab/hook_data/issue_builder.rb b/lib/gitlab/hook_data/issue_builder.rb index 22ca23cde2a..e5f86ca02b5 100644 --- a/lib/gitlab/hook_data/issue_builder.rb +++ b/lib/gitlab/hook_data/issue_builder.rb @@ -45,7 +45,7 @@ module Gitlab human_time_estimate: issue.human_time_estimate, assignee_ids: issue.assignee_ids, assignee_id: issue.assignee_ids.first, # This key is deprecated - labels: issue.labels.map(&:hook_attrs) + labels: issue.labels_hook_attrs } issue.attributes.with_indifferent_access.slice(*self.class.safe_hook_attributes) diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb index a5c7e9db2a1..d5b016dc8f6 100644 --- a/spec/models/issue_spec.rb +++ b/spec/models/issue_spec.rb @@ -862,4 +862,13 @@ describe Issue do end end end + + describe "#labels_hook_attrs" do + let(:label) { create(:label) } + let(:issue) { create(:labeled_issue, labels: [label]) } + + it "returns a list of label hook attributes" do + expect(issue.labels_hook_attrs).to eq([label.hook_attrs]) + end + end end |