Skip to content
Snippets Groups Projects
Commit cccd269d authored by Kamil Trzcińśki's avatar Kamil Trzcińśki
Browse files

Merge branch 'ci-and-ce-sitting-in-a-tree-k-i-s-s-i-n-g' into 'master'

Merge CI into CE

First step of #2164.

- [x] Merge latest CE master
- [x] Make application start
- [x] Re-use gitlab sessions (remove CI oauth part)
- [x] Get rid of gitlab_ci.yml config
- [x] Make tests start
- [x] Make most CI features works
- [x] Make tests green
- [x] Write migration documentation
- [x] Add CI builds to CE backup

See merge request !1204
parents 7d59ba00 ac8d2eb0
No related branches found
No related tags found
No related merge requests found
Showing
with 1638 additions and 3 deletions
.ci-body {
.project-title {
margin: 0;
color: #444;
font-size: 20px;
line-height: 1.5;
}
.builds {
@extend .table;
.build {
&.alert{
margin-bottom: 6px;
}
}
}
.projects-table {
td {
vertical-align: middle !important;
}
}
.commit-info {
font-size: 14px;
.attr-name {
font-weight: 300;
color: #666;
margin-right: 5px;
}
pre.commit-message {
font-size: 14px;
background: none;
padding: 0;
margin: 0;
border: none;
margin: 20px 0;
border-bottom: 1px solid #EEE;
padding-bottom: 20px;
border-radius: 0;
}
}
.loading{
font-size: 20px;
}
.ci-charts {
fieldset {
margin-bottom: 16px;
}
}
}
.ci-body {
.runner-state {
padding: 6px 12px;
margin-right: 10px;
color: #FFF;
&.runner-state-shared {
background: #32b186;
}
&.runner-state-specific {
background: #3498db;
}
}
.runner-status-online {
color: green;
}
.runner-status-offline {
color: gray;
}
.runner-status-paused {
color: red;
}
.runner {
.btn {
padding: 1px 6px;
}
h4 {
font-weight: normal;
}
}
}
.ci-body {
// color codes are based on http://en.wikipedia.org/wiki/File:Xterm_256color_chart.svg
// see also: https://gist.github.com/jasonm23/2868981
$black: #000000;
$red: #cd0000;
$green: #00cd00;
$yellow: #cdcd00;
$blue: #0000ee; // according to wikipedia, this is the xterm standard
//$blue: #1e90ff; // this is used by all the terminals I tried (when configured with the xterm color profile)
$magenta: #cd00cd;
$cyan: #00cdcd;
$white: #e5e5e5;
$l-black: #7f7f7f;
$l-red: #ff0000;
$l-green: #00ff00;
$l-yellow: #ffff00;
$l-blue: #5c5cff;
$l-magenta: #ff00ff;
$l-cyan: #00ffff;
$l-white: #ffffff;
.term-bold {
font-weight: bold;
}
.term-italic {
font-style: italic;
}
.term-conceal {
visibility: hidden;
}
.term-underline {
text-decoration: underline;
}
.term-cross {
text-decoration: line-through;
}
.term-fg-black {
color: $black;
}
.term-fg-red {
color: $red;
}
.term-fg-green {
color: $green;
}
.term-fg-yellow {
color: $yellow;
}
.term-fg-blue {
color: $blue;
}
.term-fg-magenta {
color: $magenta;
}
.term-fg-cyan {
color: $cyan;
}
.term-fg-white {
color: $white;
}
.term-fg-l-black {
color: $l-black;
}
.term-fg-l-red {
color: $l-red;
}
.term-fg-l-green {
color: $l-green;
}
.term-fg-l-yellow {
color: $l-yellow;
}
.term-fg-l-blue {
color: $l-blue;
}
.term-fg-l-magenta {
color: $l-magenta;
}
.term-fg-l-cyan {
color: $l-cyan;
}
.term-fg-l-white {
color: $l-white;
}
.term-bg-black {
background-color: $black;
}
.term-bg-red {
background-color: $red;
}
.term-bg-green {
background-color: $green;
}
.term-bg-yellow {
background-color: $yellow;
}
.term-bg-blue {
background-color: $blue;
}
.term-bg-magenta {
background-color: $magenta;
}
.term-bg-cyan {
background-color: $cyan;
}
.term-bg-white {
background-color: $white;
}
.term-bg-l-black {
background-color: $l-black;
}
.term-bg-l-red {
background-color: $l-red;
}
.term-bg-l-green {
background-color: $l-green;
}
.term-bg-l-yellow {
background-color: $l-yellow;
}
.term-bg-l-blue {
background-color: $l-blue;
}
.term-bg-l-magenta {
background-color: $l-magenta;
}
.term-bg-l-cyan {
background-color: $l-cyan;
}
.term-bg-l-white {
background-color: $l-white;
}
.xterm-fg-0 {
color: #000000;
}
.xterm-fg-1 {
color: #800000;
}
.xterm-fg-2 {
color: #008000;
}
.xterm-fg-3 {
color: #808000;
}
.xterm-fg-4 {
color: #000080;
}
.xterm-fg-5 {
color: #800080;
}
.xterm-fg-6 {
color: #008080;
}
.xterm-fg-7 {
color: #c0c0c0;
}
.xterm-fg-8 {
color: #808080;
}
.xterm-fg-9 {
color: #ff0000;
}
.xterm-fg-10 {
color: #00ff00;
}
.xterm-fg-11 {
color: #ffff00;
}
.xterm-fg-12 {
color: #0000ff;
}
.xterm-fg-13 {
color: #ff00ff;
}
.xterm-fg-14 {
color: #00ffff;
}
.xterm-fg-15 {
color: #ffffff;
}
.xterm-fg-16 {
color: #000000;
}
.xterm-fg-17 {
color: #00005f;
}
.xterm-fg-18 {
color: #000087;
}
.xterm-fg-19 {
color: #0000af;
}
.xterm-fg-20 {
color: #0000d7;
}
.xterm-fg-21 {
color: #0000ff;
}
.xterm-fg-22 {
color: #005f00;
}
.xterm-fg-23 {
color: #005f5f;
}
.xterm-fg-24 {
color: #005f87;
}
.xterm-fg-25 {
color: #005faf;
}
.xterm-fg-26 {
color: #005fd7;
}
.xterm-fg-27 {
color: #005fff;
}
.xterm-fg-28 {
color: #008700;
}
.xterm-fg-29 {
color: #00875f;
}
.xterm-fg-30 {
color: #008787;
}
.xterm-fg-31 {
color: #0087af;
}
.xterm-fg-32 {
color: #0087d7;
}
.xterm-fg-33 {
color: #0087ff;
}
.xterm-fg-34 {
color: #00af00;
}
.xterm-fg-35 {
color: #00af5f;
}
.xterm-fg-36 {
color: #00af87;
}
.xterm-fg-37 {
color: #00afaf;
}
.xterm-fg-38 {
color: #00afd7;
}
.xterm-fg-39 {
color: #00afff;
}
.xterm-fg-40 {
color: #00d700;
}
.xterm-fg-41 {
color: #00d75f;
}
.xterm-fg-42 {
color: #00d787;
}
.xterm-fg-43 {
color: #00d7af;
}
.xterm-fg-44 {
color: #00d7d7;
}
.xterm-fg-45 {
color: #00d7ff;
}
.xterm-fg-46 {
color: #00ff00;
}
.xterm-fg-47 {
color: #00ff5f;
}
.xterm-fg-48 {
color: #00ff87;
}
.xterm-fg-49 {
color: #00ffaf;
}
.xterm-fg-50 {
color: #00ffd7;
}
.xterm-fg-51 {
color: #00ffff;
}
.xterm-fg-52 {
color: #5f0000;
}
.xterm-fg-53 {
color: #5f005f;
}
.xterm-fg-54 {
color: #5f0087;
}
.xterm-fg-55 {
color: #5f00af;
}
.xterm-fg-56 {
color: #5f00d7;
}
.xterm-fg-57 {
color: #5f00ff;
}
.xterm-fg-58 {
color: #5f5f00;
}
.xterm-fg-59 {
color: #5f5f5f;
}
.xterm-fg-60 {
color: #5f5f87;
}
.xterm-fg-61 {
color: #5f5faf;
}
.xterm-fg-62 {
color: #5f5fd7;
}
.xterm-fg-63 {
color: #5f5fff;
}
.xterm-fg-64 {
color: #5f8700;
}
.xterm-fg-65 {
color: #5f875f;
}
.xterm-fg-66 {
color: #5f8787;
}
.xterm-fg-67 {
color: #5f87af;
}
.xterm-fg-68 {
color: #5f87d7;
}
.xterm-fg-69 {
color: #5f87ff;
}
.xterm-fg-70 {
color: #5faf00;
}
.xterm-fg-71 {
color: #5faf5f;
}
.xterm-fg-72 {
color: #5faf87;
}
.xterm-fg-73 {
color: #5fafaf;
}
.xterm-fg-74 {
color: #5fafd7;
}
.xterm-fg-75 {
color: #5fafff;
}
.xterm-fg-76 {
color: #5fd700;
}
.xterm-fg-77 {
color: #5fd75f;
}
.xterm-fg-78 {
color: #5fd787;
}
.xterm-fg-79 {
color: #5fd7af;
}
.xterm-fg-80 {
color: #5fd7d7;
}
.xterm-fg-81 {
color: #5fd7ff;
}
.xterm-fg-82 {
color: #5fff00;
}
.xterm-fg-83 {
color: #5fff5f;
}
.xterm-fg-84 {
color: #5fff87;
}
.xterm-fg-85 {
color: #5fffaf;
}
.xterm-fg-86 {
color: #5fffd7;
}
.xterm-fg-87 {
color: #5fffff;
}
.xterm-fg-88 {
color: #870000;
}
.xterm-fg-89 {
color: #87005f;
}
.xterm-fg-90 {
color: #870087;
}
.xterm-fg-91 {
color: #8700af;
}
.xterm-fg-92 {
color: #8700d7;
}
.xterm-fg-93 {
color: #8700ff;
}
.xterm-fg-94 {
color: #875f00;
}
.xterm-fg-95 {
color: #875f5f;
}
.xterm-fg-96 {
color: #875f87;
}
.xterm-fg-97 {
color: #875faf;
}
.xterm-fg-98 {
color: #875fd7;
}
.xterm-fg-99 {
color: #875fff;
}
.xterm-fg-100 {
color: #878700;
}
.xterm-fg-101 {
color: #87875f;
}
.xterm-fg-102 {
color: #878787;
}
.xterm-fg-103 {
color: #8787af;
}
.xterm-fg-104 {
color: #8787d7;
}
.xterm-fg-105 {
color: #8787ff;
}
.xterm-fg-106 {
color: #87af00;
}
.xterm-fg-107 {
color: #87af5f;
}
.xterm-fg-108 {
color: #87af87;
}
.xterm-fg-109 {
color: #87afaf;
}
.xterm-fg-110 {
color: #87afd7;
}
.xterm-fg-111 {
color: #87afff;
}
.xterm-fg-112 {
color: #87d700;
}
.xterm-fg-113 {
color: #87d75f;
}
.xterm-fg-114 {
color: #87d787;
}
.xterm-fg-115 {
color: #87d7af;
}
.xterm-fg-116 {
color: #87d7d7;
}
.xterm-fg-117 {
color: #87d7ff;
}
.xterm-fg-118 {
color: #87ff00;
}
.xterm-fg-119 {
color: #87ff5f;
}
.xterm-fg-120 {
color: #87ff87;
}
.xterm-fg-121 {
color: #87ffaf;
}
.xterm-fg-122 {
color: #87ffd7;
}
.xterm-fg-123 {
color: #87ffff;
}
.xterm-fg-124 {
color: #af0000;
}
.xterm-fg-125 {
color: #af005f;
}
.xterm-fg-126 {
color: #af0087;
}
.xterm-fg-127 {
color: #af00af;
}
.xterm-fg-128 {
color: #af00d7;
}
.xterm-fg-129 {
color: #af00ff;
}
.xterm-fg-130 {
color: #af5f00;
}
.xterm-fg-131 {
color: #af5f5f;
}
.xterm-fg-132 {
color: #af5f87;
}
.xterm-fg-133 {
color: #af5faf;
}
.xterm-fg-134 {
color: #af5fd7;
}
.xterm-fg-135 {
color: #af5fff;
}
.xterm-fg-136 {
color: #af8700;
}
.xterm-fg-137 {
color: #af875f;
}
.xterm-fg-138 {
color: #af8787;
}
.xterm-fg-139 {
color: #af87af;
}
.xterm-fg-140 {
color: #af87d7;
}
.xterm-fg-141 {
color: #af87ff;
}
.xterm-fg-142 {
color: #afaf00;
}
.xterm-fg-143 {
color: #afaf5f;
}
.xterm-fg-144 {
color: #afaf87;
}
.xterm-fg-145 {
color: #afafaf;
}
.xterm-fg-146 {
color: #afafd7;
}
.xterm-fg-147 {
color: #afafff;
}
.xterm-fg-148 {
color: #afd700;
}
.xterm-fg-149 {
color: #afd75f;
}
.xterm-fg-150 {
color: #afd787;
}
.xterm-fg-151 {
color: #afd7af;
}
.xterm-fg-152 {
color: #afd7d7;
}
.xterm-fg-153 {
color: #afd7ff;
}
.xterm-fg-154 {
color: #afff00;
}
.xterm-fg-155 {
color: #afff5f;
}
.xterm-fg-156 {
color: #afff87;
}
.xterm-fg-157 {
color: #afffaf;
}
.xterm-fg-158 {
color: #afffd7;
}
.xterm-fg-159 {
color: #afffff;
}
.xterm-fg-160 {
color: #d70000;
}
.xterm-fg-161 {
color: #d7005f;
}
.xterm-fg-162 {
color: #d70087;
}
.xterm-fg-163 {
color: #d700af;
}
.xterm-fg-164 {
color: #d700d7;
}
.xterm-fg-165 {
color: #d700ff;
}
.xterm-fg-166 {
color: #d75f00;
}
.xterm-fg-167 {
color: #d75f5f;
}
.xterm-fg-168 {
color: #d75f87;
}
.xterm-fg-169 {
color: #d75faf;
}
.xterm-fg-170 {
color: #d75fd7;
}
.xterm-fg-171 {
color: #d75fff;
}
.xterm-fg-172 {
color: #d78700;
}
.xterm-fg-173 {
color: #d7875f;
}
.xterm-fg-174 {
color: #d78787;
}
.xterm-fg-175 {
color: #d787af;
}
.xterm-fg-176 {
color: #d787d7;
}
.xterm-fg-177 {
color: #d787ff;
}
.xterm-fg-178 {
color: #d7af00;
}
.xterm-fg-179 {
color: #d7af5f;
}
.xterm-fg-180 {
color: #d7af87;
}
.xterm-fg-181 {
color: #d7afaf;
}
.xterm-fg-182 {
color: #d7afd7;
}
.xterm-fg-183 {
color: #d7afff;
}
.xterm-fg-184 {
color: #d7d700;
}
.xterm-fg-185 {
color: #d7d75f;
}
.xterm-fg-186 {
color: #d7d787;
}
.xterm-fg-187 {
color: #d7d7af;
}
.xterm-fg-188 {
color: #d7d7d7;
}
.xterm-fg-189 {
color: #d7d7ff;
}
.xterm-fg-190 {
color: #d7ff00;
}
.xterm-fg-191 {
color: #d7ff5f;
}
.xterm-fg-192 {
color: #d7ff87;
}
.xterm-fg-193 {
color: #d7ffaf;
}
.xterm-fg-194 {
color: #d7ffd7;
}
.xterm-fg-195 {
color: #d7ffff;
}
.xterm-fg-196 {
color: #ff0000;
}
.xterm-fg-197 {
color: #ff005f;
}
.xterm-fg-198 {
color: #ff0087;
}
.xterm-fg-199 {
color: #ff00af;
}
.xterm-fg-200 {
color: #ff00d7;
}
.xterm-fg-201 {
color: #ff00ff;
}
.xterm-fg-202 {
color: #ff5f00;
}
.xterm-fg-203 {
color: #ff5f5f;
}
.xterm-fg-204 {
color: #ff5f87;
}
.xterm-fg-205 {
color: #ff5faf;
}
.xterm-fg-206 {
color: #ff5fd7;
}
.xterm-fg-207 {
color: #ff5fff;
}
.xterm-fg-208 {
color: #ff8700;
}
.xterm-fg-209 {
color: #ff875f;
}
.xterm-fg-210 {
color: #ff8787;
}
.xterm-fg-211 {
color: #ff87af;
}
.xterm-fg-212 {
color: #ff87d7;
}
.xterm-fg-213 {
color: #ff87ff;
}
.xterm-fg-214 {
color: #ffaf00;
}
.xterm-fg-215 {
color: #ffaf5f;
}
.xterm-fg-216 {
color: #ffaf87;
}
.xterm-fg-217 {
color: #ffafaf;
}
.xterm-fg-218 {
color: #ffafd7;
}
.xterm-fg-219 {
color: #ffafff;
}
.xterm-fg-220 {
color: #ffd700;
}
.xterm-fg-221 {
color: #ffd75f;
}
.xterm-fg-222 {
color: #ffd787;
}
.xterm-fg-223 {
color: #ffd7af;
}
.xterm-fg-224 {
color: #ffd7d7;
}
.xterm-fg-225 {
color: #ffd7ff;
}
.xterm-fg-226 {
color: #ffff00;
}
.xterm-fg-227 {
color: #ffff5f;
}
.xterm-fg-228 {
color: #ffff87;
}
.xterm-fg-229 {
color: #ffffaf;
}
.xterm-fg-230 {
color: #ffffd7;
}
.xterm-fg-231 {
color: #ffffff;
}
.xterm-fg-232 {
color: #080808;
}
.xterm-fg-233 {
color: #121212;
}
.xterm-fg-234 {
color: #1c1c1c;
}
.xterm-fg-235 {
color: #262626;
}
.xterm-fg-236 {
color: #303030;
}
.xterm-fg-237 {
color: #3a3a3a;
}
.xterm-fg-238 {
color: #444444;
}
.xterm-fg-239 {
color: #4e4e4e;
}
.xterm-fg-240 {
color: #585858;
}
.xterm-fg-241 {
color: #626262;
}
.xterm-fg-242 {
color: #6c6c6c;
}
.xterm-fg-243 {
color: #767676;
}
.xterm-fg-244 {
color: #808080;
}
.xterm-fg-245 {
color: #8a8a8a;
}
.xterm-fg-246 {
color: #949494;
}
.xterm-fg-247 {
color: #9e9e9e;
}
.xterm-fg-248 {
color: #a8a8a8;
}
.xterm-fg-249 {
color: #b2b2b2;
}
.xterm-fg-250 {
color: #bcbcbc;
}
.xterm-fg-251 {
color: #c6c6c6;
}
.xterm-fg-252 {
color: #d0d0d0;
}
.xterm-fg-253 {
color: #dadada;
}
.xterm-fg-254 {
color: #e4e4e4;
}
.xterm-fg-255 {
color: #eeeeee;
}
}
Loading
Loading
@@ -134,9 +134,6 @@ class ApplicationController < ActionController::Base
 
