From f50a2a9a2b0bff60d285fb7d41feed2b9ace2fd8 Mon Sep 17 00:00:00 2001 From: Baodong Date: Wed, 3 Nov 2021 15:39:10 +0800 Subject: [PATCH 1/9] Add Shimo model Add integration of Shimo as external wiki. Changelog: added --- app/models/integration.rb | 2 +- app/models/integrations/shimo.rb | 47 ++++++++++++++++++++ app/models/project.rb | 3 +- doc/api/graphql/reference/index.md | 1 + lib/gitlab/integrations/sti_type.rb | 2 +- locale/gitlab.pot | 9 ++++ spec/factories/integrations.rb | 6 +++ spec/lib/gitlab/import_export/all_models.yml | 1 + spec/models/integrations/shimo_spec.rb | 41 +++++++++++++++++ 9 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 app/models/integrations/shimo.rb create mode 100644 spec/models/integrations/shimo_spec.rb diff --git a/app/models/integration.rb b/app/models/integration.rb index 4dd3e1a1785831..0a1f61fd540078 100644 --- a/app/models/integration.rb +++ b/app/models/integration.rb @@ -14,7 +14,7 @@ class Integration < ApplicationRecord asana assembla bamboo bugzilla buildkite campfire confluence custom_issue_tracker datadog discord drone_ci emails_on_push ewm external_wiki flowdock hangouts_chat irker jira mattermost mattermost_slash_commands microsoft_teams packagist pipelines_email - pivotaltracker prometheus pushover redmine slack slack_slash_commands teamcity unify_circuit webex_teams youtrack zentao + pivotaltracker prometheus pushover redmine shimo slack slack_slash_commands teamcity unify_circuit webex_teams youtrack zentao ].freeze PROJECT_SPECIFIC_INTEGRATION_NAMES = %w[ diff --git a/app/models/integrations/shimo.rb b/app/models/integrations/shimo.rb new file mode 100644 index 00000000000000..4f42fda257758e --- /dev/null +++ b/app/models/integrations/shimo.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +module Integrations + class Shimo < Integration + prop_accessor :external_wiki_url + validates :external_wiki_url, presence: true, public_url: true, if: :activated? + + def render? + valid? && activated? + end + + def title + s_('Shimo|Shimo') + end + + def description + s_('Shimo|Link to a Shimo Workspace from the sidebar.') + end + + def self.to_param + 'shimo' + end + + # support for `test` method + def execute(_data) + response = Gitlab::HTTP.get(properties['external_wiki_url'], verify: true, use_read_total_timeout: true) + response.body if response.code == 200 + rescue StandardError + nil + end + + def self.supported_events + %w() + end + + def fields + [ + { + type: 'text', + name: 'external_wiki_url', + title: s_('Shimo|Shimo Workspace URL'), + required: true + } + ] + end + end +end diff --git a/app/models/project.rb b/app/models/project.rb index f2c26f918069ee..f7f8ae1f77c074 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -189,6 +189,7 @@ def self.integration_association_name(name) has_one :prometheus_integration, class_name: 'Integrations::Prometheus', inverse_of: :project has_one :pushover_integration, class_name: 'Integrations::Pushover' has_one :redmine_integration, class_name: 'Integrations::Redmine' + has_one :shimo_integration, class_name: 'Integrations::Shimo' has_one :slack_integration, class_name: 'Integrations::Slack' has_one :slack_slash_commands_integration, class_name: 'Integrations::SlackSlashCommands' has_one :teamcity_integration, class_name: 'Integrations::Teamcity' @@ -1453,7 +1454,7 @@ def find_or_initialize_integrations end def disabled_integrations - [] + [:shimo] end def find_or_initialize_integration(name) diff --git a/doc/api/graphql/reference/index.md b/doc/api/graphql/reference/index.md index 4b09907b9a8747..0a835d7bbf77c8 100644 --- a/doc/api/graphql/reference/index.md +++ b/doc/api/graphql/reference/index.md @@ -16698,6 +16698,7 @@ State of a Sentry error. | `PROMETHEUS_SERVICE` | PrometheusService type. | | `PUSHOVER_SERVICE` | PushoverService type. | | `REDMINE_SERVICE` | RedmineService type. | +| `SHIMO_SERVICE` | ShimoService type. | | `SLACK_SERVICE` | SlackService type. | | `SLACK_SLASH_COMMANDS_SERVICE` | SlackSlashCommandsService type. | | `TEAMCITY_SERVICE` | TeamcityService type. | diff --git a/lib/gitlab/integrations/sti_type.rb b/lib/gitlab/integrations/sti_type.rb index 91797a7b99bcaf..1350d75b2169a0 100644 --- a/lib/gitlab/integrations/sti_type.rb +++ b/lib/gitlab/integrations/sti_type.rb @@ -7,7 +7,7 @@ class StiType < ActiveRecord::Type::String Asana Assembla Bamboo Bugzilla Buildkite Campfire Confluence CustomIssueTracker Datadog Discord DroneCi EmailsOnPush Ewm ExternalWiki Flowdock HangoutsChat Irker Jenkins Jira Mattermost MattermostSlashCommands MicrosoftTeams MockCi MockMonitoring Packagist PipelinesEmail Pivotaltracker - Prometheus Pushover Redmine Slack SlackSlashCommands Teamcity UnifyCircuit WebexTeams Youtrack Zentao + Prometheus Pushover Redmine Shimo Slack SlackSlashCommands Teamcity UnifyCircuit WebexTeams Youtrack Zentao )).freeze def self.namespaced_integrations diff --git a/locale/gitlab.pot b/locale/gitlab.pot index 766114b525521b..19da2e9b438b58 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -31638,6 +31638,15 @@ msgstr "" msgid "Sherlock Transactions" msgstr "" +msgid "Shimo|Link to a Shimo Workspace from the sidebar." +msgstr "" + +msgid "Shimo|Shimo" +msgstr "" + +msgid "Shimo|Shimo Workspace URL" +msgstr "" + msgid "Should you ever lose your phone or access to your one time password secret, each of these recovery codes can be used one time each to regain access to your account. Please save them in a safe place, or you %{boldStart}will%{boldEnd} lose access to your account." msgstr "" diff --git a/spec/factories/integrations.rb b/spec/factories/integrations.rb index 63f85c04ac7a6b..63a5fadb6a82a8 100644 --- a/spec/factories/integrations.rb +++ b/spec/factories/integrations.rb @@ -111,6 +111,12 @@ end end + factory :shimo_integration, class: 'Integrations::Shimo' do + project + active { true } + external_wiki_url { 'https://shimo.im/desktop' } + end + factory :confluence_integration, class: 'Integrations::Confluence' do project active { true } diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml index 95217b43d1397e..b474f5825fdf85 100644 --- a/spec/lib/gitlab/import_export/all_models.yml +++ b/spec/lib/gitlab/import_export/all_models.yml @@ -384,6 +384,7 @@ project: - emails_on_push_integration - pipelines_email_integration - mattermost_slash_commands_integration +- shimo_integration - slack_slash_commands_integration - irker_integration - packagist_integration diff --git a/spec/models/integrations/shimo_spec.rb b/spec/models/integrations/shimo_spec.rb new file mode 100644 index 00000000000000..17546d68bcf076 --- /dev/null +++ b/spec/models/integrations/shimo_spec.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe ::Integrations::Shimo do + describe '#fields' do + let(:shimo_integration) { create(:shimo_integration) } + + it 'returns custom fields' do + expect(shimo_integration.fields.pluck(:name)).to eq(%w[external_wiki_url]) + end + end + + describe '#create' do + let(:project) { create(:project, :repository) } + let(:external_wiki_url) { 'https://shimo.im/' } + let(:params) { { active: true, project: project, external_wiki_url: external_wiki_url } } + + context 'with valid params' do + it 'creates the Shimo integration' do + shimo = described_class.create!(params) + + expect(shimo.valid?).to be true + expect(shimo.render?).to be true + expect(shimo.external_wiki_url).to eq(external_wiki_url) + end + end + + context 'with invalid params' do + it 'cannot create the Shimo integration without external_wiki_url' do + params['external_wiki_url'] = nil + expect { described_class.create!(params) }.to raise_error(ActiveRecord::RecordInvalid) + end + + it 'cannot create the Shimo integration with invalid external_wiki_url' do + params['external_wiki_url'] = 'Fake Invalid URL' + expect { described_class.create!(params) }.to raise_error(ActiveRecord::RecordInvalid) + end + end + end +end -- GitLab From 7a179c84763e7b28e99dfbc34f110a68ab5b25e0 Mon Sep 17 00:00:00 2001 From: Baodong Date: Wed, 3 Nov 2021 18:00:21 +0800 Subject: [PATCH 2/9] Update integrations_helpers.rb --- lib/api/helpers/integrations_helpers.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/api/helpers/integrations_helpers.rb b/lib/api/helpers/integrations_helpers.rb index 7ae46abd0971c5..e7fdb6645a507f 100644 --- a/lib/api/helpers/integrations_helpers.rb +++ b/lib/api/helpers/integrations_helpers.rb @@ -530,6 +530,14 @@ def self.integrations desc: 'The Mattermost token' } ], + 'shimo' => [ + { + required: true, + name: :external_wiki_url, + type: String, + desc: 'Shimo workspace URL' + } + ], 'slack-slash-commands' => [ { required: true, -- GitLab From 124c1fc268a4a9db3b195ee2de10c06259912136 Mon Sep 17 00:00:00 2001 From: Baodong Date: Thu, 4 Nov 2021 09:21:31 +0800 Subject: [PATCH 3/9] Add Shimo metrics config --- .../20211028210001_projects_shimo_active.yml | 22 +++++++++++++++++++ .../20211028210002_groups_shimo_active.yml | 22 +++++++++++++++++++ .../20211028210003_instances_shimo_active.yml | 22 +++++++++++++++++++ ...10004_projects_inheriting_shimo_active.yml | 22 +++++++++++++++++++ ...8210005_groups_inheriting_shimo_active.yml | 22 +++++++++++++++++++ 5 files changed, 110 insertions(+) create mode 100644 config/metrics/counts_all/20211028210001_projects_shimo_active.yml create mode 100644 config/metrics/counts_all/20211028210002_groups_shimo_active.yml create mode 100644 config/metrics/counts_all/20211028210003_instances_shimo_active.yml create mode 100644 config/metrics/counts_all/20211028210004_projects_inheriting_shimo_active.yml create mode 100644 config/metrics/counts_all/20211028210005_groups_inheriting_shimo_active.yml diff --git a/config/metrics/counts_all/20211028210001_projects_shimo_active.yml b/config/metrics/counts_all/20211028210001_projects_shimo_active.yml new file mode 100644 index 00000000000000..5be51ba4cb2dd4 --- /dev/null +++ b/config/metrics/counts_all/20211028210001_projects_shimo_active.yml @@ -0,0 +1,22 @@ +--- +key_path: counts.projects_shimo_active +name: count_all_projects_shimo_active +description: Count of projects with active Shimo integrations +product_section: dev +product_stage: ecosystem +product_group: group::integrations +product_category: integrations +value_type: number +status: active +milestone: "14.5" +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/issues/343386 +time_frame: all +data_source: database +data_category: Operational +distribution: +- ce +- ee +tier: +- free +- premium +- ultimate diff --git a/config/metrics/counts_all/20211028210002_groups_shimo_active.yml b/config/metrics/counts_all/20211028210002_groups_shimo_active.yml new file mode 100644 index 00000000000000..f57deeae590d7f --- /dev/null +++ b/config/metrics/counts_all/20211028210002_groups_shimo_active.yml @@ -0,0 +1,22 @@ +--- +key_path: counts.groups_shimo_active +name: count_all_groups_shimo_active +description: Count of groups with active Shimo integrations +product_section: dev +product_stage: ecosystem +product_group: group::integrations +product_category: integrations +value_type: number +status: active +milestone: "14.5" +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/issues/343386 +time_frame: all +data_source: database +data_category: Operational +distribution: +- ce +- ee +tier: +- free +- premium +- ultimate diff --git a/config/metrics/counts_all/20211028210003_instances_shimo_active.yml b/config/metrics/counts_all/20211028210003_instances_shimo_active.yml new file mode 100644 index 00000000000000..7d1c6ea3706b75 --- /dev/null +++ b/config/metrics/counts_all/20211028210003_instances_shimo_active.yml @@ -0,0 +1,22 @@ +--- +key_path: counts.instances_shimo_active +name: count_all_instances_shimo_active +description: Count of instances with active Shimo integrations +product_section: dev +product_stage: ecosystem +product_group: group::integrations +product_category: integrations +value_type: number +status: active +milestone: "14.5" +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/issues/343386 +time_frame: all +data_source: database +data_category: Operational +distribution: +- ce +- ee +tier: +- free +- premium +- ultimate diff --git a/config/metrics/counts_all/20211028210004_projects_inheriting_shimo_active.yml b/config/metrics/counts_all/20211028210004_projects_inheriting_shimo_active.yml new file mode 100644 index 00000000000000..42f01ccff3a98d --- /dev/null +++ b/config/metrics/counts_all/20211028210004_projects_inheriting_shimo_active.yml @@ -0,0 +1,22 @@ +--- +key_path: counts.projects_inheriting_shimo_active +name: count_all_projects_inheriting_shimo_active +description: Count of projects that inherit active Shimo integrations +product_section: dev +product_stage: ecosystem +product_group: group::integrations +product_category: integrations +value_type: number +status: active +milestone: "14.5" +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/issues/343386 +time_frame: all +data_source: database +data_category: Operational +distribution: +- ce +- ee +tier: +- free +- premium +- ultimate diff --git a/config/metrics/counts_all/20211028210005_groups_inheriting_shimo_active.yml b/config/metrics/counts_all/20211028210005_groups_inheriting_shimo_active.yml new file mode 100644 index 00000000000000..6292ad0aaae431 --- /dev/null +++ b/config/metrics/counts_all/20211028210005_groups_inheriting_shimo_active.yml @@ -0,0 +1,22 @@ +--- +key_path: counts.groups_inheriting_shimo_active +name: count_all_groups_inheriting_shimo_active +description: Count of groups that inherit active Shimo integrations +product_section: dev +product_stage: ecosystem +product_group: group::integrations +product_category: integrations +value_type: number +status: active +milestone: "14.5" +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/issues/343386 +time_frame: all +data_source: database +data_category: Operational +distribution: +- ce +- ee +tier: +- free +- premium +- ultimate -- GitLab From 490c58191d727d07da08afc4cf2ff5bc738fe569 Mon Sep 17 00:00:00 2001 From: Baodong Date: Thu, 4 Nov 2021 09:27:05 +0800 Subject: [PATCH 4/9] Replace real url to example.com --- spec/factories/integrations.rb | 2 +- spec/models/integrations/shimo_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/factories/integrations.rb b/spec/factories/integrations.rb index 63a5fadb6a82a8..7205a0c40f9781 100644 --- a/spec/factories/integrations.rb +++ b/spec/factories/integrations.rb @@ -114,7 +114,7 @@ factory :shimo_integration, class: 'Integrations::Shimo' do project active { true } - external_wiki_url { 'https://shimo.im/desktop' } + external_wiki_url { 'https://shimo.example.com/desktop' } end factory :confluence_integration, class: 'Integrations::Confluence' do diff --git a/spec/models/integrations/shimo_spec.rb b/spec/models/integrations/shimo_spec.rb index 17546d68bcf076..25df8d2b2498ef 100644 --- a/spec/models/integrations/shimo_spec.rb +++ b/spec/models/integrations/shimo_spec.rb @@ -13,7 +13,7 @@ describe '#create' do let(:project) { create(:project, :repository) } - let(:external_wiki_url) { 'https://shimo.im/' } + let(:external_wiki_url) { 'https://shimo.example.com/desktop' } let(:params) { { active: true, project: project, external_wiki_url: external_wiki_url } } context 'with valid params' do -- GitLab From 0c13a2fd7871c75f985a426e7be8fa46a77e052d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Wawrzyniak?= Date: Tue, 9 Nov 2021 15:03:30 +0000 Subject: [PATCH 5/9] Apply 1 suggestion(s) to 1 file(s) --- .../metrics/counts_all/20211028210001_projects_shimo_active.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/metrics/counts_all/20211028210001_projects_shimo_active.yml b/config/metrics/counts_all/20211028210001_projects_shimo_active.yml index 5be51ba4cb2dd4..b6b11407c6a715 100644 --- a/config/metrics/counts_all/20211028210001_projects_shimo_active.yml +++ b/config/metrics/counts_all/20211028210001_projects_shimo_active.yml @@ -12,7 +12,7 @@ milestone: "14.5" introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/issues/343386 time_frame: all data_source: database -data_category: Operational +data_category: optional distribution: - ce - ee -- GitLab From d1394cfe5e7384431bae26adbf5e831597fcfc6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Wawrzyniak?= Date: Tue, 9 Nov 2021 15:04:24 +0000 Subject: [PATCH 6/9] Apply 1 suggestion(s) to 1 file(s) --- .../metrics/counts_all/20211028210002_groups_shimo_active.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/metrics/counts_all/20211028210002_groups_shimo_active.yml b/config/metrics/counts_all/20211028210002_groups_shimo_active.yml index f57deeae590d7f..3f2423f76966cb 100644 --- a/config/metrics/counts_all/20211028210002_groups_shimo_active.yml +++ b/config/metrics/counts_all/20211028210002_groups_shimo_active.yml @@ -12,7 +12,7 @@ milestone: "14.5" introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/issues/343386 time_frame: all data_source: database -data_category: Operational +data_category: optional distribution: - ce - ee -- GitLab From 6bfefc62670b1cbce1756116e6cb11aad1bef3c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Wawrzyniak?= Date: Tue, 9 Nov 2021 15:05:09 +0000 Subject: [PATCH 7/9] Apply 1 suggestion(s) to 1 file(s) --- .../counts_all/20211028210003_instances_shimo_active.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/metrics/counts_all/20211028210003_instances_shimo_active.yml b/config/metrics/counts_all/20211028210003_instances_shimo_active.yml index 7d1c6ea3706b75..2b835ef6d6c168 100644 --- a/config/metrics/counts_all/20211028210003_instances_shimo_active.yml +++ b/config/metrics/counts_all/20211028210003_instances_shimo_active.yml @@ -12,7 +12,7 @@ milestone: "14.5" introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/issues/343386 time_frame: all data_source: database -data_category: Operational +data_category: optional distribution: - ce - ee -- GitLab From 020e6239fd0c4949cf66d0d472dc4950c2f24874 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Wawrzyniak?= Date: Tue, 9 Nov 2021 15:06:21 +0000 Subject: [PATCH 8/9] Apply 1 suggestion(s) to 1 file(s) --- .../20211028210004_projects_inheriting_shimo_active.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/metrics/counts_all/20211028210004_projects_inheriting_shimo_active.yml b/config/metrics/counts_all/20211028210004_projects_inheriting_shimo_active.yml index 42f01ccff3a98d..d7d231206d582f 100644 --- a/config/metrics/counts_all/20211028210004_projects_inheriting_shimo_active.yml +++ b/config/metrics/counts_all/20211028210004_projects_inheriting_shimo_active.yml @@ -12,7 +12,7 @@ milestone: "14.5" introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/issues/343386 time_frame: all data_source: database -data_category: Operational +data_category: optional distribution: - ce - ee -- GitLab From 96d4f20fb5dba22f785b0ce62ae5cf424c7003a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Wawrzyniak?= Date: Tue, 9 Nov 2021 15:07:24 +0000 Subject: [PATCH 9/9] Apply 1 suggestion(s) to 1 file(s) --- .../20211028210005_groups_inheriting_shimo_active.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/metrics/counts_all/20211028210005_groups_inheriting_shimo_active.yml b/config/metrics/counts_all/20211028210005_groups_inheriting_shimo_active.yml index 6292ad0aaae431..d979e672f6067c 100644 --- a/config/metrics/counts_all/20211028210005_groups_inheriting_shimo_active.yml +++ b/config/metrics/counts_all/20211028210005_groups_inheriting_shimo_active.yml @@ -12,7 +12,7 @@ milestone: "14.5" introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/issues/343386 time_frame: all data_source: database -data_category: Operational +data_category: optional distribution: - ce - ee -- GitLab