vgi_forge/pulls.rs
1//! Pull requests, as far as the pull-request gate needs them
2//! (`git-ns/bridge/event` 0.4 `pullRequestOpened`, `git-ns/bridge/job` 0.5
3//! `closePullRequest`).
4//!
5//! The gate is hygiene, not the merge gate: the required commit-trust check
6//! is what keeps untrusted commits out. So this is deliberately small — the
7//! state of one pull request, whether the adapter already commented on it,
8//! a comment, a close — and it never reads what a pull request contains.
9
10use serde::{Deserialize, Serialize};
11
12use crate::model::ForgeAccount;
13
14/// Where a pull request stands.
15#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
16#[serde(rename_all = "camelCase")]
17#[non_exhaustive]
18pub enum PullRequestState {
19 /// Open.
20 Open,
21 /// Closed without being merged.
22 Closed,
23 /// Merged (and so closed).
24 Merged,
25}
26
27/// A reopen of a pull request.
28#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
29#[serde(rename_all = "camelCase")]
30#[non_exhaustive]
31pub struct Reopen {
32 /// Who reopened it, as the forge records it (not assumed to be the
33 /// author).
34 pub by: ForgeAccount,
35 /// When, in Unix seconds.
36 pub at: i64,
37}
38
39impl Reopen {
40 /// A reopen by `by` at `at` (Unix seconds).
41 pub fn new(by: ForgeAccount, at: i64) -> Self {
42 Reopen { by, at }
43 }
44}
45
46/// One pull request, as [`crate::Forge::pull_request`] reads it now.
47#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
48#[serde(rename_all = "camelCase")]
49#[non_exhaustive]
50pub struct PullRequest {
51 /// Open, closed or merged.
52 pub state: PullRequestState,
53 /// The most recent reopen by an account **other than the adapter's
54 /// own** (its App or bot), if there was one. `closePullRequest` stands
55 /// down when this is later than the job: an owner's or maintainer's
56 /// reopen is a newer fact than the VTC's order to close.
57 pub last_reopen_by_other: Option<Reopen>,
58}
59
60impl PullRequest {
61 /// A pull request in `state`, never reopened by anyone else.
62 pub fn new(state: PullRequestState) -> Self {
63 PullRequest {
64 state,
65 last_reopen_by_other: None,
66 }
67 }
68
69 /// With the most recent reopen by another account.
70 pub fn with_reopen(mut self, reopen: Reopen) -> Self {
71 self.last_reopen_by_other = Some(reopen);
72 self
73 }
74
75 /// Whether it is open.
76 pub fn is_open(&self) -> bool {
77 self.state == PullRequestState::Open
78 }
79}