Module: Metasploit::Version::Branch
- Defined in:
- lib/metasploit/version/branch.rb
Overview
Regular expressions for parsing the branch name into its component parts
Constant Summary collapse
- 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 afterref/remotes
is captured in:remote
group. %r{(?:ref/remotes/(?<remote>[^/]+)/)?}
- PRERELEASE_SEGMENT_REGEXP =
Matches runs of alphanumeric characters that are valid in prerelease segments. Prerelease segments must be separated by
.
or-
. /[0-9a-zA-Z]+/
- PRERELEASE_REGEXP =
Version pattern allowed by Rubygems for pre-release: runs of alphanumeric characters separated by
.
or-
. Group is captured to:prerelease
name. /(?<prerelease>#{PRERELEASE_SEGMENT_REGEXP}([-.]#{PRERELEASE_SEGMENT_REGEXP})*)/
- STAGING_REGEXP =
Regular expression that matches exactly a staging branch. It may optionally start with
ref/remotes
, followed by a type ofstaging
, no story ID, and a pre-release name. %r{ \A #{JENKINS_PREFIX_REGEXP} (?<type>staging) / #{PRERELEASE_REGEXP} \z }x
- STORY_REGEXP =
Regular expression that matches exactly a chore, feature or bug branch. It may optionally start with
ref/remotes
, followed by a type ofstaging
, story ID, and a pre-release name. %r{ \A #{JENKINS_PREFIX_REGEXP} (?<type>bug|chore|feature) / (?<story>[^/]+) / #{PRERELEASE_REGEXP} \z }x
- VERSION_PRERELEASE_SEGMENT_SEPARATOR_REGEXP =
Regular expression that matches separator used between prerelease segments for gem versions and tag versions.
/\.pre\./
- 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. %r{ \A v(?<major>\d+) \. (?<minor>\d+) \. (?<patch>\d+) (?: #{VERSION_PRERELEASE_SEGMENT_SEPARATOR_REGEXP} (?<gem_version_prerelease> #{PRERELEASE_SEGMENT_REGEXP} (#{VERSION_PRERELEASE_SEGMENT_SEPARATOR_REGEXP}#{PRERELEASE_SEGMENT_REGEXP})* ) )? \z }x
Class Method Summary collapse
-
.current ⇒ String
The current branch name from travis-ci or git.
-
.parse(branch) ⇒ 'HEAD', ...
Parses the branch.
-
.prerelease(gem_version_prerelease) ⇒ String?
Replaces
.pre.
ingem_version_prerelease
with-
to undo conversion to rubygems 1.8.6 compatible pre-release version.
Class Method Details
.current ⇒ String
The current branch name from travis-ci or git.
105 106 107 108 109 110 111 112 113 |
# 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 |
.parse(branch) ⇒ 'HEAD', ...
Parses the branch
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# 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 |
.prerelease(gem_version_prerelease) ⇒ String?
Replaces .pre.
in gem_version_prerelease
with -
to undo conversion to rubygems 1.8.6 compatible pre-release
version.
167 168 169 170 171 |
# 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 |