gitea_sdk/model/
repos.rs

1use serde::{Deserialize, Serialize};
2
3use crate::model::user::User;
4
5/// Represents the format of the object in the repository.
6/// Defaults to [ObjectFormatName::SHA1].
7/// SHA1 is more widely supported, but SHA256 is more secure.
8#[derive(Default, Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
9pub enum ObjectFormatName {
10    #[default]
11    #[serde(rename = "sha1")]
12    SHA1,
13    #[serde(rename = "sha256")]
14    SHA256,
15}
16
17/// Represents the trust model for verifying commits in the repository.
18/// Defaults to [TrustModel::Default] (obviously).
19/// This determines when signatures are considered "trusted".
20#[derive(Default, Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
21pub enum TrustModel {
22    /// Use the default repository trust model for this installation.
23    #[serde(rename = "default")]
24    #[default]
25    Default,
26    /// Trust signatures signed by keys of collaborators.
27    #[serde(rename = "collaborator")]
28    Collaborator,
29    /// Trust signatures that match the commiters (This matches GitHub and will force Gitea signed
30    /// commits to have Gitea as the committer).
31    #[serde(rename = "committer")]
32    Committer,
33    /// Trust signatures signed by keys of collaborators which match the committer.
34    #[serde(rename = "collaboratorcommitter")]
35    CollabroatorCommitter,
36}
37
38/// Represents a Gitea repository.
39/// This struct is a subset of the full repository object.
40/// Some fields the API provides (like external trackers) are not included here.
41#[derive(Default, Debug, Clone, Serialize, Deserialize)]
42#[serde(default)]
43pub struct Repository {
44    pub allow_fast_forward_only_merge: bool,
45    pub allow_merge_commits: bool,
46    pub allow_rebase: bool,
47    pub allow_rebase_explicit: bool,
48    pub allow_rebase_update: bool,
49    pub allow_squash_merge: bool,
50    pub archived: bool,
51    pub archived_at: String,
52    pub avatar_url: String,
53    pub clone_url: String,
54    pub created_at: String,
55    pub default_allow_maintainer_edit: bool,
56    pub default_branch: String,
57    pub default_delete_branch_after_merge: bool,
58    pub default_merge_style: String,
59    pub description: String,
60    pub empty: bool,
61    pub external_tracker: ExternalTracker,
62    pub external_wiki: ExternalWiki,
63    pub fork: bool,
64    pub forks_count: i64,
65    pub full_name: String,
66    pub has_actions: bool,
67    pub has_issues: bool,
68    pub has_packages: bool,
69    pub has_projects: bool,
70    pub has_pull_requests: bool,
71    pub has_releases: bool,
72    pub has_wiki: bool,
73    pub html_url: String,
74    pub id: i64,
75    pub ignore_whitespace_conflicts: bool,
76    pub internal: bool,
77    pub language: String,
78    pub languages_url: String,
79    pub link: String,
80    pub mirror: bool,
81    pub mirror_interval: String,
82    pub mirror_updated: String,
83    pub name: String,
84    pub object_format_name: ObjectFormatName,
85    pub open_issues_count: i64,
86    pub open_pr_counter: i64,
87    pub original_url: String,
88    pub owner: User,
89    pub private: bool,
90    pub release_counter: i64,
91    pub size: i64,
92    pub ssh_url: String,
93    pub stars_count: i64,
94    pub template: bool,
95    pub updated_at: String,
96    pub url: String,
97    pub watchers_count: i64,
98    pub website: String,
99    pub wiki_branch: String,
100}
101
102/// Represents information about a user in the context of a commit.
103///
104/// NOTE: This is not the same as the [User] struct.
105/// A CommitUser is not guaranteed to be a valid Gitea user.
106/// A commit author can set the name and email tracked in this struct to anything they want.
107#[derive(Default, Debug, Clone, Serialize, Deserialize)]
108#[serde(default)]
109pub struct CommitUser {
110    /// Date the commit was authored.
111    pub date: String,
112    /// Email of the user.
113    pub email: String,
114    /// Full name of the user.
115    pub name: String,
116}
117
118/// Represents the actual commit object in the underlying git repository.
119/// This struct is a subset of the full commit object.
120/// It does not include the full commit tree or commit verification.
121#[derive(Default, Debug, Clone, Serialize, Deserialize)]
122#[serde(default)]
123pub struct RepoCommit {
124    /// Author of the commit (usually the person who originally wrote the code).
125    pub author: CommitUser,
126    /// The person who committed the code on behalf of the author. May be the same as the author.
127    pub committer: CommitUser,
128    /// The commit message.
129    pub message: String,
130    /// The API endpoint for the commit
131    /// (https://gitea-host.com/api/v1/repos/{user}/{repo}/git/commits/{sha}.
132    pub url: String,
133}
134
135/// Represents a commit in a repository.
136/// This struct is a subset of the full commit object.
137/// It does not include the affected files, parent commits or commit stats (additions and
138/// deletions).
139#[derive(Default, Debug, Clone, Serialize, Deserialize)]
140#[serde(default)]
141pub struct Commit {
142    /// The commit author's Gitea account.
143    /// See [RepoCommit::author] for more information.
144    /// NOTE: This is not guaranteed to be a valid Gitea user.
145    /// Because of the nature of Git, this field can be null
146    pub author: Option<User>,
147    pub commit: RepoCommit,
148    /// The committer's Gitea account.
149    /// See [RepoCommit::committer] for more information.
150    /// NOTE: This is not guaranteed to be a valid Gitea user.
151    /// Because of the nature of Git, this field can be null
152    pub committer: Option<User>,
153    /// The URL to the commit on the Gitea instance.
154    pub html_url: String,
155    /// The SHA of the commit.
156    pub sha: String,
157    /// The API endpoint URL for the commit.
158    pub url: String,
159}
160
161#[derive(Default, Debug, Clone, Serialize, Deserialize)]
162pub struct PayloadUser {
163    pub email: String,
164    /// Full name of the user.
165    pub name: String,
166    pub username: String,
167}
168
169#[derive(Default, Debug, Clone, Serialize, Deserialize)]
170pub struct PayloadCommit {
171    pub author: PayloadUser,
172    pub committer: PayloadUser,
173    /// sha1 hash of the commit
174    pub id: String,
175    pub message: String,
176    pub added: Option<Vec<String>>,
177    pub modified: Option<Vec<String>>,
178    pub removed: Option<Vec<String>>,
179    pub timestamp: String,
180    pub url: String,
181    // TODO: pub verification: PayloadCommitVerification,
182}
183
184/// CommitDateOptions store dates for GIT_AUTHOR_DATE and GIT_COMMITTER_DATE
185#[derive(Default, Debug, Clone, Serialize, Deserialize)]
186#[serde(default)]
187pub struct CommitDateOptions {
188    author: String,
189    commiter: String,
190}
191
192#[derive(Default, Debug, Clone, Serialize, Deserialize)]
193pub struct Branch {
194    pub commit: PayloadCommit,
195    pub effective_branch_protection_name: String,
196    pub enable_status_check: bool,
197    pub name: String,
198    pub protected: bool,
199    pub required_approvals: i64,
200    pub status_check_contexts: Vec<String>,
201    pub user_can_merge: bool,
202    pub user_can_push: bool,
203}
204
205/// ExternalTracker represents settings for external tracker
206#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
207#[serde(default)]
208pub struct ExternalTracker {
209    /// External Issue Tracker URL Format. Use the placeholders {user}, {repo} and {index} for the username, repository name and issue index.
210    pub external_tracker_format: String,
211    /// External Issue Tracker issue regular expression
212    pub external_tracker_regexp_pattern: String,
213    /// External Issue Tracker Number Format, either numeric, alphanumeric, or regexp
214    pub external_tracker_style: String,
215    /// URL of external issue tracker.
216    pub external_tracker_url: String,
217}
218
219/// ExternalWiki represents setting for external wiki
220#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
221#[serde(default)]
222pub struct ExternalWiki {
223    /// URL of external wiki.
224    pub external_wiki_url: String,
225}
226
227/// FileLinks contains related resource URLs for a file entry.
228#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
229pub struct FileLinks {
230    /// Resource Git URL
231    pub git: String,
232    /// Resource HTML URL
233    pub html: String,
234    #[serde(rename = "self")]
235    /// Resource self link
236    pub self_link: String,
237}
238
239/// Identity for a person's identity like an author or committer
240#[derive(Default, Debug, Clone, Serialize, Deserialize)]
241#[serde(default)]
242pub struct Identity {
243    email: String,
244    name: String,
245}
246
247/// Entry represents metadata and contents of a file
248#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
249#[serde(default)]
250pub struct Entry {
251    /// Entry links
252    #[serde(rename = "_links")]
253    pub links: FileLinks,
254    /// Entry content
255    pub content: Option<String>,
256    /// Entry download URL
257    pub download_url: Option<String>,
258    /// Entry encoding type
259    pub encoding: Option<String>,
260    /// Entry Git url
261    pub git_url: String,
262    /// Entry HTML url
263    pub html_url: String,
264    /// Entry last commit SHA
265    pub last_commit_sha: String,
266    /// Entry name
267    pub name: String,
268    /// Entry path
269    pub path: Option<String>,
270    /// Entry SHA
271    pub sha: String,
272    /// Entry size
273    pub size: u64,
274    /// Entry submodule git url
275    pub submodule_git_url: Option<String>,
276    /// Entry target
277    pub target: Option<String>,
278    /// Entry type
279    #[serde(rename = "type")]
280    pub r#type: String,
281    /// Entry URL
282    pub url: String,
283}
284
285/// EntryVerification represents the verification of a given Entry change on the repository
286#[derive(Default, Debug, Clone, Serialize, Deserialize)]
287#[serde(default)]
288pub struct EntryVerification {
289    payload: String,
290    /// Why verification failed
291    reason: String,
292    signature: String,
293    /// Only set if verifed is true
294    signer: Option<PayloadUser>,
295    /// Whether has been verified or not
296    verified: bool,
297}
298
299/// EntryMutation represents mutation of an entry, it can be a creation, an update or a deletion
300#[derive(Default, Debug, Clone, Serialize, Deserialize)]
301#[serde(default)]
302pub struct EntryMutation {
303    /// Entry commit
304    commit: Commit,
305    /// File content
306    content: Option<Entry>,
307    /// Mutation verification
308    verification: EntryVerification,
309}