Skip to content
代码片段 群组 项目
未验证 提交 966309f7 编辑于 作者: Mario Celi's avatar Mario Celi
浏览文件

Add `issuableDatesUpdated` subscription to GraphQL API

Changelog: added

Updating start or due date in an Issue or WorkItem will now
trigger a relatime update so you can fetch the updated dates
上级 41a1eec4
No related branches found
No related tags found
无相关合并请求
...@@ -16,4 +16,8 @@ def self.issuable_title_updated(issuable) ...@@ -16,4 +16,8 @@ def self.issuable_title_updated(issuable)
def self.issuable_labels_updated(issuable) def self.issuable_labels_updated(issuable)
GitlabSchema.subscriptions.trigger('issuableLabelsUpdated', { issuable_id: issuable.to_gid }, issuable) GitlabSchema.subscriptions.trigger('issuableLabelsUpdated', { issuable_id: issuable.to_gid }, issuable)
end end
def self.issuable_dates_updated(issuable)
GitlabSchema.subscriptions.trigger('issuableDatesUpdated', { issuable_id: issuable.to_gid }, issuable)
end
end end
...@@ -15,5 +15,8 @@ class SubscriptionType < ::Types::BaseObject ...@@ -15,5 +15,8 @@ class SubscriptionType < ::Types::BaseObject
field :issuable_labels_updated, subscription: Subscriptions::IssuableUpdated, null: true, field :issuable_labels_updated, subscription: Subscriptions::IssuableUpdated, null: true,
description: 'Triggered when the labels of an issuable are updated.' description: 'Triggered when the labels of an issuable are updated.'
field :issuable_dates_updated, subscription: Subscriptions::IssuableUpdated, null: true,
description: 'Triggered when the due date or start date of an issuable is updated.'
end end
end end
...@@ -70,6 +70,7 @@ def handle_changes(issue, options) ...@@ -70,6 +70,7 @@ def handle_changes(issue, options)
handle_severity_change(issue, old_severity) handle_severity_change(issue, old_severity)
handle_escalation_status_change(issue) handle_escalation_status_change(issue)
handle_issue_type_change(issue) handle_issue_type_change(issue)
handle_date_changes(issue)
end end
def handle_assignee_changes(issue, old_assignees) def handle_assignee_changes(issue, old_assignees)
...@@ -116,6 +117,12 @@ def move_issue_to_new_project(issue) ...@@ -116,6 +117,12 @@ def move_issue_to_new_project(issue)
attr_reader :spam_params attr_reader :spam_params
def handle_date_changes(issue)
return unless issue.previous_changes.slice('due_date', 'start_date').any?
GraphqlTriggers.issuable_dates_updated(issue)
end
def clone_issue(issue) def clone_issue(issue)
target_project = params.delete(:target_clone_project) target_project = params.delete(:target_clone_project)
with_notes = params.delete(:clone_with_notes) with_notes = params.delete(:clone_with_notes)
......
...@@ -47,4 +47,18 @@ ...@@ -47,4 +47,18 @@
GraphqlTriggers.issuable_labels_updated(issue) GraphqlTriggers.issuable_labels_updated(issue)
end end
end end
describe '.issuable_dates_updated' do
it 'triggers the issuableDatesUpdated subscription' do
work_item = create(:work_item)
expect(GitlabSchema.subscriptions).to receive(:trigger).with(
'issuableDatesUpdated',
{ issuable_id: work_item.to_gid },
work_item
).and_call_original
GraphqlTriggers.issuable_dates_updated(work_item)
end
end
end end
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
issue_crm_contacts_updated issue_crm_contacts_updated
issuable_title_updated issuable_title_updated
issuable_labels_updated issuable_labels_updated
issuable_dates_updated
] ]
expect(described_class).to have_graphql_fields(*expected_fields).only expect(described_class).to have_graphql_fields(*expected_fields).only
......
...@@ -988,6 +988,52 @@ def update_issue(opts) ...@@ -988,6 +988,52 @@ def update_issue(opts)
end end
end end
context 'updating dates' do
subject(:result) { described_class.new(project: project, current_user: user, params: params).execute(issue) }
let(:updated_date) { 1.week.from_now.to_date }
shared_examples 'issue update service that triggers date updates' do
it 'triggers graphql date updated subscription' do
expect(GraphqlTriggers).to receive(:issuable_dates_updated).with(issue).and_call_original
result
end
end
shared_examples 'issue update service that does not trigger date updates' do
it 'does not trigger date updated subscriptions' do
expect(GraphqlTriggers).not_to receive(:issuable_dates_updated)
result
end
end
context 'when due_date is updated' do
let(:params) { { due_date: updated_date } }
it_behaves_like 'issue update service that triggers date updates'
end
context 'when start_date is updated' do
let(:params) { { start_date: updated_date } }
it_behaves_like 'issue update service that triggers date updates'
end
context 'when no date is updated' do
let(:params) { { title: 'should not trigger date updates' } }
it_behaves_like 'issue update service that does not trigger date updates'
end
context 'when update is not successful but date is provided' do
let(:params) { { title: '', due_date: updated_date } }
it_behaves_like 'issue update service that does not trigger date updates'
end
end
context 'updating asssignee_id' do context 'updating asssignee_id' do
it 'does not update assignee when assignee_id is invalid' do it 'does not update assignee when assignee_id is invalid' do
update_issue(assignee_ids: [-1]) update_issue(assignee_ids: [-1])
......
...@@ -36,6 +36,14 @@ ...@@ -36,6 +36,14 @@
stub_spam_services stub_spam_services
end end
shared_examples 'update service that triggers graphql dates updated subscription' do
it 'triggers graphql subscription issueableDatesUpdated' do
expect(GraphqlTriggers).to receive(:issuable_dates_updated).with(work_item).and_call_original
update_work_item
end
end
context 'when title is changed' do context 'when title is changed' do
let(:opts) { { title: 'changed' } } let(:opts) { { title: 'changed' } }
...@@ -187,6 +195,32 @@ ...@@ -187,6 +195,32 @@
end end
end end
context 'for start and due date widget' do
let(:updated_date) { 1.week.from_now.to_date }
context 'when due_date is updated' do
let(:widget_params) { { start_and_due_date_widget: { due_date: updated_date } } }
it_behaves_like 'update service that triggers graphql dates updated subscription'
end
context 'when start_date is updated' do
let(:widget_params) { { start_and_due_date_widget: { start_date: updated_date } } }
it_behaves_like 'update service that triggers graphql dates updated subscription'
end
context 'when no date param is updated' do
let(:opts) { { title: 'should not trigger' } }
it 'does not trigger date updated subscription' do
expect(GraphqlTriggers).not_to receive(:issuable_dates_updated)
update_work_item
end
end
end
context 'for the hierarchy widget' do context 'for the hierarchy widget' do
let(:opts) { { title: 'changed' } } let(:opts) { { title: 'changed' } }
let_it_be(:child_work_item) { create(:work_item, :task, project: project) } let_it_be(:child_work_item) { create(:work_item, :task, project: project) }
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册