Class: WhatsupGithub::Row

Inherits:
Object
  • Object
show all
Defined in:
lib/whatsup_github/row.rb

Overview

Row to be converted to entry in future table

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Row

Returns a new instance of Row.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/whatsup_github/row.rb', line 18

def initialize(args)
  @repo = args[:repo]
  @repo_url = args[:repo_url]
  @is_private = args[:private]
  @title = args[:pr_title]
  @body = args[:pr_body]
  @date = args[:date]
  @labels = args[:pr_labels]
  @assignee = args[:assignee]
  @author = args[:author]
  @author_url = args[:author_url]
  @pr_number = args[:pr_number]
  @link = args[:pr_url]
  @merge_commit = args[:merge_commit_sha]
  @membership = args[:membership]
  @config = Config.instance
end

Instance Attribute Details

#assigneeObject (readonly)

Returns the value of attribute assignee.



6
7
8
# File 'lib/whatsup_github/row.rb', line 6

def assignee
  @assignee
end

#authorObject (readonly)

Returns the value of attribute author.



6
7
8
# File 'lib/whatsup_github/row.rb', line 6

def author
  @author
end

#author_urlObject (readonly)

Returns the value of attribute author_url.



6
7
8
# File 'lib/whatsup_github/row.rb', line 6

def author_url
  @author_url
end

#bodyObject (readonly)

Returns the value of attribute body.



6
7
8
# File 'lib/whatsup_github/row.rb', line 6

def body
  @body
end

#is_privateObject (readonly)

Returns the value of attribute is_private.



6
7
8
# File 'lib/whatsup_github/row.rb', line 6

def is_private
  @is_private
end

#labelsObject (readonly)

Returns the value of attribute labels.



6
7
8
# File 'lib/whatsup_github/row.rb', line 6

def labels
  @labels
end

Returns the value of attribute link.



6
7
8
# File 'lib/whatsup_github/row.rb', line 6

def link
  @link
end

#membershipObject (readonly)

Returns the value of attribute membership.



6
7
8
# File 'lib/whatsup_github/row.rb', line 6

def membership
  @membership
end

#merge_commitObject (readonly)

Returns the value of attribute merge_commit.



6
7
8
# File 'lib/whatsup_github/row.rb', line 6

def merge_commit
  @merge_commit
end

#pr_numberObject (readonly)

Returns the value of attribute pr_number.



6
7
8
# File 'lib/whatsup_github/row.rb', line 6

def pr_number
  @pr_number
end

#titleObject (readonly)

Returns the value of attribute title.



6
7
8
# File 'lib/whatsup_github/row.rb', line 6

def title
  @title
end

Instance Method Details

#dateObject



53
54
55
# File 'lib/whatsup_github/row.rb', line 53

def date
  @date.strftime('%B %-e, %Y')
end

#descriptionObject



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/whatsup_github/row.rb', line 72

def description
  # If a PR body includes a phrase 'whatsnew', then parse the body.
  # If there are at least one required label but PR body does not include what's new, warn about missing 'whatsnew'
  if body.include?(magic_word)
    parse_body
  else
    message = "MISSING #{magic_word} in the #{type} PR \##{pr_number}: \"#{title}\" assigned to #{assignee} (#{link})"
    puts message
    message
  end
end

#labels_from_configObject



36
37
38
# File 'lib/whatsup_github/row.rb', line 36

def labels_from_config
  @config.labels
end

#magic_wordObject



44
45
46
# File 'lib/whatsup_github/row.rb', line 44

def magic_word
  @config.magic_word
end

#parse_bodyObject



61
62
63
64
65
66
67
68
69
70
# File 'lib/whatsup_github/row.rb', line 61

def parse_body
  # Split PR description in two parts by 'magic word', and take the second half
  description_splited = body.split(magic_word)[-1]
  # Convert new line separators to <br> tags
  newline_splited = description_splited.split("\n")
  cleaned_array = newline_splited.map { |e| e.delete "\r\*" }
  cleaned_array.delete('')
  striped_array = cleaned_array.map(&:strip)
  striped_array.join('<br/>')
end

#required_labelsObject



40
41
42
# File 'lib/whatsup_github/row.rb', line 40

def required_labels
  @config.required_labels
end

#typeObject



57
58
59
# File 'lib/whatsup_github/row.rb', line 57

def type
  (labels & labels_from_config).join(', ')
end

#versionsObject



48
49
50
51
# File 'lib/whatsup_github/row.rb', line 48

def versions
  label_versions = labels.select { |label| label.start_with?(/\d\./) }
  label_versions.join(', ')
end