Skip to content

Added list-projects command & spec #179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 28, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ Remove repo:

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

List repos:

./bin/gitlab-projects list-projects

Import repo:

# Default timeout is 2 minutes
Expand Down
2 changes: 2 additions & 0 deletions bin/gitlab-projects
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ require_relative '../lib/gitlab_init'
#
# /bin/gitlab-projects rm-project gitlab/gitlab-ci.git
#
# /bin/gitlab-projects list-projects
#
# /bin/gitlab-projects mv-project gitlab/gitlab-ci.git randx/fork.git
#
# /bin/gitlab-projects fork-project gitlab/gitlab-ci.git randx
Expand Down
10 changes: 9 additions & 1 deletion lib/gitlab_projects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def initialize
@command = ARGV.shift
@project_name = ARGV.shift
@repos_path = GitlabConfig.new.repos_path
@full_path = File.join(@repos_path, @project_name)
@full_path = File.join(@repos_path, @project_name) unless @project_name.nil?
end

def exec
Expand All @@ -41,6 +41,7 @@ def exec
when 'create-tag'; create_tag
when 'rm-tag'; rm_tag
when 'add-project'; add_project
when 'list-projects'; puts list_projects
when 'rm-project'; rm_project
when 'mv-project'; mv_project
when 'import-project'; import_project
Expand Down Expand Up @@ -93,6 +94,13 @@ def add_project
system(*cmd) && self.class.create_hooks(full_path)
end

def list_projects
$logger.info 'Listing projects'
Dir.chdir(repos_path) do
next Dir.glob('**/*.git')
end
end

def rm_project
$logger.info "Removing project #{@project_name} from <#{full_path}>."
FileUtils.rm_rf(full_path)
Expand Down
16 changes: 16 additions & 0 deletions spec/gitlab_projects_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,22 @@
end
end

describe :list_projects do
let(:gl_projects) do
build_gitlab_projects('add-project', "list_test/#{repo_name}")
end

before do
FileUtils.mkdir_p(tmp_repos_path)
end

it 'should create projects and list them' do
GitlabProjects.stub(create_hooks: true)
gl_projects.exec
gl_projects.send(:list_projects).should == ["list_test/#{repo_name}"]
end
end

describe :mv_project do
let(:gl_projects) { build_gitlab_projects('mv-project', repo_name, 'repo.git') }
let(:new_repo_path) { File.join(tmp_repos_path, 'repo.git') }
Expand Down