diff --git a/src/Git/Repository.php b/src/Git/Repository.php index 188c95b..72d3af6 100644 --- a/src/Git/Repository.php +++ b/src/Git/Repository.php @@ -218,4 +218,29 @@ protected static function parseShortcodes($content, $shortcodes) return $result; } + + /** + * Parse remote url. + * + * @return array|false + */ + public static function parseRemoteUrl() + { + $url = self::getRemoteUrl(); + $patterns = [ + '#^(?Phttps?|git|ssh|rsync)\://(?:(?P.+)@)*(?P[a-z0-9_.-]*)[:/]*(?P[\d]+){0,1}(?P\/((?P[\w\-]+)\/)?((?P[\w\-\.]+?)(\.git|\/)?)?)$#smi', + '#(git\+)?((?P\w+)://)((?P\w+)@)?((?P[\w\.\-]+))(:(?P\d+))?(?P(\/(?P\w+)/)?(\/?(?P[\w\-]+)(\.git|\/)?)?)$#smi', + '#^(?:(?P.+)@)*(?P[a-z0-9_.-]*)[:]*(?P[\d]+){0,1}(?P\/?(?P.+)/(?P.+).git)$#smi', + '#((?P\w+)@)?((?P[\w\.\-]+))[\:\/]{1,2}(?P((?P\w+)/)?((?P[\w\-]+)(\.git|\/)?)?)$#smi', + ]; + foreach ($patterns as $pattern) { + if (preg_match($pattern, $url, $match)) { + $match = array_filter($match, 'is_string', ARRAY_FILTER_USE_KEY); + + return $match; + } + } + + return false; + } }