def repository
@repository ||= project.repository
rescue Grit::NoSuchPathError => e
log_exception(e)
nil
end
 
def authorize_project!(action)
Loading
Loading
module Ci
module Admin
class ApplicationController < Ci::ApplicationController
before_action :authenticate_user!
before_action :authenticate_admin!
layout "ci/admin"
end
end
end
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
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
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
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
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
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.where("contacted_at > ?", 1.minutes.ago).count
end
def show
@builds = @runner.builds.order('id DESC').first(30)
@projects = Ci::Project.all
@projects = @projects.search(params[:search]) if params[:search].present?
@projects = @projects.where("ci_projects.id NOT IN (?)", @runner.projects.pluck(: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 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, :contacted_at, :active)
end
end
end
module Ci
class ApplicationController < ::ApplicationController
def self.railtie_helpers_paths
"app/helpers/ci"
end
helper_method :gl_project
private
def authenticate_public_page!
unless project.public
unless current_user
redirect_to(new_user_sessions_path) and return
end
return access_denied! unless can?(current_user, :read_project, gl_project)
end
end
def authenticate_token!
unless project.valid_token?(params[:token])
return head(403)
end
end
def authorize_access_project!
unless can?(current_user, :read_project, gl_project)
return page_404
end
end
def authorize_manage_builds!
unless can?(current_user, :admin_project, gl_project)
return page_404
end
end
def authenticate_admin!
return render_404 unless current_user.is_admin?
end
def authorize_manage_project!
unless can?(current_user, :admin_project, gl_project)
return page_404
end
end
def page_404
render file: "#{Rails.root}/public/404.html", status: 404, layout: false
end
def default_headers
headers['X-Frame-Options'] = 'DENY'
headers['X-XSS-Protection'] = '1; mode=block'
end
# JSON for infinite scroll via Pager object
def pager_json(partial, count)
html = render_to_string(
partial,
layout: false,
formats: [:html]
)
render json: {
html: html,
count: count
}
end
def gl_project
::Project.find(@project.gitlab_id)
end
end
end
module Ci
class BuildsController < Ci::ApplicationController
before_action :authenticate_user!, except: [:status, :show]
before_action :authenticate_public_page!, only: :show
before_action :project
before_action :authorize_access_project!, except: [:status, :show]
before_action :authorize_manage_project!, except: [:status, :show, :retry, :cancel]
before_action :authorize_manage_builds!, only: [:retry, :cancel]
before_action :build, except: [:show]
layout 'ci/build'
def show
if params[:id] =~ /\A\d+\Z/
@build = build
else
# try to find commit by sha
commit = commit_by_sha
if commit
# Redirect to commit page
redirect_to ci_project_ref_commit_path(@project, @build.commit.ref, @build.commit.sha)
return
end
end
raise ActiveRecord::RecordNotFound unless @build
@builds = @project.commits.find_by_sha(@build.sha).builds.order('id DESC')
@builds = @builds.where("id not in (?)", @build.id).page(params[:page]).per(20)
@commit = @build.commit
respond_to do |format|
format.html
format.json do
render json: @build.to_json(methods: :trace_html)
end
end
end
def retry
if @build.commands.blank?
return page_404
end
build = Ci::Build.retry(@build)
if params[:return_to]
redirect_to URI.parse(params[:return_to]).path
else
redirect_to ci_project_build_path(project, build)
end
end
def status
render json: @build.to_json(only: [:status, :id, :sha, :coverage], methods: :sha)
end
def cancel
@build.cancel
redirect_to ci_project_build_path(@project, @build)
end
protected
def project
@project = Ci::Project.find(params[:project_id])
end
def build
@build ||= project.builds.unscoped.find_by(id: params[:id])
end
def commit_by_sha
@project.commits.find_by(sha: params[:id])
end
end
end
module Ci
class ChartsController < Ci::ApplicationController
before_action :authenticate_user!
before_action :project
before_action :authorize_access_project!
before_action :authorize_manage_project!
layout 'ci/project'
def show
@charts = {}
@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
protected
def project
@project = Ci::Project.find(params[:project_id])
end
end
end
module Ci
class CommitsController < Ci::ApplicationController
before_action :authenticate_user!, except: [:status, :show]
before_action :authenticate_public_page!, only: :show
before_action :project
before_action :authorize_access_project!, except: [:status, :show, :cancel]
before_action :authorize_manage_builds!, only: [:cancel]
before_action :commit, only: :show
layout 'ci/commit'
def show
@builds = @commit.builds
end
def status
commit = Ci::Project.find(params[:project_id]).commits.find_by_sha_and_ref!(params[:id], params[:ref_id])
render json: commit.to_json(only: [:id, :sha], methods: [:status, :coverage])
rescue ActiveRecord::RecordNotFound
render json: { status: "not_found" }
end
def cancel
commit.builds.running_or_pending.each(&:cancel)
redirect_to ci_project_ref_commits_path(project, commit.ref, commit.sha)
end
private
def project
@project ||= Ci::Project.find(params[:project_id])
end
def commit
@commit ||= Ci::Project.find(params[:project_id]).commits.find_by_sha_and_ref!(params[:id], params[:ref_id])
end
end
end
module Ci
class EventsController < Ci::ApplicationController
EVENTS_PER_PAGE = 50
before_action :authenticate_user!
before_action :project
before_action :authorize_manage_project!
layout 'ci/project'
def index
@events = project.events.order("created_at DESC").page(params[:page]).per(EVENTS_PER_PAGE)
end
private
def project
@project ||= Ci::Project.find(params[:project_id])
end
end
end
module Ci
class HelpsController < Ci::ApplicationController
skip_filter :check_config
def show
end
def oauth2
if valid_config?
redirect_to ci_root_path
else
render layout: 'ci/empty'
end
end
end
end
module Ci
class LintsController < Ci::ApplicationController
before_action :authenticate_user!
def show
end
def create
if params[:content].blank?
@status = false
@error = "Please provide content of .gitlab-ci.yml"
else
@config_processor = Ci::GitlabCiYamlProcessor.new params[:content]
@stages = @config_processor.stages
@builds = @config_processor.builds
@status = true
end
rescue Ci::GitlabCiYamlProcessor::ValidationError => e
@error = e.message
@status = false
rescue Exception => e
@error = "Undefined error"
@status = false
end
end
end
module Ci
class ProjectsController < Ci::ApplicationController
PROJECTS_BATCH = 100
before_action :authenticate_user!, except: [:build, :badge, :index, :show]
before_action :authenticate_public_page!, only: :show
before_action :project, only: [:build, :integration, :show, :badge, :edit, :update, :destroy, :toggle_shared_runners, :dumped_yaml]
before_action :authorize_access_project!, except: [:build, :gitlab, :badge, :index, :show, :new, :create]
before_action :authorize_manage_project!, only: [:edit, :integration, :update, :destroy, :toggle_shared_runners, :dumped_yaml]
before_action :authenticate_token!, only: [:build]
before_action :no_cache, only: [:badge]
protect_from_forgery except: :build
layout 'ci/project', except: [:index, :gitlab]
def index
@projects = Ci::Project.ordered_by_last_commit_date.public_only.page(params[:page]) unless current_user
end
def gitlab
@limit, @offset = (params[:limit] || PROJECTS_BATCH).to_i, (params[:offset] || 0).to_i
@page = @offset == 0 ? 1 : (@offset / @limit + 1)
@gl_projects = current_user.authorized_projects
@gl_projects = @gl_projects.where("name LIKE ?", "%#{params[:search]}%") if params[:search]
@gl_projects = @gl_projects.page(@page).per(@limit)
@projects = Ci::Project.where(gitlab_id: @gl_projects.map(&:id)).ordered_by_last_commit_date
@total_count = @gl_projects.size
@gl_projects = @gl_projects.where.not(id: @projects.map(&:gitlab_id))
respond_to do |format|
format.json do
pager_json("ci/projects/gitlab", @total_count)
end
end
rescue
@error = 'Failed to fetch GitLab projects'
end
def show
@ref = params[:ref]
@commits = @project.commits.reverse_order
@commits = @commits.where(ref: @ref) if @ref
@commits = @commits.page(params[:page]).per(20)
end
def integration
end
def create
project_data = OpenStruct.new(JSON.parse(params["project"]))
unless can?(current_user, :admin_project, ::Project.find(project_data.id))
return redirect_to ci_root_path, alert: 'You have to have at least master role to enable CI for this project'
end
@project = Ci::CreateProjectService.new.execute(current_user, project_data, ci_project_url(":project_id"))
if @project.persisted?
redirect_to ci_project_path(@project, show_guide: true), notice: 'Project was successfully created.'
else
redirect_to :back, alert: 'Cannot save project'
end
end
def edit
end
def update
if project.update_attributes(project_params)
Ci::EventService.new.change_project_settings(current_user, project)
redirect_to :back, notice: 'Project was successfully updated.'
else
render action: "edit"
end
end
def destroy
project.gl_project.gitlab_ci_service.update_attributes(active: false)
project.destroy
Ci::EventService.new.remove_project(current_user, project)
redirect_to ci_projects_url
end
def build
@commit = Ci::CreateCommitService.new.execute(@project, params.dup)
if @commit && @commit.valid?
head 201
else
head 400
end
end
# Project status badge
# Image with build status for sha or ref
def badge
image = Ci::ImageForBuildService.new.execute(@project, params)
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 :back
end
def dumped_yaml
send_data @project.generated_yaml_config, filename: '.gitlab-ci.yml'
end
protected
def project
@project ||= Ci::Project.find(params[:id])
end
def no_cache
response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
response.headers["Pragma"] = "no-cache"
response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
end
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
end
module Ci
class RunnerProjectsController < Ci::ApplicationController
before_action :authenticate_user!
before_action :project
before_action :authorize_manage_project!
layout 'ci/project'
def create
@runner = Ci::Runner.find(params[:runner_project][:runner_id])
return head(403) unless current_user.ci_authorized_runners.include?(@runner)
if @runner.assign_to(project, current_user)
redirect_to ci_project_runners_path(project)
else
redirect_to ci_project_runners_path(project), alert: 'Failed adding runner to project'
end
end
def destroy
runner_project = project.runner_projects.find(params[:id])
runner_project.destroy
redirect_to ci_project_runners_path(project)
end
private
def project
@project ||= Ci::Project.find(params[:project_id])
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment