diff --git a/Gemfile.lock b/Gemfile.lock index 2236912c..a9b07fba 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -117,7 +117,7 @@ GEM hashie (2.0.3) hike (1.2.3) httpauth (0.2.0) - i18n (0.6.11) + i18n (0.7.0) inherited_resources (1.4.0) has_scope (~> 0.5.0) responders (~> 0.9) @@ -141,7 +141,7 @@ GEM polyamorous (~> 0.5.0) mime-types (1.25.1) mini_portile (0.5.2) - multi_json (1.10.1) + multi_json (1.11.0) multipart-post (1.2.0) newrelic_rpm (3.9.0.229) nokogiri (1.6.1) @@ -222,7 +222,7 @@ GEM sawyer (0.5.5) addressable (~> 2.3.5) faraday (~> 0.8, < 0.10) - shoulda-matchers (2.0.0) + shoulda-matchers (2.8.0) activesupport (>= 3.0.0) simple_form (2.1.0) actionpack (~> 3.0) diff --git a/app/models/organization.rb b/app/models/organization.rb index 72891fcb..cb9d2777 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -1,19 +1,23 @@ class Organization < ActiveRecord::Base before_save :delete_logo + before_create :set_github_org has_many :jobs has_many :projects has_many :organization_metrics has_many :sponsorships - attr_accessible :name, :url, :github_org, :description, :is_tax_exempt, :contact_name, :contact_role, :contact_email, :annual_budget_usd, :total_staff_size, :tech_staff_size, :notes, :image_url, :twitter, :logo, :logo_delete + attr_accessible :name, :url, :github_org, :description, + :is_tax_exempt, :contact_name, :contact_role, + :contact_email, :annual_budget_usd, :total_staff_size, + :tech_staff_size, :notes, :image_url, :twitter, :logo, + :logo_delete attr_accessible :organization_metrics_attributes, :projects_attributes attr_writer :logo_delete attr_accessor :is_public_submission - validates_presence_of :name - validates_presence_of :github_org, if: :is_public_submission + validates :name, presence: true # Paperclip has_attached_file :logo, styles: { thumb: '100x100>', medium: '250x250>' }, @@ -48,4 +52,12 @@ def logo_delete def delete_logo logo.clear if logo_delete == '1' end + + def set_github_org + if projects.first + self.github_org = Project.parse_git_url(projects.first.submitted_github_url) + .split('/') + .first + end + end end diff --git a/app/models/project.rb b/app/models/project.rb index a1b111ea..d4b66230 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1,12 +1,21 @@ class Project < ActiveRecord::Base + before_create :set_github_repo belongs_to :organization acts_as_ordered_taggable acts_as_ordered_taggable_on :technologies, :causes attr_accessible :cause_list, :description, :github_repo, :help_url, :install_url, :is_active, :is_approved, :name, :notes, - :organization_id, :technology_list, :url, :twitter - validates_presence_of :name, :github_repo + :organization_id, :technology_list, :url, :twitter, + :submitted_github_url + + attr_accessor :submitted_github_url + validates :name, presence: true + validates :github_repo, presence: true, on: :update + validates :submitted_github_url, presence: true, + format: { with: /\Ahttps?:\/\/github.com\/[\w-]+\/[\w\.-]+(\/)?\Z/i, + message: 'Please enter a valid GitHub URL.' }, + on: :create has_many :favorite_projects has_many :users, through: :favorite_projects @@ -60,4 +69,15 @@ def related_projects def tasks_url "#{github_url}/issues" end + + def self.parse_git_url(url) + url.gsub(/^(((https|http|git)?:\/\/(www\.)?)|git@)github.com(:|\/)/i, '') + .gsub(/(\.git|\/)$/i, '') + end + + private + + def set_github_repo + self.github_repo = Project.parse_git_url(submitted_github_url).split('/').last + end end diff --git a/app/views/organizations/new.html.erb b/app/views/organizations/new.html.erb index 6c19fa01..5d9e0a54 100644 --- a/app/views/organizations/new.html.erb +++ b/app/views/organizations/new.html.erb @@ -7,15 +7,14 @@ <%= f.simple_fields_for :projects do |project| %>
Already a CodeMontage Organization? <%= mail_to "projects@codemontage.com", "Submit a New Project", :subject => "New project for my organization" %>
-