forge
Explore
Log in

Don't you dare go Hollow

forge

Clone
★ 0

0 watching0 forksRustAGPL-3.010.5 MiBbcaef90Tahinli1 month ago164 commits

merge_queue.rs89 lines, 2.7 KiBHistoryRawDownload
1//! The merge queue: pull requests waiting to be merged into a protected branch that requires the
2//! queue. Each entry is `queued`, then `testing` (its candidate commit runs CI), then `merging`
3//! (the target moves to the tested commit). An entry finishes as `failed` or `removed`.
4
5use crate::error::{Error, Result};
6use crate::pulls::MergeStyle;
7
8/// Where an entry is in the queue.
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub enum QueueState {
11 Queued,
12 Testing,
13 Merging,
14 Failed,
15 Removed,
16}
17
18impl QueueState {
19 pub fn as_str(self) -> &'static str {
20 match self {
21 QueueState::Queued => "queued",
22 QueueState::Testing => "testing",
23 QueueState::Merging => "merging",
24 QueueState::Failed => "failed",
25 QueueState::Removed => "removed",
26 }
27 }
28
29 /// Whether the entry still waits for the queue (queued, testing or merging).
30 pub fn is_active(self) -> bool {
31 matches!(
32 self,
33 QueueState::Queued | QueueState::Testing | QueueState::Merging
34 )
35 }
36}
37
38impl std::str::FromStr for QueueState {
39 type Err = Error;
40
41 fn from_str(s: &str) -> Result<Self> {
42 Ok(match s {
43 "queued" => QueueState::Queued,
44 "testing" => QueueState::Testing,
45 "merging" => QueueState::Merging,
46 "failed" => QueueState::Failed,
47 "removed" => QueueState::Removed,
48 other => {
49 return Err(Error::Database(format!(
50 "unknown merge queue state {other}"
51 )));
52 }
53 })
54 }
55}
56
57/// One pull request in the queue.
58#[derive(Debug, Clone, PartialEq, Eq)]
59pub struct QueueEntry {
60 pub id: String,
61 pub repo_id: String,
62 pub branch: String,
63 pub issue_id: String,
64 pub pull_number: i64,
65 pub merge_style: MergeStyle,
66 pub state: QueueState,
67 /// Enqueue order within the branch. Smaller entries go first.
68 pub seq: i64,
69 pub enqueued_by: String,
70 pub enqueued_at: String,
71 pub updated_at: String,
72 pub finished_at: Option<String>,
73 /// Why a finished entry ended: `merged`, `removed`, `closed`, `head_changed`, `conflict` or
74 /// `tests_failed`.
75 pub reason: Option<String>,
76 /// The target tip the candidate was built on.
77 pub base_oid: Option<String>,
78 /// The candidate commit under test.
79 pub tested_oid: Option<String>,
80 /// The temporary ref that names the candidate.
81 pub test_ref: Option<String>,
82 /// The CI run that tests the candidate.
83 pub run_id: Option<String>,
84}
85
86/// The temporary ref that names a candidate of `branch` for pull request `number`.
87pub fn test_ref_name(branch: &str, number: i64) -> String {
88 format!("refs/forge/merge-queue/{branch}/{number}")
89}