File tree 3 files changed +63
-6
lines changed
main/kotlin/com/squareup/invert/internal 3 files changed +63
-6
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,8 @@ dependencies {
38
38
39
39
implementation(libs.kotlinx.serialization.json)
40
40
implementation(libs.kotlinx.coroutines.core)
41
+
42
+ testImplementation(libs.kotlin.test)
41
43
}
42
44
43
45
kotlin {
Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ import java.io.IOException
11
11
*/
12
12
internal object GitDataCollector {
13
13
14
+ private const val GIT_EXTENSION = " .git"
15
+
14
16
fun currentBranch (): GitBranch {
15
17
return exec(" git rev-parse --abbrev-ref HEAD" ).stdOut.lines()[0 ]
16
18
}
@@ -32,16 +34,19 @@ internal object GitDataCollector {
32
34
it
33
35
}
34
36
}.map {
35
- val gitExtension = " .git"
36
- if (it.endsWith(gitExtension)) {
37
- it.substring(0 , it.length - gitExtension.length)
37
+ if (it.endsWith(GIT_EXTENSION )) {
38
+ it.substringBeforeLast(GIT_EXTENSION )
38
39
} else {
39
40
it
40
41
}
41
42
}.map {
42
- buildString {
43
- append(" https://" )
44
- append(it.replace(" :" , " /" ))
43
+ if (! it.startsWith(" https://" )) {
44
+ buildString {
45
+ append(" https://" )
46
+ append(it.replace(" :" , " /" ))
47
+ }
48
+ } else {
49
+ it
45
50
}
46
51
}[0 ]
47
52
}
Original file line number Diff line number Diff line change
1
+ package com.squareup.invert.internal
2
+
3
+ import com.squareup.invert.internal.exec
4
+ import com.squareup.invert.models.GitBranch
5
+ import com.squareup.invert.models.GitSha
6
+ import org.gradle.api.GradleException
7
+ import org.gradle.api.logging.Logger
8
+ import org.junit.Test
9
+ import java.io.IOException
10
+ import kotlin.test.assertEquals
11
+
12
+ /* *
13
+ * Executes `git` commands and parses the output.
14
+ */
15
+ class GitDataCollectorTest {
16
+
17
+ @Test
18
+ fun testOrgAtGit () {
19
+ val actual = GitDataCollector .remoteRepoGitUrlToHttps(
20
+ " org-123@github.com:company/my-repo.git"
21
+ )
22
+ assertEquals(
23
+ expected = " https://github.com/company/my-repo" ,
24
+ actual = actual
25
+ )
26
+ }
27
+
28
+ @Test
29
+ fun testHttpsDotGit () {
30
+ val actual = GitDataCollector .remoteRepoGitUrlToHttps(
31
+ " git@github.com:square/invert.git"
32
+ )
33
+ assertEquals(
34
+ expected = " https://github.com/square/invert" ,
35
+ actual = actual
36
+ )
37
+ }
38
+
39
+
40
+ @Test
41
+ fun testHttps () {
42
+ val actual = GitDataCollector .remoteRepoGitUrlToHttps(
43
+ " https://github.com/company/my-repo"
44
+ )
45
+ assertEquals(
46
+ expected = " https://github.com/company/my-repo" ,
47
+ actual = actual
48
+ )
49
+ }
50
+ }
You can’t perform that action at this time.
0 commit comments