Skip to content
Snippets Groups Projects
Commit a04b3f9d authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Refactored controllers. Added build status json

parent b065c1f0
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -5,4 +5,10 @@ class ApplicationController < ActionController::Base
@error = "Project path is not a git repository"
render "errors/show", status: 500
end
def authenticate_token!
unless project.valid_token?(params[:token])
return head(403)
end
end
end
class BuildsController < ApplicationController
before_filter :authenticate_user!
before_filter :authenticate_user!, except: [:status]
before_filter :project
before_filter :authenticate_token!, only: [:build]
 
def show
@builds = @project.builds.where(sha: params[:id]).order('id DESC')
@builds = builds
 
@build = if params[:bid]
@builds.where(id: params[:bid])
Loading
Loading
@@ -15,6 +16,12 @@ class BuildsController < ApplicationController
@builds = @builds.paginate(:page => params[:page], :per_page => 20)
end
 
def status
@build = builds.limit(1).first
render json: @build.to_json(only: [:status, :id, :sha])
end
def cancel
@build = @project.builds.find(params[:id])
@build.cancel
Loading
Loading
@@ -27,4 +34,8 @@ class BuildsController < ApplicationController
def project
@project = Project.find(params[:project_id])
end
def builds
project.builds.where(sha: params[:id]).order('id DESC')
end
end
Loading
Loading
@@ -2,13 +2,14 @@ require 'runner'
 
class ProjectsController < ApplicationController
before_filter :authenticate_user!, except: [:build, :status]
before_filter :project, only: [:build, :details, :show, :status, :edit, :update, :destroy]
before_filter :authenticate_token!, only: [:build]
 
def index
@projects = Project.order('id DESC').paginate(page: params[:page], per_page: 20)
end
 
def show
@project = Project.find(params[:id])
@ref = params[:ref]
 
@builds = @project.builds
Loading
Loading
@@ -17,7 +18,6 @@ class ProjectsController < ApplicationController
end
 
def details
@project = Project.find(params[:id])
end
 
def new
Loading
Loading
@@ -25,7 +25,6 @@ class ProjectsController < ApplicationController
end
 
def edit
@project = Project.find(params[:id])
end
 
def create
Loading
Loading
@@ -39,18 +38,15 @@ class ProjectsController < ApplicationController
end
 
def update
@project = Project.find(params[:id])
if @project.update_attributes(params[:project])
redirect_to @project, notice: 'Project was successfully updated.'
if project.update_attributes(params[:project])
redirect_to project, notice: 'Project was successfully updated.'
else
render action: "edit"
end
end
 
def destroy
@project = Project.find(params[:id])
@project.destroy
project.destroy
 
redirect_to projects_url
end
Loading
Loading
@@ -68,20 +64,17 @@ class ProjectsController < ApplicationController
end
 
def build
@project = Project.find(params[:id])
if @project.token && @project.token == params[:token]
if @project.valid_token?(params[:token])
@build = @project.register_build(params)
Resque.enqueue(Runner, @build.id) if @build
head 200
else
head 403
end
end
 
# Project status badge
# Image with build status for sha or ref
def status
@project = Project.find(params[:id])
image_name = if params[:sha]
@project.sha_status_image(params[:sha])
elsif params[:ref]
Loading
Loading
@@ -92,4 +85,10 @@ class ProjectsController < ApplicationController
 
send_file Rails.root.join('public', image_name), filename: image_name, disposition: 'inline'
end
protected
def project
@project ||= Project.find(params[:id])
end
end
Loading
Loading
@@ -109,6 +109,10 @@ class Project < ActiveRecord::Base
def tracked_refs
@tracked_refs ||= default_ref.split(",").map{|ref| ref.strip}
end
def valid_token? token
self.token && self.token == token
end
end
 
 
Loading
Loading
Loading
Loading
@@ -10,9 +10,11 @@ GitlabCi::Application.routes.draw do
get :details
post :build
end
resources :builds, only: [:show] do
member do
get :cancel
get :status
end
end
end
Loading
Loading
Loading
Loading
@@ -10,9 +10,7 @@ User.create(
if Rails.env == 'development'
`cd #{Rails.root.join('tmp')} && git clone https://github.com/randx/six.git test_repo`
 
3.times do |i|
FactoryGirl.create :project,
name: "Six #{i}",
scripts: 'bundle exec rspec spec'
end
FactoryGirl.create :project,
name: "Six",
scripts: 'bundle exec rspec spec'
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