Skip to content

Compare changes

Choose two branches to see what one has that the other does not, then open a pull request for it.

Open a pull request

1 commit

4 files+26−30/4 viewed
+2−1
8585 pub issue: Option<u32>,
8686 #[serde(skip_serializing_if = "Option::is_none")]
8787 pub agent: Option<String>,
88− /// On merge: the commit the branch now points to.
88+ /// On merge: the commit the branch now points to. On update and when
89+ /// marked ready: the head of the change.
8990 #[serde(skip_serializing_if = "Option::is_none")]
9091 pub commit: Option<String>,
9192 /// On close: the pull request that was merged instead.
+1−0
412412 #[serde(rename_all = "camelCase")]
413413 pub struct HeadArgs {
414414 pub repo_id: String,
415+ /// Empty for the repository's default branch.
415416 pub branch: String,
416417 }
417418
+2−1
513513 let Some(repo) = self.registry.by_id(&a.repo_id).await? else {
514514 return Ok(None);
515515 };
516+ let branch = if a.branch.is_empty() { &repo.default_branch } else { &a.branch };
516517 let git = self.store.open(&store_key(&repo)).await?;
517518 Ok(git
518− .log(&a.branch, 1)
519+ .log(branch, 1)
519520 .await?
520521 .into_iter()
521522 .next()
+21−1
340340 }
341341 }
342342
343+ /// The commit a pull request's change is at in git right now: its
344+ /// fork's default branch, or its branch.
345+ async fn live_head(&self, pull: &Pull) -> Result<Option<String>> {
346+ g1t_kit::call(
347+ &self.repos,
348+ "head",
349+ &HeadArgs {
350+ repo_id: pull.fork_repo_id.clone().unwrap_or_else(|| pull.repo_id.clone()),
351+ branch: pull.branch.clone().unwrap_or_default(),
352+ },
353+ )
354+ .await
355+ }
356+
343357 fn pull_event(pull: &Pull) -> PullEvent {
344358 PullEvent {
345359 pull_id: pull.id.clone(),
12081222 .run()
12091223 .await?;
12101224 if pull.status == PullStatus::Draft {
1225+ // The head as it is now: the push that came just before may not
1226+ // have reached `head_commit` yet, and workflows run on it.
1227+ let commit = self.live_head(&pull).await?.or_else(|| pull.head_commit.clone());
12111228 self.publish(
12121229 "pull.ready",
12131230 &pull.repo_id,
12141231 &a.actor,
1215− Self::pull_event(&pull),
1232+ PullEvent {
1233+ commit,
1234+ ..Self::pull_event(&pull)
1235+ },
12161236 )
12171237 .await?;
12181238 }