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

Bug - Lack of issues referenced in gitlab tab

Ben Tey54cfe5dd4931
diff --git a/README.md b/README.md
index 0a497bf5b5d..3c3aeb5010a 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-## Introducing OpenProject GitLab Integration v2.1.1 GA
+## Introducing OpenProject GitLab Integration v2.1.2 GA
Based on the OpenProject Github Integration, this plugin offers the same functionalities plus other new features. This is the first version that includes the visualization of the status of the *Pipelines* (by now, it is considered in Beta status). You can test it by activating the Pipelines event in the GitLab webhook. Just keep in mind that not all pipelines will be reflected in OpenProject, only Merge Request type pipelines (for more information see the GitLab issue https://gitlab.com/gitlab-org/gitlab/-/issues/345028). Any feedback about the pipelines feature would be very appreciated, whether it works or if issues arise (you can use this ticket https://github.com/btey/openproject-gitlab-integration/issues/43).
@@ -159,7 +159,7 @@ Add the following in **Gemfile.lock**:
PATH
remote: modules/gitlab_integration
specs:
- openproject-gitlab_integration (2.1.1)
+ openproject-gitlab_integration (2.1.2)
openproject-webhooks
```
diff --git a/lib/open_project/gitlab_integration/notification_handler/note_hook.rb b/lib/open_project/gitlab_integration/notification_handler/note_hook.rb
index 0964aee7eec..b8770ad87d9 100644
--- a/lib/open_project/gitlab_integration/notification_handler/note_hook.rb
+++ b/lib/open_project/gitlab_integration/notification_handler/note_hook.rb
@@ -65,6 +65,9 @@ module OpenProject::GitlabIntegration
notes = generate_notes(payload, 'reference')
end
comment_on_referenced_work_packages(work_packages, user, notes)
+ if payload.object_attributes.noteable_type == 'Issue'
+ upsert_issue(work_packages)
+ end
end
private
@@ -141,6 +144,19 @@ module OpenProject::GitlabIntegration
return nil
end
end
+
+ def gitlab_issue
+ @gitlab_issue ||= GitlabIssue
+ .where(gitlab_id: payload.issue.iid)
+ .or(GitlabIssue.where(gitlab_html_url: payload.issue.url))
+ .take
+ end
+
+ def upsert_issue(work_packages)
+ return if work_packages.empty? && gitlab_issue.nil?
+ OpenProject::GitlabIntegration::Services::UpsertIssueNote.new.call(payload,
+ work_packages: work_packages)
+ end
end
end
end
\ No newline at end of file
diff --git a/lib/open_project/gitlab_integration/services/upsert_gitlab_user.rb b/lib/open_project/gitlab_integration/services/upsert_gitlab_user.rb
index fcc9bea5543..23c2531d316 100644
--- a/lib/open_project/gitlab_integration/services/upsert_gitlab_user.rb
+++ b/lib/open_project/gitlab_integration/services/upsert_gitlab_user.rb
@@ -2,7 +2,7 @@
#-- copyright
# OpenProject is an open source project management software.
-# Copyright (C) 2012-2021 the OpenProject GmbH
+# Copyright (C) 2023 Ben Tey
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
@@ -10,6 +10,7 @@
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
+# Copyright (C) 2012-2021 the OpenProject GmbH
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
diff --git a/lib/open_project/gitlab_integration/services/upsert_issue.rb b/lib/open_project/gitlab_integration/services/upsert_issue.rb
index 969db32a786..f222ab385d2 100644
--- a/lib/open_project/gitlab_integration/services/upsert_issue.rb
+++ b/lib/open_project/gitlab_integration/services/upsert_issue.rb
@@ -2,7 +2,7 @@
#-- copyright
# OpenProject is an open source project management software.
-# Copyright (C) 2012-2021 the OpenProject GmbH
+# Copyright (C) 2023 Ben Tey
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
@@ -10,6 +10,7 @@
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
+# Copyright (C) 2012-2021 the OpenProject GmbH
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -30,12 +31,7 @@
module OpenProject
module GitlabIntegration
module Services
- ##
- # Takes merge request data coming from Gitlab webhook data and stores
- # them as a `GitlabMergeRequest`.
- # If the `GitlabMergeRequest` already exists, it is updated.
- #
- # Returns the upserted `GitlabMergeRequest`.
+
class UpsertIssue
def call(payload, work_packages: [])
find_or_initialize(payload).tap do |issue|
diff --git a/lib/open_project/gitlab_integration/services/upsert_issue_note.rb b/lib/open_project/gitlab_integration/services/upsert_issue_note.rb
new file mode 100644
index 00000000000..72cb4400253
--- /dev/null
+++ b/lib/open_project/gitlab_integration/services/upsert_issue_note.rb
@@ -0,0 +1,88 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2023 Ben Tey
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+# Copyright (C) 2012-2021 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See docs/COPYRIGHT.rdoc for more details.
+#++
+module OpenProject
+ module GitlabIntegration
+ module Services
+
+ class UpsertIssueNote
+ def call(payload, work_packages: [])
+ find_or_initialize(payload).tap do |issue|
+ issue.update!(work_packages: issue.work_packages | work_packages, **extract_params(payload))
+ end
+ end
+
+ private
+
+ def find_or_initialize(payload)
+ GitlabIssue.find_by_gitlab_identifiers(id: payload.issue.iid,
+ url: payload.issue.url,
+ initialize: true)
+ end
+
+ # Receives the input from the gitlab webhook and translates them
+ # to our internal representation.
+ # rubocop:disable Metrics/AbcSize
+ def extract_params(payload)
+ {
+ gitlab_id: payload.issue.iid,
+ gitlab_user: gitlab_user_id(payload.user),
+ number: payload.issue.iid,
+ gitlab_html_url: payload.issue.url,
+ gitlab_updated_at: payload.issue.updated_at,
+ state: payload.issue.state,
+ title: payload.issue.title,
+ body: description(payload),
+ repository: payload.repository.name,
+ labels: payload.issue.labels.map { |values| extract_label_values(values) }
+ }
+ end
+ # rubocop:enable Metrics/AbcSize
+
+ def extract_label_values(payload)
+ {
+ title: payload['title'],
+ color: payload['color']
+ }
+ end
+
+ def gitlab_user_id(payload)
+ return if payload.blank?
+
+ ::OpenProject::GitlabIntegration::Services::UpsertGitlabUser.new.call(payload)
+ end
+
+ def description(payload)
+ payload.object_attributes.description.presence || 'No description provided'
+ end
+ end
+ end
+ end
+end
diff --git a/lib/open_project/gitlab_integration/services/upsert_merge_request.rb b/lib/open_project/gitlab_integration/services/upsert_merge_request.rb
index a81176a269b..cec74aaa6ef 100644
--- a/lib/open_project/gitlab_integration/services/upsert_merge_request.rb
+++ b/lib/open_project/gitlab_integration/services/upsert_merge_request.rb
@@ -2,7 +2,7 @@
#-- copyright
# OpenProject is an open source project management software.
-# Copyright (C) 2012-2021 the OpenProject GmbH
+# Copyright (C) 2023 Ben Tey
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
@@ -10,6 +10,7 @@
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
+# Copyright (C) 2012-2021 the OpenProject GmbH
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -30,12 +31,7 @@
module OpenProject
module GitlabIntegration
module Services
- ##
- # Takes merge request data coming from Gitlab webhook data and stores
- # them as a `GitlabMergeRequest`.
- # If the `GitlabMergeRequest` already exists, it is updated.
- #
- # Returns the upserted `GitlabMergeRequest`.
+
class UpsertMergeRequest
def call(payload, work_packages: [])
find_or_initialize(payload).tap do |mr|
diff --git a/lib/open_project/gitlab_integration/services/upsert_pipeline.rb b/lib/open_project/gitlab_integration/services/upsert_pipeline.rb
index ed91fce2190..859d74070a5 100644
--- a/lib/open_project/gitlab_integration/services/upsert_pipeline.rb
+++ b/lib/open_project/gitlab_integration/services/upsert_pipeline.rb
@@ -1,8 +1,8 @@
-#-- encoding: UTF-8
+# frozen_string_literal: true
#-- copyright
# OpenProject is an open source project management software.
-# Copyright (C) 2012-2021 the OpenProject GmbH
+# Copyright (C) 2023 Ben Tey
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
@@ -10,6 +10,7 @@
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
+# Copyright (C) 2012-2021 the OpenProject GmbH
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -25,42 +26,41 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
-# See COPYRIGHT and LICENSE files for more details.
+# See docs/COPYRIGHT.rdoc for more details.
#++
-module OpenProject::GitlabIntegration::Services
- ##
- # Takes pipelines CI data coming from Gitlab webhook data and stores
- # them as a `GitlabPipeline`.
- # If the `GitlabPipeline` already exists, it is updated.
- #
- # Returns the upserted `GitlabPipeline`.
- class UpsertPipeline
- def call(payload, merge_request:)
- GitlabPipeline.find_or_initialize_by(gitlab_id: payload.object_attributes.iid)
- .tap do |pipeline|
- pipeline.update!(gitlab_merge_request: merge_request, **extract_params(payload))
- end
- end
+module OpenProject
+ module GitlabIntegration
+ module Services
+
+ class UpsertPipeline
+ def call(payload, merge_request:)
+ GitlabPipeline.find_or_initialize_by(gitlab_id: payload.object_attributes.iid)
+ .tap do |pipeline|
+ pipeline.update!(gitlab_merge_request: merge_request, **extract_params(payload))
+ end
+ end
- private
+ private
- # Receives the input from the gitlab webhook and translates them
- # to our internal representation.
- def extract_params(payload)
- {
- gitlab_id: payload.object_attributes.iid,
- gitlab_html_url: "#{payload.project.web_url}/-/pipelines/#{payload.object_attributes.iid}",
- project_id: payload.project.id,
- gitlab_user_avatar_url: payload.user.avatar_url,
- name: payload.object_attributes.iid,
- status: payload.object_attributes.status,
- details_url: "#{payload.project.web_url}/-/commit/#{payload.object_attributes.sha[0..7]}",
- commit_id: payload.object_attributes.sha[0..7],
- username: payload.user.name,
- ci_details: payload.builds,
- started_at: payload.object_attributes.created_at,
- completed_at: payload.object_attributes.finished_at
- }
+ # Receives the input from the gitlab webhook and translates them
+ # to our internal representation.
+ def extract_params(payload)
+ {
+ gitlab_id: payload.object_attributes.iid,
+ gitlab_html_url: "#{payload.project.web_url}/-/pipelines/#{payload.object_attributes.iid}",
+ project_id: payload.project.id,
+ gitlab_user_avatar_url: payload.user.avatar_url,
+ name: payload.object_attributes.iid,
+ status: payload.object_attributes.status,
+ details_url: "#{payload.project.web_url}/-/commit/#{payload.object_attributes.sha[0..7]}",
+ commit_id: payload.object_attributes.sha[0..7],
+ username: payload.user.name,
+ ci_details: payload.builds,
+ started_at: payload.object_attributes.created_at,
+ completed_at: payload.object_attributes.finished_at
+ }
+ end
+ end
end
end
end
\ No newline at end of file
diff --git a/openproject-gitlab_integration.gemspec b/openproject-gitlab_integration.gemspec
index 9c4abf49d3a..b72ec5075fd 100644
--- a/openproject-gitlab_integration.gemspec
+++ b/openproject-gitlab_integration.gemspec
@@ -32,7 +32,7 @@
Gem::Specification.new do |s|
s.name = 'openproject-gitlab_integration'
- s.version = '2.1.1'
+ s.version = '2.1.2'
s.authors = 'Ben Tey'
s.email = '[email protected]'
s.homepage = 'https://github.com/btey/openproject-gitlab-integration'