Class: Readiness::GitLab::Epics

Inherits:
Client
  • Object
show all
Defined in:
lib/support_readiness/gitlab/epics.rb

Overview

Author:

  • Jason Colyer

Since:

  • 1.0.105

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Client

auth_error, bad_request_error, convert_actions, convert_conditions, convert_standard_names_to_ids, convert_ticket_form_agent_conditions, convert_ticket_form_brands, convert_ticket_form_end_user_conditions, convert_ticket_form_names_to_ids, convert_view_names_to_ids, convert_view_restrictions, covert_ticket_form_field_ids, create_package!, erb_renderer, handle_request_error, not_found_error, not_processible_error, put_into_archive, recursively_deflate_directory, timestamp_filename, to_clean_json, to_clean_json_with_key, to_hash, to_nearly_clean_json, to_nearly_clean_json_with_key, to_param_string, write_entries

Constructor Details

#initialize(object = {}) ⇒ Epics

Creates a new Readiness::GitLab::Epics instance

Examples:

require 'support_readiness'
group = Readiness::GitLab::Epics.new

Parameters:

Author:

  • Jason Colyer

Since:

  • 1.0.105



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/support_readiness/gitlab/epics.rb', line 28

def initialize(object = {})
  @author = object['author']
  @closed_at = object['closed_at']
  @color = object['color']
  @created_at = object['created_at']
  @description = object['description']
  @downvotes = object['downvotes']
  @due_date = object['due_date']
  @due_date_fixed = object['due_date_fixed']
  @due_date_from_inherited_source = object['due_date_from_inherited_source']
  @due_date_from_milestones = object['due_date_from_milestones']
  @due_date_is_fixed = object['due_date_is_fixed']
  @end_date = object['end_date']
  @group_id = object['group_id']
  @id = object['id']
  @iid = object['iid']
  @imported = object['imported']
  @imported_from = object['imported_from']
  @labels = object['labels']
  @_links = object['_links']
  @parent_id = object['parent_id']
  @parent_iid = object['parent_iid']
  @reference = object['reference']
  @references = object['references']
  @start_date = object['start_date']
  @start_date_fixed = object['start_date_fixed']
  @start_date_from_inherited_source = object['start_date_from_inherited_source']
  @start_date_from_milestones = object['start_date_from_milestones']
  @state = object['state']
  @subscribed = object['subscribed']
  @title = object['title']
  @updated_at = object['updated_at']
  @upvotes = object['upvotes']
  @web_url = object['web_url']
end

Instance Attribute Details

Since:

  • 1.0.105



17
18
19
# File 'lib/support_readiness/gitlab/epics.rb', line 17

def _links
  @_links
end

#authorObject

Since:

  • 1.0.105



17
18
19
# File 'lib/support_readiness/gitlab/epics.rb', line 17

def author
  @author
end

#closed_atObject

Since:

  • 1.0.105



17
18
19
# File 'lib/support_readiness/gitlab/epics.rb', line 17

def closed_at
  @closed_at
end

#colorObject

Since:

  • 1.0.105



17
18
19
# File 'lib/support_readiness/gitlab/epics.rb', line 17

def color
  @color
end

#created_atObject

Since:

  • 1.0.105



17
18
19
# File 'lib/support_readiness/gitlab/epics.rb', line 17

def created_at
  @created_at
end

#descriptionObject

Since:

  • 1.0.105



17
18
19
# File 'lib/support_readiness/gitlab/epics.rb', line 17

def description
  @description
end

#downvotesObject

Since:

  • 1.0.105



17
18
19
# File 'lib/support_readiness/gitlab/epics.rb', line 17

def downvotes
  @downvotes
end

#due_dateObject

Since:

  • 1.0.105



17
18
19
# File 'lib/support_readiness/gitlab/epics.rb', line 17

def due_date
  @due_date
end

#due_date_fixedObject

Since:

  • 1.0.105



17
18
19
# File 'lib/support_readiness/gitlab/epics.rb', line 17

def due_date_fixed
  @due_date_fixed
end

#due_date_from_inherited_sourceObject

Since:

  • 1.0.105



17
18
19
# File 'lib/support_readiness/gitlab/epics.rb', line 17

def due_date_from_inherited_source
  @due_date_from_inherited_source
end

#due_date_from_milestonesObject

Since:

  • 1.0.105



17
18
19
# File 'lib/support_readiness/gitlab/epics.rb', line 17

def due_date_from_milestones
  @due_date_from_milestones
end

#due_date_is_fixedObject

Since:

  • 1.0.105



17
18
19
# File 'lib/support_readiness/gitlab/epics.rb', line 17

def due_date_is_fixed
  @due_date_is_fixed
end

#end_dateObject

Since:

  • 1.0.105



17
18
19
# File 'lib/support_readiness/gitlab/epics.rb', line 17

def end_date
  @end_date
end

#group_idObject

Since:

  • 1.0.105



17
18
19
# File 'lib/support_readiness/gitlab/epics.rb', line 17

def group_id
  @group_id
end

#idObject

Since:

  • 1.0.105



17
18
19
# File 'lib/support_readiness/gitlab/epics.rb', line 17

def id
  @id
end

#iidObject

Since:

  • 1.0.105



17
18
19
# File 'lib/support_readiness/gitlab/epics.rb', line 17

def iid
  @iid
end

#importedObject

Since:

  • 1.0.105



17
18
19
# File 'lib/support_readiness/gitlab/epics.rb', line 17

def imported
  @imported
end

#imported_fromObject

Since:

  • 1.0.105



17
18
19
# File 'lib/support_readiness/gitlab/epics.rb', line 17

def imported_from
  @imported_from
end

#labelsObject

Since:

  • 1.0.105



17
18
19
# File 'lib/support_readiness/gitlab/epics.rb', line 17

def labels
  @labels
end

#parent_idObject

Since:

  • 1.0.105



17
18
19
# File 'lib/support_readiness/gitlab/epics.rb', line 17

def parent_id
  @parent_id
end

#parent_iidObject

Since:

  • 1.0.105



17
18
19
# File 'lib/support_readiness/gitlab/epics.rb', line 17

def parent_iid
  @parent_iid
end

#referenceObject

Since:

  • 1.0.105



17
18
19
# File 'lib/support_readiness/gitlab/epics.rb', line 17

def reference
  @reference
end

#referencesObject

Since:

  • 1.0.105



17
18
19
# File 'lib/support_readiness/gitlab/epics.rb', line 17

def references
  @references
end

#start_dateObject

Since:

  • 1.0.105



17
18
19
# File 'lib/support_readiness/gitlab/epics.rb', line 17

def start_date
  @start_date
end

#start_date_fixedObject

Since:

  • 1.0.105



17
18
19
# File 'lib/support_readiness/gitlab/epics.rb', line 17

def start_date_fixed
  @start_date_fixed
end

#start_date_from_inherited_sourceObject

Since:

  • 1.0.105



17
18
19
# File 'lib/support_readiness/gitlab/epics.rb', line 17

def start_date_from_inherited_source
  @start_date_from_inherited_source
end

#start_date_from_milestonesObject

Since:

  • 1.0.105



17
18
19
# File 'lib/support_readiness/gitlab/epics.rb', line 17

def start_date_from_milestones
  @start_date_from_milestones
end

#stateObject

Since:

  • 1.0.105



17
18
19
# File 'lib/support_readiness/gitlab/epics.rb', line 17

def state
  @state
end

#subscribedObject

Since:

  • 1.0.105



17
18
19
# File 'lib/support_readiness/gitlab/epics.rb', line 17

def subscribed
  @subscribed
end

#titleObject

Since:

  • 1.0.105



17
18
19
# File 'lib/support_readiness/gitlab/epics.rb', line 17

def title
  @title
end

#updated_atObject

Since:

  • 1.0.105



17
18
19
# File 'lib/support_readiness/gitlab/epics.rb', line 17

def updated_at
  @updated_at
end

#upvotesObject

Since:

  • 1.0.105



17
18
19
# File 'lib/support_readiness/gitlab/epics.rb', line 17

def upvotes
  @upvotes
end

#web_urlObject

Since:

  • 1.0.105



17
18
19
# File 'lib/support_readiness/gitlab/epics.rb', line 17

def web_url
  @web_url
end

Class Method Details

.assign_issue!(client, epic, issue) ⇒ Hash

Assigns an issue to an epic. This will exit on error

Examples:

require 'support_readiness'
config = Readiness::GitLab::Configuration.new
config.token = 'test123abc'
client = Readiness::GitLab::Client.new(config)
group = Readiness::GitLab::Groups.new({ 'id' => 1 })
epic = Readiness::GitLab::Epics.find!(client, group, 5)
project = Readiness::GitLab::Projects.find!(client, 66)
issue = Readiness::GitLab::Issues.find!(client, project, 23)
assign = Readiness::GitLab::Epics.assign_issue!(client, epic, issue)
puts assign['epic']['iid']
# => 5

Parameters:

Returns:

  • (Hash)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.105



214
215
216
217
218
# File 'lib/support_readiness/gitlab/epics.rb', line 214

def self.assign_issue!(client, epic, issue)
  response = client.connection.post "groups/#{epic.group_id}/epics/#{epic.iid}/issues/#{issue.id}"
  handle_request_error(1, 'GitLab', response.status, { action: "Assign issue epic #{epic.iid}", id: issue.id }) unless response.status == 200
  Oj.load(response.body)
end

.find(client, group, iid) ⇒ Hash

Locates an epic within GitLab. This will not exit on error (except Authentication errors)

Examples:

require 'support_readiness'
config = Readiness::GitLab::Configuration.new
config.token = 'test123abc'
client = Readiness::GitLab::Client.new(config)
group = Readiness::GitLab::Groups.new({ 'id' => 123 })
epic = Readiness::GitLab::Epics.find(client, group, 5)
puts epic.web_url
# => "https://gitlab.com/gitlab-com/support/support-team-meta/-/issues/5"

Parameters:

  • client (Object)

    An instance of Client

  • group (Object)

    An instance of Groups

  • iid (Integer)

    The epic ID to find

Returns:

  • (Hash)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.105



119
120
121
122
123
124
125
126
127
128
# File 'lib/support_readiness/gitlab/epics.rb', line 119

def self.find(client, group, iid)
  response = client.connection.get "groups/#{group.id}/epics/#{iid}"
  # These endpoints throw a 403 instead of 404 when it does not exist
  return { "message" => "Epic not found" } if response.status == 403

  handle_request_error(0, 'GitLab', response.status,  { action: 'get', id: iid }) unless response.status == 200
  return Epics.new(Oj.load(response.body)) if response.status == 200

  Oj.load(response.body)
end

.find!(client, group, iid) ⇒ Object

Locates an epic within GitLab. This will exit on error

Examples:

require 'support_readiness'
config = Readiness::GitLab::Configuration.new
config.token = 'test123abc'
client = Readiness::GitLab::Client.new(config)
group = Readiness::GitLab::Groups.new({ 'id' => 123 })
epic = Readiness::GitLab::Epics.find!(client, group, 5)
puts epic.web_url
# => "https://gitlab.com/gitlab-com/support/support-team-meta/-/issues/5"

Parameters:

  • client (Object)

    An instance of Client

  • group (Object)

    An instance of Groups

  • iid (Integer)

    The epic ID to find

Returns:

  • (Object)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.105



149
150
151
152
153
154
155
# File 'lib/support_readiness/gitlab/epics.rb', line 149

def self.find!(client, group, iid)
  response = client.connection.get "groups/#{group.id}/epics/#{iid}"
  # These endpoints throw a 403 instead of 404 when it does not exist
  handle_request_error(1, 'GitLab', 404, { action: 'Find epic', id: iid })  if response.status == 403
  handle_request_error(1, 'GitLab', response.status, { action: 'Find epic', id: iid }) unless response.status == 200
  Epics.new(Oj.load(response.body))
end

.issues(client, epic) ⇒ Array

Lists issues within an epic. This method can take a long time to run depending on the parameters used.

Examples:

require 'support_readiness'
config = Readiness::GitLab::Configuration.new
config.token = 'test123abc'
client = Readiness::GitLab::Client.new(config)
group = Readiness::GitLab::Groups.new({ 'id' => 1 })
epic = Readiness::GitLab::Epics.find!(client, group, 5)
issues = Readiness::GitLab::Epics.issues(client, epic)
puts issues.count
# => 45

Parameters:

Returns:

  • (Array)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.105



177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/support_readiness/gitlab/epics.rb', line 177

def self.issues(client, epic)
  array = []
  page = 1
  loop do
    response = client.connection.get "groups/#{epic.group_id}/epics/#{epic.iid}/issues?per_page=100&page=#{page}"
    handle_request_error(0, 'GitLab', response.status) unless response.status == 200
    body = Oj.load(response.body)
    array += body.map { |e| Issues.new(e) }
    break if body.count < 100

    page += 1
  end
  array
end

.list(client, group, filters = []) ⇒ Array

Lists epics in a group. This method can take a long time to run depending on the parameters used.

Examples:

require 'support_readiness'
config = Readiness::GitLab::Configuration.new
config.token = 'test123abc'
client = Readiness::GitLab::Client.new(config)
group = Readiness::GitLab::Groups.new
group.id = 1
epics = Readiness::GitLab::Epics.list(client, group, ["state=opened", "include_descendant_groups=true"])
puts epics.first.web_url
# => "https://gitlab.com/gitlab-com/support/support-ops/-/epics/22"

Parameters:

  • client (Object)

    An instance of Client

  • group (Object)

    An instance of Groups

  • filters (Array) (defaults to: [])

    An array of filter Strings to use. Should be in the format of key=value

Returns:

  • (Array)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.105



85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/support_readiness/gitlab/epics.rb', line 85

def self.list(client, group, filters = [])
  array = []
  page = 1
  loop do
    response = client.connection.get "groups/#{group.id}/epics?per_page=100&page=#{page}&#{to_param_string(filters)}"
    handle_request_error(0, 'GitLab', response.status) unless response.status == 200
    body = Oj.load(response.body)
    array += body.map { |e| Epics.new(e) }
    break if body.count < 100

    page += 1
  end
  array
end

.remove_issue!(client, epic, issue) ⇒ Hash

Removes an issue to an epic. The issue object must be obtained via #list. This will exit on error

Examples:

require 'support_readiness'
config = Readiness::GitLab::Configuration.new
config.token = 'test123abc'
client = Readiness::GitLab::Client.new(config)
group = Readiness::GitLab::Groups.new({ 'id' => 2573624 })
epic = Readiness::GitLab::Epics.find!(gitlab_client, group, 16)
issues = Readiness::GitLab::Epics.issues(gitlab_client, epic)
issue = issues.detect { |i| i.iid == 2491 }
remove = Readiness::GitLab::Epics.remove_issue!(gitlab_client, epic, issue)
puts remove['epic']['id']
# => 2087187

Parameters:

Returns:

  • (Hash)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.105



242
243
244
245
246
247
248
249
# File 'lib/support_readiness/gitlab/epics.rb', line 242

def self.remove_issue!(client, epic, issue)
  return handle_request_error(1, 'GitLab', 400, { action: "No issue provided to remove from epic #{epic.iid}", id: '' }) if issue.nil?
  return handle_request_error(1, 'GitLab', 400, { action: "Issue is not assigned to epic #{epic.iid}", id: issue.iid }) if issue.epic_issue_id.nil?

  response = client.connection.delete "groups/#{epic.group_id}/epics/#{epic.iid}/issues/#{issue.epic_issue_id}"
  handle_request_error(1, 'GitLab', response.status, { action: "Remove issue from epic #{epic.iid}", id: issue.iid }) unless response.status == 200
  Oj.load(response.body)
end