Skip to main content

jj_ryu/
types.rs

1//! Core types for jj-ryu
2
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5use std::collections::HashMap;
6
7/// A jj bookmark (branch reference)
8#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
9pub struct Bookmark {
10    /// Bookmark name
11    pub name: String,
12    /// Git commit ID (hex)
13    pub commit_id: String,
14    /// jj change ID (hex)
15    pub change_id: String,
16    /// Whether this bookmark exists on any remote
17    pub has_remote: bool,
18    /// Whether local and remote are in sync
19    pub is_synced: bool,
20}
21
22/// A commit/change entry from jj log
23#[derive(Debug, Clone, Serialize, Deserialize)]
24pub struct LogEntry {
25    /// Git commit ID (hex)
26    pub commit_id: String,
27    /// jj change ID (hex)
28    pub change_id: String,
29    /// Author name
30    pub author_name: String,
31    /// Author email
32    pub author_email: String,
33    /// First line of commit description
34    pub description_first_line: String,
35    /// Parent commit IDs
36    pub parents: Vec<String>,
37    /// Local bookmarks pointing to this commit
38    pub local_bookmarks: Vec<String>,
39    /// Remote bookmarks pointing to this commit (format: "name@remote")
40    pub remote_bookmarks: Vec<String>,
41    /// Whether this is the working copy commit
42    pub is_working_copy: bool,
43    /// When the commit was authored
44    pub authored_at: DateTime<Utc>,
45    /// When the commit was committed
46    pub committed_at: DateTime<Utc>,
47}
48
49/// A segment of changes belonging to one or more bookmarks
50#[derive(Debug, Clone)]
51pub struct BookmarkSegment {
52    /// Bookmarks pointing to the tip of this segment
53    pub bookmarks: Vec<Bookmark>,
54    /// Changes in this segment (newest first)
55    pub changes: Vec<LogEntry>,
56}
57
58/// A segment narrowed to a single bookmark (after user selection)
59#[derive(Debug, Clone)]
60pub struct NarrowedBookmarkSegment {
61    /// The selected bookmark for this segment
62    pub bookmark: Bookmark,
63    /// Changes in this segment (newest first)
64    pub changes: Vec<LogEntry>,
65}
66
67/// A stack of bookmarks from trunk to a leaf
68#[derive(Debug, Clone)]
69pub struct BranchStack {
70    /// Segments from trunk (index 0) to leaf (last index)
71    pub segments: Vec<BookmarkSegment>,
72}
73
74/// The complete change graph for a repository
75///
76/// Represents the single linear stack from trunk to working copy.
77/// Only bookmarks between trunk and working copy are included.
78#[derive(Debug, Clone, Default)]
79pub struct ChangeGraph {
80    /// All bookmarks in the stack by name
81    pub bookmarks: HashMap<String, Bookmark>,
82    /// The single stack from trunk to working copy (None if working copy is at trunk)
83    pub stack: Option<BranchStack>,
84    /// Number of bookmarks excluded due to merge commits
85    pub excluded_bookmark_count: usize,
86}
87
88/// A pull request / merge request
89#[derive(Debug, Clone, Serialize, Deserialize)]
90pub struct PullRequest {
91    /// PR/MR number
92    pub number: u64,
93    /// Web URL for the PR/MR
94    pub html_url: String,
95    /// Base branch name
96    pub base_ref: String,
97    /// Head branch name
98    pub head_ref: String,
99    /// PR/MR title
100    pub title: String,
101    /// GraphQL node ID (GitHub only, used for mutations)
102    pub node_id: Option<String>,
103    /// Whether PR is a draft
104    pub is_draft: bool,
105}
106
107/// A comment on a pull request
108#[derive(Debug, Clone, Serialize, Deserialize)]
109pub struct PrComment {
110    /// Comment ID
111    pub id: u64,
112    /// Comment body text
113    pub body: String,
114}
115
116/// A git remote
117#[derive(Debug, Clone, Serialize, Deserialize)]
118pub struct GitRemote {
119    /// Remote name (e.g., "origin")
120    pub name: String,
121    /// Remote URL
122    pub url: String,
123}
124
125/// Detected platform type
126#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
127pub enum Platform {
128    /// GitHub or GitHub Enterprise
129    GitHub,
130    /// GitLab or self-hosted GitLab
131    GitLab,
132}
133
134impl std::fmt::Display for Platform {
135    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
136        match self {
137            Self::GitHub => write!(f, "GitHub"),
138            Self::GitLab => write!(f, "GitLab"),
139        }
140    }
141}
142
143/// Platform configuration
144#[derive(Debug, Clone)]
145pub struct PlatformConfig {
146    /// Platform type
147    pub platform: Platform,
148    /// Repository owner (user or organization)
149    pub owner: String,
150    /// Repository name
151    pub repo: String,
152    /// Custom host (None for github.com/gitlab.com)
153    pub host: Option<String>,
154}