Skip to content

Commit 4908b89

Browse files
committed
Project builder
1 parent fcf70b9 commit 4908b89

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

bin/gitlab-projects

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env ruby
2+
3+
#
4+
# GitLab Projects shell. Add/remove projects from /home/git/repositories
5+
#
6+
# Ex.
7+
# /bin/gitlab-projects add-project gitlab/gitlab-ci.git
8+
#
9+
#
10+
ROOT_PATH = File.join(File.expand_path(File.dirname(__FILE__)), "..")
11+
require File.join(ROOT_PATH, 'lib', 'gitlab_projects')
12+
GitlabProjects.new.exec
13+
14+
exit

lib/gitlab_projects.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
require 'open3'
2+
require 'fileutils'
3+
require_relative 'gitlab_config'
4+
5+
class GitlabProjects
6+
attr_accessor :project_name
7+
8+
def initialize
9+
@command = ARGV.shift
10+
@project_name = ARGV.shift
11+
@repos_path = GitlabConfig.new.repos_path
12+
@full_path = File.join(@repos_path, @project_name)
13+
end
14+
15+
def exec
16+
case @command
17+
when 'add-project'; add_project
18+
when 'rm-project'; rm_project
19+
else
20+
puts 'not allowed'
21+
end
22+
end
23+
24+
protected
25+
26+
def add_project
27+
FileUtils.mkdir_p(@full_path, mode: 0770 )
28+
cmd = "cd #{@full_path} && git init --bare"
29+
system(cmd)
30+
end
31+
32+
def rm_project
33+
FileUtils.rm_rf(@full_path)
34+
end
35+
end

0 commit comments

Comments
 (0)