Skip to content

Commit

Permalink
Added support for CCMenu (resp. CCTray) by generating a CruiseControl
Browse files Browse the repository at this point in the history
XmlStatusReport.

Code was heavily influenced by https://github.com/thoughtworks/cruisecontrol.rb
  • Loading branch information
Gerrit Riessen committed Jul 6, 2011
1 parent 091c537 commit 63f3d11
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 8 deletions.
7 changes: 5 additions & 2 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
class ProjectsController < ApplicationController
before_filter :locate_project, :only => [:show, :build, :edit, :update, :remove, :destroy, :arrange, :feed]
respond_to :js, :only => [:index, :show]



def index
@projects = Project.order("position ASC")
respond_to do |format|
format.cctray { render :action => 'index_cctray', :layout => false }
format.all { render }
end
end

def show
Expand Down
26 changes: 26 additions & 0 deletions app/helpers/projects_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module ProjectsHelper
def format_time(time, format = :iso)
I18n.l time, :format => format
end

# Re-map our project statuses to match the project statuses recognized
# by CCTray.Net
def map_to_cctray_build_status(project_status)
case project_status.to_s
when Build::STATUS_OK then 'Success'
when Build::STATUS_FAILED then 'Failure'
else 'Unknown'
end
end

# Re-map our build activities to match the build activities recognized
# by CCTray.Net
def map_to_cctray_project_activity(builder_state)
case builder_state.to_s
when Build::STATUS_IN_QUEUE then 'CheckingModifications'
when Build::STATUS_PROGRESS then 'Building'
when Build::STATUS_OK then 'Sleeping'
else 'Unknown'
end
end
end
17 changes: 11 additions & 6 deletions app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ class Project < ActiveRecord::Base
before_update :rename_build_folder
before_create :set_default_build_counts
after_save :update_hooks

validates :hook_name, :uniqueness => {:allow_blank => true}
validates :name, :presence => true, :uniqueness => true
validates :vcs_type, :inclusion => BigTuna.vcses.map { |e| e::VALUE }
validates :vcs_source, :presence => true
validates :vcs_branch, :presence => true

validate :validate_vcs_incremental_support

acts_as_list

def self.ajax_reload?
Expand Down Expand Up @@ -99,16 +99,21 @@ def stability
def hooks=(hooks)
@_hooks = hooks
end

def fetch_type
if self[:fetch_type]
self[:fetch_type].to_sym
else
:clone
end
end


def last_complete_build
builds.reverse.find { |build| build.finished? }
end

private

def build_dir_from_name(name)
if BigTuna.build_dir[0] == '/'[0]
File.join(BigTuna.build_dir, name.downcase.gsub(/[^A-Za-z0-9]/, "_"))
Expand Down Expand Up @@ -161,7 +166,7 @@ def remove_project_jobs_in_queue
end
jobs_to_destroy.each { |job| job.destroy }
end

def validate_vcs_incremental_support
errors.add(:fetch_type, " #{fetch_type} not support by the vcs") if fetch_type == :incremental && !vcs.support_incremental_build?
end
Expand Down
18 changes: 18 additions & 0 deletions app/views/projects/index_cctray.rxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# List of projects and their state in XML - to be consumed by CruiseControl.NET tray.

xml.Projects do
@projects.each do |project|
last_build = project.last_complete_build

xml.Project(
:name => project.name,
:category => project.vcs_branch,
:activity => map_to_cctray_project_activity(project.status),

:lastBuildStatus => (last_build ? map_to_cctray_build_status(last_build.status) : "Unknown"),
:lastBuildLabel => (last_build ? last_build.display_name : 'Unknown'),
:lastBuildTime => (last_build ? format_time(last_build.finished_at, :round_trip_local) : '1970-01-01T00:00:00.000000-00:00'),
:nextBuildTime => '1970-01-01T00:00:00.000000-00:00',
:webUrl => url_for(:only_path => false, :controller => 'projects', :action => 'show', :id => project))
end
end
1 change: 1 addition & 0 deletions config/initializers/mime_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
# Mime::Type.register_alias "text/html", :iphone
Mime::Type.register "application/cctray", :cctray
10 changes: 10 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,13 @@ en:
time:
formats:
full: "%Y-%m-%d %H:%M:%S"
iso: "%Y-%m-%d %H:%M:%S"
iso_date: "%Y-%m-%d"
verbose: "%I:%M %p on %d %B %Y"
rss: "%a, %d %b %Y %H:%M:%S Z" # Must be in GMT to be compliant.
round_trip_local: "%Y-%m-%dT%H:%M:%S.0000000%z" # yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK
human:
future: "%Y-%m-%d %H:%M:%S ?future?"
before_this_year: "%d %b %y"
this_year: "%d %b"
today: "%H:%M"
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,9 @@
match "/hooks/build/:hook_name", :to => "hooks#autobuild"
match "/hooks/build/github/:secure", :to => "hooks#github"
match "/hooks/build/bitbucket/:secure", :to => "hooks#bitbucket"

match 'XmlStatusReport.aspx' => 'projects#index', :format => 'cctray'
match 'XmlServerReport.aspx' => 'projects#index', :format => 'cctray'

root :to => "projects#index"
end

0 comments on commit 63f3d11

Please sign in to comment.