summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-02-04 10:02:39 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-02-04 10:02:39 +0200
commit4908b89495e27b6ea829f32143c7753a6139df32 (patch)
tree8bc11743d8100772ab6163c58db08fb5a516c66e
parentfcf70b91639cc4ee369631cf8fa4ebad4fbf04c8 (diff)
downloadgitlab-shell-4908b89495e27b6ea829f32143c7753a6139df32.tar.gz
Project builder
-rwxr-xr-xbin/gitlab-projects14
-rw-r--r--lib/gitlab_projects.rb35
2 files changed, 49 insertions, 0 deletions
diff --git a/bin/gitlab-projects b/bin/gitlab-projects
new file mode 100755
index 0000000..223c69f
--- /dev/null
+++ b/bin/gitlab-projects
@@ -0,0 +1,14 @@
+#!/usr/bin/env ruby
+
+#
+# GitLab Projects shell. Add/remove projects from /home/git/repositories
+#
+# Ex.
+# /bin/gitlab-projects add-project gitlab/gitlab-ci.git
+#
+#
+ROOT_PATH = File.join(File.expand_path(File.dirname(__FILE__)), "..")
+require File.join(ROOT_PATH, 'lib', 'gitlab_projects')
+GitlabProjects.new.exec
+
+exit
diff --git a/lib/gitlab_projects.rb b/lib/gitlab_projects.rb
new file mode 100644
index 0000000..89fb603
--- /dev/null
+++ b/lib/gitlab_projects.rb
@@ -0,0 +1,35 @@
+require 'open3'
+require 'fileutils'
+require_relative 'gitlab_config'
+
+class GitlabProjects
+ attr_accessor :project_name
+
+ def initialize
+ @command = ARGV.shift
+ @project_name = ARGV.shift
+ @repos_path = GitlabConfig.new.repos_path
+ @full_path = File.join(@repos_path, @project_name)
+ end
+
+ def exec
+ case @command
+ when 'add-project'; add_project
+ when 'rm-project'; rm_project
+ else
+ puts 'not allowed'
+ end
+ end
+
+ protected
+
+ def add_project
+ FileUtils.mkdir_p(@full_path, mode: 0770 )
+ cmd = "cd #{@full_path} && git init --bare"
+ system(cmd)
+ end
+
+ def rm_project
+ FileUtils.rm_rf(@full_path)
+ end
+end