2018-10-22 03:00:50 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-28 12:52:09 -04:00
|
|
|
module Gitlab
|
|
|
|
module GlRepository
|
2017-05-03 17:07:54 -04:00
|
|
|
def self.gl_repository(project, is_wiki)
|
|
|
|
"#{is_wiki ? 'wiki' : 'project'}-#{project.id}"
|
|
|
|
end
|
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-04-28 12:52:09 -04:00
|
|
|
def self.parse(gl_repository)
|
|
|
|
match_data = /\A(project|wiki)-([1-9][0-9]*)\z/.match(gl_repository)
|
|
|
|
unless match_data
|
|
|
|
raise ArgumentError, "Invalid GL Repository \"#{gl_repository}\""
|
|
|
|
end
|
|
|
|
|
|
|
|
type, id = match_data.captures
|
|
|
|
project = Project.find_by(id: id)
|
|
|
|
wiki = type == 'wiki'
|
|
|
|
|
|
|
|
[project, wiki]
|
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-04-28 12:52:09 -04:00
|
|
|
end
|
|
|
|
end
|