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
Tatuya Kamada
gitlab-ce
Commits
a0d4235c
Commit
a0d4235c
authored
Jan 15, 2015
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Send checkout sha for web hooks and services
parent
1e0f36b4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
52 deletions
+70
-52
lib/gitlab/git.rb
lib/gitlab/git.rb
+4
-0
lib/gitlab/push_data_builder.rb
lib/gitlab/push_data_builder.rb
+66
-52
No files found.
lib/gitlab/git.rb
View file @
a0d4235c
module
Gitlab
module
Gitlab
module
Git
module
Git
BLANK_SHA
=
'0'
*
40
BLANK_SHA
=
'0'
*
40
def
self
.
extract_ref_name
(
ref
)
ref
.
gsub
(
/\Arefs\/(tags|heads)\//
,
''
)
end
end
end
end
end
lib/gitlab/push_data_builder.rb
View file @
a0d4235c
module
Gitlab
module
Gitlab
class
PushDataBuilder
class
PushDataBuilder
# Produce a hash of post-receive data
class
<<
self
#
# Produce a hash of post-receive data
# data = {
#
# before: String,
# data = {
# after: String,
# before: String,
# ref: String,
# after: String,
# user_id: String,
# ref: String,
# user_name: String,
# user_id: String,
# project_id: String,
# user_name: String,
# repository: {
# project_id: String,
# name: String,
# repository: {
# url: String,
# name: String,
# description: String,
# url: String,
# homepage: String,
# description: String,
# },
# homepage: String,
# commits: Array,
# },
# total_commits_count: Fixnum
# commits: Array,
# }
# total_commits_count: Fixnum
#
# }
def
self
.
build
(
project
,
user
,
oldrev
,
newrev
,
ref
,
commits
=
[])
#
# Total commits count
def
build
(
project
,
user
,
oldrev
,
newrev
,
ref
,
commits
=
[])
commits_count
=
commits
.
size
# Total commits count
commits_count
=
commits
.
size
# Get latest 20 commits ASC
# Get latest 20 commits ASC
commits_limited
=
commits
.
last
(
20
)
commits_limited
=
commits
.
last
(
20
)
# Hash to be passed as post_receive_data
# Hash to be passed as post_receive_data
data
=
{
data
=
{
before:
oldrev
,
before:
oldrev
,
after:
newrev
,
after:
newrev
,
ref:
ref
,
ref:
ref
,
user_id:
user
.
id
,
checkout_sha:
checkout_sha
(
project
.
repository
,
newrev
,
ref
),
user_name:
user
.
name
,
user_id:
user
.
id
,
project_id:
project
.
id
,
user_name:
user
.
name
,
repository:
{
project_id:
project
.
id
,
name:
project
.
name
,
repository:
{
url:
project
.
url_to_repo
,
name:
project
.
name
,
description:
project
.
description
,
url:
project
.
url_to_repo
,
homepage:
project
.
web_url
,
description:
project
.
description
,
},
homepage:
project
.
web_url
,
commits:
[],
},
total_commits_count:
commits_count
commits:
[],
}
total_commits_count:
commits_count
}
# For performance purposes maximum 20 latest commits
# For performance purposes maximum 20 latest commits
# will be passed as post receive hook data.
# will be passed as post receive hook data.
commits_limited
.
each
do
|
commit
|
commits_limited
.
each
do
|
commit
|
data
[
:commits
]
<<
commit
.
hook_attrs
(
project
)
data
[
:commits
]
<<
commit
.
hook_attrs
(
project
)
end
data
end
end
data
# This method provide a sample data generated with
end
# existing project and commits to test web hooks
def
build_sample
(
project
,
user
)
commits
=
project
.
repository
.
commits
(
project
.
default_branch
,
nil
,
3
)
build
(
project
,
user
,
commits
.
last
.
id
,
commits
.
first
.
id
,
"refs/heads/
#{
project
.
default_branch
}
"
,
commits
)
end
# This method provide a sample data generated with
def
checkout_sha
(
repository
,
newrev
,
ref
)
# existing project and commits to test web hooks
if
newrev
!=
Gitlab
::
Git
::
BLANK_SHA
&&
ref
.
start_with?
(
'refs/tags/'
)
def
self
.
build_sample
(
project
,
user
)
tag_name
=
Gitlab
::
Git
.
extract_ref_name
(
ref
)
commits
=
project
.
repository
.
commits
(
project
.
default_branch
,
nil
,
3
)
tag
=
repository
.
find_tag
(
tag_name
)
build
(
project
,
user
,
commits
.
last
.
id
,
commits
.
first
.
id
,
"refs/heads/
#{
project
.
default_branch
}
"
,
commits
)
commit
=
repository
.
commit
(
tag
.
target
)
commit
.
try
(
:sha
)
else
newrev
end
end
end
end
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