Class: PlanMyStuff::Label

Inherits:
ApplicationRecord show all
Defined in:
lib/plan_my_stuff/label.rb

Overview

Wraps a GitHub label with a reference to its parent issue. Class methods provide the public API for add/remove operations.

Instance Attribute Summary collapse

Class Method Summary collapse

Methods inherited from ApplicationRecord

#initialize, #new_record?, #persisted?

Constructor Details

This class inherits a constructor from PlanMyStuff::ApplicationRecord

Instance Attribute Details

#issuePlanMyStuff::Issue

Returns parent issue.

Returns:



10
11
12
# File 'lib/plan_my_stuff/label.rb', line 10

def issue
  @issue
end

#nameString

Returns label name.

Returns:

  • (String)

    label name



8
9
10
# File 'lib/plan_my_stuff/label.rb', line 8

def name
  @name
end

Class Method Details

.add(issue:, labels:) ⇒ Array<PlanMyStuff::Label>

Adds labels to a GitHub issue.

Parameters:

Returns:



20
21
22
23
24
25
26
# File 'lib/plan_my_stuff/label.rb', line 20

def add(issue:, labels:)
  result = PlanMyStuff.client.rest(
    :add_labels_to_an_issue, issue.repo, issue.number, labels,
  )

  result.map { |gh_label| build(gh_label, issue: issue) }
end

.remove(issue:, labels:) ⇒ Array<Array<PlanMyStuff::Label>>

Removes labels from a GitHub issue.

Parameters:

Returns:



35
36
37
38
39
40
# File 'lib/plan_my_stuff/label.rb', line 35

def remove(issue:, labels:)
  Array.wrap(labels).map do |label|
    result = PlanMyStuff.client.rest(:remove_label, issue.repo, issue.number, label)
    result.map { |gh_label| build(gh_label, issue: issue) }
  end
end