Skip to content

Commit d7189c9

Browse files
committed
emails: Adjust publish notification to show "by GitHub Actions" if applicable
1 parent 6d40900 commit d7189c9

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/tests/krate/publish/snapshots/crates_io__tests__krate__publish__trustpub__full_flow-11.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Content-Transfer-Encoding: quoted-printable
5454

5555
Hello foo!
5656

57-
A new version of the package foo (1.1.0) was published at [0000-00-00T00:00:00Z].
57+
A new version of the package foo (1.1.0) was published by GitHub Actions (https://github.com/rust-lang/foo-rs/actions/runs/example-run-id) at [0000-00-00T00:00:00Z].
5858

5959
If you have questions or security concerns, you can contact us at help@crates.io. If you would like to stop receiving these security notifications, you can disable them in your account settings.
6060

src/worker/jobs/send_publish_notifications.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::email::EmailMessage;
2-
use crate::models::OwnerKind;
2+
use crate::models::{OwnerKind, TrustpubData};
33
use crate::schema::{crate_owners, crates, emails, users, versions};
44
use crate::worker::Environment;
55
use anyhow::anyhow;
@@ -74,16 +74,25 @@ impl BackgroundJob for SendPublishNotificationsJob {
7474
let krate = &publish_details.krate;
7575
let version = &publish_details.version;
7676

77-
let publisher_info = match &publish_details.publisher {
78-
Some(publisher) if publisher == recipient => &format!(
77+
let publisher_info = match (&publish_details.publisher, &publish_details.trustpub_data)
78+
{
79+
(Some(publisher), _) if publisher == recipient => &format!(
7980
" by your account (https://{domain}/users/{publisher})",
8081
domain = ctx.config.domain_name
8182
),
82-
Some(publisher) => &format!(
83+
(Some(publisher), _) => &format!(
8384
" by {publisher} (https://{domain}/users/{publisher})",
8485
domain = ctx.config.domain_name
8586
),
86-
None => "",
87+
(
88+
_,
89+
Some(TrustpubData::GitHub {
90+
repository, run_id, ..
91+
}),
92+
) => &format!(
93+
" by GitHub Actions (https://github.com/{repository}/actions/runs/{run_id})",
94+
),
95+
_ => "",
8796
};
8897

8998
let email = EmailMessage::from_template(
@@ -154,6 +163,8 @@ struct PublishDetails {
154163
publish_time: DateTime<Utc>,
155164
#[diesel(select_expression = users::columns::gh_login.nullable())]
156165
publisher: Option<String>,
166+
#[diesel(select_expression = versions::columns::trustpub_data.nullable())]
167+
trustpub_data: Option<TrustpubData>,
157168
}
158169

159170
impl PublishDetails {

0 commit comments

Comments
 (0)