summaryrefslogtreecommitdiff
path: root/lib/gitlab/gl_repository.rb
blob: b54e45de4fe269e5d640d24bd48d9f2aad3d89a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
module Gitlab
  module GlRepository
    def self.gl_repository(project, is_wiki)
      "#{is_wiki ? 'wiki' : 'project'}-#{project.id}"
    end

    # rubocop: disable CodeReuse/ActiveRecord
    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
    # rubocop: enable CodeReuse/ActiveRecord
  end
end