@@ -378,25 +378,29 @@ class MonitoringManager {
378378 }
379379 }
380380
381+ struct Pattern {
382+ var expression : String
383+ var group : Int
384+ }
385+
381386 static func project( from url: String ) -> String ? {
382- let patterns = [
383- " github.com/( [^/]+/[^/]+)/?.*$ " ,
384- " gitlab.com/( [^/]+/[^/]+)/?.*$ " ,
385- " bitbucket.org/( [^/]+/[^/]+)/?.*$ " ,
386- " app.circleci.com/.*/?(github|bitbucket|gitlab)/( [^/]+/[^/]+)/?.*$ " ,
387- " app.travis-ci.com/(github|bitbucket|gitlab)/( [^/]+/[^/]+)/?.*$ " ,
388- " app.travis-ci.org/(github|bitbucket|gitlab)/( [^/]+/[^/]+)/?.*$ "
387+ let patterns : [ Pattern ] = [
388+ Pattern ( expression : " github.com/[^/]+/( [^/]+)/?.*$ " , group : 1 ) ,
389+ Pattern ( expression : " gitlab.com/[^/]+/( [^/]+)/?.*$ " , group : 1 ) ,
390+ Pattern ( expression : " bitbucket.org/[^/]+/( [^/]+)/?.*$ " , group : 1 ) ,
391+ Pattern ( expression : " app.circleci.com/.*/?(github|bitbucket|gitlab)/[^/]+/( [^/]+)/?.*$ " , group : 2 ) ,
392+ Pattern ( expression : " app.travis-ci.com/(github|bitbucket|gitlab)/[^/]+/( [^/]+)/?.*$ " , group : 2 ) ,
393+ Pattern ( expression : " app.travis-ci.org/(github|bitbucket|gitlab)/[^/]+/( [^/]+)/?.*$ " , group : 2 )
389394 ]
390395
391396 for pattern in patterns {
392397 do {
393- let regex = try NSRegularExpression ( pattern: pattern)
398+ let regex = try NSRegularExpression ( pattern: pattern. expression )
394399 let nsrange = NSRange ( url. startIndex..< url. endIndex, in: url)
395400 if let match = regex. firstMatch ( in: url, options: [ ] , range: nsrange) {
396401 // Adjusted to capture the right group based on the pattern.
397402 // The group index might be 2 if the pattern includes a platform prefix before the project name.
398- let groupIndex = pattern. contains ( " (github|bitbucket|gitlab) " ) ? 2 : 1
399- let range = match. range ( at: groupIndex)
403+ let range = match. range ( at: pattern. group)
400404
401405 if range. location != NSNotFound, let range = Range ( range, in: url) {
402406 return String ( url [ range] )
0 commit comments