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
true
supresses 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_pr_label ⇒ String?
The name of the label to apply to the release pull request.
-
#release_pr_number ⇒ String?
The number of the pull request created for the release or nil.
-
#release_pr_url ⇒ String
The url of the pull request created for the release or nil.
-
#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
true
enables 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
true
if 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() @options = 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
627 628 629 |
# File 'lib/create_github_release/project.rb', line 627 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.
656 657 658 659 660 661 662 663 664 665 666 |
# File 'lib/create_github_release/project.rb', line 656 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.
103 104 105 106 107 108 109 110 |
# File 'lib/create_github_release/project.rb', line 103 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
933 934 935 936 937 938 939 940 941 |
# File 'lib/create_github_release/project.rb', line 933 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
739 740 741 742 743 744 745 746 747 |
# File 'lib/create_github_release/project.rb', line 739 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.
241 242 243 |
# File 'lib/create_github_release/project.rb', line 241 def last_release_tag @last_release_tag ||= (first_release? ? '' : "v#{last_release_version}") end |
#last_release_version ⇒ String
The version of the last release
266 267 268 |
# File 'lib/create_github_release/project.rb', line 266 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.
781 782 783 784 |
# File 'lib/create_github_release/project.rb', line 781 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.
162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/create_github_release/project.rb', line 162 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
696 697 698 699 700 701 702 703 704 705 706 707 708 709 |
# File 'lib/create_github_release/project.rb', line 696 def next_release_description @next_release_description ||= begin header = first_release? ? 'Changes:' : "Changes since #{last_release_tag}:" <<~DESCRIPTION ## #{next_release_tag} (#{next_release_date.strftime('%Y-%m-%d')}) [Full Changelog](#{release_log_url}) #{header} #{list_of_changes} DESCRIPTION end end |
#next_release_tag ⇒ String
The tag to use for the next release
Uses the value of next_release_version
to determine the tag name.
134 135 136 |
# File 'lib/create_github_release/project.rb', line 134 def next_release_tag @next_release_tag ||= "v#{next_release_version}" end |
#next_release_version ⇒ String
The version of the next release
215 216 217 |
# File 'lib/create_github_release/project.rb', line 215 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 @options end |
#pre ⇒ Boolean
Set to true if a pre-release is be created
443 444 445 |
# File 'lib/create_github_release/project.rb', line 443 def pre @pre ||= .pre end |
#pre_type ⇒ String
Set to the pre-release type to create. For example, "alpha", "beta", "pre", etc
467 468 469 |
# File 'lib/create_github_release/project.rb', line 467 def pre_type @pre_type ||= .pre_type end |
#quiet ⇒ Boolean Also known as: quiet?
If true
supresses all output
890 891 892 |
# File 'lib/create_github_release/project.rb', line 890 def quiet @quiet ||= .quiet || false end |
#release_branch ⇒ String
The name of the release branch being created
292 293 294 |
# File 'lib/create_github_release/project.rb', line 292 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
348 349 350 351 352 353 354 |
# File 'lib/create_github_release/project.rb', line 348 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_pr_label ⇒ String?
The name of the label to apply to the release pull request
320 321 322 |
# File 'lib/create_github_release/project.rb', line 320 def release_pr_label @release_pr_label ||= .release_pr_label || nil end |
#release_pr_number ⇒ String?
The number of the pull request created for the release or nil
The PR must already exist.
371 372 373 374 375 376 |
# File 'lib/create_github_release/project.rb', line 371 def release_pr_number @release_pr_number ||= begin pr_number = `gh pr list --search "head:#{release_branch}" --json number --jq ".[].number"`.chomp pr_number.empty? ? nil : pr_number end end |
#release_pr_url ⇒ String
The url of the pull request created for the release or nil
The PR must already exist.
393 394 395 |
# File 'lib/create_github_release/project.rb', line 393 def release_pr_url @release_pr_url ||= release_pr_number.nil? ? nil : URI.parse("#{remote_url}/pull/#{release_pr_number}") end |
#release_type ⇒ String
this must be one of the values accepted by the gem-version-boss
command
The type of the release being created (e.g. 'major', 'minor', 'patch')
420 421 422 |
# File 'lib/create_github_release/project.rb', line 420 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
492 493 494 |
# File 'lib/create_github_release/project.rb', line 492 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
520 521 522 |
# File 'lib/create_github_release/project.rb', line 520 def remote @remote ||= .remote || 'origin' end |
#remote_base_url ⇒ URI::Generic
The base part of the remote url (e.g. 'https://github.com/')
544 545 546 |
# File 'lib/create_github_release/project.rb', line 544 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')
567 568 569 |
# File 'lib/create_github_release/project.rb', line 567 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')
590 591 592 593 594 595 596 597 598 599 |
# File 'lib/create_github_release/project.rb', line 590 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
865 866 867 |
# File 'lib/create_github_release/project.rb', line 865 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
914 915 916 |
# File 'lib/create_github_release/project.rb', line 914 def first_release @first_release ||= release_type == 'first' end |
#tag_exist?(tag) ⇒ Boolean
true
if the given tag exists in the local repository
187 188 189 190 191 192 |
# File 'lib/create_github_release/project.rb', line 187 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
819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 |
# File 'lib/create_github_release/project.rb', line 819 def to_s <<~OUTPUT first_release: #{first_release} default_branch: #{default_branch} next_release_tag: #{next_release_tag} next_release_date: #{next_release_date} next_release_version: #{next_release_version} last_release_tag: #{last_release_tag} last_release_version: #{last_release_version} release_branch: #{release_branch} release_log_url: #{release_log_url} release_type: #{release_type} release_url: #{release_url} remote: #{remote} remote_base_url: #{remote_base_url} remote_repository: #{remote_repository} remote_url: #{remote_url} release_pr_number: #{release_pr_number} release_pr_url: #{release_pr_url} changelog_path: #{changelog_path} verbose?: #{verbose?} quiet?: #{quiet?} OUTPUT end |