BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
be10eea9
Commit
be10eea9
authored
Oct 16, 2015
by
Zeger-Jan van de Weg
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into cross-reference-mr-on-issues
parents
94a788f6
0c2df939
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
127 additions
and
19 deletions
+127
-19
CHANGELOG
CHANGELOG
+1
-0
merge_request_diff.rb
app/models/merge_request_diff.rb
+2
-1
repository.rb
app/models/repository.rb
+4
-0
git_push_service.rb
app/services/git_push_service.rb
+4
-1
refresh_service.rb
app/services/merge_requests/refresh_service.rb
+50
-17
system_note_service.rb
app/services/system_note_service.rb
+25
-0
git_push_service_spec.rb
spec/services/git_push_service_spec.rb
+8
-0
refresh_service_spec.rb
spec/services/merge_requests/refresh_service_spec.rb
+21
-0
system_note_service_spec.rb
spec/services/system_note_service_spec.rb
+12
-0
No files found.
CHANGELOG
View file @
be10eea9
...
...
@@ -4,6 +4,7 @@ v 8.1.0 (unreleased)
- Fix error preventing displaying of commit data for a directory with a leading dot (Stan Hu)
- Speed up load times of issue detail pages by roughly 1.5x
- If a merge request is to close an issue, show this on the issue page (Zeger-Jan van de Weg)
- Add a system note and update relevant merge requests when a branch is deleted or re-added (Stan Hu)
- Make diff file view easier to use on mobile screens (Stan Hu)
- Improved performance of finding users by username or Email address
- Fix bug where merge request comments created by API would not trigger notifications (Stan Hu)
...
...
app/models/merge_request_diff.rb
View file @
be10eea9
...
...
@@ -163,7 +163,8 @@ class MergeRequestDiff < ActiveRecord::Base
merge_request
.
fetch_ref
# Get latest sha of branch from source project
source_sha
=
merge_request
.
source_project
.
commit
(
source_branch
).
sha
source_commit
=
merge_request
.
source_project
.
commit
(
source_branch
)
source_sha
=
source_commit
.
try
(
:sha
)
Gitlab
::
CompareResult
.
new
(
Gitlab
::
Git
::
Compare
.
new
(
...
...
app/models/repository.rb
View file @
be10eea9
...
...
@@ -480,6 +480,10 @@ class Repository
end
end
def
merge_base
(
first_commit_id
,
second_commit_id
)
rugged
.
merge_base
(
first_commit_id
,
second_commit_id
)
end
def
search_files
(
query
,
ref
)
offset
=
2
args
=
%W(git grep -i -n --before-context
#{
offset
}
--after-context
#{
offset
}
#{
query
}
#{
ref
||
root_ref
}
)
...
...
app/services/git_push_service.rb
View file @
be10eea9
...
...
@@ -49,10 +49,13 @@ class GitPushService
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
# Update merge requests that may be affected by this push. A new branch
# could cause the last commit of a merge request to change.
project
.
update_merge_requests
(
oldrev
,
newrev
,
ref
,
@user
)
@push_data
=
build_push_data
(
oldrev
,
newrev
,
ref
)
# If CI was disabled but .gitlab-ci.yml file was pushed
...
...
app/services/merge_requests/refresh_service.rb
View file @
be10eea9
...
...
@@ -6,12 +6,20 @@ module MergeRequests
@oldrev
,
@newrev
=
oldrev
,
newrev
@branch_name
=
Gitlab
::
Git
.
ref_name
(
ref
)
@fork_merge_requests
=
@project
.
fork_merge_requests
.
opened
@commits
=
@project
.
repository
.
commits_between
(
oldrev
,
newrev
)
@commits
=
[]
# Leave a system note if a branch were deleted/added
if
Gitlab
::
Git
.
blank_ref?
(
oldrev
)
||
Gitlab
::
Git
.
blank_ref?
(
newrev
)
comment_mr_branch_presence_changed
comment_mr_with_commits
if
@commits
.
present?
else
@commits
=
@project
.
repository
.
commits_between
(
oldrev
,
newrev
)
comment_mr_with_commits
close_merge_requests
end
close_merge_requests
reload_merge_requests
execute_mr_web_hooks
comment_mr_with_commits
true
end
...
...
@@ -31,7 +39,6 @@ module MergeRequests
commit_ids
.
include?
(
merge_request
.
last_commit
.
id
)
end
merge_requests
.
uniq
.
select
(
&
:source_project
).
each
do
|
merge_request
|
MergeRequests
::
PostMergeService
.
new
(
merge_request
.
target_project
,
@current_user
).
...
...
@@ -70,13 +77,38 @@ module MergeRequests
end
end
# Add comment about branches being deleted or added to merge requests
def
comment_mr_branch_presence_changed
presence
=
Gitlab
::
Git
.
blank_ref?
(
@oldrev
)
?
:
add
:
:delete
merge_requests_for_source_branch
.
each
do
|
merge_request
|
last_commit
=
merge_request
.
last_commit
# Only look at changed commits in restore branch case
unless
Gitlab
::
Git
.
blank_ref?
(
@newrev
)
begin
# Since any number of commits could have been made to the restored branch,
# find the common root to see what has been added.
common_ref
=
@project
.
repository
.
merge_base
(
last_commit
.
id
,
@newrev
)
# If the a commit no longer exists in this repo, gitlab_git throws
# a Rugged::OdbError. This is fixed in https://gitlab.com/gitlab-org/gitlab_git/merge_requests/52
@commits
=
@project
.
repository
.
commits_between
(
common_ref
,
@newrev
)
if
common_ref
rescue
end
# Prevent system notes from seeing a blank SHA
@oldrev
=
nil
end
SystemNoteService
.
change_branch_presence
(
merge_request
,
merge_request
.
project
,
@current_user
,
:source
,
@branch_name
,
presence
)
end
end
# Add comment about pushing new commits to merge requests
def
comment_mr_with_commits
merge_requests
=
@project
.
origin_merge_requests
.
opened
.
where
(
source_branch:
@branch_name
).
to_a
merge_requests
+=
@fork_merge_requests
.
where
(
source_branch:
@branch_name
).
to_a
merge_requests
=
filter_merge_requests
(
merge_requests
)
merge_requests
.
each
do
|
merge_request
|
merge_requests_for_source_branch
.
each
do
|
merge_request
|
mr_commit_ids
=
Set
.
new
(
merge_request
.
commits
.
map
(
&
:id
))
new_commits
,
existing_commits
=
@commits
.
partition
do
|
commit
|
...
...
@@ -91,14 +123,7 @@ module MergeRequests
# Call merge request webhook with update branches
def
execute_mr_web_hooks
merge_requests
=
@project
.
origin_merge_requests
.
opened
.
where
(
source_branch:
@branch_name
)
.
to_a
merge_requests
+=
@fork_merge_requests
.
where
(
source_branch:
@branch_name
)
.
to_a
merge_requests
=
filter_merge_requests
(
merge_requests
)
merge_requests
.
each
do
|
merge_request
|
merge_requests_for_source_branch
.
each
do
|
merge_request
|
execute_hooks
(
merge_request
,
'update'
)
end
end
...
...
@@ -106,5 +131,13 @@ module MergeRequests
def
filter_merge_requests
(
merge_requests
)
merge_requests
.
uniq
.
select
(
&
:source_project
)
end
def
merge_requests_for_source_branch
@source_merge_requests
||=
begin
merge_requests
=
@project
.
origin_merge_requests
.
opened
.
where
(
source_branch:
@branch_name
).
to_a
merge_requests
+=
@fork_merge_requests
.
where
(
source_branch:
@branch_name
).
to_a
filter_merge_requests
(
merge_requests
)
end
end
end
end
app/services/system_note_service.rb
View file @
be10eea9
...
...
@@ -168,6 +168,31 @@ class SystemNoteService
create_note
(
noteable:
noteable
,
project:
project
,
author:
author
,
note:
body
)
end
# Called when a branch in Noteable is added or deleted
#
# noteable - Noteable object
# project - Project owning noteable
# author - User performing the change
# branch_type - :source or :target
# branch - branch name
# presence - :add or :delete
#
# Example Note text:
#
# "Restored target branch `feature`"
#
# Returns the created Note object
def
self
.
change_branch_presence
(
noteable
,
project
,
author
,
branch_type
,
branch
,
presence
)
verb
=
if
presence
==
:add
'restored'
else
'deleted'
end
body
=
"
#{
verb
}
#{
branch_type
.
to_s
}
branch `
#{
branch
}
`"
.
capitalize
create_note
(
noteable:
noteable
,
project:
project
,
author:
author
,
note:
body
)
end
# Called when a Mentionable references a Noteable
#
# noteable - Noteable object being referenced
...
...
spec/services/git_push_service_spec.rb
View file @
be10eea9
...
...
@@ -112,6 +112,14 @@ describe GitPushService do
it
{
expect
(
@event
.
project
).
to
eq
(
project
)
}
it
{
expect
(
@event
.
action
).
to
eq
(
Event
::
PUSHED
)
}
it
{
expect
(
@event
.
data
).
to
eq
(
service
.
push_data
)
}
context
"Updates merge requests"
do
it
"when pushing a new branch for the first time"
do
expect
(
project
).
to
receive
(
:update_merge_requests
).
with
(
@blankrev
,
'newrev'
,
'refs/heads/master'
,
user
)
service
.
execute
(
project
,
user
,
@blankrev
,
'newrev'
,
'refs/heads/master'
)
end
end
end
describe
"Web Hooks"
do
...
...
spec/services/merge_requests/refresh_service_spec.rb
View file @
be10eea9
...
...
@@ -106,6 +106,27 @@ describe MergeRequests::RefreshService do
it
{
expect
(
@fork_merge_request
.
notes
).
to
be_empty
}
end
context
'push new branch that exists in a merge request'
do
let
(
:refresh_service
)
{
service
.
new
(
@fork_project
,
@user
)
}
it
'refreshes the merge request'
do
expect
(
refresh_service
).
to
receive
(
:execute_hooks
).
with
(
@fork_merge_request
,
'update'
)
allow_any_instance_of
(
Repository
).
to
receive
(
:merge_base
).
and_return
(
@oldrev
)
refresh_service
.
execute
(
Gitlab
::
Git
::
BLANK_SHA
,
@newrev
,
'refs/heads/master'
)
reload_mrs
expect
(
@merge_request
.
notes
).
to
be_empty
expect
(
@merge_request
).
to
be_open
notes
=
@fork_merge_request
.
notes
.
reorder
(
:created_at
).
map
(
&
:note
)
expect
(
notes
[
0
]).
to
include
(
'Restored source branch `master`'
)
expect
(
notes
[
1
]).
to
include
(
'Added 4 commits'
)
expect
(
@fork_merge_request
).
to
be_open
end
end
def
reload_mrs
@merge_request
.
reload
@fork_merge_request
.
reload
...
...
spec/services/system_note_service_spec.rb
View file @
be10eea9
...
...
@@ -242,6 +242,18 @@ describe SystemNoteService do
end
end
describe
'.change_branch_presence'
do
subject
{
described_class
.
change_branch_presence
(
noteable
,
project
,
author
,
:source
,
'feature'
,
:delete
)
}
it_behaves_like
'a system note'
context
'when source branch deleted'
do
it
'sets the note text'
do
expect
(
subject
.
note
).
to
eq
"Deleted source branch `feature`"
end
end
end
describe
'.cross_reference'
do
subject
{
described_class
.
cross_reference
(
noteable
,
mentioner
,
author
)
}
...
...
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