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
Boxiang Sun
gitlab-ce
Commits
896e09d0
Commit
896e09d0
authored
Jun 20, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
started working on a migration for projects that have current import_url issues
parent
a5abec90
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
7 deletions
+59
-7
app/validators/addressable_url_validator.rb
app/validators/addressable_url_validator.rb
+7
-7
db/migrate/20160620110927_fix_no_validatable_import_url.rb
db/migrate/20160620110927_fix_no_validatable_import_url.rb
+52
-0
No files found.
app/validators/addressable_url_validator.rb
View file @
896e09d0
# AddressableUrlValidator
#
# Custom validator for URLs. This is a
# Custom validator for URLs. This is a
#
# By default, only URLs for http, https, ssh, and git protocols will be considered valid.
# Provide a `:protocols` option to configure accepted protocols.
...
...
@@ -22,12 +22,6 @@ class AddressableUrlValidator < ActiveModel::EachValidator
end
end
private
def
default_options
@default_options
||=
{
protocols:
%w(http https ssh git)
}
end
def
valid_url?
(
value
)
return
false
unless
value
...
...
@@ -38,6 +32,12 @@ class AddressableUrlValidator < ActiveModel::EachValidator
false
end
private
def
default_options
@default_options
||=
{
protocols:
%w(http https ssh git)
}
end
def
valid_uri?
(
value
)
Addressable
::
URI
.
parse
(
value
).
is_a?
(
Addressable
::
URI
)
end
...
...
db/migrate/20160620110927_fix_no_validatable_import_url.rb
0 → 100644
View file @
896e09d0
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class
FixNoValidatableImportUrl
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
class
SqlBatches
attr_reader
:results
,
:query
def
initialize
(
batch_size:
100
,
query
:)
@offset
=
0
@batch_size
=
batch_size
@query
=
query
@results
=
[]
end
def
next
@results
=
ActiveRecord
::
Base
.
connection
.
execute
(
batched_sql
)
@offset
+=
@batch_size
@results
.
any?
end
private
def
batched_sql
"
#{
@query
}
OFFSET
#{
@offset
}
LIMIT
#{
@batch_size
}
"
end
end
def
up
invalid_import_url_project_ids
.
each
{
|
project_id
|
cleanup_import_url
(
project_id
)
}
end
def
invalid_import_url_project_ids
ids
=
[]
batches
=
SqlBatches
.
new
(
query:
"SELECT id, import_url FROM projects WHERE import_url IS NOT NULL"
)
while
batches
.
nexts
ids
+=
batches
.
results
.
map
{
|
result
|
invalid_url?
(
result
[
:import_url
])
?
result
[
:id
]
:
nil
}
end
ids
.
compact
end
def
invalid_url?
(
url
)
AddressableUrlValidator
.
new
({
attributes:
1
}).
valid_url?
(
url
)
end
def
cleanup_import_url
(
project_id
)
execute
(
"UPDATE projects SET mirror = false, import_url = NULL WHERE id =
#{
project_id
}
"
)
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