Class: EasyChangelog::Entry
- Inherits:
-
Struct
- Object
- Struct
- EasyChangelog::Entry
- Defined in:
- lib/easy_changelog/entry.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#branch_name ⇒ Object
Returns the value of attribute branch_name.
-
#card_id ⇒ Object
Returns the value of attribute card_id.
-
#cards_url ⇒ Object
Returns the value of attribute cards_url.
-
#ref_id ⇒ Object
Returns the value of attribute ref_id.
-
#ref_type ⇒ Object
Returns the value of attribute ref_type.
-
#type ⇒ Object
Returns the value of attribute type.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #card_ref ⇒ Object
- #content ⇒ Object
- #github_user ⇒ Object
-
#initialize(type:, body: last_commit_title, ref_type: nil, ref_id: nil, card_id: nil, cards_url: nil, user: github_user, branch_name: nil) ⇒ Entry
constructor
A new instance of Entry.
- #last_commit_id ⇒ Object
- #last_commit_title ⇒ Object
- #path ⇒ Object
- #ref ⇒ Object
- #write ⇒ Object
Constructor Details
#initialize(type:, body: last_commit_title, ref_type: nil, ref_id: nil, card_id: nil, cards_url: nil, user: github_user, branch_name: nil) ⇒ Entry
Returns a new instance of Entry.
5 6 7 8 9 10 11 12 13 |
# File 'lib/easy_changelog/entry.rb', line 5 def initialize(type:, body: last_commit_title, ref_type: nil, ref_id: nil, card_id: nil, cards_url: nil, user: github_user, branch_name: nil) id, body = EasyChangelog::Utility.extract_id(body) ref_id ||= id || last_commit_id ref_type ||= id ? :pull : :commit card_id ||= EasyChangelog::Utility.discover_card_id(branch_name) super end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body
4 5 6 |
# File 'lib/easy_changelog/entry.rb', line 4 def body @body end |
#branch_name ⇒ Object
Returns the value of attribute branch_name
4 5 6 |
# File 'lib/easy_changelog/entry.rb', line 4 def branch_name @branch_name end |
#card_id ⇒ Object
Returns the value of attribute card_id
4 5 6 |
# File 'lib/easy_changelog/entry.rb', line 4 def card_id @card_id end |
#cards_url ⇒ Object
Returns the value of attribute cards_url
4 5 6 |
# File 'lib/easy_changelog/entry.rb', line 4 def cards_url @cards_url end |
#ref_id ⇒ Object
Returns the value of attribute ref_id
4 5 6 |
# File 'lib/easy_changelog/entry.rb', line 4 def ref_id @ref_id end |
#ref_type ⇒ Object
Returns the value of attribute ref_type
4 5 6 |
# File 'lib/easy_changelog/entry.rb', line 4 def ref_type @ref_type end |
#type ⇒ Object
Returns the value of attribute type
4 5 6 |
# File 'lib/easy_changelog/entry.rb', line 4 def type @type end |
#user ⇒ Object
Returns the value of attribute user
4 5 6 |
# File 'lib/easy_changelog/entry.rb', line 4 def user @user end |
Instance Method Details
#card_ref ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/easy_changelog/entry.rb', line 44 def card_ref return EasyChangelog.configuration.include_empty_card_id ? '[] ' : '' if card_id.nil? || card_id.empty? link = "[#{card_id}]" base_url = cards_url || EasyChangelog.configuration.cards_url link += "(#{base_url}/#{card_id})" if base_url link end |
#content ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/easy_changelog/entry.rb', line 29 def content title = body.dup title += '.' unless title.end_with? '.' = { ref: ref, card_ref: card_ref, title: title, username: user } format(EasyChangelog.configuration.entry_row_template, ) end |
#github_user ⇒ Object
62 63 64 65 66 67 |
# File 'lib/easy_changelog/entry.rb', line 62 def github_user user = `git config --global credential.username`.chomp warn 'Set your username with `git config --global credential.username "myusernamehere"`' if user.empty? user end |
#last_commit_id ⇒ Object
58 59 60 |
# File 'lib/easy_changelog/entry.rb', line 58 def last_commit_id `git log -n1 --format="%h"`.chomp end |
#last_commit_title ⇒ Object
54 55 56 |
# File 'lib/easy_changelog/entry.rb', line 54 def last_commit_title `git log -1 --pretty=%B`.lines.first.chomp end |
#path ⇒ Object
22 23 24 25 26 27 |
# File 'lib/easy_changelog/entry.rb', line 22 def path filename = EasyChangelog::Utility.str_to_filename(body) = { type: type, name: filename, timestamp: Time.now.strftime('%Y%m%d%H%M%S') } format(EasyChangelog.configuration.entry_path_template, ) end |
#ref ⇒ Object
38 39 40 41 42 |
# File 'lib/easy_changelog/entry.rb', line 38 def ref raise ArgumentError, 'ref_type must be issues, pull, or commit' unless %w[issues pull commit].include?(ref_type) "[##{ref_id}](#{EasyChangelog.configuration.repo_url}/#{ref_type}/#{ref_id})" end |
#write ⇒ Object
15 16 17 18 19 20 |
# File 'lib/easy_changelog/entry.rb', line 15 def write EasyChangelog::Utility.ensure_entries_dir_exists File.write(path, content) path end |