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
fa07c9d6
Commit
fa07c9d6
authored
Feb 28, 2012
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
register push event
parent
dcdb2fdf
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
135 additions
and
106 deletions
+135
-106
app/models/project.rb
app/models/project.rb
+11
-0
app/workers/post_receive.rb
app/workers/post_receive.rb
+1
-0
spec/models/activity_observer_spec.rb
spec/models/activity_observer_spec.rb
+8
-6
spec/models/project_hooks_spec.rb
spec/models/project_hooks_spec.rb
+115
-0
spec/models/project_spec.rb
spec/models/project_spec.rb
+0
-100
No files found.
app/models/project.rb
View file @
fa07c9d6
...
@@ -90,6 +90,16 @@ class Project < ActiveRecord::Base
...
@@ -90,6 +90,16 @@ class Project < ActiveRecord::Base
[
GIT_HOST
[
'host'
],
code
].
join
(
"/"
)
[
GIT_HOST
[
'host'
],
code
].
join
(
"/"
)
end
end
def
observe_push
(
oldrev
,
newrev
,
ref
)
data
=
web_hook_data
(
oldrev
,
newrev
,
ref
)
Event
.
create
(
:project
=>
self
,
:action
=>
Event
::
Pushed
,
:data
=>
data
)
end
def
execute_web_hooks
(
oldrev
,
newrev
,
ref
)
def
execute_web_hooks
(
oldrev
,
newrev
,
ref
)
ref_parts
=
ref
.
split
(
'/'
)
ref_parts
=
ref
.
split
(
'/'
)
...
@@ -97,6 +107,7 @@ class Project < ActiveRecord::Base
...
@@ -97,6 +107,7 @@ class Project < ActiveRecord::Base
return
if
ref_parts
[
1
]
!~
/heads/
||
oldrev
==
"00000000000000000000000000000000"
return
if
ref_parts
[
1
]
!~
/heads/
||
oldrev
==
"00000000000000000000000000000000"
data
=
web_hook_data
(
oldrev
,
newrev
,
ref
)
data
=
web_hook_data
(
oldrev
,
newrev
,
ref
)
web_hooks
.
each
{
|
web_hook
|
web_hook
.
execute
(
data
)
}
web_hooks
.
each
{
|
web_hook
|
web_hook
.
execute
(
data
)
}
end
end
...
...
app/workers/post_receive.rb
View file @
fa07c9d6
...
@@ -5,6 +5,7 @@ class PostReceive
...
@@ -5,6 +5,7 @@ class PostReceive
project
=
Project
.
find_by_path
(
reponame
)
project
=
Project
.
find_by_path
(
reponame
)
return
false
if
project
.
nil?
return
false
if
project
.
nil?
project
.
observe_push
(
oldrev
,
newrev
,
ref
)
project
.
execute_web_hooks
(
oldrev
,
newrev
,
ref
)
project
.
execute_web_hooks
(
oldrev
,
newrev
,
ref
)
end
end
end
end
spec/models/activity_observer_spec.rb
View file @
fa07c9d6
...
@@ -3,14 +3,18 @@ require 'spec_helper'
...
@@ -3,14 +3,18 @@ require 'spec_helper'
describe
ActivityObserver
do
describe
ActivityObserver
do
let
(
:project
)
{
Factory
:project
}
let
(
:project
)
{
Factory
:project
}
def
self
.
it_should_be_valid_event
it
{
@event
.
should_not
be_nil
}
it
{
@event
.
project
.
should
==
project
}
end
describe
"Merge Request created"
do
describe
"Merge Request created"
do
before
do
before
do
@merge_request
=
Factory
:merge_request
,
:project
=>
project
@merge_request
=
Factory
:merge_request
,
:project
=>
project
@event
=
Event
.
last
@event
=
Event
.
last
end
end
it
{
@event
.
should_not
be_nil
}
it_should_be_valid_event
it
{
@event
.
project
.
should
==
project
}
it
{
@event
.
action
.
should
==
Event
::
Created
}
it
{
@event
.
action
.
should
==
Event
::
Created
}
it
{
@event
.
target
.
should
==
@merge_request
}
it
{
@event
.
target
.
should
==
@merge_request
}
end
end
...
@@ -21,8 +25,7 @@ describe ActivityObserver do
...
@@ -21,8 +25,7 @@ describe ActivityObserver do
@event
=
Event
.
last
@event
=
Event
.
last
end
end
it
{
@event
.
should_not
be_nil
}
it_should_be_valid_event
it
{
@event
.
project
.
should
==
project
}
it
{
@event
.
action
.
should
==
Event
::
Created
}
it
{
@event
.
action
.
should
==
Event
::
Created
}
it
{
@event
.
target
.
should
==
@issue
}
it
{
@event
.
target
.
should
==
@issue
}
end
end
...
@@ -34,8 +37,7 @@ describe ActivityObserver do
...
@@ -34,8 +37,7 @@ describe ActivityObserver do
@event
=
Event
.
last
@event
=
Event
.
last
end
end
it
{
@event
.
should_not
be_nil
}
it_should_be_valid_event
it
{
@event
.
project
.
should
==
project
}
it
{
@event
.
action
.
should
==
Event
::
Commented
}
it
{
@event
.
action
.
should
==
Event
::
Commented
}
it
{
@event
.
target
.
should
==
@note
}
it
{
@event
.
target
.
should
==
@note
}
end
end
...
...
spec/models/project_hooks_spec.rb
0 → 100644
View file @
fa07c9d6
require
'spec_helper'
describe
Project
,
"Hooks"
do
let
(
:project
)
{
Factory
:project
}
describe
"Post Receive Event"
do
it
"should create push event"
do
oldrev
,
newrev
,
ref
=
'00000000000000000000000000000000'
,
'newrev'
,
'refs/heads/master'
project
.
observe_push
(
oldrev
,
newrev
,
ref
)
event
=
Event
.
last
event
.
should_not
be_nil
event
.
project
.
should
==
project
event
.
action
.
should
==
Event
::
Pushed
event
.
data
==
project
.
web_hook_data
(
oldrev
,
newrev
,
ref
)
end
end
describe
"Web hooks"
do
context
"with no web hooks"
do
it
"raises no errors"
do
lambda
{
project
.
execute_web_hooks
(
'oldrev'
,
'newrev'
,
'ref'
)
}.
should_not
raise_error
end
end
context
"with web hooks"
do
before
do
@webhook
=
Factory
(
:web_hook
)
@webhook_2
=
Factory
(
:web_hook
)
project
.
web_hooks
<<
[
@webhook
,
@webhook_2
]
end
it
"executes multiple web hook"
do
@webhook
.
should_receive
(
:execute
).
once
@webhook_2
.
should_receive
(
:execute
).
once
project
.
execute_web_hooks
(
'oldrev'
,
'newrev'
,
'refs/heads/master'
)
end
end
context
"does not execute web hooks"
do
before
do
@webhook
=
Factory
(
:web_hook
)
project
.
web_hooks
<<
[
@webhook
]
end
it
"when pushing a branch for the first time"
do
@webhook
.
should_not_receive
(
:execute
)
project
.
execute_web_hooks
(
'00000000000000000000000000000000'
,
'newrev'
,
'refs/heads/master'
)
end
it
"when pushing tags"
do
@webhook
.
should_not_receive
(
:execute
)
project
.
execute_web_hooks
(
'oldrev'
,
'newrev'
,
'refs/tags/v1.0.0'
)
end
end
context
"when pushing new branches"
do
end
context
"when gathering commit data"
do
before
do
@oldrev
,
@newrev
,
@ref
=
project
.
fresh_commits
(
2
).
last
.
sha
,
project
.
fresh_commits
(
2
).
first
.
sha
,
'refs/heads/master'
@commit
=
project
.
fresh_commits
(
2
).
first
# Fill nil/empty attributes
project
.
description
=
"This is a description"
@data
=
project
.
web_hook_data
(
@oldrev
,
@newrev
,
@ref
)
end
subject
{
@data
}
it
{
should
include
(
before:
@oldrev
)
}
it
{
should
include
(
after:
@newrev
)
}
it
{
should
include
(
ref:
@ref
)
}
context
"with repository data"
do
subject
{
@data
[
:repository
]
}
it
{
should
include
(
name:
project
.
name
)
}
it
{
should
include
(
url:
project
.
web_url
)
}
it
{
should
include
(
description:
project
.
description
)
}
it
{
should
include
(
homepage:
project
.
web_url
)
}
it
{
should
include
(
private:
project
.
private?
)
}
end
context
"with commits"
do
subject
{
@data
[
:commits
]
}
it
{
should
be_an
(
Array
)
}
it
{
should
have
(
1
).
element
}
context
"the commit"
do
subject
{
@data
[
:commits
].
first
}
it
{
should
include
(
id:
@commit
.
id
)
}
it
{
should
include
(
message:
@commit
.
safe_message
)
}
it
{
should
include
(
timestamp:
@commit
.
date
.
xmlschema
)
}
it
{
should
include
(
url:
"http://localhost/
#{
project
.
code
}
/commits/
#{
@commit
.
id
}
"
)
}
context
"with a author"
do
subject
{
@data
[
:commits
].
first
[
:author
]
}
it
{
should
include
(
name:
@commit
.
author_name
)
}
it
{
should
include
(
email:
@commit
.
author_email
)
}
end
end
end
end
end
end
spec/models/project_spec.rb
View file @
fa07c9d6
...
@@ -70,106 +70,6 @@ describe Project do
...
@@ -70,106 +70,6 @@ describe Project do
end
end
end
end
describe
"web hooks"
do
let
(
:project
)
{
Factory
:project
}
context
"with no web hooks"
do
it
"raises no errors"
do
lambda
{
project
.
execute_web_hooks
(
'oldrev'
,
'newrev'
,
'ref'
)
}.
should_not
raise_error
end
end
context
"with web hooks"
do
before
do
@webhook
=
Factory
(
:web_hook
)
@webhook_2
=
Factory
(
:web_hook
)
project
.
web_hooks
<<
[
@webhook
,
@webhook_2
]
end
it
"executes multiple web hook"
do
@webhook
.
should_receive
(
:execute
).
once
@webhook_2
.
should_receive
(
:execute
).
once
project
.
execute_web_hooks
(
'oldrev'
,
'newrev'
,
'refs/heads/master'
)
end
end
context
"does not execute web hooks"
do
before
do
@webhook
=
Factory
(
:web_hook
)
project
.
web_hooks
<<
[
@webhook
]
end
it
"when pushing a branch for the first time"
do
@webhook
.
should_not_receive
(
:execute
)
project
.
execute_web_hooks
(
'00000000000000000000000000000000'
,
'newrev'
,
'refs/heads/master'
)
end
it
"when pushing tags"
do
@webhook
.
should_not_receive
(
:execute
)
project
.
execute_web_hooks
(
'oldrev'
,
'newrev'
,
'refs/tags/v1.0.0'
)
end
end
context
"when pushing new branches"
do
end
context
"when gathering commit data"
do
before
do
@oldrev
,
@newrev
,
@ref
=
project
.
fresh_commits
(
2
).
last
.
sha
,
project
.
fresh_commits
(
2
).
first
.
sha
,
'refs/heads/master'
@commit
=
project
.
fresh_commits
(
2
).
first
# Fill nil/empty attributes
project
.
description
=
"This is a description"
@data
=
project
.
web_hook_data
(
@oldrev
,
@newrev
,
@ref
)
end
subject
{
@data
}
it
{
should
include
(
before:
@oldrev
)
}
it
{
should
include
(
after:
@newrev
)
}
it
{
should
include
(
ref:
@ref
)
}
context
"with repository data"
do
subject
{
@data
[
:repository
]
}
it
{
should
include
(
name:
project
.
name
)
}
it
{
should
include
(
url:
project
.
web_url
)
}
it
{
should
include
(
description:
project
.
description
)
}
it
{
should
include
(
homepage:
project
.
web_url
)
}
it
{
should
include
(
private:
project
.
private?
)
}
end
context
"with commits"
do
subject
{
@data
[
:commits
]
}
it
{
should
be_an
(
Array
)
}
it
{
should
have
(
1
).
element
}
context
"the commit"
do
subject
{
@data
[
:commits
].
first
}
it
{
should
include
(
id:
@commit
.
id
)
}
it
{
should
include
(
message:
@commit
.
safe_message
)
}
it
{
should
include
(
timestamp:
@commit
.
date
.
xmlschema
)
}
it
{
should
include
(
url:
"http://localhost/
#{
project
.
code
}
/commits/
#{
@commit
.
id
}
"
)
}
context
"with a author"
do
subject
{
@data
[
:commits
].
first
[
:author
]
}
it
{
should
include
(
name:
@commit
.
author_name
)
}
it
{
should
include
(
email:
@commit
.
author_email
)
}
end
end
end
end
end
describe
"updates"
do
describe
"updates"
do
let
(
:project
)
{
Factory
:project
}
let
(
:project
)
{
Factory
:project
}
...
...
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