Skip to content

Commit 4384fc3

Browse files
committed
docs-update: Switch to using a separate repo for creating the commits.
1 parent 9c29701 commit 4384fc3

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

src/github.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,6 +1499,23 @@ impl Repository {
14991499
issue.pull_request = Some(PullRequestDetails {});
15001500
Ok(issue)
15011501
}
1502+
1503+
/// Synchronize a branch (in a forked repository) by pulling in its upstream contents.
1504+
pub async fn merge_upstream(&self, client: &GithubClient, branch: &str) -> anyhow::Result<()> {
1505+
let url = format!("{}/merge-upstream", self.url());
1506+
client
1507+
._send_req(client.post(&url).json(&serde_json::json!({
1508+
"branch": branch,
1509+
})))
1510+
.await
1511+
.with_context(|| {
1512+
format!(
1513+
"{} failed to merge upstream branch {branch}",
1514+
self.full_name
1515+
)
1516+
})?;
1517+
Ok(())
1518+
}
15021519
}
15031520

15041521
pub struct Query<'a> {

src/handlers/docs_update.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ use reqwest::Client;
99
use std::fmt::Write;
1010
use std::str::FromStr;
1111

12+
/// This is the repository where the commits will be created.
13+
const WORK_REPO: &str = "rustbot/rust";
14+
/// This is the repository where the PR will be created.
15+
const DEST_REPO: &str = "rust-lang/rust";
16+
/// This is the branch in `WORK_REPO` to create the commits.
1217
const BRANCH_NAME: &str = "docs-update";
1318

1419
const SUBMODULES: &[&str] = &[
@@ -56,16 +61,19 @@ pub async fn handle_job() -> Result<()> {
5661

5762
async fn docs_update() -> Result<()> {
5863
let gh = GithubClient::new_with_default_token(Client::new());
59-
let repo = gh.repository("rust-lang/rust").await?;
64+
let work_repo = gh.repository(WORK_REPO).await?;
65+
work_repo
66+
.merge_upstream(&gh, &work_repo.default_branch)
67+
.await?;
6068

61-
let updates = get_submodule_updates(&gh, &repo).await?;
69+
let updates = get_submodule_updates(&gh, &work_repo).await?;
6270
if updates.is_empty() {
6371
tracing::trace!("no updates this week?");
6472
return Ok(());
6573
}
6674

67-
create_commit(&gh, &repo, &updates).await?;
68-
create_pr(&gh, &repo, &updates).await?;
75+
create_commit(&gh, &work_repo, &updates).await?;
76+
create_pr(&gh, &updates).await?;
6977
Ok(())
7078
}
7179

@@ -176,14 +184,17 @@ async fn create_commit(
176184
Ok(())
177185
}
178186

179-
async fn create_pr(gh: &GithubClient, rust_repo: &Repository, updates: &[Update]) -> Result<()> {
187+
async fn create_pr(gh: &GithubClient, updates: &[Update]) -> Result<()> {
188+
let dest_repo = gh.repository(DEST_REPO).await?;
180189
let mut body = String::new();
181190
for update in updates {
182191
write!(body, "{}\n", update.pr_body).unwrap();
183192
}
184193

185-
let pr = rust_repo
186-
.new_pr(gh, TITLE, BRANCH_NAME, &rust_repo.default_branch, &body)
194+
let username = WORK_REPO.split('/').next().unwrap();
195+
let head = format!("{username}:{BRANCH_NAME}");
196+
let pr = dest_repo
197+
.new_pr(gh, TITLE, &head, &dest_repo.default_branch, &body)
187198
.await?;
188199
tracing::debug!("created PR {}", pr.html_url);
189200
Ok(())

0 commit comments

Comments
 (0)