Class: HornOfPlenty::Adapters::Github::Parsers::Issue

Inherits:
Object
  • Object
show all
Includes:
Parsers::Hash
Defined in:
lib/horn_of_plenty/adapters/github/parsers/issue.rb

Direct Known Subclasses

PullRequest

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw:) ⇒ Issue

Returns a new instance of Issue.



16
17
18
# File 'lib/horn_of_plenty/adapters/github/parsers/issue.rb', line 16

def initialize(raw:)
  self.raw = raw
end

Instance Attribute Details

#rawObject

Returns the value of attribute raw.



14
15
16
# File 'lib/horn_of_plenty/adapters/github/parsers/issue.rb', line 14

def raw
  @raw
end

Class Method Details

.to_model(raw_item) ⇒ Object



85
86
87
88
89
# File 'lib/horn_of_plenty/adapters/github/parsers/issue.rb', line 85

def self.to_model(raw_item)
  return NullObjects::Issue.instance unless raw_item

  Models::Issue.from_parser(parser: new(raw: raw_item))
end

Instance Method Details

#assignee_idsObject



28
29
30
31
32
# File 'lib/horn_of_plenty/adapters/github/parsers/issue.rb', line 28

def assignee_ids
  @assignee_ids                          ||= begin
    parse_key(raw, 'assignees').map { |assignee| assignee['login'] }
  end
end

#author_idObject



24
25
26
# File 'lib/horn_of_plenty/adapters/github/parsers/issue.rb', line 24

def author_id
  @author_id                             ||= parse_text(raw, 'user/:/login')
end

#closed_atObject



69
70
71
# File 'lib/horn_of_plenty/adapters/github/parsers/issue.rb', line 69

def closed_at
  @closed_at                             ||= parse_time(raw, 'closed_at')
end

#closer_idObject



34
35
36
# File 'lib/horn_of_plenty/adapters/github/parsers/issue.rb', line 34

def closer_id
  @closer_id                             ||= parse_text(raw, 'closed_by/:/login')
end

#created_atObject



73
74
75
# File 'lib/horn_of_plenty/adapters/github/parsers/issue.rb', line 73

def created_at
  @created_at                            ||= parse_time(raw, 'created_at')
end

#descriptionObject



54
55
56
57
58
# File 'lib/horn_of_plenty/adapters/github/parsers/issue.rb', line 54

def description
  @description                           ||= parse_text(raw, 'body') do |description|
    description.delete("\r")
  end
end

#has_pull_request?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/horn_of_plenty/adapters/github/parsers/issue.rb', line 81

def has_pull_request?
  @has_pull_request                      ||= parse_existance(raw, 'pull_request')
end

#idObject



20
21
22
# File 'lib/horn_of_plenty/adapters/github/parsers/issue.rb', line 20

def id
  @id                                    ||= parse_text(raw, 'number')
end

#labelsObject



60
61
62
63
64
65
66
67
# File 'lib/horn_of_plenty/adapters/github/parsers/issue.rb', line 60

def labels
  @labels                                ||= begin
    labels    = parse_key(raw, 'labels').map { |label| label['name'] }
    milestone = Array(parse_key(raw, 'milestone/:/title'))

    labels + milestone
  end
end

#repositoryObject



38
39
40
41
42
43
44
# File 'lib/horn_of_plenty/adapters/github/parsers/issue.rb', line 38

def repository
  @repository                            ||= parse_text(raw, 'url') do |url|
    repo_name = url.match(%r{\A.*/repos/((?:[^/]+/){2}).*\z})[1]

    repo_name && repo_name[0..-2]
  end
end

#statusObject



46
47
48
# File 'lib/horn_of_plenty/adapters/github/parsers/issue.rb', line 46

def status
  @status                                ||= parse_text(raw, 'state')
end

#titleObject



50
51
52
# File 'lib/horn_of_plenty/adapters/github/parsers/issue.rb', line 50

def title
  @title                                 ||= parse_text(raw, 'title')
end

#updated_atObject



77
78
79
# File 'lib/horn_of_plenty/adapters/github/parsers/issue.rb', line 77

def updated_at
  @updated_at                            ||= parse_time(raw, 'updated_at')
end