Skip to content

Commit 95e873f

Browse files
committed
Add ability to trigger a docs-update via Zulip.
1 parent 2c62a45 commit 95e873f

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

src/handlers/docs_update.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! A scheduled job to post a PR to update the documentation on rust-lang/rust.
22
33
use crate::db::jobs::JobSchedule;
4-
use crate::github::{self, GitTreeEntry, GithubClient, Repository};
4+
use crate::github::{self, GitTreeEntry, GithubClient, Issue, Repository};
55
use anyhow::Context;
66
use anyhow::Result;
77
use cron::Schedule;
@@ -56,10 +56,13 @@ pub async fn handle_job() -> Result<()> {
5656
}
5757

5858
tracing::trace!("starting docs-update");
59-
docs_update().await.context("failed to process docs update")
59+
docs_update()
60+
.await
61+
.context("failed to process docs update")?;
62+
Ok(())
6063
}
6164

62-
async fn docs_update() -> Result<()> {
65+
pub async fn docs_update() -> Result<Option<Issue>> {
6366
let gh = GithubClient::new_with_default_token(Client::new());
6467
let work_repo = gh.repository(WORK_REPO).await?;
6568
work_repo
@@ -69,12 +72,11 @@ async fn docs_update() -> Result<()> {
6972
let updates = get_submodule_updates(&gh, &work_repo).await?;
7073
if updates.is_empty() {
7174
tracing::trace!("no updates this week?");
72-
return Ok(());
75+
return Ok(None);
7376
}
7477

7578
create_commit(&gh, &work_repo, &updates).await?;
76-
create_pr(&gh, &updates).await?;
77-
Ok(())
79+
Ok(Some(create_pr(&gh, &updates).await?))
7880
}
7981

8082
struct Update {
@@ -184,7 +186,7 @@ async fn create_commit(
184186
Ok(())
185187
}
186188

187-
async fn create_pr(gh: &GithubClient, updates: &[Update]) -> Result<()> {
189+
async fn create_pr(gh: &GithubClient, updates: &[Update]) -> Result<Issue> {
188190
let dest_repo = gh.repository(DEST_REPO).await?;
189191
let mut body = String::new();
190192
for update in updates {
@@ -197,5 +199,5 @@ async fn create_pr(gh: &GithubClient, updates: &[Update]) -> Result<()> {
197199
.new_pr(gh, TITLE, &head, &dest_repo.default_branch, &body)
198200
.await?;
199201
tracing::debug!("created PR {}", pr.html_url);
200-
Ok(())
202+
Ok(pr)
201203
}

src/zulip.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::db::notifications::add_metadata;
22
use crate::db::notifications::{self, delete_ping, move_indices, record_ping, Identifier};
33
use crate::github::{self, GithubClient};
4+
use crate::handlers::docs_update::docs_update;
45
use crate::handlers::Context;
56
use anyhow::{format_err, Context as _};
67
use std::convert::TryInto;
@@ -144,6 +145,7 @@ fn handle_command<'a>(
144145
.await
145146
.map_err(|e| format_err!("Failed to await at this time: {e:?}"))
146147
}
148+
Some("docs-update") => return trigger_docs_update().await,
147149
_ => {}
148150
}
149151
}
@@ -695,3 +697,17 @@ async fn post_waiter(
695697
})
696698
.unwrap())
697699
}
700+
701+
async fn trigger_docs_update() -> anyhow::Result<String> {
702+
match docs_update().await {
703+
Ok(None) => Ok("No updates found.".to_string()),
704+
Ok(Some(pr)) => Ok(format!("Created docs update PR <{}>", pr.html_url)),
705+
Err(e) => {
706+
// Don't send errors to Zulip since they may contain sensitive data.
707+
log::error!("Docs update via Zulip failed: {e:?}");
708+
Err(format_err!(
709+
"Docs update failed, please check the logs for more details."
710+
))
711+
}
712+
}
713+
}

0 commit comments

Comments
 (0)