Workflows run when an agent's pull request is marked ready
pull.ready carried no commit, so the actions service ran a pull request's workflows on its recorded head. An agent pushes and marks the pull request ready in a moment, and when the issue has acceptance checks, starting them records the head too, so the push that follows no longer counts as a move and no pull.updated is sent. When the actions service read the pull request before then, there was no head and nothing ran: hello's #83 was green on its checks and met CI only in the merge queue. The event now carries the head as git has it, read from the repos service (head with an empty branch means the default branch, where a fork carries its change).
4 files+26−30/4 viewed
| 85 | 85 | pub issue: Option<u32>, | |
| 86 | 86 | #[serde(skip_serializing_if = "Option::is_none")] | |
| 87 | 87 | 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. | |
| 89 | 90 | #[serde(skip_serializing_if = "Option::is_none")] | |
| 90 | 91 | pub commit: Option<String>, | |
| 91 | 92 | /// On close: the pull request that was merged instead. |
| 412 | 412 | #[serde(rename_all = "camelCase")] | |
| 413 | 413 | pub struct HeadArgs { | |
| 414 | 414 | pub repo_id: String, | |
| 415 | + | /// Empty for the repository's default branch. | |
| 415 | 416 | pub branch: String, | |
| 416 | 417 | } | |
| 417 | 418 |
| 513 | 513 | let Some(repo) = self.registry.by_id(&a.repo_id).await? else { | |
| 514 | 514 | return Ok(None); | |
| 515 | 515 | }; | |
| 516 | + | let branch = if a.branch.is_empty() { &repo.default_branch } else { &a.branch }; | |
| 516 | 517 | let git = self.store.open(&store_key(&repo)).await?; | |
| 517 | 518 | Ok(git | |
| 518 | − | .log(&a.branch, 1) | |
| 519 | + | .log(branch, 1) | |
| 519 | 520 | .await? | |
| 520 | 521 | .into_iter() | |
| 521 | 522 | .next() |
| 340 | 340 | } | |
| 341 | 341 | } | |
| 342 | 342 | ||
| 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 | + | ||
| 343 | 357 | fn pull_event(pull: &Pull) -> PullEvent { | |
| 344 | 358 | PullEvent { | |
| 345 | 359 | pull_id: pull.id.clone(), | |
| 1208 | 1222 | .run() | |
| 1209 | 1223 | .await?; | |
| 1210 | 1224 | 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()); | |
| 1211 | 1228 | self.publish( | |
| 1212 | 1229 | "pull.ready", | |
| 1213 | 1230 | &pull.repo_id, | |
| 1214 | 1231 | &a.actor, | |
| 1215 | − | Self::pull_event(&pull), | |
| 1232 | + | PullEvent { | |
| 1233 | + | commit, | |
| 1234 | + | ..Self::pull_event(&pull) | |
| 1235 | + | }, | |
| 1216 | 1236 | ) | |
| 1217 | 1237 | .await?; | |
| 1218 | 1238 | } |