Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-shell
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-shell
Commits
238fd9b6
Commit
238fd9b6
authored
Mar 11, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cover with tests GitlabProjects
parent
55818a4f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
18 deletions
+67
-18
lib/gitlab_projects.rb
lib/gitlab_projects.rb
+12
-2
spec/gitlab_projects_spec.rb
spec/gitlab_projects_spec.rb
+55
-16
No files found.
lib/gitlab_projects.rb
View file @
238fd9b6
...
@@ -2,7 +2,17 @@ require 'open3'
...
@@ -2,7 +2,17 @@ require 'open3'
require
'fileutils'
require
'fileutils'
class
GitlabProjects
class
GitlabProjects
attr_reader
:project_name
,
:full_path
# Project name is a directory name for repository with .git at the end
# It may be namespaced or not. Like repo.git or gitlab/repo.git
attr_reader
:project_name
# Absolute path to directory where repositories stored
# By default it is /home/git/repositories
attr_reader
:repos_path
# Full path is an absolute path to the repository
# Ex /home/git/repositories/test.git
attr_reader
:full_path
def
initialize
def
initialize
@command
=
ARGV
.
shift
@command
=
ARGV
.
shift
...
@@ -42,7 +52,7 @@ class GitlabProjects
...
@@ -42,7 +52,7 @@ class GitlabProjects
def
import_project
def
import_project
@source
=
ARGV
.
shift
@source
=
ARGV
.
shift
cmd
=
"cd
#{
@repos_path
}
&& git clone --bare
#{
@source
}
#{
@
project_name
}
&&
#{
create_hooks_cmd
}
"
cmd
=
"cd
#{
repos_path
}
&& git clone --bare
#{
@source
}
#{
project_name
}
&&
#{
create_hooks_cmd
}
"
system
(
cmd
)
system
(
cmd
)
end
end
end
end
spec/gitlab_projects_spec.rb
View file @
238fd9b6
...
@@ -2,31 +2,31 @@ require_relative 'spec_helper'
...
@@ -2,31 +2,31 @@ require_relative 'spec_helper'
require_relative
'../lib/gitlab_projects'
require_relative
'../lib/gitlab_projects'
describe
GitlabProjects
do
describe
GitlabProjects
do
describe
:initialize
do
before
do
before
do
argv
(
'add-project'
,
'gitlab-ci.git'
)
FileUtils
.
mkdir_p
(
tmp_repos_path
)
@gl_projects
=
GitlabProjects
.
new
end
end
it
{
@gl_projects
.
project_name
.
should
==
'gitlab-ci.git'
}
after
do
it
{
@gl_projects
.
instance_variable_get
(
:@command
).
should
==
'add-project'
}
FileUtils
.
rm_rf
(
tmp_repos_path
)
it
{
@gl_projects
.
instance_variable_get
(
:@full_path
).
should
==
'/home/git/repositories/gitlab-ci.git'
}
end
end
describe
:
add_project
do
describe
:
initialize
do
before
do
before
do
argv
(
'add-project'
,
'gitlab-ci.git'
)
argv
(
'add-project'
,
repo_name
)
@gl_projects
=
GitlabProjects
.
new
@gl_projects
=
GitlabProjects
.
new
@gl_projects
.
stub
(
full_path:
tmp_repo_path
)
end
end
after
do
it
{
@gl_projects
.
project_name
.
should
==
repo_name
}
FileUtils
.
rm_rf
(
tmp_repo_path
)
it
{
@gl_projects
.
instance_variable_get
(
:@command
).
should
==
'add-project'
}
it
{
@gl_projects
.
instance_variable_get
(
:@full_path
).
should
==
'/home/git/repositories/gitlab-ci.git'
}
end
end
describe
:add_project
do
let
(
:gl_projects
)
{
build_gitlab_projects
(
'add-project'
,
repo_name
)
}
it
"should create a directory"
do
it
"should create a directory"
do
@
gl_projects
.
stub
(
system:
true
)
gl_projects
.
stub
(
system:
true
)
@gl_projects
.
send
:add_project
gl_projects
.
exec
File
.
exists?
(
tmp_repo_path
).
should
be_true
File
.
exists?
(
tmp_repo_path
).
should
be_true
end
end
...
@@ -34,18 +34,57 @@ describe GitlabProjects do
...
@@ -34,18 +34,57 @@ describe GitlabProjects do
valid_cmd
=
"cd
#{
tmp_repo_path
}
&& git init --bare"
valid_cmd
=
"cd
#{
tmp_repo_path
}
&& git init --bare"
valid_cmd
<<
" && ln -s
#{
ROOT_PATH
}
/hooks/post-receive
#{
tmp_repo_path
}
/hooks/post-receive"
valid_cmd
<<
" && ln -s
#{
ROOT_PATH
}
/hooks/post-receive
#{
tmp_repo_path
}
/hooks/post-receive"
valid_cmd
<<
" && ln -s
#{
ROOT_PATH
}
/hooks/update
#{
tmp_repo_path
}
/hooks/update"
valid_cmd
<<
" && ln -s
#{
ROOT_PATH
}
/hooks/update
#{
tmp_repo_path
}
/hooks/update"
@gl_projects
.
should_receive
(
:system
).
with
(
valid_cmd
)
gl_projects
.
should_receive
(
:system
).
with
(
valid_cmd
)
@gl_projects
.
send
:add_project
gl_projects
.
exec
end
end
describe
:rm_project
do
let
(
:gl_projects
)
{
build_gitlab_projects
(
'rm-project'
,
repo_name
)
}
before
do
FileUtils
.
mkdir_p
(
tmp_repo_path
)
end
it
"should remove a repo directory"
do
File
.
exists?
(
tmp_repo_path
).
should
be_true
gl_projects
.
exec
File
.
exists?
(
tmp_repo_path
).
should
be_false
end
end
end
end
describe
:import_project
do
let
(
:gl_projects
)
{
build_gitlab_projects
(
'import-project'
,
repo_name
,
'https://github.com/randx/six.git'
)
}
it
"should import a repo"
do
gl_projects
.
exec
File
.
exists?
(
File
.
join
(
tmp_repo_path
,
'HEAD'
)).
should
be_true
end
end
def
build_gitlab_projects
(
*
args
)
argv
(
*
args
)
gl_projects
=
GitlabProjects
.
new
gl_projects
.
stub
(
repos_path:
tmp_repos_path
)
gl_projects
.
stub
(
full_path:
tmp_repo_path
)
gl_projects
end
def
argv
(
*
args
)
def
argv
(
*
args
)
args
.
each_with_index
do
|
arg
,
i
|
args
.
each_with_index
do
|
arg
,
i
|
ARGV
[
i
]
=
arg
ARGV
[
i
]
=
arg
end
end
end
end
def
tmp_repos_path
File
.
join
(
ROOT_PATH
,
'tmp'
,
'repositories'
)
end
def
tmp_repo_path
def
tmp_repo_path
File
.
join
(
ROOT_PATH
,
'tmp'
,
'gitlab-ci.git'
)
File
.
join
(
tmp_repos_path
,
repo_name
)
end
def
repo_name
'gitlab-ci.git'
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment