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