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
Jérome Perrin
gitlab-ce
Commits
25bde28d
Commit
25bde28d
authored
12 years ago
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed tests. removed delegate to id
parent
bb164ebf
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
27 additions
and
13 deletions
+27
-13
app/models/key.rb
app/models/key.rb
+1
-1
app/models/project.rb
app/models/project.rb
+1
-1
app/models/users_project.rb
app/models/users_project.rb
+1
-1
app/workers/post_receive.rb
app/workers/post_receive.rb
+3
-0
spec/models/project_hooks_spec.rb
spec/models/project_hooks_spec.rb
+13
-7
spec/workers/post_receive_spec.rb
spec/workers/post_receive_spec.rb
+8
-3
No files found.
app/models/key.rb
View file @
25bde28d
...
@@ -14,7 +14,7 @@ class Key < ActiveRecord::Base
...
@@ -14,7 +14,7 @@ class Key < ActiveRecord::Base
before_save
:set_identifier
before_save
:set_identifier
after_save
:update_repository
after_save
:update_repository
after_destroy
:repository_delete_key
after_destroy
:repository_delete_key
delegate
:
id
,
:
name
,
:email
,
:to
=>
:user
,
:prefix
=>
true
delegate
:name
,
:email
,
:to
=>
:user
,
:prefix
=>
true
def
set_identifier
def
set_identifier
if
is_deploy_key
if
is_deploy_key
...
...
This diff is collapsed.
Click to expand it.
app/models/project.rb
View file @
25bde28d
...
@@ -117,7 +117,7 @@ class Project < ActiveRecord::Base
...
@@ -117,7 +117,7 @@ class Project < ActiveRecord::Base
before:
oldrev
,
before:
oldrev
,
after:
newrev
,
after:
newrev
,
ref:
ref
,
ref:
ref
,
user_id:
key
.
user
_
id
,
user_id:
key
.
user
.
id
,
user_name:
key
.
user_name
,
user_name:
key
.
user_name
,
repository:
{
repository:
{
name:
name
,
name:
name
,
...
...
This diff is collapsed.
Click to expand it.
app/models/users_project.rb
View file @
25bde28d
...
@@ -16,7 +16,7 @@ class UsersProject < ActiveRecord::Base
...
@@ -16,7 +16,7 @@ class UsersProject < ActiveRecord::Base
validates_presence_of
:user_id
validates_presence_of
:user_id
validates_presence_of
:project_id
validates_presence_of
:project_id
delegate
:
id
,
:
name
,
:email
,
:to
=>
:user
,
:prefix
=>
true
delegate
:name
,
:email
,
:to
=>
:user
,
:prefix
=>
true
def
self
.
bulk_import
(
project
,
user_ids
,
project_access
,
repo_access
)
def
self
.
bulk_import
(
project
,
user_ids
,
project_access
,
repo_access
)
UsersProject
.
transaction
do
UsersProject
.
transaction
do
...
...
This diff is collapsed.
Click to expand it.
app/workers/post_receive.rb
View file @
25bde28d
...
@@ -5,6 +5,9 @@ class PostReceive
...
@@ -5,6 +5,9 @@ class PostReceive
project
=
Project
.
find_by_path
(
reponame
)
project
=
Project
.
find_by_path
(
reponame
)
return
false
if
project
.
nil?
return
false
if
project
.
nil?
# Ignore push from non-gitlab users
return
false
unless
Key
.
find_by_identifier
(
author_key_id
)
project
.
observe_push
(
oldrev
,
newrev
,
ref
,
author_key_id
)
project
.
observe_push
(
oldrev
,
newrev
,
ref
,
author_key_id
)
project
.
execute_web_hooks
(
oldrev
,
newrev
,
ref
,
author_key_id
)
project
.
execute_web_hooks
(
oldrev
,
newrev
,
ref
,
author_key_id
)
end
end
...
...
This diff is collapsed.
Click to expand it.
spec/models/project_hooks_spec.rb
View file @
25bde28d
...
@@ -2,17 +2,21 @@ require 'spec_helper'
...
@@ -2,17 +2,21 @@ require 'spec_helper'
describe
Project
,
"Hooks"
do
describe
Project
,
"Hooks"
do
let
(
:project
)
{
Factory
:project
}
let
(
:project
)
{
Factory
:project
}
before
do
@key
=
Factory
:key
,
:user
=>
project
.
owner
@key_id
=
@key
.
identifier
end
describe
"Post Receive Event"
do
describe
"Post Receive Event"
do
it
"should create push event"
do
it
"should create push event"
do
oldrev
,
newrev
,
ref
=
'00000000000000000000000000000000'
,
'newrev'
,
'refs/heads/master'
oldrev
,
newrev
,
ref
=
'00000000000000000000000000000000'
,
'newrev'
,
'refs/heads/master'
project
.
observe_push
(
oldrev
,
newrev
,
ref
)
project
.
observe_push
(
oldrev
,
newrev
,
ref
,
@key_id
)
event
=
Event
.
last
event
=
Event
.
last
event
.
should_not
be_nil
event
.
should_not
be_nil
event
.
project
.
should
==
project
event
.
project
.
should
==
project
event
.
action
.
should
==
Event
::
Pushed
event
.
action
.
should
==
Event
::
Pushed
event
.
data
==
project
.
web_hook_data
(
oldrev
,
newrev
,
ref
)
event
.
data
==
project
.
web_hook_data
(
oldrev
,
newrev
,
ref
,
@key_id
)
end
end
end
end
...
@@ -20,7 +24,7 @@ describe Project, "Hooks" do
...
@@ -20,7 +24,7 @@ describe Project, "Hooks" do
context
"with no web hooks"
do
context
"with no web hooks"
do
it
"raises no errors"
do
it
"raises no errors"
do
lambda
{
lambda
{
project
.
execute_web_hooks
(
'oldrev'
,
'newrev'
,
'ref'
)
project
.
execute_web_hooks
(
'oldrev'
,
'newrev'
,
'ref'
,
@key_id
)
}.
should_not
raise_error
}.
should_not
raise_error
end
end
end
end
...
@@ -36,7 +40,7 @@ describe Project, "Hooks" do
...
@@ -36,7 +40,7 @@ describe Project, "Hooks" do
@webhook
.
should_receive
(
:execute
).
once
@webhook
.
should_receive
(
:execute
).
once
@webhook_2
.
should_receive
(
:execute
).
once
@webhook_2
.
should_receive
(
:execute
).
once
project
.
execute_web_hooks
(
'oldrev'
,
'newrev'
,
'refs/heads/master'
)
project
.
execute_web_hooks
(
'oldrev'
,
'newrev'
,
'refs/heads/master'
,
@key_id
)
end
end
end
end
...
@@ -48,12 +52,12 @@ describe Project, "Hooks" do
...
@@ -48,12 +52,12 @@ describe Project, "Hooks" do
it
"when pushing a branch for the first time"
do
it
"when pushing a branch for the first time"
do
@webhook
.
should_not_receive
(
:execute
)
@webhook
.
should_not_receive
(
:execute
)
project
.
execute_web_hooks
(
'00000000000000000000000000000000'
,
'newrev'
,
'refs/heads/master'
)
project
.
execute_web_hooks
(
'00000000000000000000000000000000'
,
'newrev'
,
'refs/heads/master'
,
@key_id
)
end
end
it
"when pushing tags"
do
it
"when pushing tags"
do
@webhook
.
should_not_receive
(
:execute
)
@webhook
.
should_not_receive
(
:execute
)
project
.
execute_web_hooks
(
'oldrev'
,
'newrev'
,
'refs/tags/v1.0.0'
)
project
.
execute_web_hooks
(
'oldrev'
,
'newrev'
,
'refs/tags/v1.0.0'
,
@key_id
)
end
end
end
end
...
@@ -69,7 +73,7 @@ describe Project, "Hooks" do
...
@@ -69,7 +73,7 @@ describe Project, "Hooks" do
# Fill nil/empty attributes
# Fill nil/empty attributes
project
.
description
=
"This is a description"
project
.
description
=
"This is a description"
@data
=
project
.
web_hook_data
(
@oldrev
,
@newrev
,
@ref
)
@data
=
project
.
web_hook_data
(
@oldrev
,
@newrev
,
@ref
,
@key_id
)
end
end
subject
{
@data
}
subject
{
@data
}
...
@@ -77,6 +81,8 @@ describe Project, "Hooks" do
...
@@ -77,6 +81,8 @@ describe Project, "Hooks" do
it
{
should
include
(
before:
@oldrev
)
}
it
{
should
include
(
before:
@oldrev
)
}
it
{
should
include
(
after:
@newrev
)
}
it
{
should
include
(
after:
@newrev
)
}
it
{
should
include
(
ref:
@ref
)
}
it
{
should
include
(
ref:
@ref
)
}
it
{
should
include
(
user_id:
project
.
owner
.
id
)
}
it
{
should
include
(
user_name:
project
.
owner
.
name
)
}
context
"with repository data"
do
context
"with repository data"
do
subject
{
@data
[
:repository
]
}
subject
{
@data
[
:repository
]
}
...
...
This diff is collapsed.
Click to expand it.
spec/workers/post_receive_spec.rb
View file @
25bde28d
...
@@ -10,17 +10,22 @@ describe PostReceive do
...
@@ -10,17 +10,22 @@ describe PostReceive do
context
"web hooks"
do
context
"web hooks"
do
let
(
:project
)
{
Factory
:project
}
let
(
:project
)
{
Factory
:project
}
before
do
@key
=
Factory
:key
,
:user
=>
project
.
owner
@key_id
=
@key
.
identifier
end
it
"it retrieves the correct project"
do
it
"it retrieves the correct project"
do
Project
.
should_receive
(
:find_by_path
).
with
(
project
.
path
)
Project
.
should_receive
(
:find_by_path
).
with
(
project
.
path
)
PostReceive
.
perform
(
project
.
path
,
'sha-old'
,
'sha-new'
,
'refs/heads/master'
)
Key
.
should_receive
(
:find_by_identifier
).
with
(
project
.
path
)
PostReceive
.
perform
(
project
.
path
,
'sha-old'
,
'sha-new'
,
'refs/heads/master'
,
@key_id
)
end
end
it
"asks the project to execute web hooks"
do
it
"asks the project to execute web hooks"
do
Project
.
stub
(
find_by_path:
project
)
Project
.
stub
(
find_by_path:
project
)
project
.
should_receive
(
:execute_web_hooks
).
with
(
'sha-old'
,
'sha-new'
,
'refs/heads/master'
)
project
.
should_receive
(
:execute_web_hooks
).
with
(
'sha-old'
,
'sha-new'
,
'refs/heads/master'
,
@key_id
)
PostReceive
.
perform
(
project
.
path
,
'sha-old'
,
'sha-new'
,
'refs/heads/master'
)
PostReceive
.
perform
(
project
.
path
,
'sha-old'
,
'sha-new'
,
'refs/heads/master'
,
@key_id
)
end
end
end
end
end
end
This diff is collapsed.
Click to expand it.
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