Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

[#56065] Fix TypeError for gitlab PRs with missing description

Judith Roth66296a45ad59
diff --git a/modules/gitlab_integration/lib/open_project/gitlab_integration/notification_handler/merge_request_hook.rb b/modules/gitlab_integration/lib/open_project/gitlab_integration/notification_handler/merge_request_hook.rb
index 943a289d77f..01619824ba2 100644
--- a/modules/gitlab_integration/lib/open_project/gitlab_integration/notification_handler/merge_request_hook.rb
+++ b/modules/gitlab_integration/lib/open_project/gitlab_integration/notification_handler/merge_request_hook.rb
@@ -48,7 +48,9 @@ module OpenProject::GitlabIntegration
return unless (accepted_actions.include? payload.object_attributes.action) || (accepted_states.include? payload.object_attributes.state)
user = User.find_by_id(payload.open_project_user_id)
- text = payload.object_attributes.title + " - " + payload.object_attributes.description
+ text = [payload.object_attributes.title, payload.object_attributes.description]
+ .select(&:present?)
+ .join(" - ")
work_packages = find_mentioned_work_packages(text, user)
notes = generate_notes(payload)
diff --git a/modules/gitlab_integration/spec/lib/open_project/gitlab_integration/notification_handler/merge_request_hook_spec.rb b/modules/gitlab_integration/spec/lib/open_project/gitlab_integration/notification_handler/merge_request_hook_spec.rb
index 93ee37967e3..7d7842c07a1 100644
--- a/modules/gitlab_integration/spec/lib/open_project/gitlab_integration/notification_handler/merge_request_hook_spec.rb
+++ b/modules/gitlab_integration/spec/lib/open_project/gitlab_integration/notification_handler/merge_request_hook_spec.rb
@@ -105,6 +105,21 @@ RSpec.describe OpenProject::GitlabIntegration::NotificationHandler::MergeRequest
comment
)
end
+
+ context "when no description is given in the payload" do
+ before do
+ payload["object_attributes"]["description"] = nil
+ end
+
+ it "does not raise (Bugfix)" do
+ process
+ expect(handler_instance).to have_received(:comment_on_referenced_work_packages).with(
+ [],
+ gitlab_system_user,
+ comment
+ )
+ end
+ end
end
shared_examples_for "calls the merge request upsert service" do