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
3f02e805
Commit
3f02e805
authored
Mar 01, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
c26c8622
5d9e00aa
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
70 additions
and
19 deletions
+70
-19
app/models/error_tracking/project_error_tracking_setting.rb
app/models/error_tracking/project_error_tracking_setting.rb
+34
-13
app/services/error_tracking/list_projects_service.rb
app/services/error_tracking/list_projects_service.rb
+2
-2
changelogs/unreleased/10097-number-utils.yml
changelogs/unreleased/10097-number-utils.yml
+5
-0
config/locales/en.yml
config/locales/en.yml
+4
-0
spec/models/error_tracking/project_error_tracking_setting_spec.rb
...els/error_tracking/project_error_tracking_setting_spec.rb
+23
-2
spec/services/error_tracking/list_projects_service_spec.rb
spec/services/error_tracking/list_projects_service_spec.rb
+2
-2
No files found.
app/models/error_tracking/project_error_tracking_setting.rb
View file @
3f02e805
...
...
@@ -2,19 +2,30 @@
module
ErrorTracking
class
ProjectErrorTrackingSetting
<
ActiveRecord
::
Base
include
Gitlab
::
Utils
::
StrongMemoize
include
ReactiveCaching
API_URL_PATH_REGEXP
=
%r{
\A
(?<prefix>/api/0/projects/+)
(?:
(?<organization>[^/]+)/+
(?<project>[^/]+)/*
)?
\z
}x
self
.
reactive_cache_key
=
->
(
setting
)
{
[
setting
.
class
.
model_name
.
singular
,
setting
.
project_id
]
}
belongs_to
:project
validates
:api_url
,
length:
{
maximum:
255
},
public_url:
true
,
url:
{
enforce_sanitization:
true
,
ascii_only:
true
},
allow_nil:
true
validates
:api_url
,
presence:
true
,
if: :enabled
validates
:api_url
,
presence:
{
message:
'is a required field'
}
,
if: :enabled
validate
:validate_api_url_path
,
if: :enabled
validates
:token
,
presence:
true
,
if: :enabled
validates
:token
,
presence:
{
message:
'is a required field'
}
,
if: :enabled
attr_encrypted
:token
,
mode: :per_attribute_iv
,
...
...
@@ -23,6 +34,11 @@ module ErrorTracking
after_save
:clear_reactive_cache!
def
api_url
=
(
value
)
super
clear_memoization
(
:api_url_slugs
)
end
def
project_name
super
||
project_name_from_slug
end
...
...
@@ -102,34 +118,39 @@ module ErrorTracking
end
def
project_slug_from_api_url
extract
_slug
(
:project
)
api_url
_slug
(
:project
)
end
def
organization_slug_from_api_url
extract_slug
(
:organization
)
api_url_slug
(
:organization
)
end
def
api_url_slug
(
capture
)
slugs
=
strong_memoize
(
:api_url_slugs
)
{
extract_api_url_slugs
||
{}
}
slugs
[
capture
]
end
def
extract_
slug
(
capture
)
def
extract_
api_url_slugs
return
if
api_url
.
blank?
begin
url
=
Addressable
::
URI
.
parse
(
api_url
)
rescue
Addressable
::
URI
::
InvalidURIError
return
nil
return
end
@slug_match
||=
url
.
path
.
match
(
%r{^/api/0/projects/+(?<organization>[^/]+)/+(?<project>[^/|$]+)}
)
||
{}
@slug_match
[
capture
]
url
.
path
.
match
(
API_URL_PATH_REGEXP
)
end
def
validate_api_url_path
return
if
api_url
.
blank?
begin
unless
Addressable
::
URI
.
parse
(
api_url
).
path
.
starts_with?
(
'/api/0/projects'
)
errors
.
add
(
:api_url
,
'path needs to start with /api/0/projects'
)
unless
api_url_slug
(
:prefix
)
return
errors
.
add
(
:api_url
,
'is invalid'
)
end
rescue
Addressable
::
URI
::
InvalidURIError
unless
api_url_slug
(
:organization
)
errors
.
add
(
:project
,
'is a required field'
)
end
end
end
...
...
app/services/error_tracking/list_projects_service.rb
View file @
3f02e805
...
...
@@ -28,8 +28,8 @@ module ErrorTracking
(
project
.
error_tracking_setting
||
project
.
build_error_tracking_setting
).
tap
do
|
setting
|
setting
.
api_url
=
ErrorTracking
::
ProjectErrorTrackingSetting
.
build_api_url_from
(
api_host:
params
[
:api_host
],
organization_slug:
nil
,
project_slug:
nil
organization_slug:
'org'
,
project_slug:
'proj'
)
setting
.
token
=
params
[
:token
]
...
...
changelogs/unreleased/10097-number-utils.yml
0 → 100644
View file @
3f02e805
---
title
:
Moves EE util into the CE file
merge_request
:
25680
author
:
type
:
other
config/locales/en.yml
View file @
3f02e805
...
...
@@ -10,6 +10,10 @@ en:
target
:
Target issue
group
:
path
:
Group URL
project/error_tracking_setting
:
token
:
"
Auth
Token"
project
:
"
Project"
api_url
:
"
Sentry
API
URL"
errors
:
messages
:
label_already_exists_at_group_level
:
"
already
exists
at
group
level
for
%{group}.
Please
choose
another
one."
...
...
spec/models/error_tracking/project_error_tracking_setting_spec.rb
View file @
3f02e805
...
...
@@ -62,11 +62,32 @@ describe ErrorTracking::ProjectErrorTrackingSetting do
end
context
'URL path'
do
it
'fails validation with
wrong path
'
do
it
'fails validation with
out api/0/projects
'
do
subject
.
api_url
=
'http://gitlab.com/project1/something'
expect
(
subject
).
not_to
be_valid
expect
(
subject
.
errors
.
messages
[
:api_url
]).
to
include
(
'path needs to start with /api/0/projects'
)
expect
(
subject
.
errors
.
messages
[
:api_url
]).
to
include
(
'is invalid'
)
end
it
'fails validation without org and project slugs'
do
subject
.
api_url
=
'http://gitlab.com/api/0/projects/'
expect
(
subject
).
not_to
be_valid
expect
(
subject
.
errors
.
messages
[
:project
]).
to
include
(
'is a required field'
)
end
it
'fails validation when api_url has extra parts'
do
subject
.
api_url
=
'http://gitlab.com/api/0/projects/org/proj/something'
expect
(
subject
).
not_to
be_valid
expect
(
subject
.
errors
.
messages
[
:api_url
]).
to
include
(
"is invalid"
)
end
it
'fails validation when api_url has less parts'
do
subject
.
api_url
=
'http://gitlab.com/api/0/projects/org'
expect
(
subject
).
not_to
be_valid
expect
(
subject
.
errors
.
messages
[
:api_url
]).
to
include
(
"is invalid"
)
end
it
'passes validation with correct path'
do
...
...
spec/services/error_tracking/list_projects_service_spec.rb
View file @
3f02e805
...
...
@@ -32,7 +32,7 @@ describe ErrorTracking::ListProjectsService do
end
context
'set model attributes to new values'
do
let
(
:new_api_url
)
{
new_api_host
+
'api/0/projects/'
}
let
(
:new_api_url
)
{
new_api_host
+
'api/0/projects/
org/proj/
'
}
before
do
expect
(
error_tracking_setting
).
to
receive
(
:list_sentry_projects
)
...
...
@@ -121,7 +121,7 @@ describe ErrorTracking::ListProjectsService do
context
'error_tracking_setting is nil'
do
let
(
:error_tracking_setting
)
{
build
(
:project_error_tracking_setting
)
}
let
(
:new_api_url
)
{
new_api_host
+
'api/0/projects/'
}
let
(
:new_api_url
)
{
new_api_host
+
'api/0/projects/
org/proj/
'
}
before
do
expect
(
project
).
to
receive
(
:build_error_tracking_setting
).
once
...
...
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