Skip to content

Commit 075e709

Browse files
authored
Merge pull request #276 from rahulsom/commented-regex
refactor: Use commented regex
2 parents 59cab66 + 9464a59 commit 075e709

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

waena-plugin/src/main/kotlin/com/github/rahulsom/waena/WaenaPublishedPlugin.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,17 @@ class WaenaPublishedPlugin : Plugin<Project> {
141141
val originUrl = origin ?: scmInfoPlugin.findProvider(project).calculateOrigin(project)
142142

143143
val hostedRepoRegex =
144-
Regex("^(?:https?://|git://|git@)(?<host>[^/:]+)[:/](?<owner>[^/]+)/(?<repo>[^/]+?)(?:.git)?$")
144+
Regex("""
145+
^ # Start of the string
146+
(?:https?://|git://|git@) # Match the protocol (http, https, git) or git@
147+
(?<host>[^/:]+) # Match the host (e.g., github.com)
148+
[/:] # Match either : or /
149+
(?<owner>[^/]+) # Match the owner (user or organization)
150+
/ # Match the / separator
151+
(?<repo>[^/]+?) # Match the repository name (non-greedy)
152+
(?:.git)? # Optionally match the .git suffix
153+
$ # End of the string
154+
""", RegexOption.COMMENTS)
145155
val matchResult = hostedRepoRegex.matchEntire(originUrl)
146156
val (host, repo) = matchResult?.let {
147157
val host = it.groups["host"]?.value ?: ""

0 commit comments

Comments
 (0)