summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/assets/stylesheets/main.scss27
-rw-r--r--app/controllers/projects_controller.rb1
-rw-r--r--app/controllers/runner_projects_controller.rb40
-rw-r--r--app/models/build.rb41
-rw-r--r--app/models/network.rb15
-rw-r--r--app/models/project.rb25
-rw-r--r--app/models/runner.rb14
-rw-r--r--app/models/runner_project.rb17
-rw-r--r--app/views/projects/index.html.haml7
-rw-r--r--app/views/projects/show.html.haml2
-rw-r--r--app/views/runner_projects/edit.html.haml~24
-rw-r--r--app/views/runner_projects/index.html.haml64
12 files changed, 232 insertions, 45 deletions
diff --git a/app/assets/stylesheets/main.scss b/app/assets/stylesheets/main.scss
index 7022cd2..fd6d747 100644
--- a/app/assets/stylesheets/main.scss
+++ b/app/assets/stylesheets/main.scss
@@ -46,29 +46,6 @@ a {
color: #888;
}
-.project_box {
- color:#777;
- border: 1px solid #ddd;
- margin-right:20px;
- margin-bottom:20px;
- float:left;
- width:330px;
-
- .title {
- font-size:16px;
- line-height:28px;
- padding: 10px;
- }
-
- .alert {
- border-radius: 0;
- }
-
- .body {
- padding:10px;
- }
-}
-
pre.trace {
background: #000;
color:#fff;
@@ -227,3 +204,7 @@ h3 {
td form {
margin: 0;
}
+
+.cred {
+ color: #900;
+}
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index 9d2a4f1..2875f75 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -106,6 +106,7 @@ class ProjectsController < ApplicationController
params = {
name: project.name_with_namespace,
+ gitlab_id: project.id,
gitlab_url: project.web_url,
scripts: 'ls -la',
default_ref: project.default_branch,
diff --git a/app/controllers/runner_projects_controller.rb b/app/controllers/runner_projects_controller.rb
new file mode 100644
index 0000000..184a5a8
--- /dev/null
+++ b/app/controllers/runner_projects_controller.rb
@@ -0,0 +1,40 @@
+class RunnerProjectsController < ApplicationController
+ before_filter :authenticate_user!
+
+ def index
+ @runner_projects = project.runner_projects.all
+ @runner_project = project.runner_projects.new
+ end
+
+ def create
+ ActiveRecord::Base.transaction do
+ @runner_project = project.runner_projects.create!(params[:runner_project])
+
+ runner = @runner_project.runner
+
+ opts = {
+ key: runner.public_key,
+ title: "gitlab-ci-runner-#{runner.id}",
+ private_token: current_user.private_token
+ }
+
+ result = Network.new.add_deploy_key(current_user.url, project.gitlab_id, opts)
+ raise "Can't add deploy key" unless result
+ end
+
+ ensure
+ redirect_to project_runner_projects_path
+ end
+
+ def destroy
+ RunnerProject.find(params[:id]).destroy
+
+ redirect_to project_runner_projects_path
+ end
+
+ private
+
+ def project
+ @project ||= Project.find(params[:project_id])
+ end
+end
diff --git a/app/models/build.rb b/app/models/build.rb
index 1301cd1..7e9d418 100644
--- a/app/models/build.rb
+++ b/app/models/build.rb
@@ -1,3 +1,23 @@
+# == Schema Information
+#
+# Table name: builds
+#
+# id :integer not null, primary key
+# project_id :integer
+# ref :string(255)
+# status :string(255)
+# finished_at :datetime
+# trace :text(2147483647)
+# created_at :datetime not null
+# updated_at :datetime not null
+# sha :string(255)
+# started_at :datetime
+# tmp_file :string(255)
+# before_sha :string(255)
+# push_data :text
+# runner_id :integer
+#
+
class Build < ActiveRecord::Base
belongs_to :project
belongs_to :runner
@@ -117,27 +137,8 @@ class Build < ActiveRecord::Base
end
def repo_url
- project.gitlab_url + '.git'
+ project.ssh_url_to_repo
end
end
-
-# == Schema Information
-#
-# Table name: builds
-#
-# id :integer(4) not null, primary key
-# project_id :integer(4)
-# ref :string(255)
-# status :string(255)
-# finished_at :datetime
-# trace :text(2147483647
-# created_at :datetime not null
-# updated_at :datetime not null
-# sha :string(255)
-# started_at :datetime
-# tmp_file :string(255)
-# before_sha :string(255)
-#
-
diff --git a/app/models/network.rb b/app/models/network.rb
index cf56d50..42cc030 100644
--- a/app/models/network.rb
+++ b/app/models/network.rb
@@ -31,6 +31,21 @@ class Network
end
end
+ def add_deploy_key(url, project_id, api_opts)
+ opts = {
+ body: api_opts.to_json,
+ headers: {"Content-Type" => "application/json"},
+ }
+
+ response = self.class.post(url + api_prefix + "projects/#{project_id}/keys.json", opts)
+
+ if response.code == 201
+ response.parsed_response
+ else
+ nil
+ end
+ end
+
private
def api_prefix
diff --git a/app/models/project.rb b/app/models/project.rb
index 4f4bc1e..4a4729c 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -1,15 +1,36 @@
+# == Schema Information
+#
+# Table name: projects
+#
+# id :integer not null, primary key
+# name :string(255) not null
+# timeout :integer default(1800), not null
+# scripts :text default(""), not null
+# created_at :datetime not null
+# updated_at :datetime not null
+# token :string(255)
+# default_ref :string(255)
+# gitlab_url :string(255)
+# always_build :boolean default(FALSE), not null
+# polling_interval :integer
+# public :boolean default(FALSE), not null
+# ssh_url_to_repo :string(255)
+#
+
class Project < ActiveRecord::Base
attr_accessible :name, :path, :scripts, :timeout, :token,
:default_ref, :gitlab_url, :always_build, :polling_interval,
- :public, :ssh_url_to_repo
+ :public, :ssh_url_to_repo, :gitlab_id
has_many :builds, dependent: :destroy
+ has_many :runner_projects, dependent: :destroy
+ has_many :runners, through: :runner_projects
#
# Validations
#
- validates_presence_of :name, :scripts, :timeout, :token, :default_ref, :gitlab_url, :ssh_url_to_repo
+ validates_presence_of :name, :scripts, :timeout, :token, :default_ref, :gitlab_url, :ssh_url_to_repo, :gitlab_id
validates_uniqueness_of :name
diff --git a/app/models/runner.rb b/app/models/runner.rb
index 2bf086f..f87838f 100644
--- a/app/models/runner.rb
+++ b/app/models/runner.rb
@@ -1,5 +1,19 @@
+# == Schema Information
+#
+# Table name: runners
+#
+# id :integer not null, primary key
+# token :string(255)
+# public_key :text
+# created_at :datetime not null
+# updated_at :datetime not null
+#
+
class Runner < ActiveRecord::Base
has_many :builds
+ has_many :runner_projects, dependent: :destroy
+ has_many :projects, through: :runner_projects
+
has_one :last_build, class_name: 'Build'
attr_accessible :token, :public_key
diff --git a/app/models/runner_project.rb b/app/models/runner_project.rb
new file mode 100644
index 0000000..fe208ff
--- /dev/null
+++ b/app/models/runner_project.rb
@@ -0,0 +1,17 @@
+# == Schema Information
+#
+# Table name: runner_projects
+#
+# id :integer not null, primary key
+# runner_id :integer not null
+# project_id :integer not null
+# created_at :datetime not null
+# updated_at :datetime not null
+#
+
+class RunnerProject < ActiveRecord::Base
+ attr_accessible :project_id, :runner_id
+
+ belongs_to :runner
+ belongs_to :project
+end
diff --git a/app/views/projects/index.html.haml b/app/views/projects/index.html.haml
index 9d5ea0f..4591f96 100644
--- a/app/views/projects/index.html.haml
+++ b/app/views/projects/index.html.haml
@@ -7,6 +7,7 @@
%th Last build
%th Access
%th Builds
+ %th Runners
%th
- @projects.each do |project|
@@ -34,6 +35,12 @@
%td
= project.builds.count
%td
+ - count = project.runners.count
+ - if count.zero?
+ %span.badge.badge-important= count
+ - else
+ %span.badge.badge-success= count
+ %td
- if current_user
%a{href: edit_project_path(project)}
%i.icon-edit.icon-white
diff --git a/app/views/projects/show.html.haml b/app/views/projects/show.html.haml
index 851d862..b68b03c 100644
--- a/app/views/projects/show.html.haml
+++ b/app/views/projects/show.html.haml
@@ -9,6 +9,8 @@
- if current_user
.pull-right
%span
+ = link_to 'Runners', project_runner_projects_path(@project), class: 'btn btn-small'
+ %span
= link_to details_project_path(@project), class: 'btn btn-small' do
Details
%span
diff --git a/app/views/runner_projects/edit.html.haml~ b/app/views/runner_projects/edit.html.haml~
new file mode 100644
index 0000000..f8f450e
--- /dev/null
+++ b/app/views/runner_projects/edit.html.haml~
@@ -0,0 +1,24 @@
+<h2>Edit <%= current_user.email %></h2>
+
+<%= form_for(current_user, :html => { :method => :put }) do |f| %>
+
+ <div><%= f.label :email %><br />
+ <%= f.email_field :email %></div>
+
+ <div><%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
+ <%= f.password_field :password, :autocomplete => "off" %></div>
+
+ <div><%= f.label :password_confirmation %><br />
+ <%= f.password_field :password_confirmation %></div>
+
+ <div><%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
+ <%= f.password_field :current_password %></div>
+
+ <div class="form-actions"><%= f.submit "Update", class: 'btn btn-primary' %></div>
+<% end %>
+
+<h3>Cancel my account</h3>
+
+<p class="alert alert-error"> <%= link_to "Cancel my account", current_user, :data => { :confirm => "Are you sure?" }, :method => :delete %>.</p>
+
+<%= link_to "Back", :back %>
diff --git a/app/views/runner_projects/index.html.haml b/app/views/runner_projects/index.html.haml
new file mode 100644
index 0000000..8c34de6
--- /dev/null
+++ b/app/views/runner_projects/index.html.haml
@@ -0,0 +1,64 @@
+%h3
+ Project: #{link_to @project.name, @project} &rarr; Runners
+%br
+
+%p
+ To register new runner visit #{link_to 'this page ', runners_path}
+
+%h5 Activated:
+
+%table.table
+ %tr
+ %th Runner ID
+ %th Runner Token
+ %th Last build
+ %th Builds Stats
+ %th Registered
+ %th
+
+ - @runner_projects.each do |runner_project|
+ - runner = runner_project.runner
+ - builds = runner.builds.where(project_id: @project.id)
+ %tr
+ %td
+ %span.badge.badge-info= runner.id
+ %td
+ = runner.token
+ %td
+ - last_build = builds.last
+ - if last_build
+ = link_to last_build.short_sha, [last_build.project, last_build]
+ - else
+ unknown
+ %td
+ %span.badge.badge-success
+ #{builds.success.count}
+ %span /
+ %span.badge.badge-important
+ #{builds.failed.count}
+ %td
+ #{time_ago_in_words(runner_project.created_at)} ago
+ %td
+ = link_to 'Disable', [@project, runner_project], data: { confirm: "Are you sure?" }, method: :delete, class: 'btn btn-danger btn-small right'
+
+- if @runner_projects.blank?
+ .alert.alert-error
+ %h5 You should add at least one runner to process project builds
+
+%h5 Available
+%table.table
+ %tr
+ %th ID
+ %th Token
+ %th
+
+ - (Runner.all - @project.runners).each do |runner|
+ %tr
+ %td
+ = runner.id
+ %td
+ = runner.token
+ %td
+ = form_for [@project, @runner_project] do |f|
+ = f.hidden_field :runner_id, value: runner.id
+ = f.submit 'Add', class: 'btn btn-small'