Skip to content

Commit dfff11c

Browse files
committed
database/NewVersion: Make published_by_email argument of save() fn optional
This "Trusted Publishing" the CI service performs the publishing, so there is no corresponding email address in that case.
1 parent 73b4dbf commit dfff11c

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

crates/crates_io_database/src/models/version.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub struct NewVersion<'a> {
9191
license: Option<&'a str>,
9292
#[builder(default, name = "size")]
9393
crate_size: i32,
94-
published_by: i32,
94+
published_by: Option<i32>,
9595
checksum: &'a str,
9696
links: Option<&'a str>,
9797
rust_version: Option<&'a str>,
@@ -110,7 +110,7 @@ impl NewVersion<'_> {
110110
pub async fn save(
111111
&self,
112112
conn: &mut AsyncPgConnection,
113-
published_by_email: &str,
113+
published_by_email: Option<&str>,
114114
) -> QueryResult<Version> {
115115
use diesel::insert_into;
116116

@@ -122,13 +122,15 @@ impl NewVersion<'_> {
122122
.get_result(conn)
123123
.await?;
124124

125-
insert_into(versions_published_by::table)
126-
.values((
127-
versions_published_by::version_id.eq(version.id),
128-
versions_published_by::email.eq(published_by_email),
129-
))
130-
.execute(conn)
131-
.await?;
125+
if let Some(published_by_email) = published_by_email {
126+
insert_into(versions_published_by::table)
127+
.values((
128+
versions_published_by::version_id.eq(version.id),
129+
versions_published_by::email.eq(published_by_email),
130+
))
131+
.execute(conn)
132+
.await?;
133+
}
132134

133135
Ok(version)
134136
}

src/tests/builders/version.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ impl VersionBuilder {
110110
.maybe_created_at(self.created_at.as_ref())
111111
.build();
112112

113-
let vers = new_version.save(connection, "[email protected]").await?;
113+
let vers = new_version
114+
.save(connection, Some("[email protected]"))
115+
.await?;
114116

115117
let new_deps = self
116118
.dependencies

src/worker/jobs/downloads/update_metadata.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ mod tests {
136136
.checksum("0000000000000000000000000000000000000000000000000000000000000000")
137137
.build();
138138

139-
let version = version.save(conn, "[email protected]").await.unwrap();
139+
let version = version.save(conn, None).await.unwrap();
140140
(krate, version)
141141
}
142142

0 commit comments

Comments
 (0)