ephemeris_forge_forgejo/api/request/labels.rs
1use facet::Facet;
2
3use crate::config::Label;
4
5/// `CreateLabelOption`, with every property the spec lists.
6#[derive(Clone, Debug, Eq, Facet, PartialEq)]
7pub struct CreateLabelOption {
8 /// The label's name.
9 pub name: String,
10 /// The label's color as six hexadecimal digits.
11 pub color: String,
12 /// The label's description, empty for none.
13 pub description: String,
14 /// Whether the label is scoped.
15 pub exclusive: bool,
16 /// Whether the label is archived.
17 pub is_archived: bool,
18}
19
20/// The managed subset of `EditLabelOption`.
21///
22/// The spec declares these properties as `*bool` and `*string` with
23/// `omitempty`, so an omitted property leaves the live value alone. The name
24/// is never written, because renames are not supported.
25#[derive(Clone, Debug, Default, Eq, Facet, PartialEq)]
26#[facet(skip_all_unless_truthy)]
27pub struct EditLabelOption {
28 /// The label's color as six hexadecimal digits.
29 pub color: Option<String>,
30 /// The label's description, empty for none.
31 pub description: Option<String>,
32 /// Whether the label is scoped.
33 pub exclusive: Option<bool>,
34 /// Whether the label is archived.
35 pub is_archived: Option<bool>,
36}
37
38impl CreateLabelOption {
39 /// The body that creates the label `name` as declared.
40 #[must_use]
41 pub fn new(name: &str, label: &Label) -> Self {
42 Self {
43 name: name.to_owned(),
44 color: label.color.to_string(),
45 description: label.description.clone().unwrap_or_default(),
46 exclusive: label.exclusive,
47 is_archived: label.is_archived,
48 }
49 }
50}
51
52impl EditLabelOption {
53 /// Whether no property would be written.
54 #[must_use]
55 pub fn is_empty(&self) -> bool {
56 *self == Self::default()
57 }
58}