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
5f04fc43
Commit
5f04fc43
authored
Sep 06, 2017
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Port changes from gitlab-org/gitlab-ce!13972 to EE
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
f915aca0
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
44 additions
and
23 deletions
+44
-23
.rubocop.yml
.rubocop.yml
+1
-1
app/helpers/projects_helper.rb
app/helpers/projects_helper.rb
+6
-2
app/services/ci/create_pipeline_service.rb
app/services/ci/create_pipeline_service.rb
+16
-15
changelogs/unreleased/31362_decrease_cyclomatic_complexity_threshold_step3.yml
.../31362_decrease_cyclomatic_complexity_threshold_step3.yml
+5
-0
spec/helpers/projects_helper_spec.rb
spec/helpers/projects_helper_spec.rb
+15
-4
spec/services/ci/create_pipeline_service_spec.rb
spec/services/ci/create_pipeline_service_spec.rb
+1
-1
No files found.
.rubocop.yml
View file @
5f04fc43
...
@@ -645,7 +645,7 @@ Metrics/ClassLength:
...
@@ -645,7 +645,7 @@ Metrics/ClassLength:
# of test cases needed to validate a method.
# of test cases needed to validate a method.
Metrics/CyclomaticComplexity
:
Metrics/CyclomaticComplexity
:
Enabled
:
true
Enabled
:
true
Max
:
1
5
Max
:
1
4
# Limit lines to 80 characters.
# Limit lines to 80 characters.
Metrics/LineLength
:
Metrics/LineLength
:
...
...
app/helpers/projects_helper.rb
View file @
5f04fc43
...
@@ -17,7 +17,11 @@ module ProjectsHelper
...
@@ -17,7 +17,11 @@ module ProjectsHelper
def
link_to_member_avatar
(
author
,
opts
=
{})
def
link_to_member_avatar
(
author
,
opts
=
{})
default_opts
=
{
avatar:
true
,
name:
true
,
size:
16
,
author_class:
'author'
,
title:
":name"
}
default_opts
=
{
avatar:
true
,
name:
true
,
size:
16
,
author_class:
'author'
,
title:
":name"
}
opts
=
default_opts
.
merge
(
opts
)
opts
=
default_opts
.
merge
(
opts
)
image_tag
(
avatar_icon
(
author
,
opts
[
:size
]),
width:
opts
[
:size
],
class:
"avatar avatar-inline
#{
"s
#{
opts
[
:size
]
}
"
if
opts
[
:size
]
}
"
,
alt:
''
)
if
opts
[
:avatar
]
classes
=
%w[avatar avatar-inline]
classes
<<
"s
#{
opts
[
:size
]
}
"
classes
<<
opts
[
:avatar_class
]
if
opts
[
:avatar_class
]
image_tag
(
avatar_icon
(
author
,
opts
[
:size
]),
width:
opts
[
:size
],
class:
classes
,
alt:
''
)
if
opts
[
:avatar
]
end
end
def
link_to_member
(
project
,
author
,
opts
=
{},
&
block
)
def
link_to_member
(
project
,
author
,
opts
=
{},
&
block
)
...
@@ -29,7 +33,7 @@ module ProjectsHelper
...
@@ -29,7 +33,7 @@ module ProjectsHelper
author_html
=
""
author_html
=
""
# Build avatar image tag
# Build avatar image tag
author_html
<<
image_tag
(
avatar_icon
(
author
,
opts
[
:size
]),
width:
opts
[
:size
],
class:
"avatar avatar-inline
#{
"s
#{
opts
[
:size
]
}
"
if
opts
[
:size
]
}
#{
opts
[
:avatar_class
]
if
opts
[
:avatar_class
]
}
"
,
alt:
''
)
if
opts
[
:avatar
]
author_html
<<
link_to_member_avatar
(
author
,
opts
)
if
opts
[
:avatar
]
# Build name span tag
# Build name span tag
if
opts
[
:by_username
]
if
opts
[
:by_username
]
...
...
app/services/ci/create_pipeline_service.rb
View file @
5f04fc43
...
@@ -16,10 +16,9 @@ module Ci
...
@@ -16,10 +16,9 @@ module Ci
protected:
project
.
protected_for?
(
ref
)
protected:
project
.
protected_for?
(
ref
)
)
)
result
=
validate
(
current_user
,
result
=
validate_project_and_git_items
(
mirror_update:
mirror_update
)
||
ignore_skip_ci:
ignore_skip_ci
,
validate_pipeline
(
ignore_skip_ci:
ignore_skip_ci
,
save_on_errors:
save_on_errors
,
save_on_errors:
save_on_errors
)
mirror_update:
mirror_update
)
return
result
if
result
return
result
if
result
...
@@ -48,17 +47,17 @@ module Ci
...
@@ -48,17 +47,17 @@ module Ci
private
private
def
validate
(
triggering_user
,
ignore_skip_ci
:,
save_on_errors
:,
mirror_update
:
)
def
validate
_project_and_git_items
(
mirror_update:
false
)
unless
project
.
builds_enabled?
unless
project
.
builds_enabled?
return
error
(
'Pipeline is disabled'
)
return
error
(
'Pipeline is disabled'
)
end
end
unless
project
.
mirror_trigger_builds?
if
mirror_update
&&
!
project
.
mirror_trigger_builds?
return
error
(
'Pipeline is disabled for mirror updates'
)
if
mirror_update
return
error
(
'Pipeline is disabled for mirror updates'
)
end
end
unless
allowed_to_trigger_pipeline?
(
triggering_user
)
unless
allowed_to_trigger_pipeline?
if
can?
(
triggering
_user
,
:create_pipeline
,
project
)
if
can?
(
current
_user
,
:create_pipeline
,
project
)
return
error
(
"Insufficient permissions for protected ref '
#{
ref
}
'"
)
return
error
(
"Insufficient permissions for protected ref '
#{
ref
}
'"
)
else
else
return
error
(
'Insufficient permissions to create a new pipeline'
)
return
error
(
'Insufficient permissions to create a new pipeline'
)
...
@@ -72,7 +71,9 @@ module Ci
...
@@ -72,7 +71,9 @@ module Ci
unless
commit
unless
commit
return
error
(
'Commit not found'
)
return
error
(
'Commit not found'
)
end
end
end
def
validate_pipeline
(
ignore_skip_ci
:,
save_on_errors
:)
unless
pipeline
.
config_processor
unless
pipeline
.
config_processor
unless
pipeline
.
ci_yaml_file
unless
pipeline
.
ci_yaml_file
return
error
(
"Missing
#{
pipeline
.
ci_yaml_file_path
}
file"
)
return
error
(
"Missing
#{
pipeline
.
ci_yaml_file_path
}
file"
)
...
@@ -90,18 +91,18 @@ module Ci
...
@@ -90,18 +91,18 @@ module Ci
end
end
end
end
def
allowed_to_trigger_pipeline?
(
triggering_user
)
def
allowed_to_trigger_pipeline?
if
triggering
_user
if
current
_user
allowed_to_create?
(
triggering_user
)
allowed_to_create?
else
# legacy triggers don't have a corresponding user
else
# legacy triggers don't have a corresponding user
!
project
.
protected_for?
(
ref
)
!
project
.
protected_for?
(
ref
)
end
end
end
end
def
allowed_to_create?
(
triggering_user
)
def
allowed_to_create?
access
=
Gitlab
::
UserAccess
.
new
(
triggering
_user
,
project:
project
)
access
=
Gitlab
::
UserAccess
.
new
(
current
_user
,
project:
project
)
can?
(
triggering
_user
,
:create_pipeline
,
project
)
&&
can?
(
current
_user
,
:create_pipeline
,
project
)
&&
if
branch?
if
branch?
access
.
can_update_branch?
(
ref
)
access
.
can_update_branch?
(
ref
)
elsif
tag?
elsif
tag?
...
...
changelogs/unreleased/31362_decrease_cyclomatic_complexity_threshold_step3.yml
0 → 100644
View file @
5f04fc43
---
title
:
Decrease Cyclomatic Complexity threshold to
14
merge_request
:
13972
author
:
Maxim Rydkin
type
:
other
spec/helpers/projects_helper_spec.rb
View file @
5f04fc43
...
@@ -191,10 +191,21 @@ describe ProjectsHelper do
...
@@ -191,10 +191,21 @@ describe ProjectsHelper do
end
end
end
end
describe
'link_to_member'
do
describe
'#link_to_member_avatar'
do
let
(
:group
)
{
create
(
:group
)
}
let
(
:user
)
{
build_stubbed
(
:user
)
}
let
(
:project
)
{
create
(
:project
,
group:
group
)
}
let
(
:user
)
{
create
(
:user
)
}
it
'returns image tag for member avatar'
do
allow
(
helper
).
to
receive
(
:image_tag
).
with
(
nil
,
{
width:
16
,
class:
[
"avatar"
,
"avatar-inline"
,
"s16"
],
alt:
""
})
allow
(
helper
).
to
receive
(
:avatar_icon
).
with
(
user
,
16
)
helper
.
link_to_member_avatar
(
user
)
end
end
describe
'#link_to_member'
do
let
(
:group
)
{
build_stubbed
(
:group
)
}
let
(
:project
)
{
build_stubbed
(
:project
,
group:
group
)
}
let
(
:user
)
{
build_stubbed
(
:user
)
}
describe
'using the default options'
do
describe
'using the default options'
do
it
'returns an HTML link to the user'
do
it
'returns an HTML link to the user'
do
...
...
spec/services/ci/create_pipeline_service_spec.rb
View file @
5f04fc43
...
@@ -489,7 +489,7 @@ describe Ci::CreatePipelineService do
...
@@ -489,7 +489,7 @@ describe Ci::CreatePipelineService do
subject
do
subject
do
described_class
.
new
(
project
,
user
,
ref:
ref
)
described_class
.
new
(
project
,
user
,
ref:
ref
)
.
send
(
:allowed_to_create?
,
user
)
.
send
(
:allowed_to_create?
)
end
end
context
'when user is a developer'
do
context
'when user is a developer'
do
...
...
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