Skip to main content

pr_bro/github/
types.rs

1use chrono::{DateTime, Utc};
2
3#[derive(Debug, Clone)]
4pub struct PullRequest {
5    pub title: String,
6    pub number: u64,
7    pub author: String,
8    pub repo: String, // "owner/repo" format
9    pub url: String,  // HTML URL for browser
10    pub created_at: DateTime<Utc>,
11    pub updated_at: DateTime<Utc>,
12    pub additions: u64, // Lines added
13    pub deletions: u64, // Lines deleted
14    pub approvals: u32, // Approval count (will need separate API call)
15    pub draft: bool,
16    pub labels: Vec<String>,        // GitHub label names on this PR
17    pub user_has_reviewed: bool,    // Whether the authenticated user has submitted a review
18    pub filtered_size: Option<u64>, // Size after applying exclude patterns (if configured)
19}
20
21impl PullRequest {
22    /// Calculate PR age from creation time
23    pub fn age(&self) -> chrono::Duration {
24        Utc::now() - self.created_at
25    }
26
27    /// Calculate total size, using filtered size if available (exclude patterns applied)
28    pub fn size(&self) -> u64 {
29        self.filtered_size
30            .unwrap_or(self.additions + self.deletions)
31    }
32
33    /// Return a short reference in the format "owner/repo#123"
34    pub fn short_ref(&self) -> String {
35        format!("{}#{}", self.repo, self.number)
36    }
37}