mesa_dev/models/
commit.rs1use serde::{Deserialize, Serialize};
4
5use super::lfs::LfsFileRef;
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct Author {
10 pub name: String,
12 pub email: String,
14 #[serde(skip_serializing_if = "Option::is_none")]
16 pub date: Option<String>,
17}
18
19#[derive(Debug, Clone, Serialize)]
21#[serde(rename_all = "lowercase")]
22pub enum CommitFileAction {
23 Upsert,
25 Delete,
27}
28
29#[derive(Debug, Clone, Serialize)]
31pub struct CommitFile {
32 pub action: CommitFileAction,
34 pub path: String,
36 #[serde(skip_serializing_if = "Option::is_none")]
38 pub content: Option<String>,
39}
40
41#[derive(Debug, Clone, Serialize)]
45#[serde(untagged)]
46pub enum CommitFileChange {
47 Content {
49 path: String,
51 content: String,
53 #[serde(skip_serializing_if = "Option::is_none")]
55 encoding: Option<String>,
56 },
57 Delete {
59 path: String,
61 action: String,
63 },
64 Lfs {
66 path: String,
68 lfs: LfsFileRef,
70 },
71}
72
73impl CommitFileChange {
74 pub fn content(path: impl Into<String>, content: impl Into<String>) -> Self {
76 Self::Content {
77 path: path.into(),
78 content: content.into(),
79 encoding: None,
80 }
81 }
82
83 pub fn content_base64(path: impl Into<String>, content: impl Into<String>) -> Self {
85 Self::Content {
86 path: path.into(),
87 content: content.into(),
88 encoding: Some("base64".to_owned()),
89 }
90 }
91
92 pub fn delete(path: impl Into<String>) -> Self {
94 Self::Delete {
95 path: path.into(),
96 action: "delete".to_owned(),
97 }
98 }
99
100 pub fn lfs(path: impl Into<String>, oid: impl Into<String>, size: u64) -> Self {
102 Self::Lfs {
103 path: path.into(),
104 lfs: LfsFileRef {
105 oid: oid.into(),
106 size,
107 },
108 }
109 }
110}
111
112#[derive(Debug, Clone, Serialize)]
114pub struct CreateCommitRequest {
115 pub branch: String,
117 pub message: String,
119 pub author: Author,
121 pub files: Vec<CommitFile>,
123 #[serde(skip_serializing_if = "Option::is_none")]
125 pub base_sha: Option<String>,
126}
127
128#[derive(Debug, Clone, Serialize)]
132pub struct CreateCommitWithLfsRequest {
133 pub branch: String,
135 pub message: String,
137 pub author: Author,
139 pub files: Vec<CommitFileChange>,
141 #[serde(skip_serializing_if = "Option::is_none")]
143 pub base_sha: Option<String>,
144}
145
146#[derive(Debug, Clone, Deserialize)]
148pub struct CommitSummary {
149 pub sha: String,
151 pub message: String,
153}
154
155#[derive(Debug, Clone, Deserialize)]
157pub struct Commit {
158 pub sha: String,
160 pub message: String,
162 pub author: Author,
164 pub committer: Author,
166}
167
168#[derive(Debug, Clone, Deserialize)]
170pub struct ListCommitsResponse {
171 pub commits: Vec<CommitSummary>,
173 pub next_cursor: Option<String>,
175 pub has_more: bool,
177}