From e38fa32822a34f8dbb7bb9af6885f30a5f0ce2a7 Mon Sep 17 00:00:00 2001 From: Jeremy Mack Date: Tue, 13 Dec 2011 09:18:36 -0500 Subject: [PATCH 01/12] Calling update_repository - Better comment too --- lib/tasks/bulk_import.rake | 94 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 lib/tasks/bulk_import.rake diff --git a/lib/tasks/bulk_import.rake b/lib/tasks/bulk_import.rake new file mode 100644 index 00000000..3c1078bc --- /dev/null +++ b/lib/tasks/bulk_import.rake @@ -0,0 +1,94 @@ +IMPORT_DIRECTORY = 'import_projects' +REPOSITORY_DIRECTORY = '/home/git/repositories' + +desc "Imports existing Git repos into new projects from the import_projects folder" +task :import_projects, [:email] => :environment do |t, args| + user_email = args.email + repos_to_import = Dir.glob("#{IMPORT_DIRECTORY}/*") + + puts "Found #{repos_to_import.length} repos to import" + + imported_count = 0 + skipped_count = 0 + failed_count = 0 + repos_to_import.each do |repo_path| + repo_name = File.basename repo_path + repo_full_path = File.join(Rails.root, repo_path) + + puts " Processing #{repo_name}" + + clone_path = "#{REPOSITORY_DIRECTORY}/#{repo_name}.git" + + if Dir.exists? clone_path + puts " INFO: #{clone_path} already exists in repositories directory, skipping." + skipped_count += 1 + next + else + if clone_bare_repo_as_git(repo_full_path, clone_path) + if create_repo_project(repo_name, user_email) + imported_count += 1 + else + failed_count += 1 + end + else + failed_count += 1 + end + end + + end + + puts "Finished importing #{imported_count} projects (skipped #{skipped_count}, failed #{failed_count})." +end + +# Clones a repo as bare git repo using the git user +def clone_bare_repo_as_git(existing_path, new_path) + begin + sh "sudo -u git -i git clone --bare '#{existing_path}' #{new_path}" + true + rescue + puts " ERROR: Faild to clone #{existing_path} to #{new_path}" + false + end +end + +# Creats a project in Gitlag given a @project_name@ to use (for name, web url, and code +# url) and a @user_email@ that will be assigned as the owner of the project. +def create_repo_project(project_name, user_email) + user = User.find_by_email(user_email) + if user + # Using find_by_code since that's the most important identifer to be unique + if Project.find_by_code(project_name) + puts " INFO: Project #{project_name} already exists in Gitlab, skipping." + false + else + project = Project.create( + name: project_name, + code: project_name, + path: project_name, + owner: user, + description: "Automatically created from CVS on #{Time.now.to_s}" + ) + + # Add user as admin for project + project.users_projects.create!( + :repo_access => Repository::REPO_RW, + :project_access => Project::PROJECT_RWA, + :user => user + ) + + # Per projects_controller.rb#37 + project.update_repository + + if project.valid? + true + else + puts " ERROR: Failed to create project #{project} because #{project.errors}" + false + end + end + else + puts " ERROR: #{user_email} not found, skipping" + false + end +end + From 2201ef80200d0a3f896a30fe10aa3a2c71b7bde1 Mon Sep 17 00:00:00 2001 From: Jeremy Mack Date: Tue, 13 Dec 2011 08:49:08 -0500 Subject: [PATCH 02/12] Add rake task for bulk repo importing Git repos should be in the import_projects directory in the root of application. The task is invoked via @rake import_projects@. --- lib/tasks/bulk_import.rake | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/tasks/bulk_import.rake b/lib/tasks/bulk_import.rake index 3c1078bc..68893a31 100644 --- a/lib/tasks/bulk_import.rake +++ b/lib/tasks/bulk_import.rake @@ -91,4 +91,3 @@ def create_repo_project(project_name, user_email) false end end - From a1cd582c67b10abbda6c2fb2c99d8735138d33db Mon Sep 17 00:00:00 2001 From: Saito Date: Tue, 13 Dec 2011 00:41:31 +0800 Subject: [PATCH 03/12] fix can not guess problem --- app/helpers/application_helper.rb | 1 + app/helpers/commits_helper.rb | 2 -- lib/utils.rb | 3 ++- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 2dd652e4..2f982dac 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,5 +1,6 @@ require 'digest/md5' module ApplicationHelper + include Utils::CharEncode def gravatar_icon(user_email) gravatar_host = request.ssl? ? "https://secure.gravatar.com" : "http://www.gravatar.com" diff --git a/app/helpers/commits_helper.rb b/app/helpers/commits_helper.rb index ae782671..98ec9936 100644 --- a/app/helpers/commits_helper.rb +++ b/app/helpers/commits_helper.rb @@ -1,6 +1,4 @@ module CommitsHelper - include Utils::CharEncode - def old_line_number(line, i) end diff --git a/lib/utils.rb b/lib/utils.rb index 17c9dfe3..2de14761 100644 --- a/lib/utils.rb +++ b/lib/utils.rb @@ -18,13 +18,14 @@ module Utils module CharEncode def encode(string) + return '' unless string cd = CharDet.detect(string) if cd.confidence > 0.6 string.force_encoding(cd.encoding) end string.encode("utf-8", :undef => :replace, :replace => "?", :invalid => :replace) rescue - "Invalid code encoding" + "Invalid Encoding" end end From a39fb5fc25f2db100115e15cdca1daee80693c94 Mon Sep 17 00:00:00 2001 From: Saito Date: Tue, 13 Dec 2011 00:42:07 +0800 Subject: [PATCH 04/12] tree view readme support --- app/assets/stylesheets/projects.css.scss | 35 ++++++++++++++++-------- app/views/refs/_tree.html.haml | 8 +++++- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/app/assets/stylesheets/projects.css.scss b/app/assets/stylesheets/projects.css.scss index 02570024..d487e581 100644 --- a/app/assets/stylesheets/projects.css.scss +++ b/app/assets/stylesheets/projects.css.scss @@ -67,8 +67,8 @@ a { } } -.view_file .view_file_header, -.diff_file .diff_file_header { +.view_file .view_file_header, +.diff_file .diff_file_header { background-image: -webkit-gradient(linear, 0 0, 0 26, color-stop(0.076, #fefefe), to(#F6F7F8)); background-image: -webkit-linear-gradient(#fefefe 7.6%, #F6F7F8); background-image: -moz-linear-gradient(#fefefe 7.6%, #F6F7F8); @@ -116,7 +116,7 @@ td.code { word-wrap:normal; } -table.highlighttable { +table.highlighttable { border: none; background: #F7F7F7; } @@ -331,7 +331,7 @@ body.project-page table .commit { border:none; text-shadow:none; - &.inline { + &.inline { display:inline; } @@ -430,28 +430,28 @@ body.projects-page input.text.git-url.project_list_url { width:165px; } body.project-page table.no-borders tr, -body.project-page table.no-borders td{ +body.project-page table.no-borders td{ border:none; } -#gitlab-tabs { +#gitlab-tabs { .ui-tabs-nav { border-bottom: 1px solid #DEDFE1; - li { + li { background: none; border:none; font-size: 16px; margin: 0; padding: 0; - a { + a { margin: 0; padding: 10px 16px; width:150px; } - &.ui-tabs-selected { + &.ui-tabs-selected { background-image: -webkit-gradient(linear, 0 0, 0 26, color-stop(0.076, #fefefe), to(#F6F7F8)); background-image: -webkit-linear-gradient(#fefefe 7.6%, #F6F7F8); background-image: -moz-linear-gradient(#fefefe 7.6%, #F6F7F8); @@ -466,17 +466,28 @@ body.project-page table.no-borders td{ border-top-left-radius: 5px; border-top-right-radius: 5px; } - } - } + } + } } -.ajax-tab-loading { +.ajax-tab-loading { padding:40px; display:none; } #tree-content-holder { float:left; width:100%; } +#tree-readme-holder { + float:left; + width:100%; + + .readme { + @include round-borders-all(4px); + padding: 4px 15px; + background:#F7F7F7; + } +} + /* Commit Page */ diff --git a/app/views/refs/_tree.html.haml b/app/views/refs/_tree.html.haml index 7400aa67..0fad2452 100644 --- a/app/views/refs/_tree.html.haml +++ b/app/views/refs/_tree.html.haml @@ -21,7 +21,7 @@ %th Last commit = link_to "history", tree.history_path, :class => "right" - + - if tree.up_dir? %tr{ :class => "tree-item", :url => tree.up_dir_path } %td.tree-item-file-name @@ -35,6 +35,12 @@ - contents.select{ |i| i.is_a?(Grit::Blob)}.each do |content| = render :partial => "refs/tree_item", :locals => { :content => content } + - if content = contents.select{ |c| c.is_a?(Grit::Blob) and c.name =~ /^readme\.(md|markdown)$/i }.first + #tree-readme-holder + %h3= content.name + .readme + = markdown(encode content.data) + :javascript $(function(){ $('select#branch').selectmenu({style:'popup', width:200}); From 8ee6d21fa1d78b327eab91ff4b3cae8c6146efd9 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 12 Dec 2011 20:08:04 +0200 Subject: [PATCH 05/12] lil js refactoring --- app/assets/javascripts/merge_requests.js | 0 .../javascripts/merge_requests.js.coffee | 3 --- app/assets/javascripts/projects.js | 13 ------------ app/assets/javascripts/tree.js | 21 +++++++++++++++++++ app/views/refs/tree.html.haml | 5 +++++ 5 files changed, 26 insertions(+), 16 deletions(-) create mode 100644 app/assets/javascripts/merge_requests.js delete mode 100644 app/assets/javascripts/merge_requests.js.coffee create mode 100644 app/assets/javascripts/tree.js diff --git a/app/assets/javascripts/merge_requests.js b/app/assets/javascripts/merge_requests.js new file mode 100644 index 00000000..e69de29b diff --git a/app/assets/javascripts/merge_requests.js.coffee b/app/assets/javascripts/merge_requests.js.coffee deleted file mode 100644 index 76156794..00000000 --- a/app/assets/javascripts/merge_requests.js.coffee +++ /dev/null @@ -1,3 +0,0 @@ -# Place all the behaviors and hooks related to the matching controller here. -# All this logic will automatically be available in application.js. -# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/javascripts/projects.js b/app/assets/javascripts/projects.js index 4ffbd140..7d21f061 100644 --- a/app/assets/javascripts/projects.js +++ b/app/assets/javascripts/projects.js @@ -1,17 +1,4 @@ $(document).ready(function(){ - $('#tree-slider td.tree-item-file-name a, #tree-breadcrumbs a').live("click", function() { - history.pushState({ path: this.path }, '', this.href) - }) - - $("#tree-slider tr.tree-item").live('click', function(e){ - if(e.target.nodeName != "A") { - e.stopPropagation(); - link = $(this).find("td.tree-item-file-name a") - link.click(); - return false; - } - }); - $("#projects-list .project").live('click', function(e){ if(e.target.nodeName != "A" && e.target.nodeName != "INPUT") { location.href = $(this).attr("url"); diff --git a/app/assets/javascripts/tree.js b/app/assets/javascripts/tree.js new file mode 100644 index 00000000..6edd7e49 --- /dev/null +++ b/app/assets/javascripts/tree.js @@ -0,0 +1,21 @@ +/** + * Tree slider for code browse + * + */ +var Tree = { + init: + function() { + $('#tree-slider td.tree-item-file-name a, #tree-breadcrumbs a').live("click", function() { + history.pushState({ path: this.path }, '', this.href) + }) + + $("#tree-slider tr.tree-item").live('click', function(e){ + if(e.target.nodeName != "A") { + e.stopPropagation(); + link = $(this).find("td.tree-item-file-name a"); + link.click(); + return false; + } + }); + } +} diff --git a/app/views/refs/tree.html.haml b/app/views/refs/tree.html.haml index e59bbf05..46eeb6f5 100644 --- a/app/views/refs/tree.html.haml +++ b/app/views/refs/tree.html.haml @@ -1 +1,6 @@ #tree-holder= render :partial => "tree", :locals => {:repo => @repo, :commit => @commit, :tree => @tree} + +:javascript + $(function() { + Tree.init(); + }); From 2e2e3521074b44d1ad24c6870dcd9abeeac4f38d Mon Sep 17 00:00:00 2001 From: Jeremy Mack Date: Mon, 12 Dec 2011 13:13:11 -0500 Subject: [PATCH 06/12] Updated validations and routes to support dots in project names --- app/models/project.rb | 4 ++-- config/routes.rb | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index a5361313..85d5416b 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -25,7 +25,7 @@ class Project < ActiveRecord::Base validates :path, :uniqueness => true, :presence => true, - :format => { :with => /^[a-zA-Z0-9_\-]*$/, + :format => { :with => /^[a-zA-Z0-9_\-\.]*$/, :message => "only letters, digits & '_' '-' allowed" }, :length => { :within => 0..255 } @@ -35,7 +35,7 @@ class Project < ActiveRecord::Base validates :code, :presence => true, :uniqueness => true, - :format => { :with => /^[a-zA-Z0-9_\-]*$/, + :format => { :with => /^[a-zA-Z0-9_\-\.]*$/, :message => "only letters, digits & '_' '-' allowed" }, :length => { :within => 3..255 } diff --git a/config/routes.rb b/config/routes.rb index 27d0612d..1fbbbfd5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,7 +6,7 @@ Gitlab::Application.routes.draw do namespace :admin do resources :users - resources :projects + resources :projects, :constraints => { :id => /[^\/]+/ } resources :team_members get 'emails', :to => 'mailer#preview' get 'mailer/preview_note' @@ -28,12 +28,12 @@ Gitlab::Application.routes.draw do #get "profile/:id", :to => "profile#show" - resources :projects, :only => [:new, :create, :index] + resources :projects, :constraints => { :id => /[^\/]+/ }, :only => [:new, :create, :index] resources :keys devise_for :users - resources :projects, :except => [:new, :create, :index], :path => "/" do + resources :projects, :constraints => { :id => /[^\/]+/ }, :except => [:new, :create, :index], :path => "/" do member do get "team" get "wall" From 5f580ab09c79a54af287cbe209485d89a854f32f Mon Sep 17 00:00:00 2001 From: Jeremy Mack Date: Mon, 12 Dec 2011 13:32:35 -0500 Subject: [PATCH 07/12] Updated error messages to include dot as valid character --- app/models/project.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index 85d5416b..d1eb2793 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -26,7 +26,7 @@ class Project < ActiveRecord::Base :uniqueness => true, :presence => true, :format => { :with => /^[a-zA-Z0-9_\-\.]*$/, - :message => "only letters, digits & '_' '-' allowed" }, + :message => "only letters, digits & '_' '-' '.' allowed" }, :length => { :within => 0..255 } validates :description, @@ -36,7 +36,7 @@ class Project < ActiveRecord::Base :presence => true, :uniqueness => true, :format => { :with => /^[a-zA-Z0-9_\-\.]*$/, - :message => "only letters, digits & '_' '-' allowed" }, + :message => "only letters, digits & '_' '-' '.' allowed" }, :length => { :within => 3..255 } validates :owner, From d5c6f27020e4bd24440c117c06868bdc806819b4 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 12 Dec 2011 22:12:37 +0200 Subject: [PATCH 08/12] increased breadcrumbs with & commit messages --- app/assets/stylesheets/projects.css.scss | 8 ++++++-- app/views/commits/_commits.html.haml | 2 +- app/views/issues/_show.html.haml | 2 +- app/views/refs/_tree.html.haml | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/assets/stylesheets/projects.css.scss b/app/assets/stylesheets/projects.css.scss index d487e581..b26ffcf2 100644 --- a/app/assets/stylesheets/projects.css.scss +++ b/app/assets/stylesheets/projects.css.scss @@ -358,8 +358,12 @@ body.project-page table .commit { color:white; } &.note { - background: #2c5c66; - color:white; + background-image: -webkit-gradient(linear, 0 0, 0 26, color-stop(0.076, #fefefe), to(#F6F7F8)); + background-image: -webkit-linear-gradient(#fefefe 7.6%, #F6F7F8); + background-image: -moz-linear-gradient(#fefefe 7.6%, #F6F7F8); + background-image: -o-linear-gradient(#fefefe 7.6%, #F6F7F8); + color: #777; + border: 1px solid #DEDFE1; } &.issue { background: #D12F19; diff --git a/app/views/commits/_commits.html.haml b/app/views/commits/_commits.html.haml index 4721d119..108d1b4c 100644 --- a/app/views/commits/_commits.html.haml +++ b/app/views/commits/_commits.html.haml @@ -17,7 +17,7 @@ = image_tag "no_avatar.png", :class => "left", :width => 40, :style => "padding-right:5px;" %span.commit-title %strong - = truncate(commit.safe_message, :length => 60) + = truncate(commit.safe_message, :length => 70) %span.commit-author %strong= commit.author_name = time_ago_in_words(commit.committed_date) diff --git a/app/views/issues/_show.html.haml b/app/views/issues/_show.html.haml index 904b1895..8c095268 100644 --- a/app/views/issues/_show.html.haml +++ b/app/views/issues/_show.html.haml @@ -2,7 +2,7 @@ %td %strong.issue-number{:class => sort_class}= "##{issue.id}" %span - = truncate(html_escape(issue.title), :length => 40) + = truncate(html_escape(issue.title), :length => 100) %br %br %div.note-author diff --git a/app/views/refs/_tree.html.haml b/app/views/refs/_tree.html.haml index 0fad2452..0c44df58 100644 --- a/app/views/refs/_tree.html.haml +++ b/app/views/refs/_tree.html.haml @@ -4,7 +4,7 @@ %d = link_to tree_project_ref_path(@project, @ref, :path => nil), :remote => true do = @project.code - - tree.breadcrumbs(2) do |link| + - tree.breadcrumbs(3) do |link| \/ = link   From 4c3a61a760b22687fd670c8b02252b20532419be Mon Sep 17 00:00:00 2001 From: Artiom Lunev Date: Mon, 12 Dec 2011 00:18:51 +0200 Subject: [PATCH 09/12] fix merge request note link --- app/helpers/dashboard_helper.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/helpers/dashboard_helper.rb b/app/helpers/dashboard_helper.rb index 78cc2343..5cf10278 100644 --- a/app/helpers/dashboard_helper.rb +++ b/app/helpers/dashboard_helper.rb @@ -10,6 +10,7 @@ module DashboardHelper when "Issue" then project_issue_path(project, note.noteable_id) when "Snippet" then project_snippet_path(project, note.noteable_id) when "Commit" then project_commit_path(project, :id => note.noteable_id) + when "MergeRequest" then project_merge_request_path(project, note.noteable_id) else wall_project_path(project) end else wall_project_path(project) From 3a14432879199f117af8a73098dce6261b0840cc Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 12 Dec 2011 23:17:28 +0200 Subject: [PATCH 10/12] fix default branch --- app/assets/stylesheets/projects.css.scss | 3 +-- app/controllers/projects_controller.rb | 1 - app/helpers/application_helper.rb | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/assets/stylesheets/projects.css.scss b/app/assets/stylesheets/projects.css.scss index b26ffcf2..dd897ed3 100644 --- a/app/assets/stylesheets/projects.css.scss +++ b/app/assets/stylesheets/projects.css.scss @@ -548,9 +548,8 @@ h4.dash-tabs { h4.middle-panel { margin: 0; border-bottom: 1px solid #ccc; - padding: 10px 10px; + padding: 10px 20px; font-size: 11px; - padding-left:20px; background: #F7F7F7; height:30px; diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 8d9adedf..1f1da559 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -9,7 +9,6 @@ class ProjectsController < ApplicationController before_filter :authorize_read_project!, :except => [:index, :new, :create] before_filter :authorize_admin_project!, :only => [:edit, :update, :destroy] before_filter :require_non_empty_project, :only => [:blob, :tree, :graph] - before_filter :load_refs, :only => :tree # load @branch, @tag & @ref def index source = current_user.projects diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 2f982dac..76323b27 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -53,7 +53,7 @@ module ApplicationHelper [ "Tag", @project.tags ] ] - grouped_options_for_select(options, @ref) + grouped_options_for_select(options, @ref || @project.default_branch) end def markdown(text) From 60fee48eaa98bf859613160dcad87b8f0908aac6 Mon Sep 17 00:00:00 2001 From: Jeremy Mack Date: Tue, 13 Dec 2011 13:25:01 -0500 Subject: [PATCH 11/12] Better description for automatically created project --- lib/tasks/bulk_import.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/bulk_import.rake b/lib/tasks/bulk_import.rake index 68893a31..f463f3b0 100644 --- a/lib/tasks/bulk_import.rake +++ b/lib/tasks/bulk_import.rake @@ -66,7 +66,7 @@ def create_repo_project(project_name, user_email) code: project_name, path: project_name, owner: user, - description: "Automatically created from CVS on #{Time.now.to_s}" + description: "Automatically created from Rake on #{Time.now.to_s}" ) # Add user as admin for project From 3fd3e1fcdf69e8544b25193a6e2a53716c65096c Mon Sep 17 00:00:00 2001 From: Jeremy Mack Date: Thu, 15 Dec 2011 16:55:53 -0500 Subject: [PATCH 12/12] Added detection and handling of exsiting repos --- lib/tasks/bulk_import.rake | 57 +++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/lib/tasks/bulk_import.rake b/lib/tasks/bulk_import.rake index f463f3b0..de00a68a 100644 --- a/lib/tasks/bulk_import.rake +++ b/lib/tasks/bulk_import.rake @@ -20,19 +20,26 @@ task :import_projects, [:email] => :environment do |t, args| clone_path = "#{REPOSITORY_DIRECTORY}/#{repo_name}.git" if Dir.exists? clone_path - puts " INFO: #{clone_path} already exists in repositories directory, skipping." - skipped_count += 1 - next - else - if clone_bare_repo_as_git(repo_full_path, clone_path) - if create_repo_project(repo_name, user_email) - imported_count += 1 - else - failed_count += 1 - end + if Project.find_by_code(repo_name) + puts " INFO: #{clone_path} already exists in repositories directory, skipping." + skipped_count += 1 + next else - failed_count += 1 + puts " INFO: Project doesn't exist for #{repo_name} (but the repo does)." end + else + # Clone the repo + unless clone_bare_repo_as_git(repo_full_path, clone_path) + failed_count += 1 + next + end + end + + # Create the project and repo + if create_repo_project(repo_name, user_email) + imported_count += 1 + else + failed_count += 1 end end @@ -61,13 +68,25 @@ def create_repo_project(project_name, user_email) puts " INFO: Project #{project_name} already exists in Gitlab, skipping." false else - project = Project.create( - name: project_name, - code: project_name, - path: project_name, - owner: user, - description: "Automatically created from Rake on #{Time.now.to_s}" - ) + project = nil + if Project.find_by_code(project_name) + puts " ERROR: Project already exists #{project_name}" + return false + project = Project.find_by_code(project_name) + else + project = Project.create( + name: project_name, + code: project_name, + path: project_name, + owner: user, + description: "Automatically created from Rake on #{Time.now.to_s}" + ) + end + + unless project.valid? + puts " ERROR: Failed to create project #{project} because #{project.errors.first}" + return false + end # Add user as admin for project project.users_projects.create!( @@ -82,7 +101,7 @@ def create_repo_project(project_name, user_email) if project.valid? true else - puts " ERROR: Failed to create project #{project} because #{project.errors}" + puts " ERROR: Failed to create project #{project} because #{project.errors.first}" false end end