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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
90748cf7
Commit
90748cf7
authored
Mar 30, 2012
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge Button v1 complete
parent
464cd59d
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
31 additions
and
25 deletions
+31
-25
app/controllers/merge_requests_controller.rb
app/controllers/merge_requests_controller.rb
+1
-0
app/models/ability.rb
app/models/ability.rb
+1
-0
app/models/merge_request.rb
app/models/merge_request.rb
+2
-2
app/views/merge_requests/show.html.haml
app/views/merge_requests/show.html.haml
+2
-1
db/schema.rb
db/schema.rb
+19
-19
lib/gitlab_merge.rb
lib/gitlab_merge.rb
+6
-3
No files found.
app/controllers/merge_requests_controller.rb
View file @
90748cf7
...
@@ -102,6 +102,7 @@ class MergeRequestsController < ApplicationController
...
@@ -102,6 +102,7 @@ class MergeRequestsController < ApplicationController
def
automerge
def
automerge
render_404
unless
@merge_request
.
open?
&&
@merge_request
.
can_be_merged?
render_404
unless
@merge_request
.
open?
&&
@merge_request
.
can_be_merged?
return
access_denied!
unless
can?
(
current_user
,
:accept_mr
,
@project
)
@merge_request
.
automerge!
(
current_user
)
@merge_request
.
automerge!
(
current_user
)
end
end
...
...
app/models/ability.rb
View file @
90748cf7
...
@@ -46,6 +46,7 @@ class Ability
...
@@ -46,6 +46,7 @@ class Ability
:admin_team_member
,
:admin_team_member
,
:admin_merge_request
,
:admin_merge_request
,
:admin_note
,
:admin_note
,
:accept_mr
,
:admin_wiki
:admin_wiki
]
if
project
.
master_access_for?
(
user
)
||
project
.
owner
==
user
]
if
project
.
master_access_for?
(
user
)
||
project
.
owner
==
user
...
...
app/models/merge_request.rb
View file @
90748cf7
...
@@ -73,7 +73,7 @@ class MergeRequest < ActiveRecord::Base
...
@@ -73,7 +73,7 @@ class MergeRequest < ActiveRecord::Base
end
end
def
check_if_can_be_merged
def
check_if_can_be_merged
self
.
state
=
if
GitlabMerge
.
new
(
self
).
can_be_merged?
self
.
state
=
if
GitlabMerge
.
new
(
self
,
self
.
author
).
can_be_merged?
CAN_BE_MERGED
CAN_BE_MERGED
else
else
CANNOT_BE_MERGED
CANNOT_BE_MERGED
...
@@ -175,7 +175,7 @@ class MergeRequest < ActiveRecord::Base
...
@@ -175,7 +175,7 @@ class MergeRequest < ActiveRecord::Base
end
end
def
automerge!
(
current_user
)
def
automerge!
(
current_user
)
if
GitlabMerge
.
new
(
self
).
merge
if
GitlabMerge
.
new
(
self
,
current_user
).
merge
self
.
merge!
(
current_user
.
id
)
self
.
merge!
(
current_user
.
id
)
true
true
end
end
...
...
app/views/merge_requests/show.html.haml
View file @
90748cf7
...
@@ -52,7 +52,8 @@
...
@@ -52,7 +52,8 @@
Closed by
#{
@merge_request
.
closed_event
.
author_name
}
Closed by
#{
@merge_request
.
closed_event
.
author_name
}
%small
#{
time_ago_in_words
(
@merge_request
.
closed_event
.
created_at
)
}
ago.
%small
#{
time_ago_in_words
(
@merge_request
.
closed_event
.
created_at
)
}
ago.
-
if
@merge_request
.
open?
&&
@commits
.
any?
-
if
@merge_request
.
open?
&&
@commits
.
any?
&&
can?
(
current_user
,
:accept_mr
,
@project
)
-
if
@merge_request
.
can_be_merged?
-
if
@merge_request
.
can_be_merged?
.ui-box.padded
.ui-box.padded
%p
%p
...
...
db/schema.rb
View file @
90748cf7
...
@@ -30,8 +30,8 @@ ActiveRecord::Schema.define(:version => 20120329170745) do
...
@@ -30,8 +30,8 @@ ActiveRecord::Schema.define(:version => 20120329170745) do
t
.
integer
"assignee_id"
t
.
integer
"assignee_id"
t
.
integer
"author_id"
t
.
integer
"author_id"
t
.
integer
"project_id"
t
.
integer
"project_id"
t
.
datetime
"created_at"
t
.
datetime
"created_at"
,
:null
=>
false
t
.
datetime
"updated_at"
t
.
datetime
"updated_at"
,
:null
=>
false
t
.
boolean
"closed"
,
:default
=>
false
,
:null
=>
false
t
.
boolean
"closed"
,
:default
=>
false
,
:null
=>
false
t
.
integer
"position"
,
:default
=>
0
t
.
integer
"position"
,
:default
=>
0
t
.
boolean
"critical"
,
:default
=>
false
,
:null
=>
false
t
.
boolean
"critical"
,
:default
=>
false
,
:null
=>
false
...
@@ -43,8 +43,8 @@ ActiveRecord::Schema.define(:version => 20120329170745) do
...
@@ -43,8 +43,8 @@ ActiveRecord::Schema.define(:version => 20120329170745) do
create_table
"keys"
,
:force
=>
true
do
|
t
|
create_table
"keys"
,
:force
=>
true
do
|
t
|
t
.
integer
"user_id"
t
.
integer
"user_id"
t
.
datetime
"created_at"
t
.
datetime
"created_at"
,
:null
=>
false
t
.
datetime
"updated_at"
t
.
datetime
"updated_at"
,
:null
=>
false
t
.
text
"key"
t
.
text
"key"
t
.
string
"title"
t
.
string
"title"
t
.
string
"identifier"
t
.
string
"identifier"
...
@@ -59,12 +59,12 @@ ActiveRecord::Schema.define(:version => 20120329170745) do
...
@@ -59,12 +59,12 @@ ActiveRecord::Schema.define(:version => 20120329170745) do
t
.
integer
"assignee_id"
t
.
integer
"assignee_id"
t
.
string
"title"
t
.
string
"title"
t
.
boolean
"closed"
,
:default
=>
false
,
:null
=>
false
t
.
boolean
"closed"
,
:default
=>
false
,
:null
=>
false
t
.
datetime
"created_at"
t
.
datetime
"created_at"
,
:null
=>
false
t
.
datetime
"updated_at"
t
.
datetime
"updated_at"
,
:null
=>
false
t
.
text
"st_commits"
t
.
text
"st_commits"
t
.
text
"st_diffs"
t
.
text
"st_diffs"
t
.
boolean
"merged"
,
:default
=>
false
,
:null
=>
false
t
.
boolean
"merged"
,
:default
=>
false
,
:null
=>
false
t
.
integer
"state"
,
:default
=>
1
,
:null
=>
false
t
.
boolean
"auto_merge"
,
:default
=>
true
,
:null
=>
false
end
end
add_index
"merge_requests"
,
[
"project_id"
],
:name
=>
"index_merge_requests_on_project_id"
add_index
"merge_requests"
,
[
"project_id"
],
:name
=>
"index_merge_requests_on_project_id"
...
@@ -74,8 +74,8 @@ ActiveRecord::Schema.define(:version => 20120329170745) do
...
@@ -74,8 +74,8 @@ ActiveRecord::Schema.define(:version => 20120329170745) do
t
.
string
"noteable_id"
t
.
string
"noteable_id"
t
.
string
"noteable_type"
t
.
string
"noteable_type"
t
.
integer
"author_id"
t
.
integer
"author_id"
t
.
datetime
"created_at"
t
.
datetime
"created_at"
,
:null
=>
false
t
.
datetime
"updated_at"
t
.
datetime
"updated_at"
,
:null
=>
false
t
.
integer
"project_id"
t
.
integer
"project_id"
t
.
string
"attachment"
t
.
string
"attachment"
t
.
string
"line_code"
t
.
string
"line_code"
...
@@ -88,8 +88,8 @@ ActiveRecord::Schema.define(:version => 20120329170745) do
...
@@ -88,8 +88,8 @@ ActiveRecord::Schema.define(:version => 20120329170745) do
t
.
string
"name"
t
.
string
"name"
t
.
string
"path"
t
.
string
"path"
t
.
text
"description"
t
.
text
"description"
t
.
datetime
"created_at"
t
.
datetime
"created_at"
,
:null
=>
false
t
.
datetime
"updated_at"
t
.
datetime
"updated_at"
,
:null
=>
false
t
.
boolean
"private_flag"
,
:default
=>
true
,
:null
=>
false
t
.
boolean
"private_flag"
,
:default
=>
true
,
:null
=>
false
t
.
string
"code"
t
.
string
"code"
t
.
integer
"owner_id"
t
.
integer
"owner_id"
...
@@ -112,8 +112,8 @@ ActiveRecord::Schema.define(:version => 20120329170745) do
...
@@ -112,8 +112,8 @@ ActiveRecord::Schema.define(:version => 20120329170745) do
t
.
text
"content"
t
.
text
"content"
t
.
integer
"author_id"
,
:null
=>
false
t
.
integer
"author_id"
,
:null
=>
false
t
.
integer
"project_id"
,
:null
=>
false
t
.
integer
"project_id"
,
:null
=>
false
t
.
datetime
"created_at"
t
.
datetime
"created_at"
,
:null
=>
false
t
.
datetime
"updated_at"
t
.
datetime
"updated_at"
,
:null
=>
false
t
.
string
"file_name"
t
.
string
"file_name"
t
.
datetime
"expires_at"
t
.
datetime
"expires_at"
end
end
...
@@ -146,8 +146,8 @@ ActiveRecord::Schema.define(:version => 20120329170745) do
...
@@ -146,8 +146,8 @@ ActiveRecord::Schema.define(:version => 20120329170745) do
t
.
datetime
"last_sign_in_at"
t
.
datetime
"last_sign_in_at"
t
.
string
"current_sign_in_ip"
t
.
string
"current_sign_in_ip"
t
.
string
"last_sign_in_ip"
t
.
string
"last_sign_in_ip"
t
.
datetime
"created_at"
t
.
datetime
"created_at"
,
:null
=>
false
t
.
datetime
"updated_at"
t
.
datetime
"updated_at"
,
:null
=>
false
t
.
string
"name"
t
.
string
"name"
t
.
boolean
"admin"
,
:default
=>
false
,
:null
=>
false
t
.
boolean
"admin"
,
:default
=>
false
,
:null
=>
false
t
.
integer
"projects_limit"
,
:default
=>
10
t
.
integer
"projects_limit"
,
:default
=>
10
...
@@ -166,16 +166,16 @@ ActiveRecord::Schema.define(:version => 20120329170745) do
...
@@ -166,16 +166,16 @@ ActiveRecord::Schema.define(:version => 20120329170745) do
create_table
"users_projects"
,
:force
=>
true
do
|
t
|
create_table
"users_projects"
,
:force
=>
true
do
|
t
|
t
.
integer
"user_id"
,
:null
=>
false
t
.
integer
"user_id"
,
:null
=>
false
t
.
integer
"project_id"
,
:null
=>
false
t
.
integer
"project_id"
,
:null
=>
false
t
.
datetime
"created_at"
t
.
datetime
"created_at"
,
:null
=>
false
t
.
datetime
"updated_at"
t
.
datetime
"updated_at"
,
:null
=>
false
t
.
integer
"project_access"
,
:default
=>
0
,
:null
=>
false
t
.
integer
"project_access"
,
:default
=>
0
,
:null
=>
false
end
end
create_table
"web_hooks"
,
:force
=>
true
do
|
t
|
create_table
"web_hooks"
,
:force
=>
true
do
|
t
|
t
.
string
"url"
t
.
string
"url"
t
.
integer
"project_id"
t
.
integer
"project_id"
t
.
datetime
"created_at"
t
.
datetime
"created_at"
,
:null
=>
false
t
.
datetime
"updated_at"
t
.
datetime
"updated_at"
,
:null
=>
false
end
end
create_table
"wikis"
,
:force
=>
true
do
|
t
|
create_table
"wikis"
,
:force
=>
true
do
|
t
|
...
...
lib/gitlab_merge.rb
View file @
90748cf7
class
GitlabMerge
class
GitlabMerge
attr_accessor
:project
,
:merge_path
,
:merge_request
attr_accessor
:project
,
:merge_path
,
:merge_request
,
:user
def
initialize
(
merge_request
)
def
initialize
(
merge_request
,
user
)
self
.
user
=
user
self
.
merge_request
=
merge_request
self
.
merge_request
=
merge_request
self
.
project
=
merge_request
.
project
self
.
project
=
merge_request
.
project
self
.
merge_path
=
File
.
join
(
Rails
.
root
,
"tmp"
,
"merge_repo"
,
project
.
path
,
merge_request
.
id
.
to_s
)
self
.
merge_path
=
File
.
join
(
Rails
.
root
,
"tmp"
,
"merge_repo"
,
project
.
path
,
merge_request
.
id
.
to_s
)
...
@@ -30,7 +31,9 @@ class GitlabMerge
...
@@ -30,7 +31,9 @@ class GitlabMerge
self
.
project
.
repo
.
git
.
clone
({
:branch
=>
merge_request
.
target_branch
},
project
.
url_to_repo
,
merge_path
)
self
.
project
.
repo
.
git
.
clone
({
:branch
=>
merge_request
.
target_branch
},
project
.
url_to_repo
,
merge_path
)
Dir
.
chdir
(
merge_path
)
do
Dir
.
chdir
(
merge_path
)
do
merge_repo
=
Grit
::
Repo
.
new
(
'.'
)
merge_repo
=
Grit
::
Repo
.
new
(
'.'
)
output
=
merge_repo
.
git
.
pull
({},
"origin"
,
merge_request
.
source_branch
)
merge_repo
.
git
.
sh
"git config user.name
\"
#{
user
.
name
}
\"
"
merge_repo
.
git
.
sh
"git config user.email
\"
#{
user
.
email
}
\"
"
output
=
merge_repo
.
git
.
pull
({},
"--no-ff"
,
"origin"
,
merge_request
.
source_branch
)
yield
(
merge_repo
,
output
)
yield
(
merge_repo
,
output
)
end
end
end
end
...
...
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