Skip to content

Commit 99fa709

Browse files
runningcodeclaude
andauthored
feat(snapshots): Wire VCS extension to snapshots upload task (#1102)
* feat(snapshots): Wire VCS extension to snapshots upload task The VcsInfoExtension was only wired to the build upload task (size analysis). This wires the same VCS properties (head-sha, base-sha, vcs-provider, head/base-repo-name, head/base-ref, pr-number) to the snapshots upload task so sentry-cli can send git metadata with snapshot uploads. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * docs: Add changelog entry for VCS info in snapshots Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 7bced10 commit 99fa709

4 files changed

Lines changed: 89 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Features
6+
7+
- (Experimental) Wire VCS info extension to snapshot uploads for git metadata support ([#1102](https://github.com/getsentry/sentry-android-gradle-plugin/pull/1102))
8+
59
### Dependencies
610

711
- Bump CLI from v3.3.2 to v3.3.3 ([#1101](https://github.com/getsentry/sentry-android-gradle-plugin/pull/1101))

plugin-build/src/main/kotlin/io/sentry/android/gradle/extensions/VcsInfoExtension.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import org.gradle.api.model.ObjectFactory
55
import org.gradle.api.provider.Property
66

77
/**
8-
* Configuration for version control system information used in build uploads.
8+
* Configuration for version control system information used in build uploads and snapshots.
99
*
10-
* This extension only applies to build upload functionality (e.g., APK/AAB uploads for size
11-
* analysis) and has no effect on other plugin features such as ProGuard mapping uploads, source
12-
* context uploads, or instrumentation.
10+
* This extension applies to build upload functionality (e.g., APK/AAB uploads for size analysis)
11+
* and snapshot uploads. It has no effect on other plugin features such as ProGuard mapping uploads,
12+
* source context uploads, or instrumentation.
1313
*/
1414
open class VcsInfoExtension @Inject constructor(objects: ObjectFactory) {
1515

plugin-build/src/main/kotlin/io/sentry/android/gradle/tasks/SentryUploadSnapshotsTask.kt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import org.gradle.api.provider.Property
1010
import org.gradle.api.provider.Provider
1111
import org.gradle.api.tasks.Input
1212
import org.gradle.api.tasks.InputDirectory
13+
import org.gradle.api.tasks.Optional
1314
import org.gradle.api.tasks.PathSensitive
1415
import org.gradle.api.tasks.PathSensitivity
1516
import org.gradle.api.tasks.TaskProvider
@@ -29,11 +30,30 @@ abstract class SentryUploadSnapshotsTask : SentryCliExecTask() {
2930
@get:PathSensitive(PathSensitivity.RELATIVE)
3031
abstract val snapshotsPath: DirectoryProperty
3132

33+
@get:Input @get:Optional abstract val vcsHeadSha: Property<String>
34+
@get:Input @get:Optional abstract val vcsBaseSha: Property<String>
35+
@get:Input @get:Optional abstract val vcsProvider: Property<String>
36+
@get:Input @get:Optional abstract val vcsHeadRepoName: Property<String>
37+
@get:Input @get:Optional abstract val vcsBaseRepoName: Property<String>
38+
@get:Input @get:Optional abstract val vcsHeadRef: Property<String>
39+
@get:Input @get:Optional abstract val vcsBaseRef: Property<String>
40+
@get:Input @get:Optional abstract val vcsPrNumber: Property<Int>
41+
3242
override fun getArguments(args: MutableList<String>) {
3343
args.add("build")
3444
args.add("snapshots")
3545
args.add("--app-id")
3646
args.add(appId.get())
47+
48+
vcsHeadSha.orNull?.let { args.addAll(listOf("--head-sha", it)) }
49+
vcsBaseSha.orNull?.let { args.addAll(listOf("--base-sha", it)) }
50+
vcsProvider.orNull?.let { args.addAll(listOf("--vcs-provider", it)) }
51+
vcsHeadRepoName.orNull?.let { args.addAll(listOf("--head-repo-name", it)) }
52+
vcsBaseRepoName.orNull?.let { args.addAll(listOf("--base-repo-name", it)) }
53+
vcsHeadRef.orNull?.let { args.addAll(listOf("--head-ref", it)) }
54+
vcsBaseRef.orNull?.let { args.addAll(listOf("--base-ref", it)) }
55+
vcsPrNumber.orNull?.let { args.addAll(listOf("--pr-number", it.toString())) }
56+
3757
args.add(snapshotsPath.get().asFile.absolutePath)
3858
}
3959

@@ -65,6 +85,14 @@ abstract class SentryUploadSnapshotsTask : SentryCliExecTask() {
6585
task.sentryUrl.set(extension.url)
6686
task.appId.set(extension.snapshots.appId)
6787
task.snapshotsPath.set(extension.snapshots.path)
88+
task.vcsHeadSha.set(extension.vcsInfo.headSha)
89+
task.vcsBaseSha.set(extension.vcsInfo.baseSha)
90+
task.vcsProvider.set(extension.vcsInfo.vcsProvider)
91+
task.vcsHeadRepoName.set(extension.vcsInfo.headRepoName)
92+
task.vcsBaseRepoName.set(extension.vcsInfo.baseRepoName)
93+
task.vcsHeadRef.set(extension.vcsInfo.headRef)
94+
task.vcsBaseRef.set(extension.vcsInfo.baseRef)
95+
task.vcsPrNumber.set(extension.vcsInfo.prNumber)
6896
task.asSentryCliExec()
6997
}
7098
}

plugin-build/src/test/kotlin/io/sentry/android/gradle/tasks/SentryUploadSnapshotsTaskTest.kt

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.sentry.android.gradle.tasks
22

3+
import com.google.common.truth.Truth.assertThat
34
import java.io.File
45
import kotlin.test.assertEquals
56
import kotlin.test.assertFalse
@@ -123,6 +124,58 @@ class SentryUploadSnapshotsTaskTest {
123124
assertEquals(1, args.indexOf("--url"))
124125
}
125126

127+
@Test
128+
fun `all vcs parameters are passed to CLI correctly`() {
129+
val task = createTestTask {
130+
it.cliExecutable.set("sentry-cli")
131+
it.appId.set("com.example")
132+
it.snapshotsPath.set(File("/path/to/snapshots"))
133+
it.vcsHeadSha.set("abc123def456")
134+
it.vcsBaseSha.set("def456abc123")
135+
it.vcsProvider.set("github")
136+
it.vcsHeadRepoName.set("getsentry/sentry-android-gradle-plugin")
137+
it.vcsBaseRepoName.set("getsentry/sentry-android-gradle-plugin")
138+
it.vcsHeadRef.set("feature-branch")
139+
it.vcsBaseRef.set("main")
140+
it.vcsPrNumber.set(123)
141+
}
142+
143+
val args = task.computeCommandLineArgs()
144+
145+
assertThat(args).containsAtLeast("--head-sha", "abc123def456").inOrder()
146+
assertThat(args).containsAtLeast("--base-sha", "def456abc123").inOrder()
147+
assertThat(args).containsAtLeast("--vcs-provider", "github").inOrder()
148+
assertThat(args)
149+
.containsAtLeast("--head-repo-name", "getsentry/sentry-android-gradle-plugin")
150+
.inOrder()
151+
assertThat(args)
152+
.containsAtLeast("--base-repo-name", "getsentry/sentry-android-gradle-plugin")
153+
.inOrder()
154+
assertThat(args).containsAtLeast("--head-ref", "feature-branch").inOrder()
155+
assertThat(args).containsAtLeast("--base-ref", "main").inOrder()
156+
assertThat(args).containsAtLeast("--pr-number", "123").inOrder()
157+
}
158+
159+
@Test
160+
fun `vcs parameters are omitted when not set`() {
161+
val task = createTestTask {
162+
it.cliExecutable.set("sentry-cli")
163+
it.appId.set("com.example")
164+
it.snapshotsPath.set(File("/path/to/snapshots"))
165+
}
166+
167+
val args = task.computeCommandLineArgs()
168+
169+
assertThat(args).doesNotContain("--head-sha")
170+
assertThat(args).doesNotContain("--base-sha")
171+
assertThat(args).doesNotContain("--vcs-provider")
172+
assertThat(args).doesNotContain("--head-repo-name")
173+
assertThat(args).doesNotContain("--base-repo-name")
174+
assertThat(args).doesNotContain("--head-ref")
175+
assertThat(args).doesNotContain("--base-ref")
176+
assertThat(args).doesNotContain("--pr-number")
177+
}
178+
126179
private fun createProject(): Project {
127180
with(ProjectBuilder.builder().build()) {
128181
plugins.apply("io.sentry.android.gradle")

0 commit comments

Comments
 (0)