Commit 0ba593ec authored by Douwe Maan's avatar Douwe Maan

Merge branch 'jej/ci-cd-only-sets-up-github-service-integration' into 'master'

CI/CD only GitHub import sets up service integrations

Closes #4721

See merge request gitlab-org/gitlab-ee!4687
parents 63130a73 89e2d070
......@@ -126,6 +126,12 @@ If you want, you can import all your GitHub projects in one go by hitting
You can also choose a different name for the project and a different namespace,
if you have the privileges to do so.
## Mirroring
[Project mirroring](../../../workflow/repository_mirroring.md) can be set up to keep your imported project in sync. Additionally you can configure GitLab to send pipeline status updates back GitHub with the [GitHub Project Integration](../integrations/github.md).
If you import you project using "CI/CD for external repo" then both of the above will be automatically configured.
## Making the import process go faster
For large projects it may take a while to import all data. To reduce the time
......
......@@ -2,6 +2,8 @@
GitLab provides integration for updating pipeline statuses on GitHub. This is especially useful if using GitLab for CI/CD only.
This project integration is separate from the [instance wide GitHub integration][gh-integration] and is automatically configured on [GitHub import][gh-import].
![Pipeline status update on GitHub](img/github_status_check_pipeline_update.png)
## Configuration
......@@ -28,3 +30,5 @@ This integration requires a [GitHub API token](https://github.com/settings/token
![Configure GitHub Project Integration](img/github_configuration.png)
[gh-import]: ../import/github.md#mirroring
[gh-integration]: ../../../integration/github.md
module CiCd
class GithubIntegrationSetupService
attr_reader :project
def initialize(project)
@project = project
end
def execute
github_integration.save
end
private
def github_integration
@github_integration ||= project.build_github_service(github_params)
end
def github_params
GithubParams.new(project).configuration_params
end
class GithubParams
def initialize(project)
@project = project
end
def repository_url
"#{import_uri.scheme}://#{import_uri.host}/#{repo_full_name}"
end
def configuration_params
{
active: true,
repository_url: repository_url,
token: github_access_token
}
end
private
def github_access_token
@project.import_data&.credentials&.dig(:user)
end
def repo_full_name
@project.import_source
end
def import_uri
URI.parse(@project.import_url)
end
end
end
end
......@@ -8,6 +8,7 @@ module CiCd
def execute
create_webhook
setup_project_integration
end
private
......@@ -15,5 +16,9 @@ module CiCd
def create_webhook
::CreateGithubWebhookWorker.perform_async(project.id)
end
def setup_project_integration
::CiCd::GithubIntegrationSetupService.new(project).execute
end
end
end
......@@ -8,6 +8,9 @@
= _('Run CI/CD pipelines for external repositories')
%p
= _('Connect your external repositories, and CI/CD pipelines will run for new commits. A GitLab project will be created with only CI/CD features enabled.')
%p
- more_info_link = link_to _('More info'), help_page_path('user/project/integrations/github')
= _('If using GitHub, you’ll see pipeline statuses on GitHub for your commits and pull requests. %{more_info_link}').html_safe % { more_info_link: more_info_link }
.form-group.import-btn-container.prepend-top-20.clearfix
= f.label :visibility_level, class: 'label-light' do
......
---
title: GitHub CI/CD import sets up pipeline notification integration
merge_request: 4687
author:
type: added
require 'spec_helper'
describe CiCd::GithubIntegrationSetupService do
let(:repo_full_name) { "MyUser/my-project" }
let(:api_token) { "abcdefghijk123" }
let(:import_url) { "https://#{api_token}@github.com/#{repo_full_name}.git" }
let(:credentials) { { user: api_token } }
let(:project) do
create(:project, import_source: repo_full_name,
import_url: import_url,
import_data_attributes: { credentials: credentials } )
end
subject { described_class.new(project) }
before do
subject.execute
end
describe 'sets up GitHub service integration' do
let(:integration) { project.github_service }
specify 'with API token' do
expect(integration.token).to eq api_token
end
specify 'with repo URL' do
expect(integration.repository_url).to eq 'https://github.com/MyUser/my-project'
end
end
end
......@@ -13,5 +13,13 @@ describe CiCd::GithubSetupService do
subject.execute
end
it 'sets up GithubService project integration' do
allow(subject).to receive(:create_webhook)
subject.execute
expect(project.github_service).to be_active
end
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