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#[derive(Default, Debug, Clone, Serialize, Deserialize)]
185pub struct Branch {
186    pub commit: PayloadCommit,
187    pub effective_branch_protection_name: String,
188    pub enable_status_check: bool,
189    pub name: String,
190    pub protected: bool,
191    pub required_approvals: i64,
192    pub status_check_contexts: Vec<String>,
193    pub user_can_merge: bool,
194    pub user_can_push: bool,
195}
196
197/// ExternalTracker represents settings for external tracker
198#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
199#[serde(default)]
200pub struct ExternalTracker {
201    /// External Issue Tracker URL Format. Use the placeholders {user}, {repo} and {index} for the username, repository name and issue index.
202    pub external_tracker_format: String,
203    /// External Issue Tracker issue regular expression
204    pub external_tracker_regexp_pattern: String,
205    /// External Issue Tracker Number Format, either numeric, alphanumeric, or regexp
206    pub external_tracker_style: String,
207    /// URL of external issue tracker.
208    pub external_tracker_url: String,
209}
210
211/// ExternalWiki represents setting for external wiki
212#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
213#[serde(default)]
214pub struct ExternalWiki {
215    /// URL of external wiki.
216    pub external_wiki_url: String,
217}