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

refactoring

Aleksey Kurepinf38ef6fb8549
diff --git a/README.md b/README.md
index a39be3e20d4..3ccbc0e9ccd 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-## Introducing OpenProject GitLab Integration v2.1.4 GA
+## Introducing OpenProject GitLab Integration v2.1.5 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.4)
+ openproject-gitlab_integration (2.1.5)
openproject-webhooks
```
diff --git a/config/locales/crowdin/js-ru.yml b/config/locales/crowdin/js-ru.yml
index 9e612d36e9e..e1877b52534 100644
--- a/config/locales/crowdin/js-ru.yml
+++ b/config/locales/crowdin/js-ru.yml
@@ -39,18 +39,18 @@ ru:
label: Создать запрос на слияние
description: Создать запрос на слияние
copy_menu:
- label: Git-сниппеты
- description: Скопипастить Git-сниппеты
+ label: Git-подсказки
+ description: Скопипастить Git-подсказки
git_actions:
branch_name: Имя ветки
commit_message: Описание коммита
cmd: Создать ветку с пустым коммитом
- title: Быстрые сниппеты для Git
+ title: Git-подсказки
copy_success: ✅ Скопировано
copy_error: ❌ Не получилось скопировать
tab_issue:
empty: Нет связанных обсуждений. Привязать обсуждение можно путём вставки кода <code>OP#%{wp_id}</code> (или <code>PP#%{wp_id}</code> для приватных ссылок) в заголовке/описании при создании/редактировании обсуждения.
tab_mrs:
- empty: Нет связанных запросов на слияние. Привязать запрос на слияние можно путём вставки кода <code>OP#%{wp_id}</code> (или <code>PP#%{wp_id}</code> для приватных ссылок) в заголовке/описании при создании/редактировании запроса на слияние. ОБЯЗАТЕЛЬНО заполните описание!
+ empty: Нет связанных запросов на слияние. Привязать запрос на слияние можно путём вставки кода <code>OP#%{wp_id}</code> (или <code>PP#%{wp_id}</code> для приватных ссылок) в заголовке/описании при создании/редактировании запроса на слияние.
gitlab_pipelines: Сборочные линии (pipelines)
updated_on: Обновлено
diff --git a/config/locales/crowdin/ru.yml b/config/locales/crowdin/ru.yml
index 3da85dbd810..829c50e3fcb 100644
--- a/config/locales/crowdin/ru.yml
+++ b/config/locales/crowdin/ru.yml
@@ -82,7 +82,7 @@ ru:
**Обсуждение переоткрыто:** Обсуждение %{issue_number} [%{issue_title}](%{issue_url}) в [%{repository}](%{repository_url})
было переоткрыто [%{gitlab_user}](%{gitlab_user_url}).
push_single_commit_comment: >
- **Коммит в MR:** [%{gitlab_user}](%{gitlab_user_url}) закоммитил [%{commit_number}](%{commit_url})
+ **Коммит:** [%{gitlab_user}](%{gitlab_user_url}) закоммитил [%{commit_number}](%{commit_url})
в [%{repository}](%{repository_url}) %{commit_timestamp}:
%{commit_note}
diff --git a/lib/api/v3/gitlab_issues/gitlab_issues_by_work_package_api.rb b/lib/api/v3/gitlab_issues/gitlab_issues_by_work_package_api.rb
index ab59f2b1c94..7604173b406 100644
--- a/lib/api/v3/gitlab_issues/gitlab_issues_by_work_package_api.rb
+++ b/lib/api/v3/gitlab_issues/gitlab_issues_by_work_package_api.rb
@@ -42,9 +42,9 @@ module API
get do
path = api_v3_paths.gitlab_issues_by_work_package(@work_package.id)
GitlabIssueCollectionRepresenter.new(@gitlab_issues,
- @gitlab_issues.count,
- self_link: path,
- current_user: current_user)
+ @gitlab_issues.count,
+ self_link: path,
+ current_user:)
end
end
end
diff --git a/lib/api/v3/gitlab_merge_requests/gitlab_merge_requests_by_work_package_api.rb b/lib/api/v3/gitlab_merge_requests/gitlab_merge_requests_by_work_package_api.rb
index a2de4eacdbe..8627ba32071 100644
--- a/lib/api/v3/gitlab_merge_requests/gitlab_merge_requests_by_work_package_api.rb
+++ b/lib/api/v3/gitlab_merge_requests/gitlab_merge_requests_by_work_package_api.rb
@@ -44,7 +44,7 @@ module API
GitlabMergeRequestCollectionRepresenter.new(@gitlab_merge_requests,
@gitlab_merge_requests.count,
self_link: path,
- current_user: current_user)
+ current_user:)
end
end
end
diff --git a/lib/open_project/gitlab_integration/engine.rb b/lib/open_project/gitlab_integration/engine.rb
index 752d2cb42c0..ce1cc92baf8 100644
--- a/lib/open_project/gitlab_integration/engine.rb
+++ b/lib/open_project/gitlab_integration/engine.rb
@@ -93,7 +93,7 @@ module OpenProject::GitlabIntegration
add_api_endpoint 'API::V3::WorkPackages::WorkPackagesAPI', :id do
mount ::API::V3::GitlabMergeRequests::GitlabMergeRequestsByWorkPackageAPI
end
-
+
add_api_endpoint 'API::V3::WorkPackages::WorkPackagesAPI', :id do
mount ::API::V3::GitlabIssues::GitlabIssuesByWorkPackageAPI
end
diff --git a/lib/open_project/gitlab_integration/notification_handler/helper.rb b/lib/open_project/gitlab_integration/notification_handler/helper.rb
index 7f9a0eed503..cf715d0bb69 100644
--- a/lib/open_project/gitlab_integration/notification_handler/helper.rb
+++ b/lib/open_project/gitlab_integration/notification_handler/helper.rb
@@ -30,7 +30,6 @@
module OpenProject::GitlabIntegration
module NotificationHandler
module Helper
-
##
# Parses the given source string and returns a list of work_package ids
# which it finds and should be considered public or private.
@@ -49,13 +48,13 @@ module OpenProject::GitlabIntegration
# e.g.,: This is a reference to OP#1234
# For private comments you can use the prefix: PP#
host_name = Regexp.escape(Setting.host_name)
- if kind == 'private'
- wp_regex = /PP#(\d+)/
- elsif kind != 'note'
- wp_regex = /OP#(\d+)|PP#(\d+)|http(?:s?):\/\/#{host_name}\/(?:\S+?\/)*(?:work_packages|wp)\/([0-9]+)/
- else
- wp_regex = /OP#(\d+)|http(?:s?):\/\/#{host_name}\/(?:\S+?\/)*(?:work_packages|wp)\/([0-9]+)/
- end
+ wp_regex = if kind == 'private'
+ /PP#(\d+)/
+ elsif kind != 'note'
+ /OP#(\d+)|PP#(\d+)|http(?:s?):\/\/#{host_name}\/(?:\S+?\/)*(?:work_packages|wp)\/([0-9]+)/
+ else
+ /OP#(\d+)|http(?:s?):\/\/#{host_name}\/(?:\S+?\/)*(?:work_packages|wp)\/([0-9]+)/
+ end
String(text)
.scan(wp_regex)
.map { |first, second| (first || second).to_i }
@@ -92,9 +91,10 @@ module OpenProject::GitlabIntegration
# Adds comments to the given WorkPackages.
def comment_on_referenced_work_packages(work_packages, user, notes)
return if notes.nil?
+
work_packages.each do |work_package|
::WorkPackages::UpdateService
- .new(user: user, model: work_package)
+ .new(user:, model: work_package)
.call(journal_notes: notes, send_notifications: false)
end
end
@@ -104,7 +104,7 @@ module OpenProject::GitlabIntegration
def status_on_referenced_work_packages(work_packages, user, status)
work_packages.each do |work_package|
::WorkPackages::UpdateService
- .new(user: user, model: work_package)
+ .new(user:, model: work_package)
.call(status_id: status)
end
end
@@ -145,7 +145,6 @@ module OpenProject::GitlabIntegration
def wrap_payload(payload)
Payload.new(payload)
end
-
end
end
-end
\ No newline at end of file
+end
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 b8770ad87d9..3bffd268341 100644
--- a/lib/open_project/gitlab_integration/notification_handler/note_hook.rb
+++ b/lib/open_project/gitlab_integration/notification_handler/note_hook.rb
@@ -33,33 +33,36 @@ module OpenProject::GitlabIntegration
# Handles Gitlab comment notifications.
class NoteHook
include OpenProject::GitlabIntegration::NotificationHandler::Helper
-
+
# TODO: this can be more refactored and simplified...
def process(payload_params)
@payload = wrap_payload(payload_params)
- user = User.find_by_id(payload.open_project_user_id)
+ user = User.find_by(id: payload.open_project_user_id)
text = payload.object_attributes.note
work_packages = find_mentioned_work_packages(text, user, payload.object_kind)
if work_packages.empty? && payload.object_attributes.noteable_type == 'Issue'
- text = payload.issue.title + ' - ' + payload.object_attributes.note
+ text = "#{payload.issue.title} - #{payload.object_attributes.note}"
work_packages = find_mentioned_work_packages(text, user, payload.object_kind)
work_packages_excluded = find_excluded_work_packages(text, user)
work_packages = work_packages - work_packages_excluded unless work_packages_excluded.empty?
return if work_packages.empty?
+
notes = generate_notes(payload, 'comment')
elsif work_packages.empty? && payload.object_attributes.noteable_type == 'Snippet'
- text = payload.snippet.title + ' - ' + payload.object_attributes.note
+ text = "#{payload.snippet.title} - #{payload.object_attributes.note}"
work_packages = find_mentioned_work_packages(text, user, payload.object_kind)
work_packages_excluded = find_excluded_work_packages(text, user)
work_packages = work_packages - work_packages_excluded unless work_packages_excluded.empty?
return if work_packages.empty?
+
notes = generate_notes(payload, 'reference')
elsif work_packages.empty? && payload.object_attributes.noteable_type == 'MergeRequest'
- text = payload.merge_request.title + ' - ' + payload.object_attributes.note
+ text = "#{payload.merge_request.title} - #{payload.object_attributes.note}"
work_packages = find_mentioned_work_packages(text, user, payload.object_kind)
work_packages_excluded = find_excluded_work_packages(text, user)
work_packages = work_packages - work_packages_excluded unless work_packages_excluded.empty?
return if work_packages.empty?
+
notes = generate_notes(payload, 'comment')
else
notes = generate_notes(payload, 'reference')
@@ -76,72 +79,71 @@ module OpenProject::GitlabIntegration
# TODO: add key list to simplify the code...
def generate_notes(payload, note_type)
- if payload.object_attributes.noteable_type == 'Commit'
+ case payload.object_attributes.noteable_type
+ when 'Commit'
commit_id = payload.commit.id
I18n.t("gitlab_integration.note_commit_referenced_comment",
- :commit_id => commit_id[0, 8],
- :commit_url => payload.object_attributes.url,
- :commit_note => payload.object_attributes.note,
- :repository => payload.repository.name,
- :repository_url => payload.repository.homepage,
- :gitlab_user => payload.user.name,
- :gitlab_user_url => payload.user.avatar_url)
- elsif payload.object_attributes.noteable_type == 'MergeRequest'
+ commit_id: commit_id[0, 8],
+ commit_url: payload.object_attributes.url,
+ commit_note: payload.object_attributes.note,
+ repository: payload.repository.name,
+ repository_url: payload.repository.homepage,
+ gitlab_user: payload.user.name,
+ gitlab_user_url: payload.user.avatar_url)
+ when 'MergeRequest'
if note_type == 'comment'
I18n.t("gitlab_integration.note_mr_commented_comment",
- :mr_number => payload.merge_request.iid,
- :mr_title => payload.merge_request.title,
- :mr_url => payload.object_attributes.url,
- :mr_note => payload.object_attributes.note,
- :repository => payload.repository.name,
- :repository_url => payload.repository.homepage,
- :gitlab_user => payload.user.name,
- :gitlab_user_url => payload.user.avatar_url)
+ mr_number: payload.merge_request.iid,
+ mr_title: payload.merge_request.title,
+ mr_url: payload.object_attributes.url,
+ mr_note: payload.object_attributes.note,
+ repository: payload.repository.name,
+ repository_url: payload.repository.homepage,
+ gitlab_user: payload.user.name,
+ gitlab_user_url: payload.user.avatar_url)
elsif note_type == 'reference'
I18n.t("gitlab_integration.note_mr_referenced_comment",
- :mr_number => payload.merge_request.iid,
- :mr_title => payload.merge_request.title,
- :mr_url => payload.object_attributes.url,
- :mr_note => payload.object_attributes.note,
- :repository => payload.repository.name,
- :repository_url => payload.repository.homepage,
- :gitlab_user => payload.user.name,
- :gitlab_user_url => payload.user.avatar_url)
+ mr_number: payload.merge_request.iid,
+ mr_title: payload.merge_request.title,
+ mr_url: payload.object_attributes.url,
+ mr_note: payload.object_attributes.note,
+ repository: payload.repository.name,
+ repository_url: payload.repository.homepage,
+ gitlab_user: payload.user.name,
+ gitlab_user_url: payload.user.avatar_url)
end
- elsif payload.object_attributes.noteable_type == 'Issue'
+ when 'Issue'
if note_type == 'comment'
I18n.t("gitlab_integration.note_issue_commented_comment",
- :issue_number => payload.issue.iid,
- :issue_title => payload.issue.title,
- :issue_url => payload.object_attributes.url,
- :issue_note => payload.object_attributes.note,
- :repository => payload.repository.name,
- :repository_url => payload.repository.homepage,
- :gitlab_user => payload.user.name,
- :gitlab_user_url => payload.user.avatar_url)
+ issue_number: payload.issue.iid,
+ issue_title: payload.issue.title,
+ issue_url: payload.object_attributes.url,
+ issue_note: payload.object_attributes.note,
+ repository: payload.repository.name,
+ repository_url: payload.repository.homepage,
+ gitlab_user: payload.user.name,
+ gitlab_user_url: payload.user.avatar_url)
elsif note_type == 'reference'
I18n.t("gitlab_integration.note_issue_referenced_comment",
- :issue_number => payload.issue.iid,
- :issue_title => payload.issue.title,
- :issue_url => payload.object_attributes.url,
- :issue_note => payload.object_attributes.note,
- :repository => payload.repository.name,
- :repository_url => payload.repository.homepage,
- :gitlab_user => payload.user.name,
- :gitlab_user_url => payload.user.avatar_url)
+ issue_number: payload.issue.iid,
+ issue_title: payload.issue.title,
+ issue_url: payload.object_attributes.url,
+ issue_note: payload.object_attributes.note,
+ repository: payload.repository.name,
+ repository_url: payload.repository.homepage,
+ gitlab_user: payload.user.name,
+ gitlab_user_url: payload.user.avatar_url)
end
- elsif payload.object_attributes.noteable_type == 'Snippet'
+ when 'Snippet'
I18n.t("gitlab_integration.note_snippet_referenced_comment",
- :snippet_number => payload.snippet.id,
- :snippet_title => payload.snippet.title,
- :snippet_url => payload.object_attributes.url,
- :snippet_note => payload.object_attributes.note,
- :repository => payload.repository.name,
- :repository_url => payload.repository.homepage,
- :gitlab_user => payload.user.name,
- :gitlab_user_url => payload.user.avatar_url)
- else
- return nil
+ snippet_number: payload.snippet.id,
+ snippet_title: payload.snippet.title,
+ snippet_url: payload.object_attributes.url,
+ snippet_note: payload.object_attributes.note,
+ repository: payload.repository.name,
+ repository_url: payload.repository.homepage,
+ gitlab_user: payload.user.name,
+ gitlab_user_url: payload.user.avatar_url)
end
end
@@ -154,9 +156,10 @@ module OpenProject::GitlabIntegration
def upsert_issue(work_packages)
return if work_packages.empty? && gitlab_issue.nil?
+
OpenProject::GitlabIntegration::Services::UpsertIssueNote.new.call(payload,
- work_packages: work_packages)
+ work_packages:)
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/open_project/gitlab_integration/notification_handler/pipeline_hook.rb b/lib/open_project/gitlab_integration/notification_handler/pipeline_hook.rb
index 1c14b01fb17..c591e18957a 100644
--- a/lib/open_project/gitlab_integration/notification_handler/pipeline_hook.rb
+++ b/lib/open_project/gitlab_integration/notification_handler/pipeline_hook.rb
@@ -37,14 +37,16 @@ module OpenProject::GitlabIntegration
def process(payload_params)
@payload = wrap_payload(payload_params)
- return unless associated_with_mr?
+ return if payload.merge_request.blank?
+
merge_request = find_merge_request
return unless merge_request
+ return unless associated_with_mr?
# disabled until gitlab issue resolution
OpenProject::GitlabIntegration::Services::UpsertPipeline.new.call(
payload,
- merge_request: merge_request
+ merge_request:
)
end
@@ -53,12 +55,12 @@ module OpenProject::GitlabIntegration
attr_reader :payload
def associated_with_mr?
- payload.merge_request.iid?.present?
+ payload.merge_request.iid.present?
end
def find_merge_request
gitlab_id = payload.merge_request.iid
- GitlabMergeRequest.find_by(gitlab_id: gitlab_id)
+ GitlabMergeRequest.find_by(gitlab_id:)
end
end
end
diff --git a/lib/open_project/gitlab_integration/patches/api/work_package_representer.rb b/lib/open_project/gitlab_integration/patches/api/work_package_representer.rb
index e16f17e6a1f..a83a247e96f 100644
--- a/lib/open_project/gitlab_integration/patches/api/work_package_representer.rb
+++ b/lib/open_project/gitlab_integration/patches/api/work_package_representer.rb
@@ -32,7 +32,7 @@ module OpenProject::GitlabIntegration
module WorkPackageRepresenter
module_function
- def extension
+ def extension # rubocop:disable Metrics/AbcSize
->(*) do
link :gitlab,
cache_if: -> { current_user.allowed_in_work_package?(:show_gitlab_content, represented) } do
diff --git a/lib/open_project/gitlab_integration/services.rb b/lib/open_project/gitlab_integration/services.rb
index adce1030509..288dc428154 100644
--- a/lib/open_project/gitlab_integration/services.rb
+++ b/lib/open_project/gitlab_integration/services.rb
@@ -27,6 +27,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
+require_relative './services/params_helper'
require_relative './services/upsert_pipeline'
require_relative './services/upsert_gitlab_user'
require_relative './services/upsert_merge_request'
diff --git a/lib/open_project/gitlab_integration/services/params_helper.rb b/lib/open_project/gitlab_integration/services/params_helper.rb
new file mode 100644
index 00000000000..ef7a9355c03
--- /dev/null
+++ b/lib/open_project/gitlab_integration/services/params_helper.rb
@@ -0,0 +1,50 @@
+# 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
+ module ParamsHelper
+ private
+
+ EMPTY_AVATAR_URL = 'https://www.gravatar.com/avatar/?d=mp'
+ EMPTY_DESCRIPTION = 'No description provided'
+
+ def avatar_url(raw_url)
+ raw_url.presence || EMPTY_AVATAR_URL
+ end
+
+ def description(raw_description)
+ raw_description.presence || EMPTY_DESCRIPTION
+ end
+ end
+ end
+ end
+end
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 23c2531d316..e9f70e340e4 100644
--- a/lib/open_project/gitlab_integration/services/upsert_gitlab_user.rb
+++ b/lib/open_project/gitlab_integration/services/upsert_gitlab_user.rb
@@ -38,6 +38,8 @@ module OpenProject
#
# Returns the upserted `GitlabUser`.
class UpsertGitlabUser
+ include ParamsHelper
+
def call(payload)
GitlabUser.find_or_initialize_by(gitlab_id: payload.id)
.tap do |gitlab_user|
@@ -56,13 +58,9 @@ module OpenProject
gitlab_name: payload.name,
gitlab_username: payload.username,
gitlab_email: payload.email,
- gitlab_avatar_url: avatar_url(payload)
+ gitlab_avatar_url: avatar_url(payload.avatar_url)
}
end
-
- def avatar_url(payload)
- payload.avatar_url.presence || 'https://www.gravatar.com/avatar/?d=mp'
- end
end
end
end
diff --git a/lib/open_project/gitlab_integration/services/upsert_issue.rb b/lib/open_project/gitlab_integration/services/upsert_issue.rb
index f222ab385d2..6eb2298d5f9 100644
--- a/lib/open_project/gitlab_integration/services/upsert_issue.rb
+++ b/lib/open_project/gitlab_integration/services/upsert_issue.rb
@@ -31,8 +31,9 @@
module OpenProject
module GitlabIntegration
module Services
-
class UpsertIssue
+ include ParamsHelper
+
def call(payload, work_packages: [])
find_or_initialize(payload).tap do |issue|
issue.update!(work_packages: issue.work_packages | work_packages, **extract_params(payload))
@@ -59,7 +60,7 @@ module OpenProject
gitlab_updated_at: payload.object_attributes.updated_at,
state: payload.object_attributes.state,
title: payload.object_attributes.title,
- body: description(payload),
+ body: description(payload.object_attributes.description),
repository: payload.repository.name,
labels: payload.labels.map { |values| extract_label_values(values) }
}
@@ -78,10 +79,6 @@ module OpenProject
::OpenProject::GitlabIntegration::Services::UpsertGitlabUser.new.call(payload)
end
-
- def description(payload)
- payload.object_attributes.description.presence || 'No description provided'
- end
end
end
end
diff --git a/lib/open_project/gitlab_integration/services/upsert_issue_note.rb b/lib/open_project/gitlab_integration/services/upsert_issue_note.rb
index 72cb4400253..eb58b8e83e3 100644
--- a/lib/open_project/gitlab_integration/services/upsert_issue_note.rb
+++ b/lib/open_project/gitlab_integration/services/upsert_issue_note.rb
@@ -31,8 +31,9 @@
module OpenProject
module GitlabIntegration
module Services
-
class UpsertIssueNote
+ include ParamsHelper
+
def call(payload, work_packages: [])
find_or_initialize(payload).tap do |issue|
issue.update!(work_packages: issue.work_packages | work_packages, **extract_params(payload))
@@ -43,8 +44,8 @@ module OpenProject
def find_or_initialize(payload)
GitlabIssue.find_by_gitlab_identifiers(id: payload.issue.iid,
- url: payload.issue.url,
- initialize: true)
+ url: payload.issue.url,
+ initialize: true)
end
# Receives the input from the gitlab webhook and translates them
@@ -59,7 +60,7 @@ module OpenProject
gitlab_updated_at: payload.issue.updated_at,
state: payload.issue.state,
title: payload.issue.title,
- body: description(payload),
+ body: description(payload.object_attributes.description),
repository: payload.repository.name,
labels: payload.issue.labels.map { |values| extract_label_values(values) }
}
@@ -78,10 +79,6 @@ module OpenProject
::OpenProject::GitlabIntegration::Services::UpsertGitlabUser.new.call(payload)
end
-
- def description(payload)
- payload.object_attributes.description.presence || 'No description provided'
- 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 cec74aaa6ef..78c8c0ccfa0 100644
--- a/lib/open_project/gitlab_integration/services/upsert_merge_request.rb
+++ b/lib/open_project/gitlab_integration/services/upsert_merge_request.rb
@@ -31,8 +31,9 @@
module OpenProject
module GitlabIntegration
module Services
-
class UpsertMergeRequest
+ include ParamsHelper
+
def call(payload, work_packages: [])
find_or_initialize(payload).tap do |mr|
mr.update!(work_packages: mr.work_packages | work_packages, **extract_params(payload))
@@ -59,7 +60,7 @@ module OpenProject
gitlab_updated_at: payload.object_attributes.updated_at,
state: payload.object_attributes.state,
title: payload.object_attributes.title,
- body: description(payload),
+ body: description(payload.object_attributes.description),
repository: payload.repository.name,
draft: payload.object_attributes.work_in_progress,
merged: payload.object_attributes.state == 'merged',
@@ -82,10 +83,6 @@ module OpenProject
::OpenProject::GitlabIntegration::Services::UpsertGitlabUser.new.call(payload)
end
-
- def description(payload)
- payload.object_attributes.description.presence || 'No description provided'
- end
end
end
end
diff --git a/lib/open_project/gitlab_integration/services/upsert_pipeline.rb b/lib/open_project/gitlab_integration/services/upsert_pipeline.rb
index 859d74070a5..0fbdd9ecf7e 100644
--- a/lib/open_project/gitlab_integration/services/upsert_pipeline.rb
+++ b/lib/open_project/gitlab_integration/services/upsert_pipeline.rb
@@ -31,8 +31,9 @@
module OpenProject
module GitlabIntegration
module Services
-
class UpsertPipeline
+ include ParamsHelper
+
def call(payload, merge_request:)
GitlabPipeline.find_or_initialize_by(gitlab_id: payload.object_attributes.iid)
.tap do |pipeline|
@@ -49,7 +50,7 @@ module OpenProject
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,
+ gitlab_user_avatar_url: 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]}",
@@ -63,4 +64,4 @@ module OpenProject
end
end
end
-end
\ No newline at end of file
+end
diff --git a/openproject-gitlab_integration.gemspec b/openproject-gitlab_integration.gemspec
index d5fe6edce69..8acf7073c24 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.4'
+ s.version = '2.1.5'
s.authors = 'Ben Tey'
s.email = '[email protected]'
s.homepage = 'https://github.com/btey/openproject-gitlab-integration'