class Checklister::Gitlab::Project

Constants

DEFAULT_OPTIONS

Default options that we want to pass when querying the gitlab project index

MAX_PAGES

Public Class Methods

new(client) click to toggle source

Initialize a gitlab project instance

@example Get a project's data

project = Checklister::Project.new(gitlab_client).get(1)

@param client [Object] an instance of Checklister::Client

# File lib/checklister/gitlab/project.rb, line 37
def initialize(client)
  @client = client
end

Public Instance Methods

all(options = {}) click to toggle source

Get all gitlab's projects @param options [optional, Hash] query options @return [Array] and array of project's properties as Hash

# File lib/checklister/gitlab/project.rb, line 51
def all(options = {})
  query_options = DEFAULT_OPTIONS.merge options
  projects = []
  page = 1
  while page <= MAX_PAGES
    projects_per_page = @client.projects(query_options.merge(page: page))
    if projects_per_page == false || projects_per_page.empty?
      page = MAX_PAGES
      return projects
    else
      projects += projects_per_page.map { |p| ProjectDecorator.new(p).to_hash }
      page += 1
    end
  end
  projects
end
filtered_by_name(name) click to toggle source

Get gitlab's projects based on a search string (LIKE on project#name) @param name [String] partial project's name @return [Array] and array of project's properties as Hash

# File lib/checklister/gitlab/project.rb, line 71
def filtered_by_name(name)
  all.select { |p| p[:name].downcase.include? name.downcase }
end
get(project_id) click to toggle source

Query a particular project based on it's id @param project_id [Integer] gitlab project id @return [Hash] a project properties

# File lib/checklister/gitlab/project.rb, line 44
def get(project_id)
  ProjectDecorator.new(@client.project(project_id)).to_hash
end