diff options
-rw-r--r-- | Gemfile | 2 | ||||
-rw-r--r-- | Gemfile.lock | 4 | ||||
-rw-r--r-- | app/assets/stylesheets/main.scss | 6 | ||||
-rw-r--r-- | app/controllers/builds_controller.rb | 9 | ||||
-rw-r--r-- | app/controllers/projects_controller.rb | 14 | ||||
-rw-r--r-- | app/helpers/projects_helper.rb | 29 | ||||
-rw-r--r-- | app/models/build.rb | 6 | ||||
-rw-r--r-- | app/models/project.rb | 4 | ||||
-rw-r--r-- | app/views/builds/show.html.haml | 42 | ||||
-rw-r--r-- | app/views/builds/show.js.haml | 7 | ||||
-rw-r--r-- | app/views/layouts/application.html.erb | 14 | ||||
-rw-r--r-- | app/views/layouts/application.html.haml | 36 | ||||
-rw-r--r-- | app/views/projects/_form.html.haml | 17 | ||||
-rw-r--r-- | app/views/projects/edit.html.haml | 4 | ||||
-rw-r--r-- | app/views/projects/index.html.haml | 38 | ||||
-rw-r--r-- | app/views/projects/new.html.haml | 4 | ||||
-rw-r--r-- | app/views/projects/show.html.haml | 34 | ||||
-rw-r--r-- | config/routes.rb | 8 | ||||
-rw-r--r-- | db/migrate/20121004140911_create_projects.rb | 7 | ||||
-rw-r--r-- | db/schema.rb | 11 | ||||
-rw-r--r-- | db/seeds.rb | 7 | ||||
-rw-r--r-- | lib/runner.rb | 2 | ||||
-rw-r--r-- | lib/tasks/resque.rake | 1 | ||||
-rw-r--r-- | public/index.html | 241 |
24 files changed, 199 insertions, 348 deletions
@@ -37,7 +37,7 @@ group :assets do gem 'uglifier', '>= 1.0.3' gem "therubyracer" - gem 'bootstrap-sass', "2.0.4" + gem 'bootstrap-sass' end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 860c885..0701b97 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -30,7 +30,7 @@ GEM multi_json (~> 1.0) arel (3.0.2) bcrypt-ruby (3.0.1) - bootstrap-sass (2.0.4.0) + bootstrap-sass (2.1.1.0) builder (3.0.4) coderay (1.0.8) coffee-rails (3.2.2) @@ -170,7 +170,7 @@ PLATFORMS ruby DEPENDENCIES - bootstrap-sass (= 2.0.4) + bootstrap-sass coffee-rails (~> 3.2.1) devise foreman diff --git a/app/assets/stylesheets/main.scss b/app/assets/stylesheets/main.scss index 1b51de9..2bbb7bf 100644 --- a/app/assets/stylesheets/main.scss +++ b/app/assets/stylesheets/main.scss @@ -2,7 +2,11 @@ body { color:#666; - margin-bottom:10px; + padding: 65px 0; +} + +.container-fluid { + padding: 0 50px; } .right { diff --git a/app/controllers/builds_controller.rb b/app/controllers/builds_controller.rb index 94de014..0b7ca64 100644 --- a/app/controllers/builds_controller.rb +++ b/app/controllers/builds_controller.rb @@ -1,5 +1,6 @@ class BuildsController < ApplicationController - before_filter :authenticate_user!, except :index, :show + before_filter :authenticate_user!, except: [:index, :show] + before_filter :project def index @builds = Build.all @@ -54,4 +55,10 @@ class BuildsController < ApplicationController format.json { head :no_content } end end + + protected + + def project + @project = Project.find(params[:project_id]) + end end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index f7707b8..3561215 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -1,5 +1,7 @@ +require 'runner' + class ProjectsController < ApplicationController - before_filter :authenticate_user!, except :index + before_filter :authenticate_user!, except: [:index] def index @projects = Project.all @@ -7,6 +9,7 @@ class ProjectsController < ApplicationController def show @project = Project.find(params[:id]) + @builds = @project.builds.order('id DESC').paginate(:page => params[:page], :per_page => 20) end def new @@ -43,4 +46,13 @@ class ProjectsController < ApplicationController redirect_to projects_url end + + def run + @project = Project.find(params[:id]) + @build = @project.register_build + + Resque.enqueue(Runner, @build.id) + + redirect_to project_build_path(@project, @build) + end end diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index db5c5ce..fbae2d8 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -1,2 +1,31 @@ module ProjectsHelper + def project_statuc_class(project) + if project.status == 'success' + 'alert-success' + elsif project.status == 'fail' + 'alert-error' + else + '' + end + end + + def build_status_class build + if build.success? + 'label-success' + elsif build.failed? + 'label-important' + else + 'label-inverse' + end + end + + def build_status_alert_class build + if build.success? + 'alert-success' + elsif build.failed? + 'alert-error' + else + '' + end + end end diff --git a/app/models/build.rb b/app/models/build.rb index 3f45148..f414857 100644 --- a/app/models/build.rb +++ b/app/models/build.rb @@ -1,6 +1,12 @@ class Build < ActiveRecord::Base belongs_to :project + attr_accessible :project_id, + :commit_ref, + :status, + :finished_at, + :trace + def failed? status == 'fail' end diff --git a/app/models/project.rb b/app/models/project.rb index 2f266f8..97ee77d 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1,7 +1,7 @@ class Project < ActiveRecord::Base - attr_accessible :name, :path, :scripts + attr_accessible :name, :path, :scripts, :timeout - validates_presence_of :name, :path, :scripts + validates_presence_of :name, :path, :scripts, :timeout has_many :builds, dependent: :destroy diff --git a/app/views/builds/show.html.haml b/app/views/builds/show.html.haml index 8c23694..d865542 100644 --- a/app/views/builds/show.html.haml +++ b/app/views/builds/show.html.haml @@ -1,12 +1,36 @@ -%p#notice= notice +%h3 + Project: #{@project.name} + .right + %a.btn.btn-small{href: project_path(@project)} Builds + - if current_user + %a.btn.btn-small{href: run_project_path(@project)} Run + %a.btn.btn-small{href: edit_project_path(@project)} + %i.icon-edit + Edit Project -%p - %b Trace: - = @build.trace -%p - %b Status: +.alert{class: build_status_alert_class(@build)} + %h4 + Build ##{@build.id} + %small= @build.commit_ref + .right + %span= @build.updated_at.stamp('19:00 Aug 27') = @build.status +.clearfix +%pre.trace#build-trace + = preserve do + = @build.trace +%br +.right + %a.btn.btn-small{href: project_path(@project)} Builds + - if current_user + %a.btn.btn-small{href: run_project_path(@project)} Run + %a.btn.btn-small{href: edit_project_path(@project)} + %i.icon-edit + Edit Project -= link_to 'Edit', edit_build_path(@build) -\| -= link_to 'Back', builds_path + +- if @build.running? + :javascript + $(function(){ + getBuild('#{project_build_path(@project, @build)}'); + }) diff --git a/app/views/builds/show.js.haml b/app/views/builds/show.js.haml new file mode 100644 index 0000000..29accab --- /dev/null +++ b/app/views/builds/show.js.haml @@ -0,0 +1,7 @@ +- if @build.running? + :plain + $('#build-trace').html("#{escape_javascript(@build.trace)}"); + getBuild('#{project_build_path(@project, @build)}'); +- else + :plain + location.href = "#{project_build_path(@project, @build)}"; diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb deleted file mode 100644 index 9fdd049..0000000 --- a/app/views/layouts/application.html.erb +++ /dev/null @@ -1,14 +0,0 @@ -<!DOCTYPE html> -<html> -<head> - <title>GitlabCi</title> - <%= stylesheet_link_tag "application", :media => "all" %> - <%= javascript_include_tag "application" %> - <%= csrf_meta_tags %> -</head> -<body> - -<%= yield %> - -</body> -</html> diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index b6d3817..054ed4e 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -3,30 +3,26 @@ %head %meta{charset: "utf-8"} %title GitLab CI - %link{:href => "/bootstrap/css/bootstrap.min.css", :media => "screen", :rel => "stylesheet", :type => "text/css"}/ - %link{:href => "/custom.css", :media => "screen", :rel => "stylesheet", :type => "text/css"}/ - %script{:src => "/jquery-1.8.2.min.js", :type => "text/javascript"} - %script{:src => "/application.js", :type => "text/javascript"} - %script{:src => "/bootstrap/js/bootstrap.min.js", :type => "text/javascript"} = stylesheet_link_tag "application", :media => "all" = javascript_include_tag "application" = csrf_meta_tags %body - .navbar + .navbar.navbar-fixed-top .navbar-inner - %a.brand{:href => "/"} GitLab CI - %ul.nav - %li - %a{:href => "/"} Home - - if is_user? + .container-fluid + %a.brand{:href => "/"} GitLab CI + %ul.nav %li - %span.btn.disabled= @user.email - %li - %a{:href => "/projects/new"} Add Project - %li - %a{:href => "/logout"} Logout - - else - %li - %a{:href => "/login"} Login - .container + = link_to 'Home', root_path + - if current_user + %li + %span.btn.disabled= current_user.email + %li + = link_to 'Add Project', new_project_path + %li + = link_to 'Logout', destroy_user_session_path, class: "logout", method: :delete + - else + %li + = link_to 'Login', new_user_session_path + .container-fluid = yield diff --git a/app/views/projects/_form.html.haml b/app/views/projects/_form.html.haml index b888b11..628bffc 100644 --- a/app/views/projects/_form.html.haml +++ b/app/views/projects/_form.html.haml @@ -1,19 +1,24 @@ = form_for @project do |f| - if @project.errors.any? #error_explanation - %h2= "#{pluralize(@project.errors.count, "error")} prohibited this project from being saved:" - %ul - - @project.errors.full_messages.each do |msg| - %li= msg + %p.lead= "#{pluralize(@project.errors.count, "error")} prohibited this project from being saved:" + .alert.alert-error + %ul + - @project.errors.full_messages.each do |msg| + %li= msg .field = f.label :name = f.text_field :name .field + = f.label :timeout + = f.number_field :timeout + .field = f.label :path = f.text_field :path .field = f.label :scripts = f.text_area :scripts - .actions - = f.submit 'Save' + .form-actions + = f.submit 'Save', class: 'btn btn-primary' + = link_to 'Cancel', projects_path, class: 'btn' diff --git a/app/views/projects/edit.html.haml b/app/views/projects/edit.html.haml index ca4e35e..97007b6 100644 --- a/app/views/projects/edit.html.haml +++ b/app/views/projects/edit.html.haml @@ -1,7 +1,3 @@ %h1 Editing project = render 'form' - -= link_to 'Show', @project -\| -= link_to 'Back', projects_path diff --git a/app/views/projects/index.html.haml b/app/views/projects/index.html.haml index fa50349..6955827 100644 --- a/app/views/projects/index.html.haml +++ b/app/views/projects/index.html.haml @@ -1,23 +1,19 @@ -%h1 Listing projects - -%table - %tr - %th Name - %th Path - %th Scripts - %th - %th - %th - - - @projects.each do |project| - %tr - %td= project.name - %td= project.path - %td= project.scripts - %td= link_to 'Show', project - %td= link_to 'Edit', edit_project_path(project) - %td= link_to 'Destroy', project, method: :delete, data: { confirm: 'Are you sure?' } - +%h2 Projects: %br +- @projects.each do |project| + .project_box + .title + %strong= project.name + .alert{class: project_statuc_class(project) } + #{project.human_status} + .body + %a.btn.btn-small{href: project_path(project)} Builds + - if current_user + %a.btn.btn-small{href: run_project_path(project)} Run + %a.btn.btn-small{href: edit_project_path(project)} + %i.icon-edit + Edit -= link_to 'New Project', new_project_path +- if @projects.empty? + .alert + No projects yet diff --git a/app/views/projects/new.html.haml b/app/views/projects/new.html.haml index ff62c19..6957e33 100644 --- a/app/views/projects/new.html.haml +++ b/app/views/projects/new.html.haml @@ -1,5 +1,5 @@ %h1 New project -= render 'form' - = link_to 'Back', projects_path + += render 'form' diff --git a/app/views/projects/show.html.haml b/app/views/projects/show.html.haml index 25e8070..c5ac165 100644 --- a/app/views/projects/show.html.haml +++ b/app/views/projects/show.html.haml @@ -1,15 +1,23 @@ -%p#notice= notice +%h3 + Project: #{@project.name} + .right + %a.btn.btn-small{href: run_project_path(@project)} Run + %a.btn.btn-small{href: edit_project_path(@project)} + %i.icon-edit + Edit +.builds + - @builds.each do |build| + .build.alert{class: build_status_alert_class(build)} + %span.label{class: build_status_class(build)}= build.status + → + %a{href: "/builds/#{build.id}"} + %strong Build #{build.id} + %small= build.commit_ref + .right + %span= build.updated_at.stamp('19:00 Aug 27') -%p - %b Name: - = @project.name -%p - %b Path: - = @project.path -%p - %b Scripts: - = @project.scripts + = will_paginate @builds +- if @builds.empty? + .alert + No builds yet -= link_to 'Edit', edit_project_path(@project) -\| -= link_to 'Back', projects_path diff --git a/config/routes.rb b/config/routes.rb index 422be5a..0d38070 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,13 @@ GitlabCi::Application.routes.draw do + # Optionally, enable Resque here + require 'resque/server' + mount Resque::Server => '/resque', as: 'resque' + resources :projects do + member do + get :run + post :build + end resources :builds end diff --git a/db/migrate/20121004140911_create_projects.rb b/db/migrate/20121004140911_create_projects.rb index 0aaf0eb..a9fee3a 100644 --- a/db/migrate/20121004140911_create_projects.rb +++ b/db/migrate/20121004140911_create_projects.rb @@ -1,9 +1,10 @@ class CreateProjects < ActiveRecord::Migration def up create_table :projects do |t| - t.string :name - t.string :path - t.text :scripts + t.string :name, null: false + t.string :path, null: false + t.integer :timeout, null: false, default: 1800 + t.text :scripts, null: false t.timestamps end end diff --git a/db/schema.rb b/db/schema.rb index e1efcaa..027334e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -24,11 +24,12 @@ ActiveRecord::Schema.define(:version => 20121101091638) do end create_table "projects", :force => true do |t| - t.string "name" - t.string "path" - t.text "scripts" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.string "name", :null => false + t.string "path", :null => false + t.integer "timeout", :default => 1800, :null => false + t.text "scripts", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "users", :force => true do |t| diff --git a/db/seeds.rb b/db/seeds.rb index ab08baa..d444ca9 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -2,7 +2,12 @@ # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). User.create( :email => "admin@local.host", - :name => "Administrator", :password => "5iveL!fe", :password_confirmation => "5iveL!fe" ) + +Project.create( + :name => "Test", + :path => "/tmp", + :scripts => "ls" +) diff --git a/lib/runner.rb b/lib/runner.rb index 13a2631..fc1a6c6 100644 --- a/lib/runner.rb +++ b/lib/runner.rb @@ -72,7 +72,7 @@ class Runner :chdir => path } - Timeout.timeout(TIMEOUT) do + Timeout.timeout(project.timeout) do Open3.popen3(vars, cmd, options) do |stdin, stdout, stderr, wait_thr| status = wait_thr.value.exitstatus @pid = wait_thr.pid diff --git a/lib/tasks/resque.rake b/lib/tasks/resque.rake new file mode 100644 index 0000000..9b30bb0 --- /dev/null +++ b/lib/tasks/resque.rake @@ -0,0 +1 @@ +require 'resque/tasks' diff --git a/public/index.html b/public/index.html deleted file mode 100644 index a1d5099..0000000 --- a/public/index.html +++ /dev/null @@ -1,241 +0,0 @@ -<!DOCTYPE html> -<html> - <head> - <title>Ruby on Rails: Welcome aboard</title> - <style type="text/css" media="screen"> - body { - margin: 0; - margin-bottom: 25px; - padding: 0; - background-color: #f0f0f0; - font-family: "Lucida Grande", "Bitstream Vera Sans", "Verdana"; - font-size: 13px; - color: #333; - } - - h1 { - font-size: 28px; - color: #000; - } - - a {color: #03c} - a:hover { - background-color: #03c; - color: white; - text-decoration: none; - } - - - #page { - background-color: #f0f0f0; - width: 750px; - margin: 0; - margin-left: auto; - margin-right: auto; - } - - #content { - float: left; - background-color: white; - border: 3px solid #aaa; - border-top: none; - padding: 25px; - width: 500px; - } - - #sidebar { - float: right; - width: 175px; - } - - #footer { - clear: both; - } - - #header, #about, #getting-started { - padding-left: 75px; - padding-right: 30px; - } - - - #header { - background-image: url("assets/rails.png"); - background-repeat: no-repeat; - background-position: top left; - height: 64px; - } - #header h1, #header h2 {margin: 0} - #header h2 { - color: #888; - font-weight: normal; - font-size: 16px; - } - - - #about h3 { - margin: 0; - margin-bottom: 10px; - font-size: 14px; - } - - #about-content { - background-color: #ffd; - border: 1px solid #fc0; - margin-left: -55px; - margin-right: -10px; - } - #about-content table { - margin-top: 10px; - margin-bottom: 10px; - font-size: 11px; - border-collapse: collapse; - } - #about-content td { - padding: 10px; - padding-top: 3px; - padding-bottom: 3px; - } - #about-content td.name {color: #555} - #about-content td.value {color: #000} - - #about-content ul { - padding: 0; - list-style-type: none; - } - - #about-content.failure { - background-color: #fcc; - border: 1px solid #f00; - } - #about-content.failure p { - margin: 0; - padding: 10px; - } - - - #getting-started { - border-top: 1px solid #ccc; - margin-top: 25px; - padding-top: 15px; - } - #getting-started h1 { - margin: 0; - font-size: 20px; - } - #getting-started h2 { - margin: 0; - font-size: 14px; - font-weight: normal; - color: #333; - margin-bottom: 25px; - } - #getting-started ol { - margin-left: 0; - padding-left: 0; - } - #getting-started li { - font-size: 18px; - color: #888; - margin-bottom: 25px; - } - #getting-started li h2 { - margin: 0; - font-weight: normal; - font-size: 18px; - color: #333; - } - #getting-started li p { - color: #555; - font-size: 13px; - } - - - #sidebar ul { - margin-left: 0; - padding-left: 0; - } - #sidebar ul h3 { - margin-top: 25px; - font-size: 16px; - padding-bottom: 10px; - border-bottom: 1px solid #ccc; - } - #sidebar li { - list-style-type: none; - } - #sidebar ul.links li { - margin-bottom: 5px; - } - - .filename { - font-style: italic; - } - </style> - <script type="text/javascript"> - function about() { - info = document.getElementById('about-content'); - if (window.XMLHttpRequest) - { xhr = new XMLHttpRequest(); } - else - { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } - xhr.open("GET","rails/info/properties",false); - xhr.send(""); - info.innerHTML = xhr.responseText; - info.style.display = 'block' - } - </script> - </head> - <body> - <div id="page"> - <div id="sidebar"> - <ul id="sidebar-items"> - <li> - <h3>Browse the documentation</h3> - <ul class="links"> - <li><a href="http://guides.rubyonrails.org/">Rails Guides</a></li> - <li><a href="http://api.rubyonrails.org/">Rails API</a></li> - <li><a href="http://www.ruby-doc.org/core/">Ruby core</a></li> - <li><a href="http://www.ruby-doc.org/stdlib/">Ruby standard library</a></li> - </ul> - </li> - </ul> - </div> - - <div id="content"> - <div id="header"> - <h1>Welcome aboard</h1> - <h2>You’re riding Ruby on Rails!</h2> - </div> - - <div id="about"> - <h3><a href="rails/info/properties" onclick="about(); return false">About your application’s environment</a></h3> - <div id="about-content" style="display: none"></div> - </div> - - <div id="getting-started"> - <h1>Getting started</h1> - <h2>Here’s how to get rolling:</h2> - - <ol> - <li> - <h2>Use <code>rails generate</code> to create your models and controllers</h2> - <p>To see all available options, run it without parameters.</p> - </li> - - <li> - <h2>Set up a default route and remove <span class="filename">public/index.html</span></h2> - <p>Routes are set up in <span class="filename">config/routes.rb</span>.</p> - </li> - - <li> - <h2>Create your database</h2> - <p>Run <code>rake db:create</code> to create your database. If you're not using SQLite (the default), edit <span class="filename">config/database.yml</span> with your username and password.</p> - </li> - </ol> - </div> - </div> - - <div id="footer"> </div> - </div> - </body> -</html> |