2018-12-13 13:39:08 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
module Gitlab
|
|
|
|
module GlRepository
|
2019-05-30 16:15:17 +05:30
|
|
|
def self.gl_repository(project, is_wiki)
|
|
|
|
"#{is_wiki ? 'wiki' : 'project'}-#{project.id}"
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2019-05-30 16:15:17 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-08-17 22:00:37 +05:30
|
|
|
def self.parse(gl_repository)
|
2019-05-30 16:15:17 +05:30
|
|
|
match_data = /\A(project|wiki)-([1-9][0-9]*)\z/.match(gl_repository)
|
|
|
|
unless match_data
|
2017-08-17 22:00:37 +05:30
|
|
|
raise ArgumentError, "Invalid GL Repository \"#{gl_repository}\""
|
|
|
|
end
|
|
|
|
|
2019-05-30 16:15:17 +05:30
|
|
|
type, id = match_data.captures
|
|
|
|
project = Project.find_by(id: id)
|
|
|
|
wiki = type == 'wiki'
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-05-30 16:15:17 +05:30
|
|
|
[project, wiki]
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2019-05-30 16:15:17 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|