Class: CreateGithubRelease::Project

Inherits:
Object
  • Object
show all
Includes:
BacktickDebug
Defined in:
lib/create_github_release/project.rb

Overview

Captures the options for this script

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BacktickDebug

#`

Constructor Details

#initialize(options) {|self| ... } ⇒ Project

Initialize a new Project

Project attributes are set using one of these methods:

  1. The attribute is explicitly set using an attribute writer
  2. The attribute is set using the options object
  3. 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.

Examples:

calling .new without a block

options = CreateGithubRelease::CommandLine::Options.new { |o| o.release_type = 'minor' }
project = CreateGithubRelease::Project.new(options)
options.release_type = 'minor'

calling .new with a block

options = CreateGithubRelease::CommandLine::Options.new { |o| o.release_type = 'minor' }
project = CreateGithubRelease::Project.new(options) do |p|
  p.release_type = 'major'
end
options.release_type = 'major'

Parameters:

Yields:

  • (self)

    an initialization block

Yield Parameters:

Yield Returns:

  • (void)

    the return value is ignored



46
47
48
49
50
51
# File 'lib/create_github_release/project.rb', line 46

def initialize(options)
  @options = options
  yield self if block_given?

  setup_first_release if release_type == 'first'
end

Instance Attribute Details

#changelog_pathString

The path relative to the project root where the changelog is located

Examples:

By default, this value is 'CHANGELOG.md'

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.changelog_path #=> 'CHANGELOG.md'

It can also be set in the options

options = CreateGithubRelease::CommandLine::Options.new(
  release_type: 'major', changelog_path: 'docs/CHANGES.txt'
)
project = CreateGithubRelease::Project.new(options)
project.remote_repository = 'docs/CHANGES.txt'

It can also be set explicitly

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.changelog_path = 'docs/CHANGES.txt'
project.remote_repository = 'docs/CHANGES.txt'

Returns:

  • (String)


627
628
629
# File 'lib/create_github_release/project.rb', line 627

def changelog_path
  @changelog_path ||= options.changelog_path || 'CHANGELOG.md'
end

#changesArray<CreateGithubRelease>

An array containing the changes since the last_release_tag

Calls git log HEAD <next_release_tag> to list the changes.

Examples:

By default, uses git log

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
pp project.changes
[
  #<CreateGithubRelease::Change:0x00000001084b92f0 @sha="24bdd02", @subject="Foo feature">,
  #<CreateGithubRelease::Change:0x00000001084b93e0 @sha="d75e1e9", @subject="Bar feature">
]

It can also be set explicitly

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.changes = 'All the changes'
project.changes #=> 'All the changes'

Returns:



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_branchString

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.

Examples:

By default, default_branch is based on git remote show

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
options.default_branch # => 'main'

default_branch can be set explicitly

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.default_branch = 'master'
project.default_branch #=> 'master'

Returns:

  • (String)

Raises:

  • (RuntimeError)

    if the git command fails



103
104
105
106
107
108
109
110
# File 'lib/create_github_release/project.rb', line 103

def default_branch
  @default_branch ||= options.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_commitString

The SHA of the oldest commit that is an ancestor of HEAD

Examples:

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.first_commit? #=> '1234567'

Returns:

  • (String)


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_changelogBoolean

true if release_type is 'first' otherwise false

Examples:

Returns true if release_type is 'first'

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'first')
project = CreateGithubRelease::Project.new(options)
project.first_release? #=> true

Returnss false if release_type is not 'first'

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.first_release? #=> false

Returns:

  • (Boolean)


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_tagString

The tag to used for the last release

Uses the value of last_release_version to determine the tag name.

Examples:

By default, last_release_tag is based on last_release_version

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.last_release_version = '0.0.1'
project.last_relase_tag #=> 'v0.0.1'

last_release_tag can be set explicitly

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.last_release_tag = 'v0.0.1'
project.last_relase_tag #=> 'v0.0.1'

Returns:

  • (String)


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_versionString

The version of the last release

Examples:

By default, last_release_version is based on the value returned by gem-version-boss current

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.last_release_version #=> '0.0.1'

