From b63d9d623e28d20967c2e3b8adfc4d6586f99efc Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Sat, 2 Jul 2016 10:49:49 +0200 Subject: [PATCH] Parser: RegExp with named capture groups --- lib/github_changelog_generator/parser.rb | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/github_changelog_generator/parser.rb b/lib/github_changelog_generator/parser.rb index 0a3833d..6275aca 100755 --- a/lib/github_changelog_generator/parser.rb +++ b/lib/github_changelog_generator/parser.rb @@ -275,8 +275,8 @@ module GitHubChangelogGenerator # https://github.com/skywinder/ChangelogMerger # ``` GIT_REMOTE_PATTERNS = [ - /.*(?:[:\/])((?:-|\w|\.)*)\/((?:-|\w|\.)*)(?:\.git).*/, - /.*\/((?:-|\w|\.)*)\/((?:-|\w|\.)*).*/ + /.*(?:[:\/])(?(?:-|\w|\.)*)\/(?(?:-|\w|\.)*)(?:\.git).*/, + /.*\/(?(?:-|\w|\.)*)\/(?(?:-|\w|\.)*).*/ ] # Returns GitHub username and project from git remote output @@ -288,15 +288,13 @@ module GitHubChangelogGenerator user = nil project = nil GIT_REMOTE_PATTERNS.each do |git_remote_pattern| - matches = Regexp.new(git_remote_pattern).match(git_remote_output) + git_remote_pattern =~ git_remote_output - if matches && matches[1] && matches[2] - puts "Detected user:#{matches[1]}, project:#{matches[2]}" - user = matches[1] - project = matches[2] + if Regexp.last_match + user = Regexp.last_match(:user) + project = Regexp.last_match(:project) + break end - - break if matches end [user, project]