Skip to content
This repository has been archived by the owner on Aug 1, 2022. It is now read-only.

Commit

Permalink
Cloning repos
Browse files Browse the repository at this point in the history
  • Loading branch information
joelmoss committed Dec 13, 2011
1 parent eddf7a5 commit 2346cfe
Show file tree
Hide file tree
Showing 26 changed files with 260 additions and 31 deletions.
4 changes: 4 additions & 0 deletions Gemfile
Expand Up @@ -17,6 +17,9 @@ gem 'devise'
gem 'omniauth-github'
gem 'github_api'
gem 'capistrano'
gem 'grit'
gem 'girl_friday'
gem 'inherited_resources'

# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
Expand All @@ -41,4 +44,5 @@ end
group :test do
gem 'sqlite3'
gem 'webmock'
gem "fakefs", :require => "fakefs/safe"
end
24 changes: 20 additions & 4 deletions Gemfile.lock
Expand Up @@ -48,6 +48,7 @@ GEM
coffee-script-source (1.1.3)
commonjs (0.2.0)
therubyracer (~> 0.9.9)
connection_pool (0.1.0)
crack (0.3.1)
database_cleaner (0.7.0)
devise (1.5.2)
Expand All @@ -56,23 +57,29 @@ GEM
warden (~> 1.1)
diff-lcs (1.1.3)
erubis (2.7.0)
execjs (1.2.11)
execjs (1.2.12)
multi_json (~> 1.0)
factory_girl (2.3.2)
activesupport
factory_girl_rails (1.4.0)
factory_girl (~> 2.3.0)
railties (>= 3.0.0)
fakefs (0.4.0)
faraday (0.7.5)
addressable (~> 2.2.6)
multipart-post (~> 1.1.3)
rack (>= 1.1.0, < 2)
ffaker (1.10.1)
girl_friday (0.9.7)
connection_pool (~> 0.1.0)
github_api (0.3.3)
faraday (~> 0.7.4)
hashie (~> 1.2.0)
multi_json (~> 1.0.3)
oauth2 (~> 0.5.0)
grit (2.4.1)
diff-lcs (~> 1.1)
mime-types (~> 1.15)
growl (1.0.3)
guard (0.8.8)
thor (~> 0.14.6)
Expand All @@ -81,12 +88,16 @@ GEM
guard (>= 0.2.2)
guard-pow (0.2.1)
guard (>= 0.3.0)
guard-rspec (0.5.8)
guard-rspec (0.5.9)
guard (>= 0.8.4)
has_scope (0.5.1)
hashie (1.2.0)
highline (1.6.8)
hike (1.2.1)
i18n (0.6.0)
inherited_resources (1.3.0)
has_scope (~> 0.5.0)
responders (~> 0.6.0)
jquery-rails (1.0.19)
railties (~> 3.0)
thor (~> 0.14)
Expand All @@ -106,7 +117,7 @@ GEM
mime-types (1.17.2)
multi_json (1.0.4)
multipart-post (1.1.4)
mysql2 (0.3.10)
mysql2 (0.3.11)
net-scp (1.0.4)
net-ssh (>= 1.99.1)
net-sftp (2.0.5)
Expand Down Expand Up @@ -156,6 +167,7 @@ GEM
rb-fsevent (0.4.3.1)
rdoc (3.11)
json (~> 1.4)
responders (0.6.4)
rspec (2.7.0)
rspec-core (~> 2.7.0)
rspec-expectations (~> 2.7.0)
Expand Down Expand Up @@ -188,7 +200,7 @@ GEM
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
twitter-bootstrap-rails (1.4.1)
twitter-bootstrap-rails (1.4.2)
actionpack
jquery-rails (~> 1.0)
less
Expand All @@ -214,13 +226,17 @@ DEPENDENCIES
database_cleaner
devise
factory_girl_rails
fakefs
ffaker
girl_friday
github_api
grit
growl
guard
guard-bundler
guard-pow
guard-rspec
inherited_resources
jquery-rails
marked
mysql2
Expand Down
11 changes: 11 additions & 0 deletions README.rdoc
Expand Up @@ -14,7 +14,18 @@ The Capistrano backed deployment management UI.
- Git pull to the local repo each time the project is accessed and/or on a schedule


==== Setup a repo

-




=== Public SSH Key

Save your server's public SSH key to ENV['STRANO_PUBLIC_SSH_KEY']


=== Repository clone location

In vendor/repos, but can be changed by setting ENV['STRANO_CLONE_PATH']
5 changes: 4 additions & 1 deletion app/assets/javascripts/bootstrap.js.coffee
@@ -1,13 +1,16 @@
$ ->
$("a[rel=twipsy]").twipsy live: true

$ ->
$("a[rel=popover]").popover offset: 10

$ ->
domModal = $(".modal").modal(
backdrop: true
closeOnEscape: true
)
$(".open-modal").click ->
domModal.toggle()
domModal.toggle()

$ ->
$(".btn").button "complete"
1 change: 1 addition & 0 deletions app/controllers/dashboard_controller.rb
Expand Up @@ -3,5 +3,6 @@ class DashboardController < ApplicationController

def index
@repos = Github::Repos.new(:oauth_token => current_user.github_access_token).repos
@projects = Project.all
end
end
10 changes: 10 additions & 0 deletions app/controllers/projects_controller.rb
@@ -0,0 +1,10 @@
class ProjectsController < InheritedResources::Base


protected

def begin_of_association_chain
current_user
end

end
14 changes: 14 additions & 0 deletions app/models/project.rb
@@ -0,0 +1,14 @@
class Project < ActiveRecord::Base

belongs_to :user

after_create :clone_repo


private

def clone_repo
CLONE_QUEUE << url
end

end
6 changes: 3 additions & 3 deletions app/models/user.rb
@@ -1,6 +1,6 @@
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
has_many :projects

devise :omniauthable

cattr_accessor :disable_ssh_github_upload
Expand Down Expand Up @@ -51,7 +51,7 @@ def authorized_for_github?
# Upload SSH key to github, but not if disable_ssh_github_upload is true.
# User must also be authorized for Github API access.
def upload_ssh_key_to_github
if !self.class.disable_ssh_github_upload && authorized_for_github?
if !ssh_key_uploaded_to_github? && !self.class.disable_ssh_github_upload && authorized_for_github?
github.create_key(:title => "Strano", :key => ENV['STRANO_PUBLIC_SSH_KEY'])
self.toggle! :ssh_key_uploaded_to_github
end
Expand Down
18 changes: 18 additions & 0 deletions app/views/dashboard/_projects.html.erb
@@ -0,0 +1,18 @@
<%- if @projects.empty? -%>

<h4 align="center">You haven't created any projects yet! Choose a repository to get started...</h4>

<% else %>

<table class="zebra-striped">
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
<tbody>
<%= render @projects %>
</tbody>
</table>

<%- end -%>
6 changes: 4 additions & 2 deletions app/views/dashboard/_repo.html.erb
@@ -1,4 +1,6 @@
<%- return if Project.exists?(:url => repo.ssh_url) -%>

<tr>
<td><%= link_to 'Setup', '#', :class => "btn primary" %></td>
<td><%= link_to 'Setup', projects_path('project[url]' => repo.ssh_url), :class => "btn primary", :method => :post %></td>
<td><h5><%= link_to repo.name, repo.html_url %></h5></td>
</tr>
</tr>
19 changes: 19 additions & 0 deletions app/views/dashboard/_repos.html.erb
@@ -0,0 +1,19 @@
<%- if @repos.empty? -%>

<h4 align="center">No repositories found in your Github account! Strano currently only supports the deployment of Github repositories.</h4>

<% else %>

<table class="zebra-striped">
<thead>
<tr>
<th width="40"></th>
<th>Name</th>
</tr>
</thead>
<tbody>
<%= render :partial => 'repo', :collection => @repos %>
</tbody>
</table>

<%- end -%>
26 changes: 8 additions & 18 deletions app/views/dashboard/index.html.erb
@@ -1,21 +1,11 @@
<%- title 'Dashboard' -%>

<%- if @repos.empty? -%>

<h4 align="center">No repositories found in your Github account!</h4>

<% else %>
<ul class="tabs" data-tabs="tabs">
<li class="active"><a href="#projects">Projects</a></li>
<li><a href="#repos">Repositories</a></li>
</ul>

<table class="zebra-striped">
<thead>
<tr>
<th width="40"></th>
<th>Name</th>
</tr>
</thead>
<tbody>
<%= render :partial => 'repo', :collection => @repos %>
</tbody>
</table>

<%- end -%>
<div class="tab-content">
<div class="tab-pane active" id="projects"><%= render 'projects' %></div>
<div class="tab-pane" id="repos"><%= render 'repos' %></div>
</div>
3 changes: 3 additions & 0 deletions app/views/projects/_project.html.erb
@@ -0,0 +1,3 @@
<tr>
<td><%= link_to project.url %></td>
</tr>
3 changes: 3 additions & 0 deletions app/views/projects/show.html.erb
@@ -0,0 +1,3 @@
<%- title "Project: ##{resource.id}" -%>


4 changes: 3 additions & 1 deletion config/application.rb
Expand Up @@ -22,7 +22,7 @@ class Application < Rails::Application
# -- all .rb files in that directory are automatically loaded.

# Custom directories with classes and modules you want to be autoloadable.
# config.autoload_paths += %W(#{config.root}/extras)
config.autoload_paths += %W(#{config.root}/lib)

# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named.
Expand Down Expand Up @@ -50,5 +50,7 @@ class Application < Rails::Application

# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'

config.threadsafe!
end
end
9 changes: 9 additions & 0 deletions config/initializers/girl_friday.rb
@@ -0,0 +1,9 @@
class MyErrorHandler
def handle(ex)
puts ex.message
end
end

CLONE_QUEUE = GirlFriday::WorkQueue.new(:git_clone, :error_handler => MyErrorHandler) do |msg|
Strano::Repo.clone(msg)
end
4 changes: 3 additions & 1 deletion config/routes.rb
Expand Up @@ -4,7 +4,9 @@
get 'sign_in', :to => 'users/sessions#new', :as => :new_user_session
delete 'sign_out', :to => 'users/sessions#destroy', :as => :destroy_user_session
end


resources :projects

root :to => "dashboard#index"

end
10 changes: 10 additions & 0 deletions db/migrate/20111210145824_create_projects.rb
@@ -0,0 +1,10 @@
class CreateProjects < ActiveRecord::Migration
def change
create_table :projects do |t|
t.string :url
t.references :user

t.timestamps
end
end
end
9 changes: 8 additions & 1 deletion db/schema.rb
Expand Up @@ -11,7 +11,14 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20111206203808) do
ActiveRecord::Schema.define(:version => 20111210145824) do

create_table "projects", :force => true do |t|
t.string "github_url"
t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "users", :force => true do |t|
t.string "email"
Expand Down
4 changes: 4 additions & 0 deletions lib/strano.rb
@@ -0,0 +1,4 @@
module Strano


end

0 comments on commit 2346cfe

Please sign in to comment.