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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kazuhiko Shiozaki
gitlab-ce
Commits
328b52d5
Commit
328b52d5
authored
Feb 09, 2016
by
Rubén Dávila
Committed by
Robert Speicher
Feb 19, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Some updates after last code review.
parent
38e708f0
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
67 additions
and
52 deletions
+67
-52
app/controllers/concerns/creates_commit.rb
app/controllers/concerns/creates_commit.rb
+27
-15
app/controllers/projects/application_controller.rb
app/controllers/projects/application_controller.rb
+8
-0
app/helpers/commits_helper.rb
app/helpers/commits_helper.rb
+22
-5
app/helpers/merge_requests_helper.rb
app/helpers/merge_requests_helper.rb
+1
-2
app/helpers/tree_helper.rb
app/helpers/tree_helper.rb
+1
-2
app/models/commit.rb
app/models/commit.rb
+3
-3
app/models/repository.rb
app/models/repository.rb
+3
-3
app/views/projects/commit/_commit_box.html.haml
app/views/projects/commit/_commit_box.html.haml
+1
-11
app/views/projects/merge_requests/show/_mr_title.html.haml
app/views/projects/merge_requests/show/_mr_title.html.haml
+1
-11
No files found.
app/controllers/concerns/creates_commit.rb
View file @
328b52d5
...
...
@@ -13,16 +13,10 @@ module CreatesCommit
result
=
service
.
new
(
@tree_edit_project
,
current_user
,
commit_params
).
execute
if
result
[
:status
]
==
:success
flash
[
:notice
]
=
success_notice
||
"Your changes have been successfully committed."
if
create_merge_request?
success_path
=
merge_request_exists?
?
existent_merge_request_path
:
new_merge_request_path
target
=
different_project?
?
"project"
:
"branch"
flash
[
:notice
]
<<
" You can now submit a merge request to get this change into the original
#{
target
}
."
end
update_flash_notice
(
success_notice
)
respond_to
do
|
format
|
format
.
html
{
redirect_to
success_path
}
format
.
html
{
redirect_to
final_success_path
(
success_path
)
}
format
.
json
{
render
json:
{
message:
"success"
,
filePath:
success_path
}
}
end
else
...
...
@@ -41,14 +35,32 @@ module CreatesCommit
end
def
authorize_edit_tree!
return
if
can?
(
current_user
,
:push_code
,
project
)
return
if
current_user
&&
current_user
.
already_forked?
(
project
)
return
if
can_collaborate_with_project?
access_denied!
end
private
def
update_flash_notice
(
success_notice
)
flash
[
:notice
]
=
success_notice
||
"Your changes have been successfully committed."
if
create_merge_request?
if
merge_request_exists?
flash
[
:notice
]
=
nil
else
target
=
different_project?
?
"project"
:
"branch"
flash
[
:notice
]
<<
" You can now submit a merge request to get this change into the original
#{
target
}
."
end
end
end
def
final_success_path
(
success_path
)
return
success_path
unless
create_merge_request?
merge_request_exists?
?
existing_merge_request_path
:
new_merge_request_path
end
def
new_merge_request_path
new_namespace_project_merge_request_path
(
@mr_source_project
.
namespace
,
...
...
@@ -62,15 +74,15 @@ module CreatesCommit
)
end
def
exist
ent
_merge_request_path
def
exist
ing
_merge_request_path
namespace_project_merge_request_path
(
@mr_target_project
.
namespace
,
@mr_target_project
,
@merge_request
)
end
def
merge_request_exists?
@merge_request
=
@mr_target_project
.
merge_requests
.
opened
.
where
(
source_branch:
@mr_source_branch
,
target_branch:
@mr_target_branch
).
first
return
@merge_request
if
defined?
(
@merge_request
)
@merge_request
=
@mr_target_project
.
merge_requests
.
opened
.
find_by
(
source_branch:
@mr_source_branch
,
target_branch:
@mr_target_branch
)
end
def
different_project?
...
...
app/controllers/projects/application_controller.rb
View file @
328b52d5
...
...
@@ -3,6 +3,7 @@ class Projects::ApplicationController < ApplicationController
before_action
:repository
layout
'project'
helper_method
:can_collaborate_with_project?
def
authenticate_user!
# Restrict access to Projects area only
# for non-signed users
...
...
@@ -36,4 +37,11 @@ class Projects::ApplicationController < ApplicationController
def
builds_enabled
return
render_404
unless
@project
.
builds_enabled?
end
def
can_collaborate_with_project?
(
project
=
nil
)
project
||=
@project
can?
(
current_user
,
:push_code
,
project
)
||
(
current_user
&&
current_user
.
already_forked?
(
project
))
end
end
app/helpers/commits_helper.rb
View file @
328b52d5
...
...
@@ -123,11 +123,28 @@ module CommitsHelper
)
end
def
can_collaborate_with_project?
(
project
=
nil
)
project
||=
@project
def
revert_commit_link
(
show_modal_condition
,
continue_to_path
)
if
show_modal_condition
link_to
(
'Revert'
,
'#modal-revert-commit'
,
'data-target'
=>
'#modal-revert-commit'
,
'data-toggle'
=>
'modal'
,
class:
'btn btn-grouped btn-close'
,
title:
'Create merge request to revert commit'
)
else
continue_params
=
{
to:
continue_to_path
,
notice:
edit_in_new_fork_notice
+
' Try to revert this commit again.'
,
notice_now:
edit_in_new_fork_notice_now
}
fork_path
=
namespace_project_forks_path
(
@project
.
namespace
,
@project
,
namespace_key:
current_user
.
namespace
.
id
,
continue:
continue_params
)
can?
(
current_user
,
:push_code
,
project
)
||
(
current_user
&&
current_user
.
already_forked?
(
project
))
link_to
'Revert'
,
fork_path
,
class:
'btn btn-grouped btn-close'
,
method: :post
,
title:
'Create merge request to revert commit'
end
end
protected
...
...
app/helpers/merge_requests_helper.rb
View file @
328b52d5
...
...
@@ -96,7 +96,6 @@ module MergeRequestsHelper
def
can_update_merge_request?
project
||=
@project
can?
(
current_user
,
:update_merge_request
,
project
)
||
(
current_user
&&
current_user
.
already_forked?
(
project
))
can_collaborate_with_project?
(
project
)
end
end
app/helpers/tree_helper.rb
View file @
328b52d5
...
...
@@ -56,8 +56,7 @@ module TreeHelper
return
false
unless
on_top_of_branch?
(
project
,
ref
)
can?
(
current_user
,
:push_code
,
project
)
||
(
current_user
&&
current_user
.
already_forked?
(
project
))
can_collaborate_with_project?
(
project
)
end
def
tree_edit_branch
(
project
=
@project
,
ref
=
@ref
)
...
...
app/models/commit.rb
View file @
328b52d5
...
...
@@ -220,17 +220,17 @@ class Commit
end
def
revert_message
"Revert
\"
#{
safe_message
.
lines
.
first
.
chomp
}
\"
"
.
truncate
(
80
)
+
"
\n\n
Reverts
#{
to_reference
}
"
"Revert
\"
#{
title
}
\"
"
.
truncate
(
80
)
+
"
\n\n
Reverts
#{
sha
}
"
end
def
is_a_
merge_commit?
def
merge_commit?
parents
.
size
>
1
end
def
merged_merge_request
return
@merged_merge_request
if
defined?
(
@merged_merge_request
)
@merged_merge_request
=
is_a_merge_commit?
&&
MergeRequest
.
where
(
merge_commit_sha:
id
).
first
@merged_merge_request
=
merge_commit?
&&
MergeRequest
.
find_by
(
merge_commit_sha:
id
)
end
private
...
...
app/models/repository.rb
View file @
328b52d5
...
...
@@ -626,7 +626,7 @@ class Repository
source_sha
=
find_branch
(
base_branch
).
target
target_branch
=
create_mr
?
commit
.
revert_branch_name
:
base_branch
args
=
[
commit
.
id
,
source_sha
]
args
<<
{
mainline:
1
}
if
commit
.
is_a_
merge_commit?
args
<<
{
mainline:
1
}
if
commit
.
merge_commit?
# Temporary branch exists and contains the revert commit
return
true
if
create_mr
&&
find_branch
(
target_branch
)
...
...
@@ -638,14 +638,14 @@ class Repository
commit_with_hooks
(
user
,
target_branch
)
do
|
ref
|
committer
=
user_to_committer
(
user
)
source_sha
=
Rugged
::
Commit
.
create
(
rugged
,
{
source_sha
=
Rugged
::
Commit
.
create
(
rugged
,
message:
commit
.
revert_message
,
author:
committer
,
committer:
committer
,
tree:
revert_index
.
write_tree
(
rugged
),
parents:
[
rugged
.
lookup
(
source_sha
)],
update_ref:
ref
}
)
)
end
end
...
...
app/views/projects/commit/_commit_box.html.haml
View file @
328b52d5
...
...
@@ -16,17 +16,7 @@
=
link_to
namespace_project_tree_path
(
@project
.
namespace
,
@project
,
@commit
),
class:
"btn btn-grouped"
do
=
icon
(
'files-o'
)
Browse Files
-
if
can_collaborate_with_project?
=
link_to
'#modal-revert-commit'
,
{
'data-target'
=>
'#modal-revert-commit'
,
'data-toggle'
=>
'modal'
,
class:
'btn btn-grouped btn-close'
}
do
Revert
-
else
-
continue_params
=
{
to:
namespace_project_commit_path
(
@project
.
namespace
,
@project
,
@commit
.
id
),
notice:
edit_in_new_fork_notice
,
notice_now:
edit_in_new_fork_notice_now
}
-
fork_path
=
namespace_project_forks_path
(
@project
.
namespace
,
@project
,
namespace_key:
current_user
.
namespace
.
id
,
continue:
continue_params
)
=
link_to
fork_path
,
{
class:
'btn btn-grouped'
,
method: :post
}
do
Revert
=
revert_commit_link
(
can_collaborate_with_project?
,
namespace_project_commit_path
(
@project
.
namespace
,
@project
,
@commit
.
id
))
%div
%p
...
...
app/views/projects/merge_requests/show/_mr_title.html.haml
View file @
328b52d5
...
...
@@ -20,14 +20,4 @@
=
link_to
'Reopen'
,
merge_request_path
(
@merge_request
,
merge_request:
{
state_event: :reopen
}),
method: :put
,
class:
'btn btn-nr btn-grouped btn-reopen reopen-mr-link'
,
title:
"Reopen merge request"
-
if
@merge_request
.
merged?
&&
@merge_request
.
merge_commit_sha
.
present?
-
if
can_update_merge_request?
=
link_to
'#modal-revert-commit'
,
{
'data-target'
=>
'#modal-revert-commit'
,
'data-toggle'
=>
'modal'
,
class:
'btn btn-grouped btn-close'
}
do
Revert
-
else
-
continue_params
=
{
to:
namespace_project_merge_request_path
(
@project
.
namespace
,
@project
,
@merge_request
),
notice:
edit_in_new_fork_notice
,
notice_now:
edit_in_new_fork_notice_now
}
-
fork_path
=
namespace_project_forks_path
(
@project
.
namespace
,
@project
,
namespace_key:
current_user
.
namespace
.
id
,
continue:
continue_params
)
=
link_to
fork_path
,
{
class:
'btn btn-grouped btn-close'
,
method: :post
}
do
Revert
=
revert_commit_link
(
can_update_merge_request?
,
namespace_project_merge_request_path
(
@project
.
namespace
,
@project
,
@merge_request
))
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