Class: Hubkit::IssueCollection

Inherits:
ChainableCollection show all
Defined in:
lib/hubkit/issue_collection.rb

Overview

A collection of GitHub issues with chainable filters

Instance Method Summary collapse

Methods inherited from ChainableCollection

#==, #initialize, #method_missing, #not, #respond_to?, scope, #select, #wrap

Constructor Details

This class inherits a constructor from Hubkit::ChainableCollection

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Hubkit::ChainableCollection

Instance Method Details

#by_assigneeHash

Group the issue collection by the current assignee

Returns:

  • (Hash)

    a hash, where the assignee's username is the key, and the values are IssueCollections of issues assigned to that user


94
95
96
97
98
99
# File 'lib/hubkit/issue_collection.rb', line 94

def by_assignee
  groups = group_by { |issue| issue.assignee.try(:login) }
  groups.each_with_object(groups) do |(key, list), memo|
    memo[key] = wrap(list)
  end
end

#closedIssueCollection

Return a collection of issues which are closed

Returns:


25
26
27
# File 'lib/hubkit/issue_collection.rb', line 25

def closed
  wrap(@inner.select { |issue| issue.state == "closed" })
end

#ever_labeled(label) ⇒ IssueCollection

Filters to issues which where at some point labeled with the given label regardless of whether it currently has that label or not

Parameters:

  • label (String)

    the label in question

Returns:

  • (IssueCollection)

    a collection of issues which were ever labeled with that label


9
10
11
12
13
14
15
# File 'lib/hubkit/issue_collection.rb', line 9

def ever_labeled(label)
  wrap(
    @inner.select do |issue|
      issue.when_labeled(label).present?
    end,
  )
end

#labeled(labels) ⇒ IssueCollection

Return a collection of issues which are labeled with any of the given labels

Parameters:

  • labels (Enumerable, String)

    if a string, then this is the single label used to filter issues. If it is an enumerable set of strings, any issues matching any of the labels will be returned.

Returns:


35
36
37
38
39
40
41
# File 'lib/hubkit/issue_collection.rb', line 35

def labeled(labels)
  return wrap(labels.flat_map { |label| labeled(label) }) if labels.respond_to?(:map)

  wrap(@inner.select do |issue|
    issue.labels.include?(labels.downcase)
  end)
end

#labeled_like(label_pattern) ⇒ IssueCollection

Return a collection of issues which have labels matching a pattern

Parameters:

  • label_pattern (Regex)

    a pattern which issues must match to be included in the collection

Returns:

  • (IssueCollection)

    a collection of issues with labels matching the pattern


54
55
56
57
58
# File 'lib/hubkit/issue_collection.rb', line 54

def labeled_like(label_pattern)
  wrap(@inner.select do |issue|
    issue.labels.any? { |label| label_pattern.match(label) }
  end)
end

#openIssueCollection

Return a collection of issues which are open

Returns:


19
20
21
# File 'lib/hubkit/issue_collection.rb', line 19

def open
  wrap(@inner.select { |issue| issue.state == "open" })
end

#opened_between(start_dt, end_dt) ⇒ IssueCollection

Returns issues opened within a date window between start_dt and end_dt

Parameters:

  • start_dt (Date)

    the beginning date of the filter window (inclusive)

  • end_dt (Date)

    the end date of the filter window (exclusive)

Returns:


83
84
85
86
87
88
89
# File 'lib/hubkit/issue_collection.rb', line 83

def opened_between(start_dt, end_dt)
  wrap(
    @inner.select do |issue|
      start_dt <= issue.when_opened && issue.when_opened < end_dt
    end,
  )
end

#pullsIssueCollection

Return issues which are pull requests

Returns:


69
70
71
# File 'lib/hubkit/issue_collection.rb', line 69

def pulls
  wrap(@inner.select(&:pull?))
end

#true_issuesIssueCollection

Return issues which are not pull requests

Returns:


63
64
65
# File 'lib/hubkit/issue_collection.rb', line 63

def true_issues
  wrap(@inner.select(&:true_issue?))
end

#unassignedIssueCollection

Return issues which are unassigned

Returns:


75
76
77
# File 'lib/hubkit/issue_collection.rb', line 75

def unassigned
  wrap(@inner.select { |issue| issue.assignee.nil? })
end

#unlabeledIssueCollection

Return a collection of issues which are not labeled

Returns:


45
46
47
# File 'lib/hubkit/issue_collection.rb', line 45

def unlabeled
  wrap(@inner.select { |issue| issue.labels.empty? })
end