rung_github/
types.rs

1//! GitHub API types.
2
3use serde::{Deserialize, Serialize};
4
5/// A GitHub Pull Request.
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct PullRequest {
8    /// PR number.
9    pub number: u64,
10
11    /// PR title.
12    pub title: String,
13
14    /// PR body/description.
15    pub body: Option<String>,
16
17    /// PR state.
18    pub state: PullRequestState,
19
20    /// Whether this is a draft PR.
21    pub draft: bool,
22
23    /// Head branch name.
24    pub head_branch: String,
25
26    /// Base branch name.
27    pub base_branch: String,
28
29    /// PR URL.
30    pub html_url: String,
31}
32
33/// State of a pull request.
34#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
35#[serde(rename_all = "lowercase")]
36pub enum PullRequestState {
37    /// PR is open.
38    Open,
39    /// PR was closed without merging.
40    Closed,
41    /// PR was merged.
42    Merged,
43}
44
45/// A CI check run.
46#[derive(Debug, Clone, Serialize, Deserialize)]
47pub struct CheckRun {
48    /// Check name.
49    pub name: String,
50
51    /// Check status.
52    pub status: CheckStatus,
53
54    /// URL to view check details.
55    pub details_url: Option<String>,
56}
57
58/// Status of a CI check.
59#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
60#[serde(rename_all = "lowercase")]
61pub enum CheckStatus {
62    /// Check is queued.
63    Queued,
64    /// Check is in progress.
65    InProgress,
66    /// Check completed successfully.
67    Success,
68    /// Check failed.
69    Failure,
70    /// Check was skipped.
71    Skipped,
72    /// Check was cancelled.
73    Cancelled,
74}
75
76impl CheckStatus {
77    /// Check if this status indicates success.
78    #[must_use]
79    pub const fn is_success(&self) -> bool {
80        matches!(self, Self::Success | Self::Skipped)
81    }
82
83    /// Check if this status indicates failure.
84    #[must_use]
85    pub const fn is_failure(&self) -> bool {
86        matches!(self, Self::Failure)
87    }
88
89    /// Check if this status indicates the check is still running.
90    #[must_use]
91    pub const fn is_pending(&self) -> bool {
92        matches!(self, Self::Queued | Self::InProgress)
93    }
94}
95
96/// Request to create a pull request.
97#[derive(Debug, Serialize)]
98pub struct CreatePullRequest {
99    /// PR title.
100    pub title: String,
101
102    /// PR body.
103    pub body: String,
104
105    /// Head branch.
106    pub head: String,
107
108    /// Base branch.
109    pub base: String,
110
111    /// Whether to create as draft.
112    pub draft: bool,
113}
114
115/// Request to update a pull request.
116#[derive(Debug, Serialize)]
117pub struct UpdatePullRequest {
118    /// New title (optional).
119    #[serde(skip_serializing_if = "Option::is_none")]
120    pub title: Option<String>,
121
122    /// New body (optional).
123    #[serde(skip_serializing_if = "Option::is_none")]
124    pub body: Option<String>,
125
126    /// New base branch (optional).
127    #[serde(skip_serializing_if = "Option::is_none")]
128    pub base: Option<String>,
129}
130
131/// Method used to merge a pull request.
132#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
133#[serde(rename_all = "lowercase")]
134pub enum MergeMethod {
135    /// Create a merge commit.
136    Merge,
137    /// Squash all commits into one.
138    #[default]
139    Squash,
140    /// Rebase commits onto base.
141    Rebase,
142}
143
144/// Request to merge a pull request.
145#[derive(Debug, Serialize)]
146pub struct MergePullRequest {
147    /// Commit title (for squash/merge).
148    #[serde(skip_serializing_if = "Option::is_none")]
149    pub commit_title: Option<String>,
150
151    /// Commit message (for squash/merge).
152    #[serde(skip_serializing_if = "Option::is_none")]
153    pub commit_message: Option<String>,
154
155    /// Merge method.
156    pub merge_method: MergeMethod,
157}
158
159/// Result of merging a pull request.
160#[derive(Debug, Clone, Deserialize)]
161pub struct MergeResult {
162    /// SHA of the merge commit.
163    pub sha: String,
164
165    /// Whether the merge was successful.
166    pub merged: bool,
167
168    /// Message from the API.
169    pub message: String,
170}
171
172/// A comment on an issue or pull request.
173#[derive(Debug, Clone, Deserialize)]
174pub struct IssueComment {
175    /// Comment ID.
176    pub id: u64,
177
178    /// Comment body.
179    pub body: Option<String>,
180}
181
182/// Request to create an issue/PR comment.
183#[derive(Debug, Serialize)]
184pub struct CreateComment {
185    /// Comment body.
186    pub body: String,
187}
188
189/// Request to update an issue/PR comment.
190#[derive(Debug, Serialize)]
191pub struct UpdateComment {
192    /// New comment body.
193    pub body: String,
194}