Commit 3f8193f8 authored by Alex Kalderimis's avatar Alex Kalderimis

Merge branch '330300-ajk-m' into 'master'

Rename project integration associations: M [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!64199
parents d25b1266 25104fb1
...@@ -49,6 +49,7 @@ class Integration < ApplicationRecord ...@@ -49,6 +49,7 @@ class Integration < ApplicationRecord
hangouts_chat hangouts_chat
irker irker
packagist pipelines_email pivotaltracker pushover packagist pipelines_email pivotaltracker pushover
mattermost mattermost_slash_commands microsoft_teams mock_ci mock_monitoring
].to_set.freeze ].to_set.freeze
def self.renamed?(name) def self.renamed?(name)
......
...@@ -174,10 +174,11 @@ class Project < ApplicationRecord ...@@ -174,10 +174,11 @@ class Project < ApplicationRecord
has_one :irker_integration, class_name: 'Integrations::Irker' has_one :irker_integration, class_name: 'Integrations::Irker'
has_one :jenkins_service, class_name: 'Integrations::Jenkins' has_one :jenkins_service, class_name: 'Integrations::Jenkins'
has_one :jira_service, class_name: 'Integrations::Jira' has_one :jira_service, class_name: 'Integrations::Jira'
has_one :mattermost_service, class_name: 'Integrations::Mattermost' has_one :mattermost_integration, class_name: 'Integrations::Mattermost'
has_one :mattermost_slash_commands_service, class_name: 'Integrations::MattermostSlashCommands' has_one :mattermost_slash_commands_integration, class_name: 'Integrations::MattermostSlashCommands'
has_one :microsoft_teams_service, class_name: 'Integrations::MicrosoftTeams' has_one :microsoft_teams_integration, class_name: 'Integrations::MicrosoftTeams'
has_one :mock_ci_service, class_name: 'Integrations::MockCi' has_one :mock_ci_integration, class_name: 'Integrations::MockCi'
has_one :mock_monitoring_integration, class_name: 'MockMonitoringService'
has_one :packagist_integration, class_name: 'Integrations::Packagist' has_one :packagist_integration, class_name: 'Integrations::Packagist'
has_one :pipelines_email_integration, class_name: 'Integrations::PipelinesEmail' has_one :pipelines_email_integration, class_name: 'Integrations::PipelinesEmail'
has_one :pivotaltracker_integration, class_name: 'Integrations::Pivotaltracker' has_one :pivotaltracker_integration, class_name: 'Integrations::Pivotaltracker'
...@@ -190,7 +191,6 @@ class Project < ApplicationRecord ...@@ -190,7 +191,6 @@ class Project < ApplicationRecord
has_one :webex_teams_service, class_name: 'Integrations::WebexTeams' has_one :webex_teams_service, class_name: 'Integrations::WebexTeams'
has_one :youtrack_service, class_name: 'Integrations::Youtrack' has_one :youtrack_service, class_name: 'Integrations::Youtrack'
has_one :prometheus_service, inverse_of: :project has_one :prometheus_service, inverse_of: :project
has_one :mock_monitoring_service
has_one :root_of_fork_network, has_one :root_of_fork_network,
foreign_key: 'root_project_id', foreign_key: 'root_project_id',
......
...@@ -6,7 +6,7 @@ class Gitlab::Seeder::Environments ...@@ -6,7 +6,7 @@ class Gitlab::Seeder::Environments
end end
def seed! def seed!
@project.create_mock_monitoring_service!(active: true) @project.create_mock_monitoring_integration!(active: true)
create_master_deployments!('production') create_master_deployments!('production')
create_master_deployments!('staging') create_master_deployments!('staging')
......
...@@ -44,10 +44,10 @@ RSpec.describe Projects::ServicesController do ...@@ -44,10 +44,10 @@ RSpec.describe Projects::ServicesController do
let(:project) { create(:project) } let(:project) { create(:project) }
context 'with chat notification service' do context 'with chat notification service' do
let(:service) { project.create_microsoft_teams_service(webhook: 'http://webhook.com') } let(:service) { project.create_microsoft_teams_integration(webhook: 'http://webhook.com') }
it 'returns success' do it 'returns success' do
allow_any_instance_of(::MicrosoftTeams::Notifier).to receive(:ping).and_return(true) allow_next(::MicrosoftTeams::Notifier).to receive(:ping).and_return(true)
put :test, params: project_params put :test, params: project_params
......
...@@ -368,7 +368,7 @@ project: ...@@ -368,7 +368,7 @@ project:
- drone_ci_integration - drone_ci_integration
- emails_on_push_integration - emails_on_push_integration
- pipelines_email_integration - pipelines_email_integration
- mattermost_slash_commands_service - mattermost_slash_commands_integration
- slack_slash_commands_service - slack_slash_commands_service
- irker_integration - irker_integration
- packagist_integration - packagist_integration
...@@ -378,8 +378,8 @@ project: ...@@ -378,8 +378,8 @@ project:
- assembla_integration - assembla_integration
- asana_integration - asana_integration
- slack_service - slack_service
- microsoft_teams_service - microsoft_teams_integration
- mattermost_service - mattermost_integration
- hangouts_chat_integration - hangouts_chat_integration
- unify_circuit_service - unify_circuit_service
- buildkite_integration - buildkite_integration
...@@ -393,8 +393,8 @@ project: ...@@ -393,8 +393,8 @@ project:
- bugzilla_integration - bugzilla_integration
- ewm_integration - ewm_integration
- external_wiki_integration - external_wiki_integration
- mock_ci_service - mock_ci_integration
- mock_monitoring_service - mock_monitoring_integration
- forked_to_members - forked_to_members
- forked_from_project - forked_from_project
- forks - forks
......
...@@ -5,27 +5,29 @@ require 'spec_helper' ...@@ -5,27 +5,29 @@ require 'spec_helper'
RSpec.describe Integrations::MattermostSlashCommands do RSpec.describe Integrations::MattermostSlashCommands do
it_behaves_like Integrations::BaseSlashCommands it_behaves_like Integrations::BaseSlashCommands
context 'Mattermost API' do describe 'Mattermost API' do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:service) { project.build_mattermost_slash_commands_service } let(:integration) { project.build_mattermost_slash_commands_integration }
let(:user) { create(:user) } let(:user) { create(:user) }
before do before do
session = ::Mattermost::Session.new(nil) session = ::Mattermost::Session.new(nil)
session.base_uri = 'http://mattermost.example.com' session.base_uri = 'http://mattermost.example.com'
allow_any_instance_of(::Mattermost::Client).to receive(:with_session) allow(session).to receive(:with_session).and_yield(session)
.and_yield(session) allow(::Mattermost::Session).to receive(:new).and_return(session)
end end
describe '#configure' do describe '#configure' do
subject do subject do
service.configure(user, team_id: 'abc', integration.configure(user,
trigger: 'gitlab', url: 'http://trigger.url', team_id: 'abc',
trigger: 'gitlab',
url: 'http://trigger.url',
icon_url: 'http://icon.url/icon.png') icon_url: 'http://icon.url/icon.png')
end end
context 'the requests succeeds' do context 'when the request succeeds' do
before do before do
stub_request(:post, 'http://mattermost.example.com/api/v4/commands') stub_request(:post, 'http://mattermost.example.com/api/v4/commands')
.with(body: { .with(body: {
...@@ -48,18 +50,18 @@ RSpec.describe Integrations::MattermostSlashCommands do ...@@ -48,18 +50,18 @@ RSpec.describe Integrations::MattermostSlashCommands do
) )
end end
it 'saves the service' do it 'saves the integration' do
expect { subject }.to change { project.integrations.count }.by(1) expect { subject }.to change { project.integrations.count }.by(1)
end end
it 'saves the token' do it 'saves the token' do
subject subject
expect(service.reload.token).to eq('token') expect(integration.reload.token).to eq('token')
end end
end end
context 'an error is received' do context 'when an error is received' do
before do before do
stub_request(:post, 'http://mattermost.example.com/api/v4/commands') stub_request(:post, 'http://mattermost.example.com/api/v4/commands')
.to_return( .to_return(
...@@ -86,10 +88,10 @@ RSpec.describe Integrations::MattermostSlashCommands do ...@@ -86,10 +88,10 @@ RSpec.describe Integrations::MattermostSlashCommands do
describe '#list_teams' do describe '#list_teams' do
subject do subject do
service.list_teams(user) integration.list_teams(user)
end end
context 'the requests succeeds' do context 'when the request succeeds' do
before do before do
stub_request(:get, 'http://mattermost.example.com/api/v4/users/me/teams') stub_request(:get, 'http://mattermost.example.com/api/v4/users/me/teams')
.to_return( .to_return(
...@@ -104,7 +106,7 @@ RSpec.describe Integrations::MattermostSlashCommands do ...@@ -104,7 +106,7 @@ RSpec.describe Integrations::MattermostSlashCommands do
end end
end end
context 'an error is received' do context 'when an error is received' do
before do before do
stub_request(:get, 'http://mattermost.example.com/api/v4/users/me/teams') stub_request(:get, 'http://mattermost.example.com/api/v4/users/me/teams')
.to_return( .to_return(
......
...@@ -64,7 +64,8 @@ RSpec.describe Integrations::MicrosoftTeams do ...@@ -64,7 +64,8 @@ RSpec.describe Integrations::MicrosoftTeams do
end end
it 'specifies the webhook when it is configured' do it 'specifies the webhook when it is configured' do
expect(::MicrosoftTeams::Notifier).to receive(:new).with(webhook_url).and_return(double(:microsoft_teams_service).as_null_object) integration = double(:microsoft_teams_integration).as_null_object
expect(::MicrosoftTeams::Notifier).to receive(:new).with(webhook_url).and_return(integration)
chat_service.execute(push_sample_data) chat_service.execute(push_sample_data)
end end
......
...@@ -36,8 +36,8 @@ RSpec.describe Project, factory_default: :keep do ...@@ -36,8 +36,8 @@ RSpec.describe Project, factory_default: :keep do
it { is_expected.to have_many(:protected_branches) } it { is_expected.to have_many(:protected_branches) }
it { is_expected.to have_many(:exported_protected_branches) } it { is_expected.to have_many(:exported_protected_branches) }
it { is_expected.to have_one(:slack_service) } it { is_expected.to have_one(:slack_service) }
it { is_expected.to have_one(:microsoft_teams_service) } it { is_expected.to have_one(:microsoft_teams_integration) }
it { is_expected.to have_one(:mattermost_service) } it { is_expected.to have_one(:mattermost_integration) }
it { is_expected.to have_one(:hangouts_chat_integration) } it { is_expected.to have_one(:hangouts_chat_integration) }
it { is_expected.to have_one(:unify_circuit_service) } it { is_expected.to have_one(:unify_circuit_service) }
it { is_expected.to have_one(:webex_teams_service) } it { is_expected.to have_one(:webex_teams_service) }
...@@ -56,7 +56,7 @@ RSpec.describe Project, factory_default: :keep do ...@@ -56,7 +56,7 @@ RSpec.describe Project, factory_default: :keep do
it { is_expected.to have_one(:flowdock_integration) } it { is_expected.to have_one(:flowdock_integration) }
it { is_expected.to have_one(:assembla_integration) } it { is_expected.to have_one(:assembla_integration) }
it { is_expected.to have_one(:slack_slash_commands_service) } it { is_expected.to have_one(:slack_slash_commands_service) }
it { is_expected.to have_one(:mattermost_slash_commands_service) } it { is_expected.to have_one(:mattermost_slash_commands_integration) }
it { is_expected.to have_one(:buildkite_integration) } it { is_expected.to have_one(:buildkite_integration) }
it { is_expected.to have_one(:bamboo_integration) } it { is_expected.to have_one(:bamboo_integration) }
it { is_expected.to have_one(:teamcity_service) } it { is_expected.to have_one(:teamcity_service) }
...@@ -80,6 +80,8 @@ RSpec.describe Project, factory_default: :keep do ...@@ -80,6 +80,8 @@ RSpec.describe Project, factory_default: :keep do
it { is_expected.to have_one(:error_tracking_setting).class_name('ErrorTracking::ProjectErrorTrackingSetting') } it { is_expected.to have_one(:error_tracking_setting).class_name('ErrorTracking::ProjectErrorTrackingSetting') }
it { is_expected.to have_one(:project_setting) } it { is_expected.to have_one(:project_setting) }
it { is_expected.to have_one(:alerting_setting).class_name('Alerting::ProjectAlertingSetting') } it { is_expected.to have_one(:alerting_setting).class_name('Alerting::ProjectAlertingSetting') }
it { is_expected.to have_one(:mock_ci_integration) }
it { is_expected.to have_one(:mock_monitoring_integration) }
it { is_expected.to have_many(:commit_statuses) } it { is_expected.to have_many(:commit_statuses) }
it { is_expected.to have_many(:ci_pipelines) } it { is_expected.to have_many(:ci_pipelines) }
it { is_expected.to have_many(:ci_refs) } it { is_expected.to have_many(:ci_refs) }
......
...@@ -179,10 +179,10 @@ RSpec.describe API::Services do ...@@ -179,10 +179,10 @@ RSpec.describe API::Services do
end end
describe 'POST /projects/:id/services/:slug/trigger' do describe 'POST /projects/:id/services/:slug/trigger' do
describe 'Mattermost Service' do describe 'Mattermost integration' do
let(:service_name) { 'mattermost_slash_commands' } let(:integration_name) { 'mattermost_slash_commands' }
context 'no service is available' do context 'when no integration is available' do
it 'returns a not found message' do it 'returns a not found message' do
post api("/projects/#{project.id}/services/idonotexist/trigger") post api("/projects/#{project.id}/services/idonotexist/trigger")
...@@ -191,34 +191,34 @@ RSpec.describe API::Services do ...@@ -191,34 +191,34 @@ RSpec.describe API::Services do
end end
end end
context 'the service exists' do context 'when the integration exists' do
let(:params) { { token: 'token' } } let(:params) { { token: 'token' } }
context 'the service is not active' do context 'when the integration is not active' do
before do before do
project.create_mattermost_slash_commands_service( project.create_mattermost_slash_commands_integration(
active: false, active: false,
properties: params properties: params
) )
end end
it 'when the service is inactive' do it 'when the integration is inactive' do
post api("/projects/#{project.id}/services/#{service_name}/trigger"), params: params post api("/projects/#{project.id}/services/#{integration_name}/trigger"), params: params
expect(response).to have_gitlab_http_status(:not_found) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
context 'the service is active' do context 'when the integration is active' do
before do before do
project.create_mattermost_slash_commands_service( project.create_mattermost_slash_commands_integration(
active: true, active: true,
properties: params properties: params
) )
end end
it 'returns status 200' do it 'returns status 200' do
post api("/projects/#{project.id}/services/#{service_name}/trigger"), params: params post api("/projects/#{project.id}/services/#{integration_name}/trigger"), params: params
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
end end
...@@ -226,7 +226,7 @@ RSpec.describe API::Services do ...@@ -226,7 +226,7 @@ RSpec.describe API::Services do
context 'when the project can not be found' do context 'when the project can not be found' do
it 'returns a generic 404' do it 'returns a generic 404' do
post api("/projects/404/services/#{service_name}/trigger"), params: params post api("/projects/404/services/#{integration_name}/trigger"), params: params
expect(response).to have_gitlab_http_status(:not_found) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response["message"]).to eq("404 Service Not Found") expect(json_response["message"]).to eq("404 Service Not Found")
...@@ -254,29 +254,29 @@ RSpec.describe API::Services do ...@@ -254,29 +254,29 @@ RSpec.describe API::Services do
end end
end end
describe 'Mattermost service' do describe 'Mattermost integration' do
let(:service_name) { 'mattermost' } let(:integration_name) { 'mattermost' }
let(:params) do let(:params) do
{ webhook: 'https://hook.example.com', username: 'username' } { webhook: 'https://hook.example.com', username: 'username' }
end end
before do before do
project.create_mattermost_service( project.create_mattermost_integration(
active: true, active: true,
properties: params properties: params
) )
end end
it 'accepts a username for update' do it 'accepts a username for update' do
put api("/projects/#{project.id}/services/#{service_name}", user), params: params.merge(username: 'new_username') put api("/projects/#{project.id}/services/#{integration_name}", user), params: params.merge(username: 'new_username')
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['properties']['username']).to eq('new_username') expect(json_response['properties']['username']).to eq('new_username')
end end
end end
describe 'Microsoft Teams service' do describe 'Microsoft Teams integration' do
let(:service_name) { 'microsoft-teams' } let(:integration_name) { 'microsoft-teams' }
let(:params) do let(:params) do
{ {
webhook: 'https://hook.example.com', webhook: 'https://hook.example.com',
...@@ -286,21 +286,23 @@ RSpec.describe API::Services do ...@@ -286,21 +286,23 @@ RSpec.describe API::Services do
end end
before do before do
project.create_microsoft_teams_service( project.create_microsoft_teams_integration(
active: true, active: true,
properties: params properties: params
) )
end end
it 'accepts branches_to_be_notified for update' do it 'accepts branches_to_be_notified for update' do
put api("/projects/#{project.id}/services/#{service_name}", user), params: params.merge(branches_to_be_notified: 'all') put api("/projects/#{project.id}/services/#{integration_name}", user),
params: params.merge(branches_to_be_notified: 'all')
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['properties']['branches_to_be_notified']).to eq('all') expect(json_response['properties']['branches_to_be_notified']).to eq('all')
end end
it 'accepts notify_only_broken_pipelines for update' do it 'accepts notify_only_broken_pipelines for update' do
put api("/projects/#{project.id}/services/#{service_name}", user), params: params.merge(notify_only_broken_pipelines: true) put api("/projects/#{project.id}/services/#{integration_name}", user),
params: params.merge(notify_only_broken_pipelines: true)
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['properties']['notify_only_broken_pipelines']).to eq(true) expect(json_response['properties']['notify_only_broken_pipelines']).to eq(true)
......
...@@ -66,14 +66,14 @@ RSpec.shared_examples Integrations::BaseSlashCommands do ...@@ -66,14 +66,14 @@ RSpec.shared_examples Integrations::BaseSlashCommands do
} }
end end
let(:service) do let(:integration) do
project.create_mattermost_slash_commands_service( project.create_mattermost_slash_commands_integration(
properties: { token: 'token' } properties: { token: 'token' }
) )
end end
it 'generates the url' do it 'generates the url' do
response = service.trigger(params) response = integration.trigger(params)
expect(response[:text]).to start_with(':wave: Hi there!') expect(response[:text]).to start_with(':wave: Hi there!')
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment