Class: Manifestly::ManifestDiff::ItemDiff
- Inherits:
-
Object
- Object
- Manifestly::ManifestDiff::ItemDiff
- Defined in:
- lib/manifestly/manifest_diff.rb
Instance Method Summary collapse
- #commits_markdown ⇒ Object
- #from_sha ⇒ Object
-
#initialize(from_item, to_item) ⇒ ItemDiff
constructor
A new instance of ItemDiff.
- #item_source_info ⇒ Object
- #new_item? ⇒ Boolean
- #to_markdown ⇒ Object
- #to_sha ⇒ Object
Constructor Details
#initialize(from_item, to_item) ⇒ ItemDiff
Returns a new instance of ItemDiff.
5 6 7 8 9 10 |
# File 'lib/manifestly/manifest_diff.rb', line 5 def initialize(from_item, to_item) @from_item = from_item @to_item = to_item @markdown = "## #{to_item.repository_name}#{item_source_info}\n\n#{commits_markdown}\n" end |
Instance Method Details
#commits_markdown ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/manifestly/manifest_diff.rb', line 34 def commits_markdown if new_item? "* This manifest item was not in the prior manifest, so all of its commits are new." else repository = @from_item.repository repository.toggle_prs_only is_rollback = false commits = repository.commits(between: [from_sha, to_sha]) if commits.size == 0 # This might be a rollback, so try them backwards commits = repository.commits(between: [to_sha, from_sha]) is_rollback = commits.size != 0 end if commits.size == 0 "* There were no pull requests merged in this range of commits." else entries = commits.collect do |commit| wrapper = Commit.new(commit) entry = wrapper. entry = "[#{entry}](https://github.com/#{repository.display_name}/pull/#{wrapper.pr_number})" if wrapper.is_pr? "1. #{entry}" end.join("\n") is_rollback ? "These commits were ***rolled back***:\n\n#{entries}" : entries end end end |
#from_sha ⇒ Object
16 17 18 |
# File 'lib/manifestly/manifest_diff.rb', line 16 def from_sha @from_item.commit.sha end |
#item_source_info ⇒ Object
24 25 26 27 28 |
# File 'lib/manifestly/manifest_diff.rb', line 24 def item_source_info new_item? ? " (new manifest entry)" : " (`#{from_sha[0..9]}` to `#{to_sha[0..9]}`)" end |
#new_item? ⇒ Boolean
30 31 32 |
# File 'lib/manifestly/manifest_diff.rb', line 30 def new_item? @from_item.nil? end |
#to_markdown ⇒ Object
12 13 14 |
# File 'lib/manifestly/manifest_diff.rb', line 12 def to_markdown @markdown end |
#to_sha ⇒ Object
20 21 22 |
# File 'lib/manifestly/manifest_diff.rb', line 20 def to_sha @to_item.commit.sha end |