Class: CreateGithubRelease::Project
- Inherits:
-
Object
- Object
- CreateGithubRelease::Project
- Includes:
- BacktickDebug
- Defined in:
- lib/create_github_release/project.rb
Overview
Captures the options for this script
Instance Attribute Summary collapse
-
#changelog_path ⇒ String
The path relative to the project root where the changelog is located.
-
#changes ⇒ Array<CreateGithubRelease>
An array containing the changes since the last_release_tag.
-
#default_branch ⇒ String
The default branch of the remote repository.
-
#first_commit ⇒ String
The SHA of the oldest commit that is an ancestor of HEAD.
-
#last_release_changelog ⇒ Boolean
true if release_type is 'first' otherwise false.
-
#last_release_tag ⇒ String
The tag to used for the last release.
-
#last_release_version ⇒ String
The version of the last release.
-
#next_release_changelog ⇒ String
The changelog of the next release as a string.
-
#next_release_date ⇒ Date
The date next_release_tag was created.
-
#next_release_description ⇒ String
The formatted release description.
-
#next_release_tag ⇒ String
The tag to use for the next release.
-
#next_release_version ⇒ String
The version of the next release.
-
#options ⇒ CreateGithubRelease::CommandLine::Options
readonly
The command line options used to initialize this project.
-
#pre ⇒ Boolean
Set to true if a pre-release is be created.
-
#pre_type ⇒ String
Set to the pre-release type to create.
-
#quiet ⇒ Boolean
(also: #quiet?)
If
truesupresses all output. -
#release_branch ⇒ String
The name of the release branch being created.
-
#release_log_url ⇒ URI
The URL of the page containing a list of the changes in the release.
-
#release_type ⇒ String
The type of the release being created (e.g. 'major', 'minor', 'patch').
-
#release_url ⇒ URI::Generic
The URL of the page containing a list of the changes in the release.
-
#remote ⇒ String
The git remote used to determine the repository url.
-
#remote_base_url ⇒ URI::Generic
The base part of the remote url (e.g. 'https://github.com/').
-
#remote_repository ⇒ String
The git remote owner and repository name (e.g. 'org/repo').
-
#remote_url ⇒ URI
The URL of the git remote repository (e.g. 'https://github.com/org/repo').
-
#verbose ⇒ Boolean
(also: #verbose?)
If
trueenables verbose output.
Instance Method Summary collapse
-
#first_release ⇒ Boolean
(also: #first_release?)
true if release_type is 'first' otherwise false.
-
#initialize(options) {|self| ... } ⇒ Project
constructor
Initialize a new Project.
-
#tag_exist?(tag) ⇒ Boolean
trueif the given tag exists in the local repository. -
#to_s ⇒ String
Show the project details as a string.
Methods included from BacktickDebug
Constructor Details
#initialize(options) {|self| ... } ⇒ Project
Initialize a new Project
Project attributes are set using one of these methods:
- The attribute is explicitly set using an attribute writer
- The attribute is set using the options object
- The attribute is set using the default value or running some command
Method 1 takes precedence, then method 2, then method 3.
The recommended way to set the attributes is to use method 2 to override values and otherwise method 3 to use the default value. Method 1 is only recommended for testing or if there is no other way to accomplish what you need. Method 1 should ONLY be used in the block passed to the initializer.
46 47 48 49 50 51 |
# File 'lib/create_github_release/project.rb', line 46 def initialize() = yield self if block_given? setup_first_release if release_type == 'first' end |
Instance Attribute Details
#changelog_path ⇒ String
The path relative to the project root where the changelog is located
557 558 559 |
# File 'lib/create_github_release/project.rb', line 557 def changelog_path @changelog_path ||= .changelog_path || 'CHANGELOG.md' end |
#changes ⇒ Array<CreateGithubRelease>
An array containing the changes since the last_release_tag
Calls git log HEAD <next_release_tag> to list the changes.
586 587 588 589 590 591 592 593 594 595 596 |
# File 'lib/create_github_release/project.rb', line 586 def changes @changes ||= begin tip = "'HEAD'" base = first_release? ? '' : "'^#{last_release_tag}' " command = "git log #{tip} #{base}--oneline --format='format:%h\t%s'" git_log = `#{command}` raise "Could not determine changes since #{last_release_tag}" unless $CHILD_STATUS.success? git_log.split("\n").map { |l| ::CreateGithubRelease::Change.new(*l.split("\t")) } end end |
#default_branch ⇒ String
The default branch of the remote repository
This is the default branch as reported by the HEAD branch returned by
git remote show #{remote}.
Uses the value of remote to determine the remote repository to query.
102 103 104 105 106 107 108 109 |
# File 'lib/create_github_release/project.rb', line 102 def default_branch @default_branch ||= .default_branch || begin output = `git remote show '#{remote}'` raise "Could not determine default branch for remote '#{remote}'" unless $CHILD_STATUS.success? output.match(/HEAD branch: (.*?)$/)[1] end end |
#first_commit ⇒ String
The SHA of the oldest commit that is an ancestor of HEAD
853 854 855 856 857 858 859 860 861 |
# File 'lib/create_github_release/project.rb', line 853 def first_commit @first_commit ||= begin command = "git log 'HEAD' --oneline --format='format:%h'" git_log = `#{command}` raise "Could not list changes from first commit up to #{last_release_tag}" unless $CHILD_STATUS.success? git_log.split("\n").last.chomp end end |
#last_release_changelog ⇒ Boolean
true if release_type is 'first' otherwise false
669 670 671 672 673 674 675 676 677 |
# File 'lib/create_github_release/project.rb', line 669 def last_release_changelog @last_release_changelog ||= begin File.read(changelog_path) rescue Errno::ENOENT '' rescue StandardError raise 'Could not read the changelog file' end end |
#last_release_tag ⇒ String
The tag to used for the last release
Uses the value of last_release_version to determine the tag name.
240 241 242 |
# File 'lib/create_github_release/project.rb', line 240 def last_release_tag @last_release_tag ||= (first_release? ? '' : "v#{last_release_version}") end |
#last_release_version ⇒ String
The version of the last release
265 266 267 |
# File 'lib/create_github_release/project.rb', line 265 def last_release_version @last_release_version ||= .last_release_version || current_version end |
#next_release_changelog ⇒ String
The changelog of the next release as a string
This is the result of inserting next_release_description into last_release_changelog.
711 712 713 714 |
# File 'lib/create_github_release/project.rb', line 711 def next_release_changelog @next_release_changelog ||= CreateGithubRelease::Changelog.new(last_release_changelog, next_release_description).to_s end |
#next_release_date ⇒ Date
The date next_release_tag was created
If the next_release_tag does not exist, Date.today is returned.
161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/create_github_release/project.rb', line 161 def next_release_date @next_release_date ||= if tag_exist?(next_release_tag) date = `git show --format=format:%aI --quiet "#{next_release_tag}"` raise "Could not determine date for tag '#{next_release_tag}'" unless $CHILD_STATUS.success? Date.parse(date.chomp) else Date.today end end |
#next_release_description ⇒ String
The formatted release description
626 627 628 629 630 631 632 633 634 635 636 637 638 639 |
# File 'lib/create_github_release/project.rb', line 626 def next_release_description @next_release_description ||= begin header = first_release? ? 'Changes:' : "Changes since #{last_release_tag}:" " ## \#{next_release_tag} (\#{next_release_date.strftime('%Y-%m-%d')})\n\n [Full Changelog](\#{release_log_url})\n\n \#{header}\n\n \#{list_of_changes}\n DESCRIPTION\n end\nend\n" |
#next_release_tag ⇒ String
The tag to use for the next release
Uses the value of next_release_version to determine the tag name.
133 134 135 |
# File 'lib/create_github_release/project.rb', line 133 def next_release_tag @next_release_tag ||= "v#{next_release_version}" end |
#next_release_version ⇒ String
The version of the next release
214 215 216 |
# File 'lib/create_github_release/project.rb', line 214 def next_release_version @next_release_version ||= .next_release_version || next_version end |
#options ⇒ CreateGithubRelease::CommandLine::Options (readonly)
The command line options used to initialize this project
64 65 66 |
# File 'lib/create_github_release/project.rb', line 64 def end |
#pre ⇒ Boolean
Set to true if a pre-release is be created
373 374 375 |
# File 'lib/create_github_release/project.rb', line 373 def pre @pre ||= .pre end |
#pre_type ⇒ String
Set to the pre-release type to create. For example, "alpha", "beta", "pre", etc
397 398 399 |
# File 'lib/create_github_release/project.rb', line 397 def pre_type @pre_type ||= .pre_type end |
#quiet ⇒ Boolean Also known as: quiet?
If true supresses all output
810 811 812 |
# File 'lib/create_github_release/project.rb', line 810 def quiet @quiet ||= .quiet || false end |
#release_branch ⇒ String
The name of the release branch being created
291 292 293 |
# File 'lib/create_github_release/project.rb', line 291 def release_branch @release_branch ||= .release_branch || "release-#{next_release_tag}" end |
#release_log_url ⇒ URI
The URL of the page containing a list of the changes in the release
319 320 321 322 323 324 325 |
# File 'lib/create_github_release/project.rb', line 319 def release_log_url @release_log_url ||= begin from = first_release? ? first_commit : last_release_tag to = next_release_tag URI.parse("#{remote_url}/compare/#{from}..#{to}") end end |
#release_type ⇒ String
this must be one of the values accepted by the semverify command
The type of the release being created (e.g. 'major', 'minor', 'patch')
350 351 352 |
# File 'lib/create_github_release/project.rb', line 350 def release_type @release_type ||= .release_type || raise(ArgumentError, 'release_type is required') end |
#release_url ⇒ URI::Generic
The URL of the page containing a list of the changes in the release
422 423 424 |
# File 'lib/create_github_release/project.rb', line 422 def release_url @release_url ||= URI.parse("#{remote_url}/releases/tag/#{next_release_tag}") end |
#remote ⇒ String
The git remote used to determine the repository url
450 451 452 |
# File 'lib/create_github_release/project.rb', line 450 def remote @remote ||= .remote || 'origin' end |
#remote_base_url ⇒ URI::Generic
The base part of the remote url (e.g. 'https://github.com/')
474 475 476 |
# File 'lib/create_github_release/project.rb', line 474 def remote_base_url @remote_base_url ||= URI.parse(remote_url.to_s[0..-remote_url.path.length]) end |
#remote_repository ⇒ String
The git remote owner and repository name (e.g. 'org/repo')
497 498 499 |
# File 'lib/create_github_release/project.rb', line 497 def remote_repository @remote_repository ||= remote_url.path.sub(%r{^/}, '').sub(/\.git$/, '') end |
#remote_url ⇒ URI
The URL of the git remote repository (e.g. 'https://github.com/org/repo')
520 521 522 523 524 525 526 527 528 529 |
# File 'lib/create_github_release/project.rb', line 520 def remote_url @remote_url ||= begin remote_url_string = `git remote get-url '#{remote}'` raise "Could not determine remote url for remote '#{remote}'" unless $CHILD_STATUS.success? remote_url_string = remote_url_string.chomp remote_url_string = remote_url_string[0..-5] if remote_url_string.end_with?('.git') URI.parse(remote_url_string) end end |
#verbose ⇒ Boolean Also known as: verbose?
If true enables verbose output
785 786 787 |
# File 'lib/create_github_release/project.rb', line 785 def verbose @verbose ||= .verbose || false end |
Instance Method Details
#first_release ⇒ Boolean Also known as: first_release?
true if release_type is 'first' otherwise false
834 835 836 |
# File 'lib/create_github_release/project.rb', line 834 def first_release @first_release ||= release_type == 'first' end |
#tag_exist?(tag) ⇒ Boolean
true if the given tag exists in the local repository
186 187 188 189 190 191 |
# File 'lib/create_github_release/project.rb', line 186 def tag_exist?(tag) = `git tag --list "#{tag}"`.chomp raise 'Could not list tags' unless $CHILD_STATUS.success? !.empty? end |
#to_s ⇒ String
Show the project details as a string
744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 |
# File 'lib/create_github_release/project.rb', line 744 def to_s " first_release: \#{first_release}\n default_branch: \#{default_branch}\n next_release_tag: \#{next_release_tag}\n next_release_date: \#{next_release_date}\n next_release_version: \#{next_release_version}\n last_release_tag: \#{last_release_tag}\n last_release_version: \#{last_release_version}\n release_branch: \#{release_branch}\n release_log_url: \#{release_log_url}\n release_type: \#{release_type}\n release_url: \#{release_url}\n remote: \#{remote}\n remote_base_url: \#{remote_base_url}\n remote_repository: \#{remote_repository}\n remote_url: \#{remote_url}\n verbose?: \#{verbose?}\n quiet?: \#{quiet?}\n OUTPUT\nend\n" |