ephemeris_forge_forgejo/api/request/repository.rs
1use facet::Facet;
2
3use crate::api::model;
4use crate::config;
5
6/// `InternalTracker`. Forgejo reads a missing property as false, so every
7/// property is always sent.
8#[derive(Clone, Copy, Debug, Eq, Facet, PartialEq)]
9pub struct InternalTracker {
10 /// Whether time tracking is enabled.
11 pub enable_time_tracker: bool,
12 /// Whether only contributors may track time.
13 pub allow_only_contributors_to_track_time: bool,
14 /// Whether issues and pull requests may depend on each other.
15 pub enable_issue_dependencies: bool,
16}
17
18/// `ExternalTracker`, with every property the spec lists.
19#[derive(Clone, Debug, Eq, Facet, PartialEq)]
20pub struct ExternalTracker {
21 /// The URL of the tracker.
22 pub external_tracker_url: String,
23 /// The issue URL format.
24 pub external_tracker_format: String,
25 /// How the tracker numbers its issues.
26 pub external_tracker_style: String,
27 /// The expression that finds issues when the style is `regexp`.
28 pub external_tracker_regexp_pattern: String,
29}
30
31impl InternalTracker {
32 /// The body that writes the declared settings and keeps the live value of
33 /// every undeclared one.
34 #[must_use]
35 pub fn new(tracker: config::InternalTracker, live: model::InternalTracker) -> Self {
36 Self {
37 enable_time_tracker: tracker
38 .enable_time_tracker
39 .or(live.enable_time_tracker)
40 .unwrap_or_default(),
41 allow_only_contributors_to_track_time: tracker
42 .allow_only_contributors_to_track_time
43 .or(live.allow_only_contributors_to_track_time)
44 .unwrap_or_default(),
45 enable_issue_dependencies: tracker
46 .enable_issue_dependencies
47 .or(live.enable_issue_dependencies)
48 .unwrap_or_default(),
49 }
50 }
51}
52
53impl ExternalTracker {
54 /// The body that writes the declared settings and keeps the live value of
55 /// every undeclared one.
56 #[must_use]
57 pub fn new(tracker: &config::ExternalTracker, live: &model::ExternalTracker) -> Self {
58 Self {
59 external_tracker_url: tracker.external_tracker_url.clone(),
60 external_tracker_format: tracker.external_tracker_format.clone(),
61 external_tracker_style: tracker
62 .external_tracker_style
63 .map(|style| style.as_str().to_owned())
64 .or_else(|| live.external_tracker_style.clone())
65 .unwrap_or_else(|| config::TrackerStyle::Numeric.as_str().to_owned()),
66 external_tracker_regexp_pattern: tracker
67 .external_tracker_regexp_pattern
68 .clone()
69 .or_else(|| live.external_tracker_regexp_pattern.clone())
70 .unwrap_or_default(),
71 }
72 }
73}
74
75/// The managed subset of `EditRepoOption`.
76///
77/// The spec declares these properties as `*bool` and `*string` with
78/// `omitempty`, so an omitted property leaves the live value alone. That makes
79/// a differential `PATCH` correct, and it makes an explicit `false` different
80/// from an absent property: `Some(false)` is written, `None` is not.
81#[derive(Clone, Debug, Default, Eq, Facet, PartialEq)]
82#[facet(skip_all_unless_truthy)]
83pub struct EditRepoOption {
84 /// The repository's slug.
85 pub name: Option<String>,
86 /// The one-line summary shown on the repository's landing page.
87 pub description: Option<String>,
88 /// Whether a merge is rejected unless the branch can fast-forward.
89 pub allow_fast_forward_only_merge: Option<bool>,
90 /// Whether merging is allowed to create a merge commit.
91 pub allow_merge_commits: Option<bool>,
92 /// Whether merging is allowed to rebase commits onto the base branch.
93 pub allow_rebase: Option<bool>,
94 /// Whether rebase merges may be done with an explicit merge commit.
95 pub allow_rebase_explicit: Option<bool>,
96 /// Whether a pull request branch may be updated by rebasing it.
97 pub allow_rebase_update: Option<bool>,
98 /// Whether merging is allowed to squash commits into one.
99 pub allow_squash_merge: Option<bool>,
100 /// Whether the source branch is deleted automatically after merging.
101 pub default_delete_branch_after_merge: Option<bool>,
102 /// The merge strategy preselected in the merge dialog.
103 pub default_merge_style: Option<String>,
104 /// The strategy preselected for updating an out-of-date pull request.
105 pub default_update_style: Option<String>,
106 /// Whether CI/CD actions are enabled.
107 pub has_actions: Option<bool>,
108 /// Whether the issue tracker is enabled.
109 pub has_issues: Option<bool>,
110 /// Whether the package registry is enabled.
111 pub has_packages: Option<bool>,
112 /// Whether project boards are enabled.
113 pub has_projects: Option<bool>,
114 /// Whether pull requests are enabled.
115 pub has_pull_requests: Option<bool>,
116 /// Whether releases are enabled.
117 pub has_releases: Option<bool>,
118 /// Whether the wiki is enabled.
119 pub has_wiki: Option<bool>,
120 /// The URL with more information about the repository.
121 pub website: Option<String>,
122 /// Whether the repository is private.
123 pub private: Option<bool>,
124 /// Whether the repository is a template.
125 pub template: Option<bool>,
126 /// The default branch.
127 pub default_branch: Option<String>,
128 /// Whether the repository is archived.
129 pub archived: Option<bool>,
130 /// The external wiki.
131 pub external_wiki: Option<config::ExternalWiki>,
132 /// The built-in issue tracker.
133 pub internal_tracker: Option<InternalTracker>,
134 /// The external issue tracker.
135 pub external_tracker: Option<ExternalTracker>,
136 /// Whether whitespace is ignored when checking pull requests for
137 /// conflicts.
138 pub ignore_whitespace_conflicts: Option<bool>,
139 /// Whether a pull request may be marked as merged by hand.
140 pub allow_manual_merge: Option<bool>,
141 /// Whether manual merges are detected automatically.
142 pub autodetect_manual_merge: Option<bool>,
143 /// Whether maintainers may edit pull requests by default.
144 pub default_allow_maintainer_edit: Option<bool>,
145 /// Whether anyone with write access may edit the wiki.
146 pub globally_editable_wiki: Option<bool>,
147 /// The branch that holds the wiki.
148 pub wiki_branch: Option<String>,
149 /// The mirror sync interval.
150 pub mirror_interval: Option<String>,
151 /// Whether a mirror removes obsolete remote-tracking references.
152 pub enable_prune: Option<bool>,
153}
154
155impl EditRepoOption {
156 /// Whether the body would carry no property at all, in which case the
157 /// request is skipped rather than sent.
158 #[must_use]
159 pub fn is_empty(&self) -> bool {
160 *self == Self::default()
161 }
162}