Skip to content

Validate Release environment name when querying

Context

The current logic of ReleaseTools::ReleaseEnvironment::Environment when it comes to creating a new environment includes copy the configuration file of the latest environment. At the same time, the name of a Release environment (RE) is arbitrary, not only a stable branch name (e.g. 17-10-stable-ee). The list of current environments can be seen here.

Example

Let say we have four environments 17-9-stable-ee, 17-10-stable-ee, 17-11-stable-ee and dat-test , when I put the version in the latest_environment method:

      def latest_environment
        @latest_environment ||= begin
          versions_hash = {}

          tree.each do |hash|
            branch_name = hash.to_h.fetch('name')
            version = branch(branch_name).version
            puts version # Add for testing
            versions_hash[version] = branch_name
          end

          latest_version = ReleaseTools::Versions.sort(versions_hash.keys).last

          versions_hash[latest_version]
        end
      end

The output is:

[1] pry(main)> ReleaseTools::ReleaseEnvironment::Environment.new("18.0.0-rc42").latest_environment
17.10.0
17.11.0
17.9.0

TypeError: no implicit conversion of nil into String (TypeError)

      ::VersionSorter.sort(versions).uniq
                           ^^^^^^^^
from /Users/dattang/git/gitlab-org/release-tools/lib/release_tools/versions.rb:55:in 'VersionSorter.sort'

You see the empty line after 17.9.0. It is because dat-test cannot be translated to any version, thus the error.

Proposal

Add a validation to ignore non-stable-branch environments.