Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
90a0bebdf281
Commit
90a0bebd
authored
Sep 23, 2015
by
Dmitriy Zaporozhets
Browse files
Enable CI for gitlab when .gitlab-ci.yml is pushed
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
33c085678862
Changes
5
Hide whitespace changes
Inline
Side-by-side
CHANGELOG
View file @
90a0bebd
...
...
@@ -2,6 +2,7 @@
v 8.1.0 (unreleased)
- Show CI status on all pages where commits list is rendered
- Automatically enable CI when push .gitlab-ci.yml file to repository
v 8.0.1
- Improve CI migration procedure and documentation
...
...
app/models/project.rb
View file @
90a0bebd
...
...
@@ -739,4 +739,23 @@
def
ci_commit
(
sha
)
gitlab_ci_project
.
commits
.
find_by
(
sha:
sha
)
if
gitlab_ci?
end
def
enable_ci
(
user
)
# Enable service
service
=
gitlab_ci_service
||
create_gitlab_ci_service
service
.
active
=
true
service
.
save
# Create Ci::Project
params
=
OpenStruct
.
new
({
id:
self
.
id
,
name_with_namespace:
self
.
name_with_namespace
,
path_with_namespace:
self
.
path_with_namespace
,
web_url:
self
.
web_url
,
default_branch:
self
.
default_branch
,
ssh_url_to_repo:
self
.
ssh_url_to_repo
})
Ci
::
CreateProjectService
.
new
.
execute
(
user
,
params
)
end
end
app/models/project_services/gitlab_ci_service.rb
View file @
90a0bebd
...
...
@@ -72,7 +72,7 @@
})
ci_project
=
Ci
::
Project
.
find_by!
(
gitlab_id:
project
.
id
)
Ci
::
CreateProjectService
.
new
.
execute
(
current_user
,
params
,
...
...
app/services/git_push_service.rb
View file @
90a0bebd
...
...
@@ -55,6 +55,12 @@
@push_data
=
build_push_data
(
oldrev
,
newrev
,
ref
)
# If CI was disabled but .gitlab-ci.yml file was pushed
# we enable CI automatically
if
!
project
.
gitlab_ci?
&&
gitlab_ci_yaml?
(
newrev
)
project
.
enable_ci
(
user
)
end
EventCreateService
.
new
.
push
(
project
,
user
,
@push_data
)
project
.
execute_hooks
(
@push_data
.
dup
,
:push_hooks
)
project
.
execute_services
(
@push_data
.
dup
,
:push_hooks
)
...
...
@@ -143,4 +149,8 @@
def
commit_user
(
commit
)
commit
.
author
||
user
end
def
gitlab_ci_yaml?
(
sha
)
@project
.
repository
.
blob_at
(
sha
,
'.gitlab-ci.yml'
)
end
end
spec/models/project_spec.rb
View file @
90a0bebd
...
...
@@ -411,4 +411,14 @@
it
{
expect
(
project
.
ci_commit
(
commit
.
sha
)).
to
eq
(
commit
)
}
end
describe
:enable_ci
do
let
(
:project
)
{
create
:project
}
let
(
:user
)
{
create
:user
}
before
{
project
.
enable_ci
(
user
)
}
it
{
expect
(
project
.
gitlab_ci?
).
to
be_truthy
}
it
{
expect
(
project
.
gitlab_ci_project
).
to
be_a
(
Ci
::
Project
)
}
end
end
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment