Class: Geet::Github::AbstractIssue

Inherits:
Object
  • Object
show all
Defined in:
lib/geet/github/abstract_issue.rb

Overview

For clarity, in this class we keep only the identical logic between the subclasses, but other methods could be moved in here at some complexity cost.

Direct Known Subclasses

Issue, PR

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number, api_interface, title, link) ⇒ AbstractIssue

Returns a new instance of AbstractIssue.



16
17
18
19
20
21
# File 'lib/geet/github/abstract_issue.rb', line 16

def initialize(number, api_interface, title, link)
  @number = number
  @api_interface = api_interface
  @title = title
  @link = link
end

Instance Attribute Details

Returns the value of attribute link.



14
15
16
# File 'lib/geet/github/abstract_issue.rb', line 14

def link
  @link
end

#numberObject (readonly)

Returns the value of attribute number.



14
15
16
# File 'lib/geet/github/abstract_issue.rb', line 14

def number
  @number
end

#titleObject (readonly)

Returns the value of attribute title.



14
15
16
# File 'lib/geet/github/abstract_issue.rb', line 14

def title
  @title
end

Class Method Details

.list(api_interface, milestone: nil, assignee: nil, &type_filter) ⇒ Object

See developer.github.com/v3/issues/#list-issues-for-a-repository

This works both for Issues and PRs, however, when the ‘/pulls` API (path) is used, additional information is provided (e.g. `head`).



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/geet/github/abstract_issue.rb', line 28

def self.list(api_interface, milestone: nil, assignee: nil, &type_filter)
  api_path = 'issues'

  request_params = {}
  request_params[:milestone] = milestone.number if milestone
  request_params[:assignee] = assignee.username if assignee

  response = api_interface.send_request(api_path, params: request_params, multipage: true)

  abstract_issues_list = response.map do |issue_data|
    number = issue_data.fetch('number')
    title = issue_data.fetch('title')
    link = issue_data.fetch('html_url')

    new(number, api_interface, title, link) if type_filter.nil? || type_filter.call(issue_data)
  end

  abstract_issues_list.compact
end

Instance Method Details

#add_labels(labels) ⇒ Object

labels: array of strings.



60
61
62
63
64
65
# File 'lib/geet/github/abstract_issue.rb', line 60

def add_labels(labels)
  api_path = "issues/#{@number}/labels"
  request_data = labels

  @api_interface.send_request(api_path, data: request_data)
end

#assign_users(users) ⇒ Object

params:

users:   String, or Array of strings.


51
52
53
54
55
56
# File 'lib/geet/github/abstract_issue.rb', line 51

def assign_users(users)
  api_path = "issues/#{@number}/assignees"
  request_data = { assignees: Array(users) }

  @api_interface.send_request(api_path, data: request_data)
end

#comment(comment) ⇒ Object



69
70
71
72
73
74
# File 'lib/geet/github/abstract_issue.rb', line 69

def comment(comment)
  api_path = "issues/#{@number}/comments"
  request_data = { body: comment }

  @api_interface.send_request(api_path, data: request_data)
end

#edit(milestone:) ⇒ Object



78
79
80
81
82
83
# File 'lib/geet/github/abstract_issue.rb', line 78

def edit(milestone:)
  request_data = { milestone: milestone }
  api_path = "issues/#{@number}"

  @api_interface.send_request(api_path, data: request_data, http_method: :patch)
end