Skip to content

Commit 6cd167e

Browse files
committed
Added list-projects command & spec
list-projects command usage Single quotes Use single quotes Use single quotes
1 parent 7e74d05 commit 6cd167e

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ Remove repo:
3131

3232
./bin/gitlab-projects rm-project gitlab/gitlab-ci.git
3333

34+
List repos:
35+
36+
./bin/gitlab-projects list-projects
37+
3438
Import repo:
3539

3640
# Default timeout is 2 minutes

bin/gitlab-projects

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ require_relative '../lib/gitlab_init'
1111
#
1212
# /bin/gitlab-projects rm-project gitlab/gitlab-ci.git
1313
#
14+
# /bin/gitlab-projects list-projects
15+
#
1416
# /bin/gitlab-projects mv-project gitlab/gitlab-ci.git randx/fork.git
1517
#
1618
# /bin/gitlab-projects fork-project gitlab/gitlab-ci.git randx

lib/gitlab_projects.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def initialize
3131
@command = ARGV.shift
3232
@project_name = ARGV.shift
3333
@repos_path = GitlabConfig.new.repos_path
34-
@full_path = File.join(@repos_path, @project_name)
34+
@full_path = File.join(@repos_path, @project_name) unless @project_name.nil?
3535
end
3636

3737
def exec
@@ -41,6 +41,7 @@ def exec
4141
when 'create-tag'; create_tag
4242
when 'rm-tag'; rm_tag
4343
when 'add-project'; add_project
44+
when 'list-projects'; puts list_projects
4445
when 'rm-project'; rm_project
4546
when 'mv-project'; mv_project
4647
when 'import-project'; import_project
@@ -93,6 +94,13 @@ def add_project
9394
system(*cmd) && self.class.create_hooks(full_path)
9495
end
9596

97+
def list_projects
98+
$logger.info 'Listing projects'
99+
Dir.chdir(repos_path) do
100+
next Dir.glob('**/*.git')
101+
end
102+
end
103+
96104
def rm_project
97105
$logger.info "Removing project #{@project_name} from <#{full_path}>."
98106
FileUtils.rm_rf(full_path)

spec/gitlab_projects_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,22 @@
135135
end
136136
end
137137

138+
describe :list_projects do
139+
let(:gl_projects) do
140+
build_gitlab_projects('add-project', "list_test/#{repo_name}")
141+
end
142+
143+
before do
144+
FileUtils.mkdir_p(tmp_repos_path)
145+
end
146+
147+
it 'should create projects and list them' do
148+
GitlabProjects.stub(create_hooks: true)
149+
gl_projects.exec
150+
gl_projects.send(:list_projects).should == ["list_test/#{repo_name}"]
151+
end
152+
end
153+
138154
describe :mv_project do
139155
let(:gl_projects) { build_gitlab_projects('mv-project', repo_name, 'repo.git') }
140156
let(:new_repo_path) { File.join(tmp_repos_path, 'repo.git') }

0 commit comments

Comments
 (0)