Skip to main content

libverify_github/
types.rs

1use serde::Deserialize;
2
3/// GitHub API response type for PR changed files.
4#[derive(Debug, Clone, Deserialize)]
5pub struct PrFile {
6    pub filename: String,
7    pub patch: Option<String>,
8    #[serde(default)]
9    pub additions: u32,
10    #[serde(default)]
11    pub deletions: u32,
12    #[serde(default)]
13    pub status: String,
14}
15
16/// GitHub API response type for PR metadata.
17#[derive(Debug, Clone, Deserialize)]
18pub struct PrMetadata {
19    pub number: u32,
20    pub title: String,
21    pub body: Option<String>,
22    pub user: Option<PrUser>,
23    pub head: PrHead,
24    pub base: PrBase,
25}
26
27/// The head branch/commit info from a PR.
28#[derive(Debug, Clone, Deserialize)]
29pub struct PrHead {
30    pub sha: String,
31}
32
33/// The base branch info from a PR.
34#[derive(Debug, Clone, Deserialize)]
35pub struct PrBase {
36    /// The branch name (e.g. "main").
37    #[serde(rename = "ref")]
38    pub ref_name: String,
39}
40
41/// Pull request summary from the list pulls endpoint.
42#[derive(Debug, Clone, Deserialize)]
43pub struct PullRequestListItem {
44    pub number: u32,
45    pub title: String,
46    pub merged_at: Option<String>,
47}
48
49/// GitHub API response type for a tag.
50#[derive(Debug, Clone, Deserialize)]
51pub struct Tag {
52    pub name: String,
53    pub commit: TagCommit,
54}
55
56#[derive(Debug, Clone, Deserialize)]
57pub struct TagCommit {
58    pub sha: String,
59}
60
61/// Commit verification info from GitHub API.
62#[derive(Debug, Clone, Deserialize)]
63pub struct CommitVerification {
64    pub verified: bool,
65    pub reason: String,
66}
67
68/// Commit author info (top-level, optional).
69#[derive(Debug, Clone, Deserialize)]
70pub struct CommitAuthor {
71    pub login: String,
72}
73
74/// Inner commit data.
75#[derive(Debug, Clone, Deserialize)]
76pub struct CompareCommitInner {
77    pub message: String,
78    pub verification: CommitVerification,
79}
80
81/// Parent commit reference from the GitHub API.
82#[derive(Debug, Clone, Deserialize)]
83pub struct CommitParent {
84    pub sha: String,
85}
86
87/// A commit from the compare API.
88#[derive(Debug, Clone, Deserialize)]
89pub struct CompareCommit {
90    pub sha: String,
91    pub commit: CompareCommitInner,
92    pub author: Option<CommitAuthor>,
93    #[serde(default)]
94    pub parents: Vec<CommitParent>,
95}
96
97/// Response from the compare API.
98#[derive(Debug, Clone, Deserialize)]
99pub struct CompareResponse {
100    pub commits: Vec<CompareCommit>,
101}
102
103/// A pull request summary (from commits/{sha}/pulls).
104#[derive(Debug, Clone, Deserialize)]
105pub struct PullRequestSummary {
106    pub number: u32,
107    pub merged_at: Option<String>,
108    pub user: PrUser,
109}
110
111/// Pull request user.
112#[derive(Debug, Clone, Deserialize)]
113pub struct PrUser {
114    pub login: String,
115}
116
117/// A release from the GitHub Releases API.
118#[derive(Debug, Clone, Deserialize)]
119pub struct Release {
120    pub tag_name: String,
121    pub assets: Vec<ReleaseAsset>,
122}
123
124/// An asset attached to a GitHub release.
125#[derive(Debug, Clone, Deserialize)]
126pub struct ReleaseAsset {
127    pub name: String,
128    pub browser_download_url: String,
129}
130
131/// A PR review.
132#[derive(Debug, Clone, Deserialize)]
133pub struct Review {
134    pub user: PrUser,
135    pub state: String,
136    pub submitted_at: Option<String>,
137    /// Review body text. Used to detect bot-mediated approvals
138    /// (e.g., Prow `/lgtm`, `/approve` commands).
139    #[serde(default)]
140    pub body: Option<String>,
141}
142
143/// A commit on a PR (from the pulls/{number}/commits endpoint).
144#[derive(Debug, Clone, Deserialize)]
145pub struct PrCommit {
146    pub sha: String,
147    pub commit: PrCommitInner,
148    pub author: Option<PrUser>,
149}
150
151/// Inner commit data for a PR commit.
152#[derive(Debug, Clone, Deserialize)]
153pub struct PrCommitInner {
154    pub committer: Option<PrCommitAuthor>,
155    pub verification: Option<CommitVerification>,
156}
157
158/// Committer info with timestamp.
159#[derive(Debug, Clone, Deserialize)]
160pub struct PrCommitAuthor {
161    pub date: Option<String>,
162}
163
164/// Minimal app info from a check run.
165#[derive(Debug, Clone, Deserialize)]
166pub struct CheckRunApp {
167    pub slug: String,
168}
169
170/// A single check run from the GitHub Check Runs API.
171#[derive(Debug, Clone, Deserialize)]
172pub struct CheckRunItem {
173    pub name: String,
174    /// "completed", "in_progress", "queued", etc.
175    pub status: String,
176    /// "success", "failure", "neutral", "cancelled", "skipped", "timed_out", "action_required", or null if not completed.
177    pub conclusion: Option<String>,
178    /// The GitHub App that created this check run (e.g. "github-actions").
179    pub app: Option<CheckRunApp>,
180}
181
182/// Response from GET /repos/{owner}/{repo}/commits/{ref}/check-runs.
183#[derive(Debug, Clone, Deserialize)]
184pub struct CheckRunsResponse {
185    pub total_count: u32,
186    pub check_runs: Vec<CheckRunItem>,
187}
188
189/// Response from GET /repos/{owner}/{repo}/commits/{ref}/status.
190#[derive(Debug, Clone, Deserialize)]
191pub struct CombinedStatusResponse {
192    pub state: String,
193    pub statuses: Vec<CommitStatusItem>,
194}
195
196/// A single status from the combined status API.
197#[derive(Debug, Clone, Deserialize)]
198pub struct CommitStatusItem {
199    pub context: String,
200    pub state: String,
201}
202
203/// Wrapper for GitHub Search API responses.
204#[derive(Debug, Clone, Deserialize)]
205pub struct SearchResponse<T> {
206    pub total_count: u32,
207    pub items: Vec<T>,
208}
209
210/// A PR item from the GitHub Search API (issues endpoint).
211#[derive(Debug, Clone, Deserialize)]
212pub struct SearchPrItem {
213    pub number: u32,
214    pub pull_request: Option<SearchPrMeta>,
215}
216
217/// Pull request metadata within a search result.
218#[derive(Debug, Clone, Deserialize)]
219pub struct SearchPrMeta {
220    pub merged_at: Option<String>,
221}