Class: Checklister::Gitlab::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/checklister/gitlab/project.rb

Constant Summary collapse

DEFAULT_OPTIONS =

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

{ order_by: "id", sort: "asc", per_page: "100" }
MAX_PAGES =
5

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Project

Initialize a gitlab project instance

Examples:

Get a project's data

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

Parameters:

  • client (Object)

    an instance of Checklister::Client



37
38
39
# File 'lib/checklister/gitlab/project.rb', line 37

def initialize(client)
  @client = client
end

Instance Method Details

#all(options = {}) ⇒ Array

Get all gitlab's projects

Parameters:

  • options (optional, Hash) (defaults to: {})

    query options

Returns:

  • (Array)

    and array of project's properties as Hash



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# 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) ⇒ Array

Get gitlab's projects based on a search string (LIKE on project#name)

Parameters:

  • name (String)

    partial project's name

Returns:

  • (Array)

    and array of project's properties as Hash



71
72
73
# 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) ⇒ Hash

Query a particular project based on it's id

Parameters:

  • project_id (Integer)

    gitlab project id

Returns:

  • (Hash)

    a project properties



44
45
46
# File 'lib/checklister/gitlab/project.rb', line 44

def get(project_id)
  ProjectDecorator.new(@client.project(project_id)).to_hash
end