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
44ffde08
Commit
44ffde08
authored
Dec 01, 2020
by
Francisco Javier López
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add exception logging in SnippetsCheck
parent
f3bde212
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
6 deletions
+22
-6
lib/gitlab/checks/snippet_check.rb
lib/gitlab/checks/snippet_check.rb
+4
-0
spec/lib/gitlab/checks/snippet_check_spec.rb
spec/lib/gitlab/checks/snippet_check_spec.rb
+18
-6
No files found.
lib/gitlab/checks/snippet_check.rb
View file @
44ffde08
...
...
@@ -26,6 +26,10 @@ module Gitlab
end
true
rescue
GitAccess
::
ForbiddenError
=>
e
Gitlab
::
ErrorTracking
.
log_exception
(
e
,
default_branch:
@default_branch
,
branch_name:
@branch_name
,
creation:
creation?
,
deletion:
deletion?
)
raise
e
end
private
...
...
spec/lib/gitlab/checks/snippet_check_spec.rb
View file @
44ffde08
...
...
@@ -9,6 +9,9 @@ RSpec.describe Gitlab::Checks::SnippetCheck do
let
(
:user_access
)
{
Gitlab
::
UserAccessSnippet
.
new
(
user
,
snippet:
snippet
)
}
let
(
:default_branch
)
{
snippet
.
default_branch
}
let
(
:branch_name
)
{
default_branch
}
let
(
:creation
)
{
false
}
let
(
:deletion
)
{
false
}
subject
{
Gitlab
::
Checks
::
SnippetCheck
.
new
(
changes
,
default_branch:
default_branch
,
logger:
logger
)
}
...
...
@@ -17,11 +20,19 @@ RSpec.describe Gitlab::Checks::SnippetCheck do
expect
{
subject
.
validate!
}.
not_to
raise_error
end
shared_examples
'raises and logs error'
do
specify
do
expect
(
Gitlab
::
ErrorTracking
).
to
receive
(
:log_exception
).
with
(
instance_of
(
Gitlab
::
GitAccess
::
ForbiddenError
),
default_branch:
default_branch
,
branch_name:
branch_name
,
creation:
creation
,
deletion:
deletion
)
expect
{
subject
.
validate!
}.
to
raise_error
(
Gitlab
::
GitAccess
::
ForbiddenError
,
'You can not create or delete branches.'
)
end
end
context
'trying to delete the branch'
do
let
(
:newrev
)
{
'0000000000000000000000000000000000000000'
}
it
'raises an
error'
do
expect
{
subject
.
validate!
}.
to
raise_error
(
Gitlab
::
GitAccess
::
ForbiddenError
,
'You can not create or delete branches.'
)
it
_behaves_like
'raises and logs
error'
do
let
(
:deletion
)
{
true
}
end
end
...
...
@@ -29,8 +40,9 @@ RSpec.describe Gitlab::Checks::SnippetCheck do
let
(
:oldrev
)
{
'0000000000000000000000000000000000000000'
}
let
(
:ref
)
{
'refs/heads/feature'
}
it
'raises an error'
do
expect
{
subject
.
validate!
}.
to
raise_error
(
Gitlab
::
GitAccess
::
ForbiddenError
,
'You can not create or delete branches.'
)
it_behaves_like
'raises and logs error'
do
let
(
:creation
)
{
true
}
let
(
:branch_name
)
{
'feature'
}
end
context
"when branch is 'master'"
do
...
...
@@ -45,8 +57,8 @@ RSpec.describe Gitlab::Checks::SnippetCheck do
context
'when default_branch is nil'
do
let
(
:default_branch
)
{
nil
}
it
'raises an
error'
do
expect
{
subject
.
validate!
}.
to
raise_error
(
Gitlab
::
GitAccess
::
ForbiddenError
,
'You can not create or delete branches.'
)
it
_behaves_like
'raises and logs
error'
do
let
(
:branch_name
)
{
'master'
}
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