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
3d50b99d
Commit
3d50b99d
authored
Oct 19, 2015
by
Dirceu Pereira Tiegs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add option to create merge request when editing/creating a file
parent
6df06ded
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
80 additions
and
30 deletions
+80
-30
app/assets/javascripts/blob/edit_blob.js.coffee
app/assets/javascripts/blob/edit_blob.js.coffee
+7
-0
app/assets/javascripts/blob/new_blob.js.coffee
app/assets/javascripts/blob/new_blob.js.coffee
+7
-0
app/assets/stylesheets/pages/editor.scss
app/assets/stylesheets/pages/editor.scss
+4
-0
app/controllers/application_controller.rb
app/controllers/application_controller.rb
+30
-0
app/controllers/projects/blob_controller.rb
app/controllers/projects/blob_controller.rb
+16
-2
app/helpers/merge_requests_helper.rb
app/helpers/merge_requests_helper.rb
+0
-28
app/views/projects/blob/edit.html.haml
app/views/projects/blob/edit.html.haml
+8
-0
app/views/projects/blob/new.html.haml
app/views/projects/blob/new.html.haml
+8
-0
No files found.
app/assets/javascripts/blob/edit_blob.js.coffee
View file @
3d50b99d
...
...
@@ -11,6 +11,13 @@ class @EditBlob
if
ace_mode
editor
.
getSession
().
setMode
"ace/mode/"
+
ace_mode
$
(
'#new_branch'
).
keyup
->
if
$
(
this
).
val
()
!=
$
(
'#original_branch'
).
val
()
$
(
'.form-group.destination'
).
show
()
else
$
(
'.form-group.destination'
).
hide
()
$
(
'#create_merge_request'
).
prop
(
'checked'
,
false
)
$
(
".js-commit-button"
).
click
->
$
(
"#file-content"
).
val
editor
.
getValue
()
$
(
".file-editor form"
).
submit
()
...
...
app/assets/javascripts/blob/new_blob.js.coffee
View file @
3d50b99d
...
...
@@ -11,6 +11,13 @@ class @NewBlob
if
ace_mode
editor
.
getSession
().
setMode
"ace/mode/"
+
ace_mode
$
(
'#new_branch'
).
keyup
->
if
$
(
this
).
val
()
!=
$
(
'#original_branch'
).
val
()
$
(
'.form-group.destination'
).
show
()
else
$
(
'.form-group.destination'
).
hide
()
$
(
'#create_merge_request'
).
prop
(
'checked'
,
false
)
$
(
".js-commit-button"
).
click
->
$
(
"#file-content"
).
val
editor
.
getValue
()
$
(
".file-editor form"
).
submit
()
...
...
app/assets/stylesheets/pages/editor.scss
View file @
3d50b99d
...
...
@@ -63,4 +63,8 @@
margin-top
:
0
;
padding
:
$gl-padding
}
.destination
{
display
:
none
;
}
}
app/controllers/application_controller.rb
View file @
3d50b99d
...
...
@@ -22,6 +22,7 @@ class ApplicationController < ActionController::Base
helper_method
:abilities
,
:can?
,
:current_application_settings
helper_method
:import_sources_enabled?
,
:github_import_enabled?
,
:github_import_configured?
,
:gitlab_import_enabled?
,
:gitlab_import_configured?
,
:bitbucket_import_enabled?
,
:bitbucket_import_configured?
,
:gitorious_import_enabled?
,
:google_code_import_enabled?
,
:fogbugz_import_enabled?
,
:git_import_enabled?
helper_method
:new_mr_from_push_event
,
:new_mr_path_for_fork_from_push_event
,
:new_mr_path_from_push_event
rescue_from
Encoding
::
CompatibilityError
do
|
exception
|
log_exception
(
exception
)
...
...
@@ -343,4 +344,33 @@ class ApplicationController < ActionController::Base
def
git_import_enabled?
current_application_settings
.
import_sources
.
include?
(
'git'
)
end
# new merge requests routing helpers
def
new_mr_path_from_push_event
(
event
,
target_branch
=
nil
)
target_project
=
event
.
project
.
forked_from_project
||
event
.
project
new_namespace_project_merge_request_path
(
event
.
project
.
namespace
,
event
.
project
,
new_mr_from_push_event
(
event
,
target_project
,
target_branch
)
)
end
def
new_mr_path_for_fork_from_push_event
(
event
,
target_branch
=
nil
)
new_namespace_project_merge_request_path
(
event
.
project
.
namespace
,
event
.
project
,
new_mr_from_push_event
(
event
,
event
.
project
.
forked_from_project
,
target_branch
)
)
end
def
new_mr_from_push_event
(
event
,
target_project
,
target_branch
)
{
merge_request:
{
source_project_id:
event
.
project
.
id
,
target_project_id:
target_project
.
id
,
source_branch:
event
.
branch_name
,
target_branch:
target_branch
||
target_project
.
repository
.
root_ref
}
}
end
end
app/controllers/projects/blob_controller.rb
View file @
3d50b99d
...
...
@@ -27,7 +27,14 @@ class Projects::BlobController < Projects::ApplicationController
if
result
[
:status
]
==
:success
flash
[
:notice
]
=
"The changes have been successfully committed"
respond_to
do
|
format
|
format
.
html
{
redirect_to
namespace_project_blob_path
(
@project
.
namespace
,
@project
,
File
.
join
(
@target_branch
,
@file_path
))
}
format
.
html
do
url
=
if
params
[
:create_merge_request
]
new_mr_path_from_push_event
(
current_user
.
recent_push
(
@project
.
id
),
@ref
)
else
namespace_project_blob_path
(
@project
.
namespace
,
@project
,
File
.
join
(
@target_branch
,
@file_path
))
end
redirect_to
url
end
format
.
json
{
render
json:
{
message:
"success"
,
filePath:
namespace_project_blob_path
(
@project
.
namespace
,
@project
,
File
.
join
(
@target_branch
,
@file_path
))
}
}
end
else
...
...
@@ -52,7 +59,14 @@ class Projects::BlobController < Projects::ApplicationController
if
result
[
:status
]
==
:success
flash
[
:notice
]
=
"Your changes have been successfully committed"
respond_to
do
|
format
|
format
.
html
{
redirect_to
after_edit_path
}
format
.
html
do
url
=
if
params
[
:create_merge_request
]
new_mr_path_from_push_event
(
current_user
.
recent_push
(
@project
.
id
),
@ref
)
else
after_edit_path
end
redirect_to
url
end
format
.
json
{
render
json:
{
message:
"success"
,
filePath:
after_edit_path
}
}
end
else
...
...
app/helpers/merge_requests_helper.rb
View file @
3d50b99d
module
MergeRequestsHelper
def
new_mr_path_from_push_event
(
event
)
target_project
=
event
.
project
.
forked_from_project
||
event
.
project
new_namespace_project_merge_request_path
(
event
.
project
.
namespace
,
event
.
project
,
new_mr_from_push_event
(
event
,
target_project
)
)
end
def
new_mr_path_for_fork_from_push_event
(
event
)
new_namespace_project_merge_request_path
(
event
.
project
.
namespace
,
event
.
project
,
new_mr_from_push_event
(
event
,
event
.
project
.
forked_from_project
)
)
end
def
new_mr_from_push_event
(
event
,
target_project
)
{
merge_request:
{
source_project_id:
event
.
project
.
id
,
target_project_id:
target_project
.
id
,
source_branch:
event
.
branch_name
,
target_branch:
target_project
.
repository
.
root_ref
}
}
end
def
mr_css_classes
(
mr
)
classes
=
"merge-request"
classes
<<
" closed"
if
mr
.
closed?
...
...
app/views/projects/blob/edit.html.haml
View file @
3d50b99d
...
...
@@ -23,9 +23,17 @@
.col-sm-10
=
text_field_tag
'new_branch'
,
@ref
,
class:
"form-control"
.form-group.destination
.col-sm-offset-2.col-sm-10
.checkbox
=
label_tag
:create_merge_request
do
=
check_box_tag
:create_merge_request
,
1
,
false
Start a new merge request
=
hidden_field_tag
'last_commit'
,
@last_commit
=
hidden_field_tag
'content'
,
''
,
id:
"file-content"
=
hidden_field_tag
'from_merge_request_id'
,
params
[
:from_merge_request_id
]
=
hidden_field_tag
'original_branch'
,
@ref
=
render
'projects/commit_button'
,
ref:
@ref
,
cancel_path:
@after_edit_path
:javascript
...
...
app/views/projects/blob/new.html.haml
View file @
3d50b99d
...
...
@@ -17,7 +17,15 @@
.col-sm-10
=
text_field_tag
'new_branch'
,
@ref
,
class:
"form-control js-quick-submit"
.form-group.destination
.col-sm-offset-2.col-sm-10
.checkbox
=
label_tag
:create_merge_request
do
=
check_box_tag
:create_merge_request
,
1
,
false
Start a new merge request
=
hidden_field_tag
'content'
,
''
,
id:
'file-content'
=
hidden_field_tag
'original_branch'
,
@ref
=
render
'projects/commit_button'
,
ref:
@ref
,
cancel_path:
namespace_project_tree_path
(
@project
.
namespace
,
@project
,
@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