Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
6b99dfedf884
Commit
5b432e76
authored
Dec 05, 2014
by
Kamil Trzcinski
Browse files
Extend push_tag event to include tag message and last commit
parent
08ce9e33b108
Changes
7
Hide whitespace changes
Inline
Side-by-side
CHANGELOG
View file @
6b99dfed
...
...
@@ -15,6 +15,7 @@ v 7.10.0 (unreleased)
- Improve error message when save profile has error.
- Passing the name of pushed ref to CI service (requires GitLab CI 7.9+)
- Add location field to user profile
- Add tag message and last commit to tag hook (Kamil Trzciński)
v 7.9.0 (unreleased)
- Add HipChat integration documentation (Stan Hu)
...
...
app/services/create_tag_service.rb
View file @
6b99dfed
...
...
@@ -40,7 +40,8 @@ def success(branch)
end
def
create_push_data
(
project
,
user
,
tag
)
commits
=
[
project
.
repository
.
commit
(
tag
.
target
)].
compact
Gitlab
::
PushDataBuilder
.
build
(
project
,
user
,
Gitlab
::
Git
::
BLANK_SHA
,
tag
.
target
,
"
#{
Gitlab
::
Git
::
TAG_REF_PREFIX
}#{
tag
.
name
}
"
,
[]
)
build
(
project
,
user
,
Gitlab
::
Git
::
BLANK_SHA
,
tag
.
target
,
"
#{
Gitlab
::
Git
::
TAG_REF_PREFIX
}#{
tag
.
name
}
"
,
commits
,
tag
.
message
)
end
end
app/services/git_push_service.rb
View file @
6b99dfed
...
...
@@ -23,42 +23,40 @@ def execute(project, user, oldrev, newrev, ref)
project
.
repository
.
expire_cache
project
.
update_repository_size
if
push_to_branch?
(
ref
)
if
push_remove_branch?
(
ref
,
newrev
)
@push_commits
=
[]
elsif
push_to_new_branch?
(
ref
,
oldrev
)
# Re-find the pushed commits.
if
is_default_branch?
(
ref
)
# Initial push to the default branch. Take the full history of that branch as "newly pushed".
@push_commits
=
project
.
repository
.
commits
(
newrev
)
# Set protection on the default branch if configured
if
(
current_application_settings
.
default_branch_protection
!=
PROTECTION_NONE
)
developers_can_push
=
current_application_settings
.
default_branch_protection
==
PROTECTION_DEV_CAN_PUSH
?
true
:
false
project
.
protected_branches
.
create
({
name:
project
.
default_branch
,
developers_can_push:
developers_can_push
})
end
else
# Use the pushed commits that aren't reachable by the default branch
# as a heuristic. This may include more commits than are actually pushed, but
# that shouldn't matter because we check for existing cross-references later.
@push_commits
=
project
.
repository
.
commits_between
(
project
.
default_branch
,
newrev
)
# don't process commits for the initial push to the default branch
process_commit_messages
(
ref
)
if
push_remove_branch?
(
ref
,
newrev
)
@push_commits
=
[]
elsif
push_to_new_branch?
(
ref
,
oldrev
)
# Re-find the pushed commits.
if
is_default_branch?
(
ref
)
# Initial push to the default branch. Take the full history of that branch as "newly pushed".
@push_commits
=
project
.
repository
.
commits
(
newrev
)
# Set protection on the default branch if configured
if
(
current_application_settings
.
default_branch_protection
!=
PROTECTION_NONE
)
developers_can_push
=
current_application_settings
.
default_branch_protection
==
PROTECTION_DEV_CAN_PUSH
?
true
:
false
project
.
protected_branches
.
create
({
name:
project
.
default_branch
,
developers_can_push:
developers_can_push
})
end
elsif
push_to_existing_branch?
(
ref
,
oldrev
)
# Collect data for this git push
@push_commits
=
project
.
repository
.
commits_between
(
oldrev
,
newrev
)
project
.
update_merge_requests
(
oldrev
,
newrev
,
ref
,
@user
)
else
# Use the pushed commits that aren't reachable by the default branch
# as a heuristic. This may include more commits than are actually pushed, but
# that shouldn't matter because we check for existing cross-references later.
@push_commits
=
project
.
repository
.
commits_between
(
project
.
default_branch
,
newrev
)
# don't process commits for the initial push to the default branch
process_commit_messages
(
ref
)
end
elsif
push_to_existing_branch?
(
ref
,
oldrev
)
# Collect data for this git push
@push_commits
=
project
.
repository
.
commits_between
(
oldrev
,
newrev
)
project
.
update_merge_requests
(
oldrev
,
newrev
,
ref
,
@user
)
process_commit_messages
(
ref
)
end
@push_data
=
build_push_data
(
oldrev
,
newrev
,
ref
)
@push_data
=
build_push_data
(
oldrev
,
newrev
,
ref
)
EventCreateService
.
new
.
push
(
project
,
user
,
@push_data
)
project
.
execute_hooks
(
@push_data
.
dup
,
:push_hooks
)
project
.
execute_services
(
@push_data
.
dup
,
:push_hooks
)
end
EventCreateService
.
new
.
push
(
project
,
user
,
@push_data
)
project
.
execute_hooks
(
@push_data
.
dup
,
:push_hooks
)
project
.
execute_services
(
@push_data
.
dup
,
:push_hooks
)
end
protected
...
...
app/services/git_tag_push_service.rb
View file @
6b99dfed
...
...
@@ -3,7 +3,7 @@ class GitTagPushService
def
execute
(
project
,
user
,
oldrev
,
newrev
,
ref
)
@project
,
@user
=
project
,
user
@push_data
=
build_push_data
(
oldrev
,
newrev
,
ref
)
EventCreateService
.
new
.
push
(
project
,
user
,
@push_data
)
...
...
@@ -18,6 +18,20 @@ def execute(project, user, oldrev, newrev, ref)
private
def
build_push_data
(
oldrev
,
newrev
,
ref
)
Gitlab
::
PushDataBuilder
.
build
(
project
,
user
,
oldrev
,
newrev
,
ref
,
[])
commits
=
[]
message
=
nil
if
!
Gitlab
::
Git
.
blank_ref?
(
newrev
)
tag_name
=
Gitlab
::
Git
.
ref_name
(
ref
)
tag
=
project
.
repository
.
find_tag
(
tag_name
)
if
tag
&&
tag
.
target
==
newrev
commit
=
project
.
repository
.
commit
(
tag
.
target
)
commits
=
[
commit
].
compact
message
=
tag
.
message
end
end
Gitlab
::
PushDataBuilder
.
build
(
project
,
user
,
oldrev
,
newrev
,
ref
,
commits
,
message
)
end
end
lib/gitlab/push_data_builder.rb
View file @
6b99dfed
...
...
@@ -21,7 +21,7 @@ class << self
# total_commits_count: Fixnum
# }
#
def
build
(
project
,
user
,
oldrev
,
newrev
,
ref
,
commits
=
[])
def
build
(
project
,
user
,
oldrev
,
newrev
,
ref
,
commits
=
[]
,
message
=
nil
)
# Total commits count
commits_count
=
commits
.
size
...
...
@@ -42,6 +42,7 @@ def build(project, user, oldrev, newrev, ref, commits = [])
after:
newrev
,
ref:
ref
,
checkout_sha:
checkout_sha
(
project
.
repository
,
newrev
,
ref
),
message:
message
,
user_id:
user
.
id
,
user_name:
user
.
name
,
user_email:
user
.
email
,
...
...
spec/services/git_push_service_spec.rb
View file @
6b99dfed
...
...
@@ -145,11 +145,6 @@
expect
(
project
).
to
receive
(
:execute_hooks
)
service
.
execute
(
project
,
user
,
'oldrev'
,
'newrev'
,
'refs/heads/master'
)
end
it
"when pushing tags"
do
expect
(
project
).
not_to
receive
(
:execute_hooks
)
service
.
execute
(
project
,
user
,
'newrev'
,
'newrev'
,
'refs/tags/v1.0.0'
)
end
end
end
...
...
spec/services/git_tag_push_service_spec.rb
View file @
6b99dfed
require
'spec_helper'
describe
GitTagPushService
do
include
RepoHelpers
let
(
:user
)
{
create
:user
}
let
(
:project
)
{
create
:project
}
let
(
:service
)
{
GitTagPushService
.
new
}
before
do
@re
f
=
'refs/tags/super-tag'
@
old
rev
=
'b98a310def241a6fd9c9a9a3e7934c48e498fe81'
@
new
re
v
=
'
b19a04f53caeebf4fe5ec2327cb83e9253dc91bb
'
@
old
re
v
=
Gitlab
::
Git
::
BLANK_SHA
@
new
rev
=
"8a2a6eb295bb170b34c24c76c49ed0e9b2eaf34b"
# gitlab-test: git rev-parse refs/tags/v1.1.0
@re
f
=
'
refs/tags/v1.1.0
'
end
describe
'
Git Tag Push Data
'
do
describe
"
Git Tag Push Data
"
do
before
do
service
.
execute
(
project
,
user
,
@oldrev
,
@newrev
,
@ref
)
@push_data
=
service
.
push_data
@tag_name
=
Gitlab
::
Git
.
ref_name
(
@ref
)
@tag
=
project
.
repository
.
find_tag
(
@tag_name
)
@commit
=
project
.
repository
.
commit
(
@tag
.
target
)
end
subject
{
@push_data
}
it
{
is_expected
.
to
include
(
object_kind:
'tag_push'
)
}
it
{
is_expected
.
to
include
(
ref:
@ref
)
}
it
{
is_expected
.
to
include
(
before:
@oldrev
)
}
it
{
is_expected
.
to
include
(
after:
@newrev
)
}
it
{
is_expected
.
to
include
(
message:
@tag
.
message
)
}
it
{
is_expected
.
to
include
(
user_id:
user
.
id
)
}
it
{
is_expected
.
to
include
(
user_name:
user
.
name
)
}
it
{
is_expected
.
to
include
(
project_id:
project
.
id
)
}
context
'W
ith repository data
'
do
context
"w
ith repository data
"
do
subject
{
@push_data
[
:repository
]
}
it
{
is_expected
.
to
include
(
name:
project
.
name
)
}
...
...
@@ -34,6 +41,41 @@
it
{
is_expected
.
to
include
(
description:
project
.
description
)
}
it
{
is_expected
.
to
include
(
homepage:
project
.
web_url
)
}
end
context
"with commits"
do
subject
{
@push_data
[
:commits
]
}
it
{
is_expected
.
to
be_an
(
Array
)
}
it
'has 1 element'
do
expect
(
subject
.
size
).
to
eq
(
1
)
end
context
"the commit"
do
subject
{
@push_data
[
:commits
].
first
}
it
{
is_expected
.
to
include
(
id:
@commit
.
id
)
}
it
{
is_expected
.
to
include
(
message:
@commit
.
safe_message
)
}
it
{
is_expected
.
to
include
(
timestamp:
@commit
.
date
.
xmlschema
)
}
it
do
is_expected
.
to
include
(
url:
[
Gitlab
.
config
.
gitlab
.
url
,
project
.
namespace
.
to_param
,
project
.
to_param
,
'commit'
,
@commit
.
id
].
join
(
'/'
)
)
end
context
"with a author"
do
subject
{
@push_data
[
:commits
].
first
[
:author
]
}
it
{
is_expected
.
to
include
(
name:
@commit
.
author_name
)
}
it
{
is_expected
.
to
include
(
email:
@commit
.
author_email
)
}
end
end
end
end
describe
"Web Hooks"
do
...
...
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