Skip to content

Commit bd33a24

Browse files
ref(bundles): Introduce BundleContext struct (#2923)
### Description As we don't need all of the fields of the `UploadContext` struct for `source_bundle::build` (in particular, we don't need the `chunk_upload_options`), we introduce a new struct with only the fields needed for the function. We will use this new struct in the next PR to avoid needing to get chunk upload options for the `bundle-jvm` command. ### Issues - See #2927 - See [CLI-220](https://linear.app/getsentry/issue/CLI-220/dont-call-chunk-upload-for-bundle-jvm)
1 parent edd0d61 commit bd33a24

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

src/utils/source_bundle.rs

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,39 @@ use url::Url;
1010

1111
use crate::utils::file_upload::{SourceFiles, UploadContext};
1212
use crate::utils::fs::TempFile;
13+
use crate::utils::non_empty::NonEmptySlice;
1314
use crate::utils::progress::ProgressBar;
1415

16+
#[derive(Clone, Copy, Debug, Default)]
17+
pub struct BundleContext<'a> {
18+
org: &'a str,
19+
projects: Option<NonEmptySlice<'a, String>>,
20+
note: Option<&'a str>,
21+
release: Option<&'a str>,
22+
dist: Option<&'a str>,
23+
}
24+
25+
impl<'a> From<&'a UploadContext<'a>> for BundleContext<'a> {
26+
fn from(context: &'a UploadContext<'a>) -> Self {
27+
Self {
28+
org: context.org,
29+
projects: context.projects,
30+
note: context.note,
31+
release: context.release,
32+
dist: context.dist,
33+
}
34+
}
35+
}
36+
1537
/// Builds a source bundle from a list of source files, setting the metadata
1638
/// from the upload context.
1739
///
1840
/// Returns a `TempFile` containing the source bundle.
19-
pub fn build(
20-
context: &UploadContext,
21-
files: &SourceFiles,
22-
debug_id: Option<DebugId>,
23-
) -> Result<TempFile> {
41+
pub fn build<'a, C>(context: C, files: &SourceFiles, debug_id: Option<DebugId>) -> Result<TempFile>
42+
where
43+
C: Into<BundleContext<'a>>,
44+
{
45+
let context = context.into();
2446
let progress_style = ProgressStyle::default_bar().template(
2547
"{prefix:.dim} Bundling files for upload... {msg:.dim}\
2648
\n{wide_bar} {pos}/{len}",
@@ -152,7 +174,7 @@ mod tests {
152174
use sha1_smol::Sha1;
153175
use symbolic::debuginfo::sourcebundle::SourceFileType;
154176

155-
use crate::{constants::DEFAULT_MAX_WAIT, utils::file_upload::SourceFile};
177+
use crate::utils::file_upload::SourceFile;
156178

157179
use super::*;
158180

@@ -184,15 +206,12 @@ mod tests {
184206
#[test]
185207
fn build_deterministic() {
186208
let projects_slice = &["wat-project".into()];
187-
let context = UploadContext {
209+
let context = BundleContext {
188210
org: "wat-org",
189211
projects: Some(projects_slice.into()),
190212
release: None,
191213
dist: None,
192214
note: None,
193-
wait: false,
194-
max_wait: DEFAULT_MAX_WAIT,
195-
chunk_upload_options: None,
196215
};
197216

198217
let source_files = ["bundle.min.js.map", "vendor.min.js.map"]
@@ -213,7 +232,7 @@ mod tests {
213232
})
214233
.collect();
215234

216-
let file = build(&context, &source_files, None).unwrap();
235+
let file = build(context, &source_files, None).unwrap();
217236

218237
let buf = std::fs::read(file.path()).unwrap();
219238
let hash = Sha1::from(buf);

0 commit comments

Comments
 (0)