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
60e590cc054f
Commit
60e590cc
authored
Dec 04, 2015
by
Kamil Trzcinski
Browse files
Migrate CI::Project to Project
parent
4b780924c743
Changes
168
Hide whitespace changes
Inline
Side-by-side
app/controllers/admin/builds_controller.rb
0 → 100644
View file @
60e590cc
class
Admin::BuildsController
<
Admin
::
ApplicationController
def
index
@scope
=
params
[
:scope
]
@all_builds
=
Ci
::
Build
@builds
=
@all_builds
.
order
(
'created_at DESC'
)
@builds
=
case
@scope
when
'all'
@builds
when
'finished'
@builds
.
finished
else
@builds
.
running_or_pending
.
reverse_order
end
@builds
=
@builds
.
page
(
params
[
:page
]).
per
(
30
)
end
def
cancel_all
Ci
::
Build
.
running_or_pending
.
each
(
&
:cancel
)
redirect_to
admin_builds_path
end
end
app/controllers/admin/runner_projects_controller.rb
0 → 100644
View file @
60e590cc
class
Admin::RunnerProjectsController
<
Admin
::
ApplicationController
before_action
:project
,
only:
[
:create
]
def
index
@runner_projects
=
project
.
ci_runner_projects
.
all
@runner_project
=
project
.
ci_runner_projects
.
new
end
def
create
@runner
=
Ci
::
Runner
.
find
(
params
[
:runner_project
][
:runner_id
])
if
@runner
.
assign_to
(
@project
,
current_user
)
redirect_to
admin_runner_path
(
@runner
)
else
redirect_to
admin_runner_path
(
@runner
),
alert:
'Failed adding runner to project'
end
end
def
destroy
rp
=
Ci
::
RunnerProject
.
find
(
params
[
:id
])
runner
=
rp
.
runner
rp
.
destroy
redirect_to
admin_runner_path
(
runner
)
end
private
def
project
@project
=
Project
.
find_with_namespace
(
[
params
[
:namespace_id
],
'/'
,
params
[
:project_id
]].
join
(
''
)
)
@project
||
render_404
end
end
app/controllers/admin/runners_controller.rb
0 → 100644
View file @
60e590cc
class
Admin::RunnersController
<
Admin
::
ApplicationController
before_action
:runner
,
except: :index
def
index
@runners
=
Ci
::
Runner
.
order
(
'id DESC'
)
@runners
=
@runners
.
search
(
params
[
:search
])
if
params
[
:search
].
present?
@runners
=
@runners
.
page
(
params
[
:page
]).
per
(
30
)
@active_runners_cnt
=
Ci
::
Runner
.
online
.
count
end
def
show
@builds
=
@runner
.
builds
.
order
(
'id DESC'
).
first
(
30
)
@projects
=
if
params
[
:search
].
present?
::
Project
.
search
(
params
[
:search
])
else
Project
.
all
end
@projects
=
@projects
.
where
.
not
(
id:
@runner
.
projects
.
select
(
:id
))
if
@runner
.
projects
.
any?
@projects
=
@projects
.
page
(
params
[
:page
]).
per
(
30
)
end
def
update
@runner
.
update_attributes
(
runner_params
)
respond_to
do
|
format
|
format
.
js
format
.
html
{
redirect_to
admin_runner_path
(
@runner
)
}
end
end
def
destroy
@runner
.
destroy
redirect_to
admin_runners_path
end
def
resume
if
@runner
.
update_attributes
(
active:
true
)
redirect_to
admin_runners_path
,
notice:
'Runner was successfully updated.'
else
redirect_to
admin_runners_path
,
alert:
'Runner was not updated.'
end
end
def
pause
if
@runner
.
update_attributes
(
active:
false
)
redirect_to
admin_runners_path
,
notice:
'Runner was successfully updated.'
else
redirect_to
admin_runners_path
,
alert:
'Runner was not updated.'
end
end
private
def
runner
@runner
||=
Ci
::
Runner
.
find
(
params
[
:id
])
end
def
runner_params
params
.
require
(
:runner
).
permit
(
:token
,
:description
,
:tag_list
,
:active
)
end
end
app/controllers/ci/admin/application_controller.rb
deleted
100644 → 0
View file @
4b780924
module
Ci
module
Admin
class
ApplicationController
<
Ci
::
ApplicationController
before_action
:authenticate_user!
before_action
:authenticate_admin!
layout
"ci/admin"
end
end
end
app/controllers/ci/admin/application_settings_controller.rb
deleted
100644 → 0
View file @
4b780924
module
Ci
class
Admin::ApplicationSettingsController
<
Ci
::
Admin
::
ApplicationController
before_action
:set_application_setting
def
show
end
def
update
if
@application_setting
.
update_attributes
(
application_setting_params
)
redirect_to
ci_admin_application_settings_path
,
notice:
'Application settings saved successfully'
else
render
:show
end
end
private
def
set_application_setting
@application_setting
=
Ci
::
ApplicationSetting
.
current
@application_setting
||=
Ci
::
ApplicationSetting
.
create_from_defaults
end
def
application_setting_params
params
.
require
(
:application_setting
).
permit
(
:all_broken_builds
,
:add_pusher
,
)
end
end
end
app/controllers/ci/admin/builds_controller.rb
deleted
100644 → 0
View file @
4b780924
module
Ci
class
Admin::BuildsController
<
Ci
::
Admin
::
ApplicationController
def
index
@scope
=
params
[
:scope
]
@builds
=
Ci
::
Build
.
order
(
'created_at DESC'
).
page
(
params
[
:page
]).
per
(
30
)
@builds
=
case
@scope
when
"pending"
@builds
.
pending
when
"running"
@builds
.
running
else
@builds
end
end
end
end
app/controllers/ci/admin/events_controller.rb
deleted
100644 → 0
View file @
4b780924
module
Ci
class
Admin::EventsController
<
Ci
::
Admin
::
ApplicationController
EVENTS_PER_PAGE
=
50
def
index
@events
=
Ci
::
Event
.
admin
.
order
(
'created_at DESC'
).
page
(
params
[
:page
]).
per
(
EVENTS_PER_PAGE
)
end
end
end
app/controllers/ci/admin/projects_controller.rb
deleted
100644 → 0
View file @
4b780924
module
Ci
class
Admin::ProjectsController
<
Ci
::
Admin
::
ApplicationController
def
index
@projects
=
Ci
::
Project
.
ordered_by_last_commit_date
.
page
(
params
[
:page
]).
per
(
30
)
end
def
destroy
project
.
destroy
redirect_to
ci_projects_url
end
protected
def
project
@project
||=
Ci
::
Project
.
find
(
params
[
:id
])
end
end
end
app/controllers/ci/admin/runner_projects_controller.rb
deleted
100644 → 0
View file @
4b780924
module
Ci
class
Admin::RunnerProjectsController
<
Ci
::
Admin
::
ApplicationController
layout
'ci/project'
def
index
@runner_projects
=
project
.
runner_projects
.
all
@runner_project
=
project
.
runner_projects
.
new
end
def
create
@runner
=
Ci
::
Runner
.
find
(
params
[
:runner_project
][
:runner_id
])
if
@runner
.
assign_to
(
project
,
current_user
)
redirect_to
ci_admin_runner_path
(
@runner
)
else
redirect_to
ci_admin_runner_path
(
@runner
),
alert:
'Failed adding runner to project'
end
end
def
destroy
rp
=
Ci
::
RunnerProject
.
find
(
params
[
:id
])
runner
=
rp
.
runner
rp
.
destroy
redirect_to
ci_admin_runner_path
(
runner
)
end
private
def
project
@project
||=
Ci
::
Project
.
find
(
params
[
:project_id
])
end
end
end
app/controllers/ci/admin/runners_controller.rb
deleted
100644 → 0
View file @
4b780924
module
Ci
class
Admin::RunnersController
<
Ci
::
Admin
::
ApplicationController
before_action
:runner
,
except: :index
def
index
@runners
=
Ci
::
Runner
.
order
(
'id DESC'
)
@runners
=
@runners
.
search
(
params
[
:search
])
if
params
[
:search
].
present?
@runners
=
@runners
.
page
(
params
[
:page
]).
per
(
30
)
@active_runners_cnt
=
Ci
::
Runner
.
online
.
count
end
def
show
@builds
=
@runner
.
builds
.
order
(
'id DESC'
).
first
(
30
)
@projects
=
Ci
::
Project
.
all
if
params
[
:search
].
present?
@gl_projects
=
::
Project
.
search
(
params
[
:search
])
@projects
=
@projects
.
where
(
gitlab_id:
@gl_projects
.
select
(
:id
))
end
@projects
=
@projects
.
where
(
"ci_projects.id NOT IN (?)"
,
@runner
.
projects
.
pluck
(
:id
))
if
@runner
.
projects
.
any?
@projects
=
@projects
.
joins
(
:gl_project
)
@projects
=
@projects
.
page
(
params
[
:page
]).
per
(
30
)
end
def
update
@runner
.
update_attributes
(
runner_params
)
respond_to
do
|
format
|
format
.
js
format
.
html
{
redirect_to
ci_admin_runner_path
(
@runner
)
}
end
end
def
destroy
@runner
.
destroy
redirect_to
ci_admin_runners_path
end
def
resume
if
@runner
.
update_attributes
(
active:
true
)
redirect_to
ci_admin_runners_path
,
notice:
'Runner was successfully updated.'
else
redirect_to
ci_admin_runners_path
,
alert:
'Runner was not updated.'
end
end
def
pause
if
@runner
.
update_attributes
(
active:
false
)
redirect_to
ci_admin_runners_path
,
notice:
'Runner was successfully updated.'
else
redirect_to
ci_admin_runners_path
,
alert:
'Runner was not updated.'
end
end
def
assign_all
Ci
::
Project
.
unassigned
(
@runner
).
all
.
each
do
|
project
|
@runner
.
assign_to
(
project
,
current_user
)
end
redirect_to
ci_admin_runner_path
(
@runner
),
notice:
"Runner was assigned to all projects"
end
private
def
runner
@runner
||=
Ci
::
Runner
.
find
(
params
[
:id
])
end
def
runner_params
params
.
require
(
:runner
).
permit
(
:token
,
:description
,
:tag_list
,
:active
)
end
end
end
app/controllers/ci/application_controller.rb
View file @
60e590cc
...
...
@@ -4,8 +4,6 @@
"app/helpers/ci"
end
helper_method
:gl_project
private
def
authenticate_token!
...
...
@@ -15,9 +13,9 @@
end
def
authorize_access_project!
unless
can?
(
current_user
,
:read_project
,
gl_
project
)
unless
can?
(
current_user
,
:read_project
,
project
)
return
page_404
end
end
def
authorize_manage_builds!
...
...
@@ -19,9 +17,9 @@
return
page_404
end
end
def
authorize_manage_builds!
unless
can?
(
current_user
,
:manage_builds
,
gl_
project
)
unless
can?
(
current_user
,
:manage_builds
,
project
)
return
page_404
end
end
...
...
@@ -31,7 +29,7 @@
end
def
authorize_manage_project!
unless
can?
(
current_user
,
:admin_project
,
gl_
project
)
unless
can?
(
current_user
,
:admin_project
,
project
)
return
page_404
end
end
...
...
@@ -58,9 +56,5 @@
count:
count
}
end
def
gl_project
::
Project
.
find
(
@project
.
gitlab_id
)
end
end
end
app/controllers/ci/lints_controller.rb
View file @
60e590cc
module
Ci
class
LintsController
<
Ci
::
ApplicationController
class
LintsController
<
ApplicationController
before_action
:authenticate_user!
def
show
...
...
app/controllers/ci/projects_controller.rb
View file @
60e590cc
...
...
@@ -3,9 +3,8 @@
before_action
:project
,
except:
[
:index
]
before_action
:authenticate_user!
,
except:
[
:index
,
:build
,
:badge
]
before_action
:authorize_access_project!
,
except:
[
:index
,
:badge
]
before_action
:authorize_manage_project!
,
only:
[
:toggle_shared_runners
,
:dumped_yaml
]
before_action
:no_cache
,
only:
[
:badge
]
protect_from_forgery
def
show
# Temporary compatibility with CI badges pointing to CI project page
...
...
@@ -7,9 +6,9 @@
before_action
:no_cache
,
only:
[
:badge
]
protect_from_forgery
def
show
# Temporary compatibility with CI badges pointing to CI project page
redirect_to
namespace_project_path
(
project
.
gl_project
.
namespace
,
project
.
gl_
project
)
redirect_to
namespace_project_path
(
project
.
namespace
,
project
)
end
# Project status badge
...
...
@@ -20,12 +19,6 @@
send_file
image
.
path
,
filename:
image
.
name
,
disposition:
'inline'
,
type
:"image/svg+xml"
end
def
toggle_shared_runners
project
.
toggle!
(
:shared_runners_enabled
)
redirect_to
namespace_project_runners_path
(
project
.
gl_project
.
namespace
,
project
.
gl_project
)
end
protected
def
project
...
...
@@ -29,7 +22,8 @@
protected
def
project
@project
||=
Ci
::
Project
.
find
(
params
[
:id
])
# TODO: what to do here?
@project
||=
Project
.
find_by_ci_id
(
params
[
:id
])
end
def
no_cache
...
...
app/controllers/ci/runner_projects_controller.rb
deleted
100644 → 0
View file @
4b780924
module
Ci
class
RunnerProjectsController
<
Ci
::
ApplicationController
before_action
:authenticate_user!
before_action
:project
before_action
:authorize_manage_project!
def
create
@runner
=
Ci
::
Runner
.
find
(
params
[
:runner_project
][
:runner_id
])
return
head
(
403
)
unless
current_user
.
ci_authorized_runners
.
include?
(
@runner
)
path
=
runners_path
(
@project
.
gl_project
)
if
@runner
.
assign_to
(
project
,
current_user
)
redirect_to
path
else
redirect_to
path
,
alert:
'Failed adding runner to project'
end
end
def
destroy
runner_project
=
project
.
runner_projects
.
find
(
params
[
:id
])
runner_project
.
destroy
redirect_to
runners_path
(
@project
.
gl_project
)
end
private
def
project
@project
||=
Ci
::
Project
.
find
(
params
[
:project_id
])
end
end
end
app/controllers/projects/application_controller.rb
View file @
60e590cc
...
...
@@ -31,8 +31,4 @@
def
builds_enabled
return
render_404
unless
@project
.
builds_enabled?
end
def
ci_project
@ci_project
||=
@project
.
ensure_gitlab_ci_project
end
end
app/controllers/projects/builds_controller.rb
View file @
60e590cc
class
Projects::BuildsController
<
Projects
::
ApplicationController
before_action
:ci_project
before_action
:build
,
except:
[
:index
,
:cancel_all
]
before_action
:authorize_manage_builds!
,
except:
[
:index
,
:show
,
:status
]
...
...
@@ -30,7 +29,7 @@
end
def
show
@builds
=
@
ci_
project
.
commits
.
find_by_sha
(
@build
.
sha
).
builds
.
order
(
'id DESC'
)
@builds
=
@project
.
ci_
commits
.
find_by_sha
(
@build
.
sha
).
builds
.
order
(
'id DESC'
)
@builds
=
@builds
.
where
(
"id not in (?)"
,
@build
.
id
)
@commit
=
@build
.
commit
...
...
@@ -77,7 +76,7 @@
private
def
build
@build
||=
ci_
project
.
builds
.
unscoped
.
find_by!
(
id:
params
[
:id
])
@build
||=
project
.
ci_
builds
.
unscoped
.
find_by!
(
id:
params
[
:id
])
end
def
artifacts_file
...
...
@@ -85,7 +84,7 @@
end
def
build_path
(
build
)
namespace_project_build_path
(
build
.
gl_
project
.
namespace
,
build
.
gl_
project
,
build
)
namespace_project_build_path
(
build
.
project
.
namespace
,
build
.
project
,
build
)
end
def
authorize_manage_builds!
...
...
app/controllers/projects/ci_settings_controller.rb
deleted
100644 → 0
View file @
4b780924
class
Projects::CiSettingsController
<
Projects
::
ApplicationController
before_action
:ci_project
before_action
:authorize_admin_project!
layout
"project_settings"
def
edit
end
def
update
if
ci_project
.
update_attributes
(
project_params
)
Ci
::
EventService
.
new
.
change_project_settings
(
current_user
,
ci_project
)
redirect_to
edit_namespace_project_ci_settings_path
(
project
.
namespace
,
project
),
notice:
'Project was successfully updated.'
else
render
action:
"edit"
end
end
def
destroy
ci_project
.
destroy
Ci
::
EventService
.
new
.
remove_project
(
current_user
,
ci_project
)
project
.
gitlab_ci_service
.
update_attributes
(
active:
false
)
redirect_to
project_path
(
project
),
notice:
"CI was disabled for this project"
end
protected
def
project_params
params
.
require
(
:project
).
permit
(
:path
,
:timeout
,
:timeout_in_minutes
,
:default_ref
,
:always_build
,
:polling_interval
,
:public
,
:ssh_url_to_repo
,
:allow_git_fetch
,
:email_recipients
,
:email_add_pusher
,
:email_only_broken_builds
,
:coverage_regex
,
:shared_runners_enabled
,
:token
,
{
variables_attributes:
[
:id
,
:key
,
:value
,
:_destroy
]
})
end
end
app/controllers/projects/commit_controller.rb
View file @
60e590cc
...
...
@@ -31,7 +31,6 @@
end
def
builds
@ci_project
=
@project
.
gitlab_ci_project
end
def
cancel_builds
...
...
app/controllers/projects/graphs_controller.rb
View file @
60e590cc
...
...
@@ -25,6 +25,4 @@
end
def
ci
ci_project
=
@project
.
gitlab_ci_project
@charts
=
{}
...
...
@@ -30,8 +28,8 @@
@charts
=
{}
@charts
[
:week
]
=
Ci
::
Charts
::
WeekChart
.
new
(
ci_
project
)
@charts
[
:month
]
=
Ci
::
Charts
::
MonthChart
.
new
(
ci_
project
)
@charts
[
:year
]
=
Ci
::
Charts
::
YearChart
.
new
(
ci_
project
)
@charts
[
:build_times
]
=
Ci
::
Charts
::
BuildTime
.
new
(
ci_
project
)
@charts
[
:week
]
=
Ci
::
Charts
::
WeekChart
.
new
(
project
)
@charts
[
:month
]
=
Ci
::
Charts
::
MonthChart
.
new
(
project
)
@charts
[
:year
]
=
Ci
::
Charts
::
YearChart
.
new
(
project
)
@charts
[
:build_times
]
=
Ci
::
Charts
::
BuildTime
.
new
(
project
)
end
def
languages
...
...
app/controllers/projects/runner_projects_controller.rb
0 → 100644
View file @
60e590cc
class
Projects::RunnerProjectsController
<
Projects
::
ApplicationController
before_action
:authorize_admin_project!
layout
'project_settings'
def
create
@runner
=
Ci
::
Runner
.
find
(
params
[
:runner_project
][
:runner_id
])
return
head
(
403
)
unless
current_user
.
ci_authorized_runners
.
include?
(
@runner
)
path
=
runners_path
(
project
)
if
@runner
.
assign_to
(
project
,
current_user
)
redirect_to
path
else
redirect_to
path
,
alert:
'Failed adding runner to project'
end
end
def
destroy
runner_project
=
project
.
ci_runner_projects
.
find
(
params
[
:id
])
runner_project
.
destroy
redirect_to
runners_path
(
project
)
end
end
Prev
1
2
3
4
5
…
9
Next
Write
Preview