Skip to content

Commit a0e4c05

Browse files
committed
emails: Adjust publish notification to show "by GitHub Actions" if applicable
1 parent d47a5b5 commit a0e4c05

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-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: 10 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,19 @@ 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+
(Some(publisher), _) if publisher == recipient => &format!(
7979
" by your account (https://{domain}/users/{publisher})",
8080
domain = ctx.config.domain_name
8181
),
82-
Some(publisher) => &format!(
82+
(Some(publisher), _) => &format!(
8383
" by {publisher} (https://{domain}/users/{publisher})",
8484
domain = ctx.config.domain_name
8585
),
86-
None => "",
86+
(None, Some(TrustpubData::GitHub { repository, run_id, .. })) => &format!(
87+
" by GitHub Actions (https://github.com/{repository}/actions/runs/{run_id})",
88+
),
89+
(None, _) => "",
8790
};
8891

8992
let email = EmailMessage::from_template(
@@ -154,6 +157,8 @@ struct PublishDetails {
154157
publish_time: DateTime<Utc>,
155158
#[diesel(select_expression = users::columns::gh_login.nullable())]
156159
publisher: Option<String>,
160+
#[diesel(select_expression = versions::columns::trustpub_data.nullable())]
161+
trustpub_data: Option<TrustpubData>,
157162
}
158163

159164
impl PublishDetails {

0 commit comments

Comments
 (0)