module Metasploit::Version::Branch
Regular expressions for parsing the branch name into its component parts
Constants
- JENKINS_PREFIX_REGEXP
Regular expression that matches, but does not capture an optional prefix of ‘ref/remotes` for when a branch name is fully qualified on Jenkins. Remote name after `ref/remotes` is captured in `:remote` group.
- PRERELEASE_REGEXP
Version
pattern allowed by Rubygems for pre-release: runs of alphanumeric characters separated by ‘.` or `-`. Group is captured to `:prerelease` name.- PRERELEASE_SEGMENT_REGEXP
Matches runs of alphanumeric characters that are valid in prerelease segments. Prerelease segments must be separated by ‘.` or `-`.
- STAGING_REGEXP
Regular expression that matches exactly a staging branch. It may {JENKINS_PREFIX_REGEXP optionally start with ‘ref/remotes`}, followed by a type of `staging`, no story ID, and a {PRERELEASE_REGEXP pre-release name}.
@example Staging
Branch
'staging/long-running'
@example Staging
Branch
on Jenkins'ref/remotes/origin/staging/long-running'
- STORY_REGEXP
Regular expression that matches exactly a chore, feature or bug branch. It may {JENKINS_PREFIX_REGEXP optionally start with ‘ref/remotes`}, followed by a type of `staging`, story ID, and a {PRERELEASE_REGEXP pre-release name}.
@example Bug
Branch
'bug/MSP-666/nasty'
@example Bug
Branch
on Jenkins'ref/remotes/origin/bug/MSP-666/nasty'
@example Chore
Branch
'chore/MSP-1234/recurring'
@example Chore
Branch
on Jenkins'ref/remotes/origin/chore/MSP-1234/recurring'
@example Feature
Branch
'feature/MSP-31337/cool'
@example Feature
Branch
on Jenkins'ref/remotes/origin/feature/MSP-31337/cool'
- VERSION_PRERELEASE_SEGMENT_SEPARATOR_REGEXP
Regular expression that matches separator used between {PRERELEASE_SEGMENT_REGEXP prerelease segments} for gem versions and tag versions.
- VERSION_REGEXP
Regular expression that exactly matches a release or pre-release version tag prefixed with ‘v` and followed by the major, minor, and patch numbers separated by ’.‘ with an optional prerelease version suffix.
@example Releease Tag
'v1.2.3'
@example Prerelease Tag
'v1.2.3.pre.cool'
Public Class Methods
The current branch name from travis-ci or git.
@return [String]
# File lib/metasploit/version/branch.rb, line 105 def self.current branch = ENV['TRAVIS_BRANCH'] if branch.nil? || branch.empty? branch = `git rev-parse --abbrev-ref HEAD`.strip end branch end
Parses the branch
@param branch [String] the branch name @return [‘HEAD’] if ‘branch` is ’HEAD’ (such as in a detached head state for git) @return [‘master’] if ‘branch` is `master` @return [Hash{type: ’staging’, prerelease: String}] if a staging branch @return [Hash{type: String, story: String, prerelease: String}] if not a staging branch @return [Hash{major: Integer, minor: Integer, patch: Integer, prerelease: String}] @return [nil] if ‘branch` does not match any of the formats
# File lib/metasploit/version/branch.rb, line 124 def self.parse(branch) if ['HEAD', 'master'].include? branch branch else match = branch.match(STAGING_REGEXP) if match { prerelease: match[:prerelease], type: match[:type] } else match = branch.match(STORY_REGEXP) if match { prerelease: match[:prerelease], story: match[:story], type: match[:type] } else match = branch.match(VERSION_REGEXP) if match prerelease = prerelease(match[:gem_version_prerelease]) { major: match[:major].to_i, minor: match[:minor].to_i, patch: match[:patch].to_i, prerelease: prerelease } end end end end end
Replaces ‘.pre.` in `gem_version_prerelease` with `-` to undo conversion to rubygems 1.8.6 compatible pre-release version.
@return [String] unless ‘gem_version_prerelease` is `nil`. @return [nil] if `gem_version_prerelease` is `nil`.
# File lib/metasploit/version/branch.rb, line 167 def self.prerelease(gem_version_prerelease) unless gem_version_prerelease.nil? gem_version_prerelease.gsub('.pre.', '-') end end