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
hangouts_chat
irker
packagist pipelines_email pivotaltracker pushover
mattermost mattermost_slash_commands microsoft_teams mock_ci mock_monitoring
].to_set.freeze
def self.renamed?(name)
......
......@@ -174,10 +174,11 @@ class Project < ApplicationRecord
has_one :irker_integration, class_name: 'Integrations::Irker'
has_one :jenkins_service, class_name: 'Integrations::Jenkins'
has_one :jira_service, class_name: 'Integrations::Jira'
has_one :mattermost_service, class_name: 'Integrations::Mattermost'
has_one :mattermost_slash_commands_service, class_name: 'Integrations::MattermostSlashCommands'
has_one :microsoft_teams_service, class_name: 'Integrations::MicrosoftTeams'
has_one :mock_ci_service, class_name: 'Integrations::MockCi'
has_one :mattermost_integration, class_name: 'Integrations::Mattermost'
has_one :mattermost_slash_commands_integration, class_name: 'Integrations::MattermostSlashCommands'
has_one :microsoft_teams_integration, class_name: 'Integrations::MicrosoftTeams'
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 :pipelines_email_integration, class_name: 'Integrations::PipelinesEmail'
has_one :pivotaltracker_integration, class_name: 'Integrations::Pivotaltracker'
......@@ -190,7 +191,6 @@ class Project < ApplicationRecord
has_one :webex_teams_service, class_name: 'Integrations::WebexTeams'
has_one :youtrack_service, class_name: 'Integrations::Youtrack'
has_one :prometheus_service, inverse_of: :project
has_one :mock_monitoring_service
has_one :root_of_fork_network,
foreign_key: 'root_project_id',
......
......@@ -6,7 +6,7 @@ class Gitlab::Seeder::Environments
end
def seed!
@project.create_mock_monitoring_service!(active: true)
@project.create_mock_monitoring_integration!(active: true)
create_master_deployments!('production')
create_master_deployments!('staging')
......
......@@ -44,10 +44,10 @@ RSpec.describe Projects::ServicesController do
let(:project) { create(:project) }
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
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
......
......@@ -368,7 +368,7 @@ project:
- drone_ci_integration
- emails_on_push_integration
- pipelines_email_integration
- mattermost_slash_commands_service
- mattermost_slash_commands_integration
- slack_slash_commands_service
- irker_integration
- packagist_integration
......@@ -378,8 +378,8 @@ project:
- assembla_integration
- asana_integration
- slack_service
- microsoft_teams_service
- mattermost_service
- microsoft_teams_integration
- mattermost_integration
- hangouts_chat_integration
- unify_circuit_service
- buildkite_integration
......@@ -393,8 +393,8 @@ project:
- bugzilla_integration
- ewm_integration
- external_wiki_integration
- mock_ci_service
- mock_monitoring_service
- mock_ci_integration
- mock_monitoring_integration
- forked_to_members
- forked_from_project
- forks
......
......@@ -5,27 +5,29 @@ require 'spec_helper'
RSpec.describe Integrations::MattermostSlashCommands do
it_behaves_like Integrations::BaseSlashCommands
context 'Mattermost API' do
describe 'Mattermost API' do
let(:project) { create(:project) }
let(:service) { project.build_mattermost_slash_commands_service }
let(:integration) { project.build_mattermost_slash_commands_integration }
let(:user) { create(:user) }
before do
session = ::Mattermost::Session.new(nil)
session.base_uri = 'http://mattermost.example.com'
allow_any_instance_of(::Mattermost::Client).to receive(:with_session)
.and_yield(session)
allow(session).to receive(:with_session).and_yield(session)
allow(::Mattermost::Session).to receive(:new).and_return(session)
end
describe '#configure' do
subject do
service.configure(user, team_id: 'abc',
trigger: 'gitlab', url: 'http://trigger.url',
icon_url: 'http://icon.url/icon.png')
integration.configure(user,
team_id: 'abc',
trigger: 'gitlab',
url: 'http://trigger.url',
icon_url: 'http://icon.url/icon.png')
end
context 'the requests succeeds' do
context 'when the request succeeds' do
before do
stub_request(:post, 'http://mattermost.example.com/api/v4/commands')
.with(body: {
......@@ -48,18 +50,18 @@ RSpec.describe Integrations::MattermostSlashCommands do
)
end
it 'saves the service' do
it 'saves the integration' do
expect { subject }.to change { project.integrations.count }.by(1)
end
it 'saves the token' do
subject
expect(service.reload.token).to eq('token')
expect(integration.reload.token).to eq('token')
end
end
context 'an error is received' do
context 'when an error is received' do
before do
stub_request(:post, 'http://mattermost.example.com/api/v4/commands')
.to_return(
......@@ -86,10 +88,10 @@ RSpec.describe Integrations::MattermostSlashCommands do
describe '#list_teams' do
subject do
service.list_teams(user)
integration.list_teams(user)
end
context 'the requests succeeds' do
context 'when the request succeeds' do
before do
stub_request(:get, 'http://mattermost.example.com/api/v4/users/me/teams')
.to_return(
......@@ -104,7 +106,7 @@ RSpec.describe Integrations::MattermostSlashCommands do
end
end
context 'an error is received' do
context 'when an error is received' do
before do
stub_request(:get, 'http://mattermost.example.com/api/v4/users/me/teams')
.to_return(
......
......@@ -64,7 +64,8 @@ RSpec.describe Integrations::MicrosoftTeams do
end
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)
end
......
......@@ -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(:exported_protected_branches) }
it { is_expected.to have_one(:slack_service) }
it { is_expected.to have_one(:microsoft_teams_service) }
it { is_expected.to have_one(:mattermost_service) }
it { is_expected.to have_one(:microsoft_teams_integration) }
it { is_expected.to have_one(:mattermost_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(:webex_teams_service) }
......@@ -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(:assembla_integration) }
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(:bamboo_integration) }
it { is_expected.to have_one(:teamcity_service) }
......@@ -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(:project_setting) }
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(:ci_pipelines) }
it { is_expected.to have_many(:ci_refs) }
......
......@@ -179,10 +179,10 @@ RSpec.describe API::Services do
end
describe 'POST /projects/:id/services/:slug/trigger' do
describe 'Mattermost Service' do
let(:service_name) { 'mattermost_slash_commands' }
describe 'Mattermost integration' do
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
post api("/projects/#{project.id}/services/idonotexist/trigger")
......@@ -191,34 +191,34 @@ RSpec.describe API::Services do
end
end
context 'the service exists' do
context 'when the integration exists' do
let(:params) { { token: 'token' } }
context 'the service is not active' do
context 'when the integration is not active' do
before do
project.create_mattermost_slash_commands_service(
project.create_mattermost_slash_commands_integration(
active: false,
properties: params
)
end
it 'when the service is inactive' do
post api("/projects/#{project.id}/services/#{service_name}/trigger"), params: params
it 'when the integration is inactive' do
post api("/projects/#{project.id}/services/#{integration_name}/trigger"), params: params
expect(response).to have_gitlab_http_status(:not_found)
end
end
context 'the service is active' do
context 'when the integration is active' do
before do
project.create_mattermost_slash_commands_service(
project.create_mattermost_slash_commands_integration(
active: true,
properties: params
)
end
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)
end
......@@ -226,7 +226,7 @@ RSpec.describe API::Services do
context 'when the project can not be found' 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(json_response["message"]).to eq("404 Service Not Found")
......@@ -254,29 +254,29 @@ RSpec.describe API::Services do
end
end
describe 'Mattermost service' do
let(:service_name) { 'mattermost' }
describe 'Mattermost integration' do
let(:integration_name) { 'mattermost' }
let(:params) do
{ webhook: 'https://hook.example.com', username: 'username' }
end
before do
project.create_mattermost_service(
project.create_mattermost_integration(
active: true,
properties: params
)
end
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(json_response['properties']['username']).to eq('new_username')
end
end
describe 'Microsoft Teams service' do
let(:service_name) { 'microsoft-teams' }
describe 'Microsoft Teams integration' do
let(:integration_name) { 'microsoft-teams' }
let(:params) do
{
webhook: 'https://hook.example.com',
......@@ -286,21 +286,23 @@ RSpec.describe API::Services do
end
before do
project.create_microsoft_teams_service(
project.create_microsoft_teams_integration(
active: true,
properties: params
)
end
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(json_response['properties']['branches_to_be_notified']).to eq('all')
end
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(json_response['properties']['notify_only_broken_pipelines']).to eq(true)
......
......@@ -66,14 +66,14 @@ RSpec.shared_examples Integrations::BaseSlashCommands do
}
end
let(:service) do
project.create_mattermost_slash_commands_service(
let(:integration) do
project.create_mattermost_slash_commands_integration(
properties: { token: 'token' }
)
end
it 'generates the url' do
response = service.trigger(params)
response = integration.trigger(params)
expect(response[:text]).to start_with(':wave: Hi there!')
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