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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
464c939a
Commit
464c939a
authored
Oct 21, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up MR refresh service somewhat.
parent
9c61b73c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
28 deletions
+48
-28
app/services/merge_requests/refresh_service.rb
app/services/merge_requests/refresh_service.rb
+47
-27
app/services/system_note_service.rb
app/services/system_note_service.rb
+1
-1
No files found.
app/services/merge_requests/refresh_service.rb
View file @
464c939a
...
...
@@ -5,17 +5,15 @@ module MergeRequests
@oldrev
,
@newrev
=
oldrev
,
newrev
@branch_name
=
Gitlab
::
Git
.
ref_name
(
ref
)
@fork_merge_requests
=
@project
.
fork_merge_requests
.
opened
@commits
=
[]
find_new_commits
reload_merge_requests
# Leave a system note if a branch w
ere
deleted/added
if
Gitlab
::
Git
.
blank_ref?
(
oldrev
)
||
Gitlab
::
Git
.
blank_ref?
(
newrev
)
# Leave a system note if a branch w
as
deleted/added
if
branch_added?
||
branch_removed?
comment_mr_branch_presence_changed
comment_mr_with_commits
if
@commits
.
present?
comment_mr_with_commits
else
@commits
=
@project
.
repository
.
commits_between
(
oldrev
,
newrev
)
comment_mr_with_commits
close_merge_requests
end
...
...
@@ -55,7 +53,7 @@ module MergeRequests
# Note: we should update merge requests from forks too
def
reload_merge_requests
merge_requests
=
@project
.
merge_requests
.
opened
.
by_branch
(
@branch_name
).
to_a
merge_requests
+=
@
fork_merge_requests
.
by_branch
(
@branch_name
).
to_a
merge_requests
+=
fork_merge_requests
.
by_branch
(
@branch_name
).
to_a
merge_requests
=
filter_merge_requests
(
merge_requests
)
merge_requests
.
each
do
|
merge_request
|
...
...
@@ -78,29 +76,37 @@ module MergeRequests
end
end
# Add comment about branches being deleted or added to merge reques
ts
def
comment_mr_branch_presence_changed
presence
=
Gitlab
::
Git
.
blank_ref?
(
@oldrev
)
?
:add
:
:delete
def
find_new_commi
ts
if
branch_added?
@commits
=
[]
merge_requests_for_source_branch
.
each
do
|
merge_request
|
last_commit
=
merge_request
.
last_commi
t
merge_request
=
merge_requests_for_source_branch
.
first
return
unless
merge_reques
t
# 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
last_commit
=
merge_request
.
last_commit
# Prevent system notes from seeing a blank SHA
@oldrev
=
nil
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
elsif
branch_removed?
# No commits for a deleted branch.
@commits
=
[]
else
@commits
=
@project
.
repository
.
commits_between
(
@oldrev
,
@newrev
)
end
end
# Add comment about branches being deleted or added to merge requests
def
comment_mr_branch_presence_changed
presence
=
branch_added?
?
:add
:
:delete
merge_requests_for_source_branch
.
each
do
|
merge_request
|
SystemNoteService
.
change_branch_presence
(
merge_request
,
merge_request
.
project
,
@current_user
,
:source
,
@branch_name
,
presence
)
...
...
@@ -109,6 +115,8 @@ module MergeRequests
# Add comment about pushing new commits to merge requests
def
comment_mr_with_commits
return
unless
@commits
.
present?
merge_requests_for_source_branch
.
each
do
|
merge_request
|
mr_commit_ids
=
Set
.
new
(
merge_request
.
commits
.
map
(
&
:id
))
...
...
@@ -136,9 +144,21 @@ module MergeRequests
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
merge_requests
+=
fork_merge_requests
.
where
(
source_branch:
@branch_name
).
to_a
filter_merge_requests
(
merge_requests
)
end
end
def
fork_merge_requests
@fork_merge_requests
||=
@project
.
fork_merge_requests
.
opened
end
def
branch_added?
Gitlab
::
Git
.
blank_ref?
(
@oldrev
)
end
def
branch_removed?
Gitlab
::
Git
.
blank_ref?
(
@newrev
)
end
end
end
app/services/system_note_service.rb
View file @
464c939a
...
...
@@ -327,7 +327,7 @@ class SystemNoteService
commit_ids
=
if
count
==
1
existing_commits
.
first
.
short_id
else
if
oldrev
if
oldrev
&&
!
Gitlab
::
Git
.
blank_ref?
(
oldrev
)
"
#{
Commit
.
truncate_sha
(
oldrev
)
}
...
#{
existing_commits
.
last
.
short_id
}
"
else
"
#{
existing_commits
.
first
.
short_id
}
..
#{
existing_commits
.
last
.
short_id
}
"
...
...
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