Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
5d88cdd9
Commit
5d88cdd9
authored
Aug 29, 2012
by
randx
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'refactor/githost'
parents
aded7056
7cdc5b9e
Changes
20
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
155 additions
and
88 deletions
+155
-88
app/models/key.rb
app/models/key.rb
+4
-1
app/models/protected_branch.rb
app/models/protected_branch.rb
+3
-1
app/models/users_project.rb
app/models/users_project.rb
+3
-3
app/observers/key_observer.rb
app/observers/key_observer.rb
+5
-2
app/roles/git_host.rb
app/roles/git_host.rb
+5
-0
app/roles/git_merge.rb
app/roles/git_merge.rb
+0
-2
app/roles/repository.rb
app/roles/repository.rb
+5
-3
app/roles/ssh_key.rb
app/roles/ssh_key.rb
+0
-18
config/environment.rb
config/environment.rb
+0
-2
config/initializers/5_backend.rb
config/initializers/5_backend.rb
+5
-0
features/support/env.rb
features/support/env.rb
+8
-0
lib/gitlab/backend/gitolite.rb
lib/gitlab/backend/gitolite.rb
+43
-5
lib/gitlab/backend/grack_auth.rb
lib/gitlab/backend/grack_auth.rb
+0
-0
lib/gitlab/git_host.rb
lib/gitlab/git_host.rb
+0
-17
lib/tasks/gitlab/enable_automerge.rake
lib/tasks/gitlab/enable_automerge.rake
+1
-3
lib/tasks/gitlab/gitolite_rebuild.rake
lib/tasks/gitlab/gitolite_rebuild.rake
+1
-1
spec/observers/key_observer_spec.rb
spec/observers/key_observer_spec.rb
+34
-0
spec/spec_helper.rb
spec/spec_helper.rb
+3
-0
spec/support/gitolite_stub.rb
spec/support/gitolite_stub.rb
+35
-0
spec/support/monkeypatch.rb
spec/support/monkeypatch.rb
+0
-30
No files found.
app/models/key.rb
View file @
5d88cdd9
require
'digest/md5'
require
'digest/md5'
class
Key
<
ActiveRecord
::
Base
class
Key
<
ActiveRecord
::
Base
include
SshKey
belongs_to
:user
belongs_to
:user
belongs_to
:project
belongs_to
:project
...
@@ -50,6 +49,10 @@ class Key < ActiveRecord::Base
...
@@ -50,6 +49,10 @@ class Key < ActiveRecord::Base
user
.
projects
user
.
projects
end
end
end
end
def
last_deploy?
Key
.
where
(
identifier:
identifier
).
count
==
0
end
end
end
# == Schema Information
# == Schema Information
#
#
...
...
app/models/protected_branch.rb
View file @
5d88cdd9
class
ProtectedBranch
<
ActiveRecord
::
Base
class
ProtectedBranch
<
ActiveRecord
::
Base
include
GitHost
belongs_to
:project
belongs_to
:project
validates_presence_of
:project_id
validates_presence_of
:project_id
validates_presence_of
:name
validates_presence_of
:name
...
@@ -7,7 +9,7 @@ class ProtectedBranch < ActiveRecord::Base
...
@@ -7,7 +9,7 @@ class ProtectedBranch < ActiveRecord::Base
after_destroy
:update_repository
after_destroy
:update_repository
def
update_repository
def
update_repository
Gitlab
::
GitHost
.
system
.
update_project
(
project
.
path
,
project
)
git_host
.
update_repository
(
project
)
end
end
def
commit
def
commit
...
...
app/models/users_project.rb
View file @
5d88cdd9
class
UsersProject
<
ActiveRecord
::
Base
class
UsersProject
<
ActiveRecord
::
Base
include
GitHost
GUEST
=
10
GUEST
=
10
REPORTER
=
20
REPORTER
=
20
DEVELOPER
=
30
DEVELOPER
=
30
...
@@ -58,9 +60,7 @@ class UsersProject < ActiveRecord::Base
...
@@ -58,9 +60,7 @@ class UsersProject < ActiveRecord::Base
end
end
def
update_repository
def
update_repository
Gitlab
::
GitHost
.
system
.
new
.
configure
do
|
c
|
git_host
.
update_repository
(
project
)
c
.
update_project
(
project
.
path
,
project
)
end
end
end
def
project_access_human
def
project_access_human
...
...
app/observers/key_observer.rb
View file @
5d88cdd9
class
KeyObserver
<
ActiveRecord
::
Observer
class
KeyObserver
<
ActiveRecord
::
Observer
include
GitHost
def
after_save
(
key
)
def
after_save
(
key
)
key
.
update_repository
git_host
.
set_key
(
key
.
identifier
,
key
.
key
,
key
.
projects
)
end
end
def
after_destroy
(
key
)
def
after_destroy
(
key
)
key
.
repository_delete_key
return
if
key
.
is_deploy_key
&&
!
key
.
last_deploy?
git_host
.
remove_key
(
key
.
identifier
,
key
.
projects
)
end
end
end
end
app/roles/git_host.rb
0 → 100644
View file @
5d88cdd9
module
GitHost
def
git_host
Gitlab
::
Gitolite
.
new
end
end
app/roles/git_merge.rb
deleted
100644 → 0
View file @
aded7056
module
GitMerge
end
app/roles/repository.rb
View file @
5d88cdd9
module
Repository
module
Repository
include
GitHost
def
valid_repo?
def
valid_repo?
repo
repo
rescue
rescue
...
@@ -48,7 +50,7 @@ module Repository
...
@@ -48,7 +50,7 @@ module Repository
end
end
def
url_to_repo
def
url_to_repo
Gitlab
::
GitH
ost
.
url_to_repo
(
path
)
git_h
ost
.
url_to_repo
(
path
)
end
end
def
path_to_repo
def
path_to_repo
...
@@ -56,11 +58,11 @@ module Repository
...
@@ -56,11 +58,11 @@ module Repository
end
end
def
update_repository
def
update_repository
Gitlab
::
GitHost
.
system
.
update_project
(
path
,
self
)
git_host
.
update_repository
(
self
)
end
end
def
destroy_repository
def
destroy_repository
Gitlab
::
GitHost
.
system
.
destroy_project
(
self
)
git_host
.
remove_repository
(
self
)
end
end
def
repo_exists?
def
repo_exists?
...
...
app/roles/ssh_key.rb
deleted
100644 → 0
View file @
aded7056
module
SshKey
def
update_repository
Gitlab
::
GitHost
.
system
.
new
.
configure
do
|
c
|
c
.
update_keys
(
identifier
,
key
)
c
.
update_projects
(
projects
)
end
end
def
repository_delete_key
Gitlab
::
GitHost
.
system
.
new
.
configure
do
|
c
|
#delete key file is there is no identically deploy keys
if
!
is_deploy_key
||
Key
.
where
(
identifier:
identifier
).
count
()
==
0
c
.
delete_key
(
identifier
)
end
c
.
update_projects
(
projects
)
end
end
end
config/environment.rb
View file @
5d88cdd9
...
@@ -3,5 +3,3 @@ require File.expand_path('../application', __FILE__)
...
@@ -3,5 +3,3 @@ require File.expand_path('../application', __FILE__)
# Initialize the rails application
# Initialize the rails application
Gitlab
::
Application
.
initialize!
Gitlab
::
Application
.
initialize!
require
File
.
join
(
Rails
.
root
,
"lib"
,
"gitlab"
,
"git_host"
)
config/initializers/5_backend.rb
0 → 100644
View file @
5d88cdd9
# GIT over HTTP
require
Rails
.
root
.
join
(
"lib"
,
"gitlab"
,
"backend"
,
"grack_auth"
)
# GITOLITE backend
require
Rails
.
root
.
join
(
"lib"
,
"gitlab"
,
"backend"
,
"gitolite"
)
features/support/env.rb
View file @
5d88cdd9
...
@@ -5,10 +5,12 @@ end
...
@@ -5,10 +5,12 @@ end
require
'cucumber/rails'
require
'cucumber/rails'
require
'webmock/cucumber'
require
'webmock/cucumber'
WebMock
.
allow_net_connect!
WebMock
.
allow_net_connect!
require
Rails
.
root
.
join
'spec/factories'
require
Rails
.
root
.
join
'spec/factories'
require
Rails
.
root
.
join
'spec/support/monkeypatch'
require
Rails
.
root
.
join
'spec/support/monkeypatch'
require
Rails
.
root
.
join
'spec/support/gitolite_stub'
require
Rails
.
root
.
join
'spec/support/login_helpers'
require
Rails
.
root
.
join
'spec/support/login_helpers'
require
Rails
.
root
.
join
'spec/support/valid_commit'
require
Rails
.
root
.
join
'spec/support/valid_commit'
...
@@ -48,3 +50,9 @@ headless = Headless.new
...
@@ -48,3 +50,9 @@ headless = Headless.new
headless
.
start
headless
.
start
require
'cucumber/rspec/doubles'
require
'cucumber/rspec/doubles'
include
GitoliteStub
Before
do
stub_gitolite!
end
lib/gitlab/gitolite.rb
→
lib/gitlab/
backend/
gitolite.rb
View file @
5d88cdd9
...
@@ -2,24 +2,62 @@ require 'gitolite'
...
@@ -2,24 +2,62 @@ require 'gitolite'
require
'timeout'
require
'timeout'
require
'fileutils'
require
'fileutils'
# TODO: refactor & cleanup
module
Gitlab
module
Gitlab
class
Gitolite
class
Gitolite
class
AccessDenied
<
StandardError
;
end
class
AccessDenied
<
StandardError
;
end
def
self
.
update_project
(
path
,
project
)
def
set_key
key_id
,
key_content
,
projects
self
.
new
.
configure
{
|
git
|
git
.
update_project
(
path
,
project
)
}
self
.
configure
do
|
c
|
c
.
update_keys
(
key_id
,
key_content
)
c
.
update_project
(
project
.
path
,
projects
)
end
end
end
def
remove_key
key_id
,
projects
self
.
configure
do
|
c
|
c
.
delete_key
(
key_id
)
c
.
update_project
(
project
.
path
,
projects
)
end
end
def
update_repository
project
self
.
configure
do
|
c
|
c
.
update_project
(
project
.
path
,
project
)
end
end
alias_method
:create_repository
,
:update_repository
def
self
.
destroy_project
(
project
)
def
remove_repository
project
self
.
new
.
configure
{
|
git
|
git
.
destroy_project
(
project
)
}
self
.
configure
do
|
c
|
c
.
destroy_project
(
project
)
end
end
end
def
url_to_repo
path
Gitlab
.
config
.
ssh_path
+
"
#{
path
}
.git"
end
def
initialize
# create tmp dir
@local_dir
=
File
.
join
(
Rails
.
root
,
'tmp'
,
"gitlabhq-gitolite-
#{
Time
.
now
.
to_i
}
"
)
end
def
enable_automerge
self
.
configure
do
|
git
|
git
.
admin_all_repo
end
end
private
def
pull
def
pull
# create tmp dir
# create tmp dir
@local_dir
=
File
.
join
(
Rails
.
root
,
'tmp'
,
"gitlabhq-gitolite-
#{
Time
.
now
.
to_i
}
"
)
@local_dir
=
File
.
join
(
Rails
.
root
,
'tmp'
,
"gitlabhq-gitolite-
#{
Time
.
now
.
to_i
}
"
)
Dir
.
mkdir
@local_dir
Dir
.
mkdir
@local_dir
`git clone
#{
GitHost
.
admin_uri
}
#{
@local_dir
}
/gitolite`
`git clone
#{
self
.
class
.
admin_uri
}
#{
@local_dir
}
/gitolite`
end
end
def
push
def
push
...
...
config/initializers
/grack_auth.rb
→
lib/gitlab/backend
/grack_auth.rb
View file @
5d88cdd9
File moved
lib/gitlab/git_host.rb
deleted
100644 → 0
View file @
aded7056
require
File
.
join
(
Rails
.
root
,
"lib"
,
"gitlab"
,
"gitolite"
)
module
Gitlab
class
GitHost
def
self
.
system
Gitlab
::
Gitolite
end
def
self
.
admin_uri
Gitlab
.
config
.
git_host
.
admin_uri
end
def
self
.
url_to_repo
(
path
)
Gitlab
.
config
.
ssh_path
+
"
#{
path
}
.git"
end
end
end
lib/tasks/gitlab/enable_automerge.rake
View file @
5d88cdd9
...
@@ -2,9 +2,7 @@ namespace :gitlab do
...
@@ -2,9 +2,7 @@ namespace :gitlab do
namespace
:app
do
namespace
:app
do
desc
"GITLAB | Enable auto merge"
desc
"GITLAB | Enable auto merge"
task
:enable_automerge
=>
:environment
do
task
:enable_automerge
=>
:environment
do
Gitlab
::
GitHost
.
system
.
new
.
configure
do
|
git
|
Gitlab
::
Gitolite
.
new
.
enable_automerge
git
.
admin_all_repo
end
Project
.
find_each
do
|
project
|
Project
.
find_each
do
|
project
|
if
project
.
repo_exists?
&&
!
project
.
satellite
.
exists?
if
project
.
repo_exists?
&&
!
project
.
satellite
.
exists?
...
...
lib/tasks/gitlab/gitolite_rebuild.rake
View file @
5d88cdd9
...
@@ -16,7 +16,7 @@ namespace :gitlab do
...
@@ -16,7 +16,7 @@ namespace :gitlab do
task
:update_keys
=>
:environment
do
task
:update_keys
=>
:environment
do
puts
"Starting Key"
puts
"Starting Key"
Key
.
find_each
(
:batch_size
=>
100
)
do
|
key
|
Key
.
find_each
(
:batch_size
=>
100
)
do
|
key
|
key
.
update_repository
Gitlab
::
Gitolite
.
new
.
set_key
(
key
.
identifier
,
key
.
key
,
key
.
projects
)
print
'.'
print
'.'
end
end
puts
"Done with keys"
puts
"Done with keys"
...
...
spec/observers/key_observer_spec.rb
0 → 100644
View file @
5d88cdd9
require
'spec_helper'
describe
KeyObserver
do
before
do
@key
=
double
(
'Key'
,
identifier:
'admin_654654'
,
key:
'== a vaild ssh key'
,
projects:
[],
is_deploy_key:
false
)
@gitolite
=
double
(
'Gitlab::Gitolite'
,
set_key:
true
,
remove_key:
true
)
@observer
=
KeyObserver
.
instance
@observer
.
stub
(
:git_host
=>
@gitolite
)
end
context
:after_save
do
it
do
@gitolite
.
should_receive
(
:set_key
).
with
(
@key
.
identifier
,
@key
.
key
,
@key
.
projects
)
@observer
.
after_save
(
@key
)
end
end
context
:after_destroy
do
it
do
@gitolite
.
should_receive
(
:remove_key
).
with
(
@key
.
identifier
,
@key
.
projects
)
@observer
.
after_destroy
(
@key
)
end
end
end
spec/spec_helper.rb
View file @
5d88cdd9
...
@@ -27,6 +27,7 @@ RSpec.configure do |config|
...
@@ -27,6 +27,7 @@ RSpec.configure do |config|
config
.
mock_with
:rspec
config
.
mock_with
:rspec
config
.
include
LoginHelpers
,
type: :request
config
.
include
LoginHelpers
,
type: :request
config
.
include
GitoliteStub
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# examples within a transaction, remove the following line or assign false
...
@@ -39,6 +40,8 @@ RSpec.configure do |config|
...
@@ -39,6 +40,8 @@ RSpec.configure do |config|
end
end
config
.
before
do
config
.
before
do
stub_gitolite!
# !!! Observers disabled by default in tests
# !!! Observers disabled by default in tests
ActiveRecord
::
Base
.
observers
.
disable
(
:all
)
ActiveRecord
::
Base
.
observers
.
disable
(
:all
)
# ActiveRecord::Base.observers.enable(:all)
# ActiveRecord::Base.observers.enable(:all)
...
...
spec/support/gitolite_stub.rb
0 → 100644
View file @
5d88cdd9
module
GitoliteStub
def
stub_gitolite!
stub_gitlab_gitolite
stub_gitolite_admin
end
def
stub_gitolite_admin
gitolite_repo
=
mock
(
clean_permissions:
true
,
add_permission:
true
)
gitolite_config
=
mock
(
add_repo:
true
,
get_repo:
gitolite_repo
,
has_repo?:
true
)
gitolite_admin
=
double
(
'Gitolite::GitoliteAdmin'
,
config:
gitolite_config
,
save:
true
,
)
Gitolite
::
GitoliteAdmin
.
stub
(
new:
gitolite_admin
)
end
def
stub_gitlab_gitolite
gitlab_gitolite
=
Gitlab
::
Gitolite
.
new
Gitlab
::
Gitolite
.
stub
(
new:
gitlab_gitolite
)
gitlab_gitolite
.
stub
(
configure:
->
()
{
yield
(
self
)
})
gitlab_gitolite
.
stub
(
update_keys:
true
)
end
end
spec/support/monkeypatch.rb
View file @
5d88cdd9
# Stubbing Project <-> git host path
# Stubbing Project <-> git host path
# create project using Factory only
# create project using Factory only
class
Project
class
Project
def
update_repository
true
end
def
destroy_repository
true
end
def
path_to_repo
def
path_to_repo
File
.
join
(
Rails
.
root
,
"tmp"
,
"tests"
,
path
)
File
.
join
(
Rails
.
root
,
"tmp"
,
"tests"
,
path
)
end
end
...
@@ -18,22 +10,6 @@ class Project
...
@@ -18,22 +10,6 @@ class Project
end
end
end
end
class
Key
def
update_repository
true
end
def
repository_delete_key
true
end
end
class
UsersProject
def
update_repository
true
end
end
class
FakeSatellite
class
FakeSatellite
def
exists?
def
exists?
true
true
...
@@ -43,9 +19,3 @@ class FakeSatellite
...
@@ -43,9 +19,3 @@ class FakeSatellite
true
true
end
end
end
end
class
ProtectedBranch
def
update_repository
true
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