Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Allow non github projects #22

Merged
merged 3 commits into from

3 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
4 app/controllers/projects_controller.rb
@@ -2,7 +2,7 @@ class ProjectsController < InheritedResources::Base
before_filter :authenticate_user!
before_filter :pull_repo, :only => [:show, :edit]
- before_filter :ensure_accessibility_by_current_user, :except => [:index, :new, :create]
+ before_filter :ensure_accessibility_by_current_user, :except => [:index, :new, :new_github, :create]
respond_to :json, :only => :show
@@ -37,4 +37,4 @@ def pull_repo
resource.pull
end
-end
+end
View
27 app/models/project.rb
@@ -4,7 +4,7 @@
class Project < ActiveRecord::Base
# The github data will be serialzed as a Hash.
- serialize :github_data
+ serialize :data
has_many :jobs, :dependent => :destroy
has_one :job_in_progress, :class_name => "Job"
@@ -13,12 +13,12 @@ class Project < ActiveRecord::Base
before_create :ensure_allowed_repo
after_create :clone_repo
- before_save :update_github_data
+ before_save :update_data
after_destroy :remove_repo
# Lets do some delegation so that we can access some common methods directly.
delegate :user_name, :repo_name, :cloned?, :capified?, :to => :repo
- delegate :html_url, :description, :organization, :to => :github_data
+ delegate :html_url, :description, :organization, :to => :data
default_scope where(:deleted_at => nil)
@@ -56,7 +56,7 @@ def cloned?
#
# Returns a Boolean true if the user has access.
def accessible_by?(user)
- !!github.to_hash
+ !github? || !!github.to_hash
rescue
false
end
@@ -64,8 +64,8 @@ def accessible_by?(user)
# Convert the github data into a Hashie::Mash object, so that delegation works.
#
# Returns a Hashie::Mash object.
- def github_data
- @github_data ||= Hashie::Mash.new(read_attribute(:github_data))
+ def data
+ @data ||= Hashie::Mash.new(read_attribute(:data))
end
# Returns an un-authenticated instance of Github::Repos.
@@ -73,11 +73,20 @@ def github
@github ||= Github.new.repo(repo.user_name, repo.repo_name)
end
+ def github?
+ self.url =~ /github.com/
+ end
+
# Returns a Strano::Repo instance.
def repo
@repo ||= Strano::Repo.new(url)
end
+ # Returns a Strano::Repo instance of the repository referenced in the Capistrano file.
+ def target_repo
+ @target_repo = Strano::Repo.new(cap.repository)
+ end
+
# The public task list for this project's repository.
#
# Returns an Array of tasks.
@@ -146,8 +155,10 @@ def remove_repo
RemoveRepo.perform_async id
end
- def update_github_data
- self.github_data = github.to_hash
+ def update_data
+ if github?
+ self.data = github.to_hash
+ end
end
def ensure_allowed_repo
View
14 app/views/projects/_form.html.erb
@@ -0,0 +1,14 @@
+<%= simple_form_for resource, :html => { :class => 'form-horizontal' } do |f| %>
+
+ <%= f.input :url, :placeholder => 'git@git.server.com:project/repo.git' %>
+ <%= f.simple_fields_for :data do |d| %>
+ <%= d.input :html_url, :placeholder => 'http://www.project-page.com' %>
+ <%= d.input :description, :as => :text, :input_html => { :class => "span8", :rows => 5, :style => "height:80px;" } %>
+ <% end %>
+
+ <div class="form-actions">
+ <%= f.button :submit, 'Create' %>
+ <%= f.button :cancel, :url => collection_path %>
+ </div>
+
+<%- end %>
View
37 app/views/projects/_new_github.html.erb
@@ -0,0 +1,37 @@
+<div class="tabbable">
+ <ul class="nav nav-tabs">
+ <%- if Strano.allow_users_include?(current_user.username) -%>
+ <li class="active"><a href="#repos" data-toggle="tab">My Repositories</a></li>
+ <%- end -%>
+
+ <%- if Strano.allow_organizations? -%>
+ <li class="dropdown">
+ <a href="#" class="dropdown-toggle" data-toggle="dropdown">Organisations... <b class="caret"></b></a>
+ <ul class="dropdown-menu">
+ <%- current_user.github.orgs.each do |org| -%>
+ <li><a href="#<%= org.login %>" data-toggle="tab"><%= org.login %></a></li>
+ <%- end -%>
+ </ul>
+ </li>
+ <%- end -%>
+ </ul>
+
+ <div class="tab-content">
+ <%- if Strano.allow_users_include?(current_user.username) -%>
+ <div class="tab-pane active" id="repos"><%= render 'repos', :repos => current_user.github.repos %></div>
+ <%- end -%>
+
+ <%- current_user.github.orgs.each do |org| -%>
+
+ <div class="tab-pane" id="<%= org.login %>">
+ <h2 class="page-header">
+ <%= image_tag org.avatar_url, :size => "26x26", :class => "org-avatar" %>
+ <span class="padding-bottom3"><%= org.login %></span>
+ </h2>
+
+ <%= render 'repos', :repos => org.repos %>
+ </div>
+
+ <%- end if Strano.allow_organizations? -%>
+ </div>
+</div>
View
7 app/views/projects/index.html.erb
@@ -1,13 +1,14 @@
<%- title 'Projects' -%>
<div class="well">
+ <%= link_to 'Create github project...', new_resource_path(:type => :github), :class => "btn btn-primary" %>
<%= link_to 'Create project...', new_resource_path, :class => "btn btn-primary" %>
</div>
<%- if collection.empty? -%>
-
+
<h4 align="center">You haven't created any projects yet! <%= link_to "Create a project now", new_resource_path %>...</h4>
-
+
<% else %>
<table class="table table-striped">
@@ -23,4 +24,4 @@
</tbody>
</table>
-<%- end -%>
+<%- end -%>
View
45 app/views/projects/new.html.erb
@@ -1,41 +1,10 @@
<%- title "Create Project" -%>
-<%- subtitle "from a github repo", true, true -%>
<%- breadcrumb 'Projects', collection_path -%>
-<div class="tabbable">
- <ul class="nav nav-tabs">
- <%- if Strano.allow_users_include?(current_user.username) -%>
- <li class="active"><a href="#repos" data-toggle="tab">My Repositories</a></li>
- <%- end -%>
-
- <%- if Strano.allow_organizations? -%>
- <li class="dropdown">
- <a href="#" class="dropdown-toggle" data-toggle="dropdown">Organisations... <b class="caret"></b></a>
- <ul class="dropdown-menu">
- <%- current_user.github.orgs.each do |org| -%>
- <li><a href="#<%= org.login %>" data-toggle="tab"><%= org.login %></a></li>
- <%- end -%>
- </ul>
- </li>
- <%- end -%>
- </ul>
-
- <div class="tab-content">
- <%- if Strano.allow_users_include?(current_user.username) -%>
- <div class="tab-pane active" id="repos"><%= render 'repos', :repos => current_user.github.repos %></div>
- <%- end -%>
-
- <%- current_user.github.orgs.each do |org| -%>
-
- <div class="tab-pane" id="<%= org.login %>">
- <h2 class="page-header">
- <%= image_tag org.avatar_url, :size => "26x26", :class => "org-avatar" %>
- <span class="padding-bottom3"><%= org.login %></span>
- </h2>
-
- <%= render 'repos', :repos => org.repos %>
- </div>
-
- <%- end if Strano.allow_organizations? -%>
- </div>
-</div>
+<% if params[:type] == 'github' %>
+ <%- subtitle "from a github repo", true, true -%>
+ <%= render 'new_github' %>
+<% else %>
+ <%- subtitle "from a git repo", true, true -%>
+ <%= render 'form' %>
+<% end %>
View
4 app/views/projects/show/_info.html.erb
@@ -17,7 +17,7 @@
</div>
<div class="span9">
- <p><strong><%= resource.description %></strong></p>
+ <p><strong><%= resource.description.blank? ? '&nbsp;'.html_safe : resource.description %></strong></p>
<p><%= link_to resource.html_url, resource.html_url %></p>
<%- if resource.organization? -%>
<p><%= link_to resource.organization.login, "https://github.com/#{resource.organization.login}" %></p>
@@ -69,4 +69,4 @@
<p class="quieter small"><%= resource.created_at.to_s :long_ordinal %></p>
<p class="quieter small"><%= resource.updated_at.to_s :long_ordinal %></p>
</div>
-</div>
+</div>
View
5 db/migrate/20120913160334_rename_github_data_to_data.rb
@@ -0,0 +1,5 @@
+class RenameGithubDataToData < ActiveRecord::Migration
+ def change
+ rename_column :projects, :github_data, :data
+ end
+end
View
4 db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120323122036) do
+ActiveRecord::Schema.define(:version => 20120913160334) do
create_table "jobs", :force => true do |t|
t.string "task"
@@ -33,7 +33,7 @@
t.string "url"
t.datetime "created_at"
t.datetime "updated_at"
- t.text "github_data"
+ t.text "data"
t.datetime "cloned_at"
t.datetime "deleted_at"
t.boolean "pull_in_progress", :default => false
Something went wrong with that request. Please try again.