It can also be set explicitly

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.last_release_version = '0.0.1
project.last_release_version #=> '0.0.1'

Returns:

  • (String)

Raises:

  • (RuntimeError)

    if the gem-version-boss command fails



266
267
268
# File 'lib/create_github_release/project.rb', line 266

def last_release_version
  @last_release_version ||= options.last_release_version || current_version
end

#next_release_changelogString

The changelog of the next release as a string

This is the result of inserting next_release_description into last_release_changelog.

Examples:

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options) do |p|
  p.last_release_changelog = <<~CHANGELOG
    # Project Changelog

    ## v0.1.0 (2021-11-07)

    * e718690 Release v0.1.0 (#3)
  CHANGELOG
  p.next_release_description = <<~next_release_description
    ## v1.0.0 (2022-11-07)

    [Full Changelog](http://github.com/org/repo/compare/v0.1.0...v1.0.0)

    * e718690 Release v1.0.0 (#3)
    * ab598f3 Add the FizzBuzz Feature (#2)
  next_release_description
end
puts project.next_release_changelog

Returns:

  • (String)


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_dateDate

The date next_release_tag was created

If the next_release_tag does not exist, Date.today is returned.

Examples:

By default, next_release_date is based on next_release_tag

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.next_release_tag = 'v1.0.0'
project.next_release_date #=> #<Date: 2023-02-01 ((2459189j,0s,0n),+0s,2299161j)>

It can also be set explicitly

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.next_release_date = Date.new(2023, 2, 1)
project.next_release_date #=> #<Date: 2023-02-01 ((2459189j,0s,0n),+0s,2299161j)>

Returns:

  • (Date)

Raises:

  • (RuntimeError)

    if the git command fails



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_descriptionString

The formatted release description

Examples:

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options) do |p|
  p.remote_url = URI.parse('https://github.com/username/repo')
  p.last_release_tag = 'v0.1.0'
  p.next_release_tag = 'v1.0.0'
  p.next_release_date = Date.new(2022, 11, 7)
  p.changes = [
    CreateGithubRelease::Change.new('e718690', 'Release v1.0.0 (#3)'),
    CreateGithubRelease::Change.new('ab598f3', 'Fix Rubocop offenses (#2)')
  ]
end
puts project.next_release_description
## v1.0.0 (2022-11-07)

[Full Changelog](https://github.com/username/repo/compare/v0.1.0...v1.0.0

* e718690 Release v1.0.0 (#3)
* ab598f3 Fix Rubocop offenses (#2)

Returns:

  • (String)


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_tagString

The tag to use for the next release

Uses the value of next_release_version to determine the tag name.

Examples:

By default, next_release_tag is based on next_release_version

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.next_release_version = '1.0.0'
project.next_relase_tag #=> 'v1.0.0'

next_tag can be set explicitly

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.next_release_tag = 'v1.0.0'
project.next_relase_tag #=> 'v1.0.0'

Returns:

  • (String)


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_versionString

The version of the next release

Examples:

By default, next_release_version is based on gem-version-boss <release_type> --dry-run

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.next_release_version #=> '1.0.0'

It can also be set explicitly

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.next_release_version = '1.0.0
project.next_release_version #=> '1.0.0'

Returns:

  • (String)

Raises:

  • (RuntimeError)

    if the gem-version-boss command fails



215
216
217
# File 'lib/create_github_release/project.rb', line 215

def next_release_version
  @next_release_version ||= options.next_release_version || next_version
end

#optionsCreateGithubRelease::CommandLine::Options (readonly)

The command line options used to initialize this project

Examples:

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.options == options #=> true

Returns:



64
65
66
# File 'lib/create_github_release/project.rb', line 64

def options
  @options
end

#preBoolean

Set to true if a pre-release is be created

Examples:

By default, this value comes from the options object

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major', pre: true, pre_type: 'alpha')
project = CreateGithubRelease::Project.new(options)
project.pre #=> 'true'

It can also be set explicitly

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.pre = true
project.pre #=> true

Returns:

  • (Boolean)


443
444
445
# File 'lib/create_github_release/project.rb', line 443

def pre
  @pre ||= options.pre
end

#pre_typeString

Set to the pre-release type to create. For example, "alpha", "beta", "pre", etc

Examples:

By default, this value comes from the options object

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major', pre: true, pre_type: 'alpha')
project = CreateGithubRelease::Project.new(options)
project.pre_type #=> 'alpha'

It can also be set explicitly

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.pre = true
project.pre_type = 'alpha'
project.pre_type #=> 'alpha'

Returns:

  • (String)


467
468
469
# File 'lib/create_github_release/project.rb', line 467

def pre_type
  @pre_type ||= options.pre_type
end

#quietBoolean Also known as: quiet?

If true supresses all output

Examples:

By default, this value is based on the quiet option

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major', quiet: true)
project = CreateGithubRelease::Project.new(options)
project.quiet? #=> true

It can also be set explicitly

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.quiet = true
project.quiet? #=> true

Returns:

  • (Boolean)


890
891
892
# File 'lib/create_github_release/project.rb', line 890

def quiet
  @quiet ||= options.quiet || false
end

#release_branchString

The name of the release branch being created

Examples:

By default, release_branch is based on the value returned by next_release_tag

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.next_release_tag = 'v1.0.0'
project.release_branch #=> 'release-v1.0.0'

It can also be set explicitly

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.next_release_branch = 'release-v1.0.0'
project.next_release_branch #=> 'release-v1.0.0'

Returns:

  • (String)

Raises:

  • (RuntimeError)

    if the gem-version-boss command fails



292
293
294
# File 'lib/create_github_release/project.rb', line 292

def release_branch
  @release_branch ||= options.release_branch || "release-#{next_release_tag}"
end

#release_log_urlURI

The URL of the page containing a list of the changes in the release

Examples:

By default, release_log_url is based on remote_url, last_release_tag, and next_release_tag

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.remote_url = URI.parse('https://github.com/org/repo')
project.last_release_tag = 'v0.0.1'
project.next_release_tag = 'v1.0.0'
project.release_log_url #=> #<URI::HTTPS https://github.com/org/repo/compare/v0.0.1..v1.0.0>

It can also be set explicitly

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.release_log_url = URI.parse('https://github.com/org/repo/compare/v0.0.1..v1.0.0')
project.release_log_url #=> #<URI::HTTPS https://github.com/org/repo/compare/v0.0.1..v1.0.0>

Returns:

  • (URI)

Raises:

  • (RuntimeError)

    if the gem-version-boss command fails



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_labelString?

The name of the label to apply to the release pull request

Examples:

By default, release_pr_label is nil indicating no label should be applied

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.release_pr_label #=> nil

Set to 'release'

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major', release_pr_label: 'release')
project = CreateGithubRelease::Project.new(options)
project.release_pr_label #=> 'release'

It can also be set explicitly

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.release_pr_label = 'release' # could be set to nil to remove the label
project.release_pr_label #=> 'release'

Returns:

  • (String, nil)


320
321
322
# File 'lib/create_github_release/project.rb', line 320

def release_pr_label
  @release_pr_label ||= options.release_pr_label || nil
end

#release_pr_numberString?

The number of the pull request created for the release or nil

The PR must already exist.

Examples:

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.release_pr_number #=> '123'

Returns:

  • (String, nil)


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_urlString

The url of the pull request created for the release or nil

The PR must already exist.

Examples:

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.release_pr_url #=> 'https://github.com/org/repo/pull/123'

Returns:

  • (String)


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_typeString

Note:

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')

Examples:

By default, this value comes from the options object

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.release_type #=> 'major'

It can also be set explicitly

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.release_type = 'patch'
project.release_type #=> 'patch'

Returns:

  • (String)

Raises:

  • (ArgumentError)

    if a release type was not provided



420
421
422
# File 'lib/create_github_release/project.rb', line 420

def release_type
  @release_type ||= options.release_type || raise(ArgumentError, 'release_type is required')
end

#release_urlURI::Generic

The URL of the page containing a list of the changes in the release

Examples:

By default, release_url is based on remote_url and next_release_tag

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.remote_url = URI.parse('https://github.com/org/repo')
project.next_release_tag = 'v1.0.0'
project.release_url #=> #<URI::HTTPS https://github.com/org/repo/releases/tag/v1.0.0>

It can also be set explicitly

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.release_url = URI.parse('https://github.com/org/repo/releases/tag/v1.0.0')
project.release_url #=> #<URI::HTTPS https://github.com/org/repo/releases/tag/v1.0.0>

Returns:

  • (URI::Generic)


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

#remoteString

The git remote used to determine the repository url

Examples:

By default, 'origin' is used

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.remote #=> 'origin'

It can also be set in the options

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major', remote: 'upstream')
project = CreateGithubRelease::Project.new(options)
project.remote #=> 'upstream'

It can also be set explicitly

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.remote = 'upstream'
project.remote #=> 'upstream'

Returns:

  • (String)


520
521
522
# File 'lib/create_github_release/project.rb', line 520

def remote
  @remote ||= options.remote || 'origin'
end

#remote_base_urlURI::Generic

The base part of the remote url (e.g. 'https://github.com/')

Examples:

By default, this value is based on remote_url

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.remote_url = URI.parse('https://github.com/org/repo')
project.remote #=> #<URI::HTTPS https://github.com/>

It can also be set explicitly

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.remote_base_url = URI.parse('https://github.com/')
project.remote_base_url #=> #<URI::HTTPS https://github.com/>

Returns:

  • (URI::Generic)


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_repositoryString

The git remote owner and repository name (e.g. 'org/repo')

Examples:

By default, this value is based on remote_url

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.remote_url = URI.parse('htps://github.com/org/repo')
project.remote_repository #=> 'org/repo'

It can also be set explicitly

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.remote_repository = 'org/repo'

Returns:

  • (String)


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_urlURI

The URL of the git remote repository (e.g. 'https://github.com/org/repo')

Examples:

By default, this value is based on remote and the git remote get-url command

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.remote #=> #<URI::HTTPS https://github.com/org/repo>

It can also be set explicitly

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.remote_url = URI.parse('https://github.com/org/repo')
project.remote_url #=> #<URI::HTTPS https://github.com/org/repo>

Returns:

  • (URI)


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

#verboseBoolean Also known as: verbose?

If true enables verbose output

Examples:

By default, this value is based on the verbose option

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major', verbose: true)
project = CreateGithubRelease::Project.new(options)
project.verbose? #=> true

It can also be set explicitly

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.verbose = true
project.verbose? #=> true

Returns:

  • (Boolean)


865
866
867
# File 'lib/create_github_release/project.rb', line 865

def verbose
  @verbose ||= options.verbose || false
end

Instance Method Details

#first_releaseBoolean Also known as: first_release?

true if release_type is 'first' otherwise false

Examples:

Returns true if release_type is 'first'

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'first')
project = CreateGithubRelease::Project.new(options)
project.first_release? #=> true

Returnss false if release_type is not 'first'

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.first_release? #=> false

Returns:

  • (Boolean)


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

Examples:

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
project.tag_exist?('v1.0.0') #=> false

Parameters:

  • tag (String)

    the tag to check

Returns:

  • (Boolean)


187
188
189
190
191
192
# File 'lib/create_github_release/project.rb', line 187

def tag_exist?(tag)
  tags = `git tag --list "#{tag}"`.chomp
  raise 'Could not list tags' unless $CHILD_STATUS.success?

  !tags.empty?
end

#to_sString

Show the project details as a string

Examples:

options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
project = CreateGithubRelease::Project.new(options)
puts projects.to_s
first_release: false
default_branch: main
next_release_tag: v1.0.0
next_release_date: 2023-02-01
next_release_version: 1.0.0
last_release_tag: v0.1.0
last_release_version: 0.1.0
release_branch: release-v1.0.0
release_log_url: https://github.com/org/repo/compare/v0.1.0..v1.0.0
release_type: major
release_url: https://github.com/org/repo/releases/tag/v1.0.0
remote: origin
remote_base_url: https://github.com/
remote_repository: org/repo
remote_url: https://github.com/org/repo
release_pr_number: 123
release_pr_url: https://github.com/org/repo/pull/123
changelog_path: CHANGELOG.md
verbose?: false
quiet?: false

Returns:

  • (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