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
Léo-Paul Géneau
gitlab-ce
Commits
383c56ef
Commit
383c56ef
authored
Mar 10, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use Gitlab::Git helper methods and constants as much as possible.
parent
e0caed91
Changes
21
Hide whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
73 additions
and
78 deletions
+73
-78
app/controllers/projects/tags_controller.rb
app/controllers/projects/tags_controller.rb
+1
-1
app/mailers/emails/projects.rb
app/mailers/emails/projects.rb
+1
-1
app/models/event.rb
app/models/event.rb
+6
-6
app/models/project_services/asana_service.rb
app/models/project_services/asana_service.rb
+1
-1
app/models/project_services/campfire_service.rb
app/models/project_services/campfire_service.rb
+3
-3
app/models/project_services/hipchat_service.rb
app/models/project_services/hipchat_service.rb
+4
-9
app/models/project_services/pushover_service.rb
app/models/project_services/pushover_service.rb
+3
-3
app/models/project_services/slack_service/push_message.rb
app/models/project_services/slack_service/push_message.rb
+4
-9
app/models/project_services/teamcity_service.rb
app/models/project_services/teamcity_service.rb
+1
-1
app/services/create_tag_service.rb
app/services/create_tag_service.rb
+2
-2
app/services/event_create_service.rb
app/services/event_create_service.rb
+4
-4
app/services/git_push_service.rb
app/services/git_push_service.rb
+5
-11
app/services/merge_requests/refresh_service.rb
app/services/merge_requests/refresh_service.rb
+2
-2
app/workers/emails_on_push_worker.rb
app/workers/emails_on_push_worker.rb
+1
-1
app/workers/irker_worker.rb
app/workers/irker_worker.rb
+3
-3
app/workers/post_receive.rb
app/workers/post_receive.rb
+1
-7
lib/gitlab/git.rb
lib/gitlab/git.rb
+18
-2
lib/gitlab/git_access.rb
lib/gitlab/git_access.rb
+5
-5
lib/gitlab/push_data_builder.rb
lib/gitlab/push_data_builder.rb
+4
-3
spec/models/project_services/hipchat_service_spec.rb
spec/models/project_services/hipchat_service_spec.rb
+1
-1
spec/models/project_services/slack_service/push_message_spec.rb
...odels/project_services/slack_service/push_message_spec.rb
+3
-3
No files found.
app/controllers/projects/tags_controller.rb
View file @
383c56ef
...
...
@@ -27,7 +27,7 @@ class Projects::TagsController < Projects::ApplicationController
tag
=
@repository
.
find_tag
(
params
[
:id
])
if
tag
&&
@repository
.
rm_tag
(
tag
.
name
)
EventCreateService
.
new
.
push_ref
(
@project
,
current_user
,
tag
,
'rm'
,
'refs/tags'
)
EventCreateService
.
new
.
push_ref
(
@project
,
current_user
,
tag
,
'rm'
,
Gitlab
::
Git
::
TAG_REF_PREFIX
)
end
respond_to
do
|
format
|
...
...
app/mailers/emails/projects.rb
View file @
383c56ef
...
...
@@ -23,7 +23,7 @@ module Emails
@compare
=
compare
@commits
=
Commit
.
decorate
(
compare
.
commits
)
@diffs
=
compare
.
diffs
@branch
=
branch
.
gsub
(
"refs/heads/"
,
""
)
@branch
=
Gitlab
::
Git
.
ref_name
(
branch
)
@disable_diffs
=
disable_diffs
@subject
=
"[
#{
@project
.
path_with_namespace
}
][
#{
@branch
}
] "
...
...
app/models/event.rb
View file @
383c56ef
...
...
@@ -190,19 +190,19 @@ class Event < ActiveRecord::Base
end
def
tag?
data
[
:ref
][
"refs/tags"
]
Gitlab
::
Git
.
tag_ref?
(
data
[
:ref
])
end
def
branch?
data
[
:ref
][
"refs/heads"
]
Gitlab
::
Git
.
branch_ref?
(
data
[
:ref
])
end
def
new_ref?
commit_from
=~
/^00000/
Gitlab
::
Git
.
blank_ref?
(
commit_from
)
end
def
rm_ref?
commit_to
=~
/^00000/
Gitlab
::
Git
.
blank_ref?
(
commit_to
)
end
def
md_ref?
...
...
@@ -226,11 +226,11 @@ class Event < ActiveRecord::Base
end
def
branch_name
@branch_name
||=
data
[
:ref
].
gsub
(
"refs/heads/"
,
""
)
@branch_name
||=
Gitlab
::
Git
.
ref_name
(
data
[
:ref
]
)
end
def
tag_name
@tag_name
||=
data
[
:ref
].
gsub
(
"refs/tags/"
,
""
)
@tag_name
||=
Gitlab
::
Git
.
ref_name
(
data
[
:ref
]
)
end
# Max 20 commits from push DESC
...
...
app/models/project_services/asana_service.rb
View file @
383c56ef
...
...
@@ -77,7 +77,7 @@ automatically inspected. Leave blank to include all branches.'
end
user
=
data
[
:user_name
]
branch
=
data
[
:ref
].
gsub
(
'refs/heads/'
,
''
)
branch
=
Gitlab
::
Git
.
ref_name
(
data
[
:ref
]
)
branch_restriction
=
restrict_to_branch
.
to_s
...
...
app/models/project_services/campfire_service.rb
View file @
383c56ef
...
...
@@ -64,7 +64,7 @@ class CampfireService < Service
end
def
build_message
(
push
)
ref
=
push
[
:ref
].
gsub
(
"refs/heads/"
,
""
)
ref
=
Gitlab
::
Git
.
ref_name
(
push
[
:ref
]
)
before
=
push
[
:before
]
after
=
push
[
:after
]
...
...
@@ -72,9 +72,9 @@ class CampfireService < Service
message
<<
"[
#{
project
.
name_with_namespace
}
] "
message
<<
"
#{
push
[
:user_name
]
}
"
if
before
.
include?
(
'000000'
)
if
Gitlab
::
Git
.
blank_ref?
(
before
)
message
<<
"pushed new branch
#{
ref
}
\n
"
elsif
after
.
include?
(
'000000'
)
elsif
Gitlab
::
Git
.
blank_ref?
(
after
)
message
<<
"removed branch
#{
ref
}
\n
"
else
message
<<
"pushed
#{
push
[
:total_commits_count
]
}
commits to
#{
ref
}
. "
...
...
app/models/project_services/hipchat_service.rb
View file @
383c56ef
...
...
@@ -79,24 +79,19 @@ class HipchatService < Service
end
def
create_push_message
(
push
)
if
push
[
:ref
].
starts_with?
(
'refs/tags/'
)
ref_type
=
'tag'
ref
=
push
[
:ref
].
gsub
(
'refs/tags/'
,
''
)
else
ref_type
=
'branch'
ref
=
push
[
:ref
].
gsub
(
'refs/heads/'
,
''
)
end
ref_type
=
Gitlab
::
Git
.
tag_ref?
(
push
[
:ref
])
?
'tag'
:
'branch'
ref
=
Gitlab
::
Git
.
ref_name
(
push
[
:ref
])
before
=
push
[
:before
]
after
=
push
[
:after
]
message
=
""
message
<<
"
#{
push
[
:user_name
]
}
"
if
before
.
include?
(
'000000'
)
if
Gitlab
::
Git
.
blank_ref?
(
before
)
message
<<
"pushed new
#{
ref_type
}
<a href=
\"
"
\
"
#{
project_url
}
/commits/
#{
URI
.
escape
(
ref
)
}
\"
>
#{
ref
}
</a>"
\
" to
#{
project_link
}
\n
"
elsif
after
.
include?
(
'000000'
)
elsif
Gitlab
::
Git
.
blank_ref?
(
after
)
message
<<
"removed
#{
ref_type
}
<b>
#{
ref
}
</b> from <a href=
\"
#{
project
.
web_url
}
\"
>
#{
project_name
}
</a>
\n
"
else
message
<<
"pushed to
#{
ref_type
}
<a href=
\"
"
\
...
...
app/models/project_services/pushover_service.rb
View file @
383c56ef
...
...
@@ -88,13 +88,13 @@ class PushoverService < Service
def
execute
(
data
)
return
unless
supported_events
.
include?
(
data
[
:object_kind
])
ref
=
data
[
:ref
].
gsub
(
'refs/heads/'
,
''
)
ref
=
Gitlab
::
Git
.
ref_name
(
data
[
:ref
]
)
before
=
data
[
:before
]
after
=
data
[
:after
]
if
before
.
include?
(
'000000'
)
if
Gitlab
::
Git
.
blank_ref?
(
before
)
message
=
"
#{
data
[
:user_name
]
}
pushed new branch
\"
#{
ref
}
\"
."
elsif
after
.
include?
(
'000000'
)
elsif
Gitlab
::
Git
.
blank_ref?
(
after
)
message
=
"
#{
data
[
:user_name
]
}
deleted branch
\"
#{
ref
}
\"
."
else
message
=
"
#{
data
[
:user_name
]
}
push to branch
\"
#{
ref
}
\"
."
...
...
app/models/project_services/slack_service/push_message.rb
View file @
383c56ef
...
...
@@ -15,13 +15,8 @@ class SlackService
@commits
=
params
.
fetch
(
:commits
,
[])
@project_name
=
params
[
:project_name
]
@project_url
=
params
[
:project_url
]
if
params
[
:ref
].
starts_with?
(
'refs/tags/'
)
@ref_type
=
'tag'
@ref
=
params
[
:ref
].
gsub
(
'refs/tags/'
,
''
)
else
@ref_type
=
'branch'
@ref
=
params
[
:ref
].
gsub
(
'refs/heads/'
,
''
)
end
@ref_type
=
Gitlab
::
Git
.
tag_ref?
(
params
[
:ref
])
?
'tag'
:
'branch'
@ref
=
Gitlab
::
Git
.
ref_name
(
params
[
:ref
])
@user_name
=
params
[
:user_name
]
end
...
...
@@ -81,11 +76,11 @@ class SlackService
end
def
new_branch?
before
.
include?
(
'000000'
)
Gitlab
::
Git
.
blank_ref?
(
before
)
end
def
removed_branch?
after
.
include?
(
'000000'
)
Gitlab
::
Git
.
blank_ref?
(
after
)
end
def
branch_url
...
...
app/models/project_services/teamcity_service.rb
View file @
383c56ef
...
...
@@ -132,7 +132,7 @@ class TeamcityService < CiService
password:
password
,
}
branch
=
data
[
:ref
].
gsub
(
'refs/heads/'
,
''
)
branch
=
Gitlab
::
Git
.
ref_name
(
data
[
:ref
]
)
self
.
class
.
post
(
"
#{
teamcity_url
}
/httpAuth/app/rest/buildQueue"
,
body:
"<build branchName=
\"
#{
branch
}
\"
>"
\
...
...
app/services/create_tag_service.rb
View file @
383c56ef
...
...
@@ -21,7 +21,7 @@ class CreateTagService < BaseService
new_tag
=
repository
.
find_tag
(
tag_name
)
if
new_tag
EventCreateService
.
new
.
push_ref
(
project
,
current_user
,
new_tag
,
'add'
,
'refs/tags'
)
EventCreateService
.
new
.
push_ref
(
project
,
current_user
,
new_tag
,
'add'
,
Gitlab
::
Git
::
TAG_REF_PREFIX
)
push_data
=
create_push_data
(
project
,
current_user
,
new_tag
)
project
.
execute_hooks
(
push_data
.
dup
,
:tag_push_hooks
)
...
...
@@ -41,7 +41,7 @@ class CreateTagService < BaseService
def
create_push_data
(
project
,
user
,
tag
)
data
=
Gitlab
::
PushDataBuilder
.
build
(
project
,
user
,
Gitlab
::
Git
::
BLANK_SHA
,
tag
.
target
,
'refs/tags/'
+
tag
.
name
,
[])
build
(
project
,
user
,
Gitlab
::
Git
::
BLANK_SHA
,
tag
.
target
,
"
#{
Gitlab
::
Git
::
TAG_REF_PREFIX
}#{
tag
.
name
}
"
,
[])
data
[
:object_kind
]
=
"tag_push"
data
end
...
...
app/services/event_create_service.rb
View file @
383c56ef
...
...
@@ -62,19 +62,19 @@ class EventCreateService
create_event
(
project
,
current_user
,
Event
::
CREATED
)
end
def
push_ref
(
project
,
current_user
,
ref
,
action
=
'add'
,
prefix
=
'refs/heads'
)
def
push_ref
(
project
,
current_user
,
ref
,
action
=
'add'
,
prefix
=
Gitlab
::
Git
::
BRANCH_REF_PREFIX
)
commit
=
project
.
repository
.
commit
(
ref
.
target
)
if
action
.
to_s
==
'add'
before
=
'00000000'
before
=
Gitlab
::
Git
::
BLANK_SHA
after
=
commit
.
id
else
before
=
commit
.
id
after
=
'00000000'
after
=
Gitlab
::
Git
::
BLANK_SHA
end
data
=
{
ref:
"
#{
prefix
}
/
#{
ref
.
name
}
"
,
ref:
"
#{
prefix
}#{
ref
.
name
}
"
,
before:
before
,
after:
after
}
...
...
app/services/git_push_service.rb
View file @
383c56ef
...
...
@@ -107,30 +107,24 @@ class GitPushService
end
def
push_to_existing_branch?
(
ref
,
oldrev
)
ref_parts
=
ref
.
split
(
'/'
)
# Return if this is not a push to a branch (e.g. new commits)
ref_parts
[
1
].
include?
(
'heads'
)
&&
oldrev
!=
Gitlab
::
Git
::
BLANK_SHA
Gitlab
::
Git
.
branch_ref?
(
ref
)
&&
oldrev
!=
Gitlab
::
Git
::
BLANK_SHA
end
def
push_to_new_branch?
(
ref
,
oldrev
)
ref_parts
=
ref
.
split
(
'/'
)
ref_parts
[
1
].
include?
(
'heads'
)
&&
oldrev
==
Gitlab
::
Git
::
BLANK_SHA
Gitlab
::
Git
.
branch_ref?
(
ref
)
&&
Gitlab
::
Git
.
blank_ref?
(
oldrev
)
end
def
push_remove_branch?
(
ref
,
newrev
)
ref_parts
=
ref
.
split
(
'/'
)
ref_parts
[
1
].
include?
(
'heads'
)
&&
newrev
==
Gitlab
::
Git
::
BLANK_SHA
Gitlab
::
Git
.
branch_ref?
(
ref
)
&&
Gitlab
::
Git
.
blank_ref?
(
newrev
)
end
def
push_to_branch?
(
ref
)
ref
.
include?
(
'refs/heads'
)
Gitlab
::
Git
.
branch_ref?
(
ref
)
end
def
is_default_branch?
(
ref
)
ref
==
"refs/heads/
#{
project
.
default_branch
}
"
Gitlab
::
Git
.
branch_ref?
(
ref
)
&&
Gitlab
::
Git
.
ref_name
(
ref
)
==
project
.
default_branch
end
def
commit_user
(
commit
)
...
...
app/services/merge_requests/refresh_service.rb
View file @
383c56ef
module
MergeRequests
class
RefreshService
<
MergeRequests
::
BaseService
def
execute
(
oldrev
,
newrev
,
ref
)
return
true
unless
ref
=~
/heads/
return
true
unless
Gitlab
::
Git
.
branch_ref?
(
ref
)
@oldrev
,
@newrev
=
oldrev
,
newrev
@branch_name
=
ref
.
gsub
(
"refs/heads/"
,
""
)
@branch_name
=
Gitlab
::
Git
.
ref_name
(
ref
)
@fork_merge_requests
=
@project
.
fork_merge_requests
.
opened
@commits
=
@project
.
repository
.
commits_between
(
oldrev
,
newrev
)
...
...
app/workers/emails_on_push_worker.rb
View file @
383c56ef
...
...
@@ -8,7 +8,7 @@ class EmailsOnPushWorker
branch
=
push_data
[
"ref"
]
author_id
=
push_data
[
"user_id"
]
if
before_sha
=~
/^000000/
||
after_sha
=~
/^000000/
if
Gitlab
::
Git
.
blank_ref?
(
before_sha
)
||
Gitlab
::
Git
.
blank_ref?
(
after_sha
)
# skip if new branch was pushed or branch was removed
return
true
end
...
...
app/workers/irker_worker.rb
View file @
383c56ef
...
...
@@ -57,9 +57,9 @@ class IrkerWorker
end
def
send_branch_updates
(
push_data
,
project
,
repo_name
,
committer
,
branch
)
if
push_data
[
'before'
]
=
~
/^000000/
if
push_data
[
'before'
]
=
=
Gitlab
::
Git
::
BLANK_SHA
send_new_branch
project
,
repo_name
,
committer
,
branch
elsif
push_data
[
'after'
]
=
~
/^000000/
elsif
push_data
[
'after'
]
=
=
Gitlab
::
Git
::
BLANK_SHA
send_del_branch
repo_name
,
committer
,
branch
end
end
...
...
@@ -83,7 +83,7 @@ class IrkerWorker
return
if
push_data
[
'total_commits_count'
]
==
0
# Next message is for number of commit pushed, if any
if
push_data
[
'before'
]
=
~
/^000000/
if
push_data
[
'before'
]
=
=
Gitlab
::
Git
::
BLANK_SHA
# Tweak on push_data["before"] in order to have a nice compare URL
push_data
[
'before'
]
=
before_on_new_branch
push_data
,
project
end
...
...
app/workers/post_receive.rb
View file @
383c56ef
...
...
@@ -33,7 +33,7 @@ class PostReceive
return
false
end
if
tag
?
(
ref
)
if
Gitlab
::
Git
.
tag_ref
?
(
ref
)
GitTagPushService
.
new
.
execute
(
project
,
@user
,
oldrev
,
newrev
,
ref
)
else
GitPushService
.
new
.
execute
(
project
,
@user
,
oldrev
,
newrev
,
ref
)
...
...
@@ -44,10 +44,4 @@ class PostReceive
def
log
(
message
)
Gitlab
::
GitLogger
.
error
(
"POST-RECEIVE:
#{
message
}
"
)
end
private
def
tag?
(
ref
)
!!
(
/refs\/tags\/(.*)/
.
match
(
ref
))
end
end
lib/gitlab/git.rb
View file @
383c56ef
module
Gitlab
module
Git
BLANK_SHA
=
'0'
*
40
TAG_REF_PREFIX
=
"refs/tags/"
BRANCH_REF_PREFIX
=
"refs/heads/"
def
self
.
extract_ref_name
(
ref
)
ref
.
gsub
(
/\Arefs\/(tags|heads)\//
,
''
)
class
<<
self
def
ref_name
(
ref
)
ref
.
gsub
(
/\Arefs\/(tags|heads)\//
,
''
)
end
def
tag_ref?
(
ref
)
ref
.
start_with?
(
TAG_REF_PREFIX
)
end
def
branch_ref?
(
ref
)
ref
.
start_with?
(
BRANCH_REF_PREFIX
)
end
def
blank_ref?
(
ref
)
ref
==
BLANK_SHA
end
end
end
end
lib/gitlab/git_access.rb
View file @
383c56ef
...
...
@@ -115,7 +115,7 @@ module Gitlab
# we dont allow force push to protected branch
if
forced_push?
(
project
,
oldrev
,
newrev
)
:force_push_code_to_protected_branches
elsif
newrev
==
Gitlab
::
Git
::
BLANK_SHA
elsif
Gitlab
::
Git
.
blank_ref?
(
newrev
)
# and we dont allow remove of protected branch
:remove_protected_branches
elsif
project
.
developers_can_push_to_protected_branch?
(
branch_name
)
...
...
@@ -135,8 +135,8 @@ module Gitlab
def
branch_name
(
ref
)
ref
=
ref
.
to_s
if
ref
.
start_with?
(
'refs/heads'
)
ref
.
sub
(
%r{
\A
refs/heads/}
,
''
)
if
Gitlab
::
Git
.
branch_ref?
(
ref
)
Gitlab
::
Git
.
ref_name
(
ref
)
else
nil
end
...
...
@@ -144,8 +144,8 @@ module Gitlab
def
tag_name
(
ref
)
ref
=
ref
.
to_s
if
ref
.
start_with?
(
'refs/tags'
)
ref
.
sub
(
%r{
\A
refs/tags/}
,
''
)
if
Gitlab
::
Git
.
tag_ref?
(
ref
)
Gitlab
::
Git
.
ref_name
(
ref
)
else
nil
end
...
...
lib/gitlab/push_data_builder.rb
View file @
383c56ef
...
...
@@ -65,12 +65,13 @@ module Gitlab
# 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
)
ref
=
"
#{
Gitlab
::
Git
::
BRANCH_REF_PREFIX
}#{
project
.
default_branch
}
"
build
(
project
,
user
,
commits
.
last
.
id
,
commits
.
first
.
id
,
ref
,
commits
)
end
def
checkout_sha
(
repository
,
newrev
,
ref
)
if
newrev
!=
Gitlab
::
Git
::
BLANK_SHA
&&
ref
.
start_with?
(
'refs/tags/'
)
tag_name
=
Gitlab
::
Git
.
extract_
ref_name
(
ref
)
if
newrev
!=
Gitlab
::
Git
::
BLANK_SHA
&&
Gitlab
::
Git
.
tag_ref?
(
ref
)
tag_name
=
Gitlab
::
Git
.
ref_name
(
ref
)
tag
=
repository
.
find_tag
(
tag_name
)
if
tag
...
...
spec/models/project_services/hipchat_service_spec.rb
View file @
383c56ef
...
...
@@ -63,7 +63,7 @@ describe HipchatService do
end
context
'tag_push events'
do
let
(
:push_sample_data
)
{
Gitlab
::
PushDataBuilder
.
build
(
project
,
user
,
'000000'
,
'111111'
,
'refs/tags/test'
,
[])
}
let
(
:push_sample_data
)
{
Gitlab
::
PushDataBuilder
.
build
(
project
,
user
,
Gitlab
::
Git
::
BLANK_SHA
,
'1'
*
40
,
'refs/tags/test'
,
[])
}
it
"should call Hipchat API for tag push events"
do
hipchat
.
execute
(
push_sample_data
)
...
...
spec/models/project_services/slack_service/push_message_spec.rb
View file @
383c56ef
...
...
@@ -43,7 +43,7 @@ describe SlackService::PushMessage do
let
(
:args
)
{
{
after:
'after'
,
before:
'000000'
,
before:
Gitlab
::
Git
::
BLANK_SHA
,
project_name:
'project_name'
,
ref:
'refs/tags/new_tag'
,
user_name:
'user_name'
,
...
...
@@ -61,7 +61,7 @@ describe SlackService::PushMessage do
context
'new branch'
do
before
do
args
[
:before
]
=
'000000'
args
[
:before
]
=
Gitlab
::
Git
::
BLANK_SHA
end
it
'returns a message regarding a new branch'
do
...
...
@@ -75,7 +75,7 @@ describe SlackService::PushMessage do
context
'removed branch'
do
before
do
args
[
:after
]
=
'000000'
args
[
:after
]
=
Gitlab
::
Git
::
BLANK_SHA
end
it
'returns a message regarding a removed branch'
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