Added labels_hook_attrs method
Based on review comment fetching labels hook_attrs is now wrapped in an issue's model method.
This commit is contained in:
parent
da4702493d
commit
4189ffe214
|
|
@ -254,6 +254,10 @@ class Issue < ApplicationRecord
|
||||||
merge_requests_closing_issues.count
|
merge_requests_closing_issues.count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def labels_hook_attrs
|
||||||
|
labels.map(&:hook_attrs)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def ensure_metrics
|
def ensure_metrics
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ module Gitlab
|
||||||
data[:commit] = build_data_for_commit(project, user, note)
|
data[:commit] = build_data_for_commit(project, user, note)
|
||||||
elsif note.for_issue?
|
elsif note.for_issue?
|
||||||
data[:issue] = note.noteable.hook_attrs
|
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?
|
elsif note.for_merge_request?
|
||||||
data[:merge_request] = note.noteable.hook_attrs
|
data[:merge_request] = note.noteable.hook_attrs
|
||||||
elsif note.for_snippet?
|
elsif note.for_snippet?
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ module Gitlab
|
||||||
human_time_estimate: issue.human_time_estimate,
|
human_time_estimate: issue.human_time_estimate,
|
||||||
assignee_ids: issue.assignee_ids,
|
assignee_ids: issue.assignee_ids,
|
||||||
assignee_id: issue.assignee_ids.first, # This key is deprecated
|
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)
|
issue.attributes.with_indifferent_access.slice(*self.class.safe_hook_attributes)
|
||||||
|
|
|
||||||
|
|
@ -862,4 +862,13 @@ describe Issue do
|
||||||
end
|
end
|
||||||
end
|
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
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue