@@ -378,25 +378,29 @@ class MonitoringManager {
378
378
}
379
379
}
380
380
381
+ struct Pattern {
382
+ var expression : String
383
+ var group : Int
384
+ }
385
+
381
386
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 )
389
394
]
390
395
391
396
for pattern in patterns {
392
397
do {
393
- let regex = try NSRegularExpression ( pattern: pattern)
398
+ let regex = try NSRegularExpression ( pattern: pattern. expression )
394
399
let nsrange = NSRange ( url. startIndex..< url. endIndex, in: url)
395
400
if let match = regex. firstMatch ( in: url, options: [ ] , range: nsrange) {
396
401
// Adjusted to capture the right group based on the pattern.
397
402
// 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)
400
404
401
405
if range. location != NSNotFound, let range = Range ( range, in: url) {
402
406
return String ( url [ range] )
0 commit comments