JavaScript is disabled, refresh for a better experience. ambee/giterated

ambee/giterated

Git repository hosting, collaboration, and discovery for the Fediverse.

Simple branch staleness implementation

Emilia - ⁨1⁩ year ago

parent: tbd commit: ⁨efc3f02

⁨giterated-models/src/repository/values.rs⁩ - ⁨3031⁩ bytes
Raw
1 use std::fmt::Display;
2
3 use serde::{Deserialize, Serialize};
4
5 use crate::{settings::Setting, value::GiteratedObjectValue};
6
7 use super::{Commit, CommitBodyType, Repository, RepositoryVisibility};
8
9 // pub struct RepositorySetting<V: GiteratedObjectValue>(pub V);
10
11 // impl<O: GiteratedObject, V: GiteratedObjectValue<Object = O> + Send> GiteratedOperation<O>
12 // for RepositorySetting<V>
13 // {
14 // fn operation_name(&self) -> &'static str {
15 // "setting_get"
16 // }
17 // type Success = V;
18 // type Failure = GetValueError;
19 // }
20
21 #[derive(Debug, Hash, Clone, PartialEq, Eq, Serialize, Deserialize)]
22 pub struct Description(pub String);
23
24 impl Display for Description {
25 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26 f.write_str(&self.0)
27 }
28 }
29
30 impl GiteratedObjectValue for Description {
31 type Object = Repository;
32
33 fn value_name() -> &'static str {
34 "description"
35 }
36 }
37
38 impl Setting for Description {
39 fn name() -> &'static str {
40 "description"
41 }
42 }
43
44 #[derive(Debug, Hash, Clone, PartialEq, Eq, Serialize, Deserialize)]
45 #[repr(transparent)]
46 #[serde(transparent)]
47 pub struct Visibility(pub RepositoryVisibility);
48
49 impl GiteratedObjectValue for Visibility {
50 type Object = Repository;
51
52 fn value_name() -> &'static str {
53 "visibility"
54 }
55 }
56
57 impl Setting for Visibility {
58 fn name() -> &'static str {
59 "visibility"
60 }
61 }
62
63 #[derive(Debug, Hash, Clone, PartialEq, Eq, Serialize, Deserialize)]
64 #[serde(transparent)]
65 #[repr(transparent)]
66 pub struct DefaultBranch(pub String);
67
68 impl Display for DefaultBranch {
69 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
70 f.write_str(&self.0)
71 }
72 }
73
74 impl GiteratedObjectValue for DefaultBranch {
75 type Object = Repository;
76
77 fn value_name() -> &'static str {
78 "default_branch"
79 }
80 }
81
82 #[derive(Debug, Hash, Clone, PartialEq, Eq, Serialize, Deserialize)]
83 pub struct LatestCommit(pub Option<Commit>);
84
85 impl GiteratedObjectValue for LatestCommit {
86 type Object = Repository;
87
88 fn value_name() -> &'static str {
89 "latest_commit"
90 }
91 }
92
93 impl GiteratedObjectValue for CommitBodyType {
94 type Object = Repository;
95
96 fn value_name() -> &'static str {
97 "commit_body_type"
98 }
99 }
100
101 /// This value determines after how long of a period of inactivity a branch is marked stale in seconds.
102 /// The default (as we have not implemented it via config) is about 3 months.
103 #[derive(Debug, Hash, Clone, PartialEq, Eq, Serialize, Deserialize)]
104 pub struct BranchStaleAfter(pub u32);
105
106 impl Default for BranchStaleAfter {
107 fn default() -> Self {
108 // TODO: Make default configurable using config
109 // This is about 3 months in seconds
110 Self(7889238)
111 }
112 }
113
114 impl GiteratedObjectValue for BranchStaleAfter {
115 type Object = Repository;
116
117 fn value_name() -> &'static str {
118 "branch_stale_after"
119 }
120 }
121
122 impl Setting for BranchStaleAfter {
123 fn name() -> &'static str {
124 "branch_stale_after"
125 }
126 }
127