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
5a3f23f3
Commit
5a3f23f3
authored
Mar 15, 2012
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Persist Merge Request diff. Auto merge request close on push
parent
27e36998
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
121 additions
and
28 deletions
+121
-28
app/controllers/merge_requests_controller.rb
app/controllers/merge_requests_controller.rb
+7
-6
app/models/event.rb
app/models/event.rb
+1
-0
app/models/merge_request.rb
app/models/merge_request.rb
+53
-2
app/models/project.rb
app/models/project.rb
+34
-0
app/views/merge_requests/_commits.html.haml
app/views/merge_requests/_commits.html.haml
+3
-1
app/views/merge_requests/show.html.haml
app/views/merge_requests/show.html.haml
+3
-5
app/workers/post_receive.rb
app/workers/post_receive.rb
+6
-0
db/migrate/20120315111711_add_commits_diff_store_to_merge_request.rb
...20120315111711_add_commits_diff_store_to_merge_request.rb
+6
-0
db/migrate/20120315132931_add_merged_to_merge_request.rb
db/migrate/20120315132931_add_merged_to_merge_request.rb
+5
-0
db/schema.rb
db/schema.rb
+3
-14
No files found.
app/controllers/merge_requests_controller.rb
View file @
5a3f23f3
...
...
@@ -41,13 +41,12 @@ class MergeRequestsController < ApplicationController
@note
=
@project
.
notes
.
new
(
:noteable
=>
@merge_request
)
@commits
=
@project
.
repo
.
commits_between
(
@merge_request
.
target_branch
,
@merge_request
.
source_branch
).
map
{
|
c
|
Commit
.
new
(
c
)}.
sort_by
(
&
:created_at
).
reverse
# Get commits from repository
# or from cache if already merged
@commits
=
@merge_request
.
commits
render_full_content
# Close MR if nothing to merge
#@merge_request.mark_as_merged! if @merge_request.probably_merged?
respond_to
do
|
format
|
format
.
html
...
...
@@ -76,6 +75,8 @@ class MergeRequestsController < ApplicationController
respond_to
do
|
format
|
if
@merge_request
.
save
@merge_request
.
reloaded_commits
@merge_request
.
reloaded_diffs
format
.
html
{
redirect_to
[
@project
,
@merge_request
],
notice:
'Merge request was successfully created.'
}
format
.
json
{
render
json:
@merge_request
,
status: :created
,
location:
@merge_request
}
else
...
...
app/models/event.rb
View file @
5a3f23f3
...
...
@@ -7,6 +7,7 @@ class Event < ActiveRecord::Base
Reopened
=
4
Pushed
=
5
Commented
=
6
Merged
=
7
belongs_to
:project
belongs_to
:target
,
:polymorphic
=>
true
...
...
app/models/merge_request.rb
View file @
5a3f23f3
require
File
.
join
(
Rails
.
root
,
"app/models/commit"
)
class
MergeRequest
<
ActiveRecord
::
Base
belongs_to
:project
belongs_to
:author
,
:class_name
=>
"User"
belongs_to
:assignee
,
:class_name
=>
"User"
has_many
:notes
,
:as
=>
:noteable
,
:dependent
=>
:destroy
serialize
:st_commits
serialize
:st_diffs
attr_protected
:author
,
:author_id
,
:project
,
:project_id
attr_accessor
:author_id_of_changes
...
...
@@ -32,7 +37,6 @@ class MergeRequest < ActiveRecord::Base
scope
:closed
,
where
(
:closed
=>
true
)
scope
:assigned
,
lambda
{
|
u
|
where
(
:assignee_id
=>
u
.
id
)}
def
validate_branches
if
target_branch
==
source_branch
errors
.
add
:base
,
"You can not use same branch for source and target branches"
...
...
@@ -44,18 +48,65 @@ class MergeRequest < ActiveRecord::Base
end
def
diffs
st_diffs
||
[]
end
def
reloaded_diffs
if
open
?
&&
unmerged_diffs
.
any?
self
.
st_diffs
=
unmerged_diffs
save
end
diffs
end
def
unmerged_diffs
commits
=
project
.
repo
.
commits_between
(
target_branch
,
source_branch
).
map
{
|
c
|
Commit
.
new
(
c
)}
diffs
=
project
.
repo
.
diff
(
commits
.
first
.
prev_commit
.
id
,
commits
.
last
.
id
)
rescue
[]
end
def
last_commit
project
.
commit
(
source_branch
)
commits
.
first
end
# Return the number of +1 comments (upvotes)
def
upvotes
notes
.
select
(
&
:
upvote?
).
size
end
def
commits
st_commits
||
[]
end
def
probably_merged?
unmerged_commits
.
empty?
&&
commits
.
any?
&&
open
?
end
def
open?
!
closed
end
def
mark_as_merged!
self
.
merged
=
true
self
.
closed
=
true
save
end
def
reloaded_commits
if
open
?
&&
unmerged_commits
.
any?
self
.
st_commits
=
unmerged_commits
save
end
commits
end
def
unmerged_commits
self
.
project
.
repo
.
commits_between
(
self
.
target_branch
,
self
.
source_branch
).
map
{
|
c
|
Commit
.
new
(
c
)}.
sort_by
(
&
:
created_at
).
reverse
end
end
# == Schema Information
#
...
...
app/models/project.rb
View file @
5a3f23f3
...
...
@@ -73,6 +73,40 @@ class Project < ActiveRecord::Base
)
end
def
update_merge_requests
(
oldrev
,
newrev
,
ref
,
author_key_id
)
return
true
unless
ref
=~
/heads/
branch_name
=
ref
.
gsub
(
"refs/heads/"
,
""
)
key
=
Key
.
find_by_identifier
(
author_key_id
)
user
=
key
.
user
c_ids
=
self
.
commits_between
(
oldrev
,
newrev
).
map
(
&
:id
)
# update commits & diffs for existing MR
mrs
=
self
.
merge_requests
.
opened
.
where
(
:source_branch
=>
branch_name
).
all
mrs
.
each
do
|
merge_request
|
merge_request
.
reloaded_commits
merge_request
.
reloaded_diffs
end
# Close merge requests
mrs
=
self
.
merge_requests
.
opened
.
where
(
:target_branch
=>
branch_name
).
all
mrs
.
each
do
|
merge_request
|
next
unless
merge_request
.
last_commit
# Mark as merged & create event if merged
if
c_ids
.
include?
(
merge_request
.
last_commit
.
id
)
merge_request
.
mark_as_merged!
Event
.
create
(
:project
=>
self
,
:action
=>
Event
::
Merged
,
:data
=>
{
:merge_request_id
=>
merge_request
.
id
},
:author_id
=>
user
.
id
)
end
end
true
end
def
execute_web_hooks
(
oldrev
,
newrev
,
ref
,
author_key_id
)
ref_parts
=
ref
.
split
(
'/'
)
...
...
app/views/merge_requests/_commits.html.haml
View file @
5a3f23f3
...
...
@@ -2,7 +2,9 @@
.ui-box
%h5
Commits
.merge-request-commits
%ul
.unstyled
=
render
@commits
%ul
.unstyled
-
@commits
.
each
do
|
commit
|
=
render
"commits/commit"
,
:commit
=>
commit
-
else
%h5
...
...
app/views/merge_requests/show.html.haml
View file @
5a3f23f3
...
...
@@ -11,9 +11,7 @@
%span
.right
-
if
can?
(
current_user
,
:modify_merge_request
,
@merge_request
)
-
if
@merge_request
.
closed
=
link_to
'Reopen'
,
project_merge_request_path
(
@project
,
@merge_request
,
:merge_request
=>
{
:closed
=>
false
},
:status_only
=>
true
),
:method
=>
:put
,
:class
=>
"btn"
-
else
-
if
@merge_request
.
open?
=
link_to
'Close'
,
project_merge_request_path
(
@project
,
@merge_request
,
:merge_request
=>
{
:closed
=>
true
},
:status_only
=>
true
),
:method
=>
:put
,
:class
=>
"btn"
,
:title
=>
"Close merge request"
=
link_to
edit_project_merge_request_path
(
@project
,
@merge_request
),
:class
=>
"btn"
do
Edit
...
...
app/workers/post_receive.rb
View file @
5a3f23f3
...
...
@@ -8,7 +8,13 @@ class PostReceive
# Ignore push from non-gitlab users
return
false
unless
Key
.
find_by_identifier
(
author_key_id
)
# Create push event
project
.
observe_push
(
oldrev
,
newrev
,
ref
,
author_key_id
)
# Close merged MR
project
.
update_merge_requests
(
oldrev
,
newrev
,
ref
,
author_key_id
)
# Execute web hooks
project
.
execute_web_hooks
(
oldrev
,
newrev
,
ref
,
author_key_id
)
end
end
db/migrate/20120315111711_add_commits_diff_store_to_merge_request.rb
0 → 100644
View file @
5a3f23f3
class
AddCommitsDiffStoreToMergeRequest
<
ActiveRecord
::
Migration
def
change
add_column
:merge_requests
,
:st_commits
,
:text
,
:null
=>
true
add_column
:merge_requests
,
:st_diffs
,
:text
,
:null
=>
true
end
end
db/migrate/20120315132931_add_merged_to_merge_request.rb
0 → 100644
View file @
5a3f23f3
class
AddMergedToMergeRequest
<
ActiveRecord
::
Migration
def
change
add_column
:merge_requests
,
:merged
,
:true
,
:null
=>
false
,
:default
=>
false
end
end
db/schema.rb
View file @
5a3f23f3
...
...
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
:version
=>
201203
07095918
)
do
ActiveRecord
::
Schema
.
define
(
:version
=>
201203
15132931
)
do
create_table
"events"
,
:force
=>
true
do
|
t
|
t
.
string
"target_type"
...
...
@@ -50,19 +50,8 @@ ActiveRecord::Schema.define(:version => 20120307095918) do
t
.
integer
"project_id"
end
create_table
"merge_requests"
,
:force
=>
true
do
|
t
|
t
.
string
"target_branch"
,
:null
=>
false
t
.
string
"source_branch"
,
:null
=>
false
t
.
integer
"project_id"
,
:null
=>
false
t
.
integer
"author_id"
t
.
integer
"assignee_id"
t
.
string
"title"
t
.
boolean
"closed"
,
:default
=>
false
,
:null
=>
false
t
.
datetime
"created_at"
,
:null
=>
false
t
.
datetime
"updated_at"
,
:null
=>
false
end
add_index
"merge_requests"
,
[
"project_id"
],
:name
=>
"index_merge_requests_on_project_id"
# Could not dump table "merge_requests" because of following StandardError
# Unknown type 'true' for column 'merged'
create_table
"notes"
,
:force
=>
true
do
|
t
|
t
.
text
"note"
...
...
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