Commit

Author:

Hash:

Timestamp:

+113 -13 +/-3 browse

Kevin Schoon [me@kevinschoon.com]

187e5da977ae31c3a0347c16d62bc64a45d94699

Sun, 21 Jan 2024 13:54:19 +0000 (1.4 years ago)

do not generate summary pages with no content
do not generate summary pages with no content

RSS feeds no longer will generate a summary item if no activities happened
within the timeframe.
1diff --git a/crates/git/src/wrapper.rs b/crates/git/src/wrapper.rs
2index 32eb539..71a2ae8 100644
3--- a/crates/git/src/wrapper.rs
4+++ b/crates/git/src/wrapper.rs
5 @@ -168,10 +168,10 @@ impl Wrapper {
6 let epoch_time = commit.time().seconds();
7 match timeframe {
8 Some((start, end)) => {
9- if epoch_time > start {
10+ if epoch_time >= start && epoch_time <= end {
11 tags.push(lite::Tag::from((tag, commit)));
12 true
13- } else if epoch_time < end {
14+ } else if epoch_time < start {
15 false
16 } else {
17 tags.push(lite::Tag::from((tag, commit)));
18 @@ -633,10 +633,7 @@ impl Wrapper {
19 let mut commits: Vec<lite::Commit> = Vec::new();
20 let mut objects: HashMap<String, Oid> = HashMap::new();
21 for item in items {
22- let mut object_path = base_path
23- .clone()
24- .map(Wrapper::relative)
25- .unwrap_or_default();
26+ let mut object_path = base_path.clone().map(Wrapper::relative).unwrap_or_default();
27 object_path.push(item.name.clone());
28 let object = t1.get_path(Wrapper::relative(object_path).as_path())?;
29 objects.insert(item.name.to_string(), object.id());
30 diff --git a/src/web2/routes/refs.rs b/src/web2/routes/refs.rs
31index 968cecf..390aa9e 100644
32--- a/src/web2/routes/refs.rs
33+++ b/src/web2/routes/refs.rs
34 @@ -27,6 +27,8 @@ struct Item {
35 commit_hash: String,
36 }
37
38+ // TODO: need an individual branch page
39+
40 pub async fn branches(
41 Extension(preamble): Extension<Preamble>,
42 Extension((templates, mut ctx)): Extension<Template>,
43 @@ -56,6 +58,8 @@ pub async fn branches(
44 Ok(Html(body))
45 }
46
47+ // TODO: need an individual ref page
48+
49 pub async fn tags(
50 Extension(preamble): Extension<Preamble>,
51 Extension((templates, mut ctx)): Extension<Template>,
52 diff --git a/src/web2/routes/rss.rs b/src/web2/routes/rss.rs
53index 47ddf09..dcb142f 100644
54--- a/src/web2/routes/rss.rs
55+++ b/src/web2/routes/rss.rs
56 @@ -157,13 +157,14 @@ impl Builder {
57 )))?;
58 for bug in bugs {
59 let mut item = rss::Item::default();
60+ let link = format!("{}/bugs/{}", entry.1, bug.human_id);
61 item.set_title(format!("Bug: {}", bug.title));
62 item.set_description(
63 bug.comments
64 .first()
65 .map_or(String::new(), |comment| comment.message.to_string()),
66 );
67- item.set_link(Some(format!("{}/bugs/{}", entry.1, bug.human_id)));
68+ item.set_link(Some(link.clone()));
69 item.set_author(bug.author.name);
70 item.set_pub_date(
71 time::OffsetDateTime::from_unix_timestamp(bug.edit_time.timestamp as i64)
72 @@ -171,6 +172,10 @@ impl Builder {
73 .format(&Rfc2822)
74 .unwrap(),
75 );
76+ item.set_guid(Some(Guid {
77+ permalink: true,
78+ value: link,
79+ }));
80 items.push((item, bug.create_time.timestamp as i64))
81 }
82 for tag in repository.tags_range(Some((
83 @@ -178,7 +183,8 @@ impl Builder {
84 self.current_time.unix_timestamp(),
85 )))? {
86 let mut item = rss::Item::default();
87- item.set_title(format!("Tag {}", tag.name));
88+ // FIXME: need a tag page before we can set a GUID/link
89+ item.set_title(format!("Tag: {}", tag.name));
90 item.set_description(tag.summary);
91 item.set_author(tag.author_name);
92 items.push((item, tag.commit.epoch));
93 @@ -238,6 +244,11 @@ impl Builder {
94 }
95 }
96
97+ // don't generate a new rss item if there is nothing within it
98+ if all_data.len() == 0 {
99+ return Ok(self.channel(vec![]));
100+ }
101+
102 let mut ctx = self.context.clone();
103
104 ctx.insert("origin", &self.origin);
105 @@ -256,7 +267,6 @@ impl Builder {
106 .iter()
107 .fold(0, |accm, entries| accm + entries.commits.len());
108 ctx.insert("n_commits", &n_commits);
109-
110 ctx.insert("n_projects", &all_data.len());
111 ctx.insert("entries", &all_data);
112
113 @@ -589,23 +599,79 @@ mod tests {
114 .title
115 .as_ref()
116 .is_some_and(|title| title == "Commit: commit 1"));
117+ assert!(channel.items[1]
118+ .title
119+ .as_ref()
120+ .is_some_and(|title| title == "Tag: v0.0.1"));
121+ assert!(channel.items[1]
122+ .description
123+ .as_ref()
124+ .is_some_and(|description| description == "release version 0.0.1!\n"));
125+ assert!(channel.items[2]
126+ .title
127+ .as_ref()
128+ .is_some_and(|title| title == "Commit: commit 2"));
129 assert!(channel.items[0].guid.is_some());
130- // TODO: validate tag
131+ // FIXME: assert!(channel.items[1].guid.is_some());
132+ assert!(channel.items[2].guid.is_some());
133 test_repo.cleanup().expect("failed to cleanup repo");
134 }
135
136 #[test]
137+ fn test_feed_1d() {
138+ let mut test_repo = testing::Builder::default().with_commands(vec![
139+ // older commit which is filtered
140+ format!(
141+ "echo 'content' > file_1.txt && git add file_1.txt && {} git commit -m 'commit 1'",
142+ testing::timestamp_envs("Tue Dec 16 20:00:00 2023 +0000")
143+ )
144+ .as_str(),
145+ format!(
146+ "echo 'content' > file_2.txt && git add file_2.txt && {} git commit -m 'commit 2'",
147+ testing::timestamp_envs("Tue Dec 18 20:01:00 2023 +0000")
148+ )
149+ .as_str(),
150+ format!(
151+ "echo 'content' > file_3.txt && git add file_3.txt && {} git commit -m 'commit 3'",
152+ testing::timestamp_envs("Tue Dec 18 20:02:00 2023 +0000")
153+ )
154+ .as_str(),
155+ ]);
156+ let (name, path) = test_repo.build().expect("failed to init repo");
157+ let templates =
158+ Tera::new("themes/default/templates/*.html").expect("failed to load templates");
159+ let context = Context::new();
160+ let builder = Builder {
161+ templates,
162+ context,
163+ origin: String::from("localhost:8080"),
164+ title: String::from("test"),
165+ time_to_live: Some(Duration::HOUR),
166+ current_time: OffsetDateTime::parse(CURRENT_TIME, &Rfc2822).unwrap(),
167+ };
168+ let channel = builder
169+ .summary(vec![(path, name)], Timeframe::DAILY)
170+ .expect("failed to build items");
171+ assert!(channel.items.len() == 1);
172+ assert!(channel.items[0]
173+ .description
174+ .as_ref()
175+ .is_some_and(|content| content.contains("commit 2") && content.contains("commit 3")));
176+ assert!(channel.items[0].guid.is_some());
177+ assert!(channel.ttl.as_ref().is_some_and(|ttl| ttl == "60"))
178+ }
179+
180+ #[test]
181 fn test_feed_1w() {
182- // TODO: I think this is broken
183 let mut test_repo = testing::Builder::default().with_commands(vec![
184 format!(
185 "echo 'content' > file_1.txt && git add file_1.txt && {} git commit -m 'commit 1'",
186- testing::timestamp_envs("Tue Dec 19 20:00:00 2023 +0000")
187+ testing::timestamp_envs("Tue Dec 15 20:00:00 2023 +0000")
188 )
189 .as_str(),
190 format!(
191 "echo 'content' > file_2.txt && git add file_2.txt && {} git commit -m 'commit 2'",
192- testing::timestamp_envs("Tue Dec 19 20:01:00 2023 +0000")
193+ testing::timestamp_envs("Tue Dec 16 20:01:00 2023 +0000")
194 )
195 .as_str(),
196 ]);
197 @@ -625,6 +691,10 @@ mod tests {
198 .summary(vec![(path, name)], Timeframe::WEEKLY)
199 .expect("failed to build items");
200 assert!(channel.items.len() == 1);
201+ assert!(channel.items[0]
202+ .description
203+ .as_ref()
204+ .is_some_and(|content| content.contains("commit 1") && content.contains("commit 2")));
205 assert!(channel.items[0].guid.is_some());
206 assert!(channel.ttl.as_ref().is_some_and(|ttl| ttl == "60"))
207 }
208 @@ -674,6 +744,35 @@ mod tests {
209 }
210
211 #[test]
212+ fn test_feed_1d_no_commits() {
213+ let mut test_repo = testing::Builder::default().with_commands(vec![
214+ // older commit which is filtered
215+ format!(
216+ "echo 'content' > file_1.txt && git add file_1.txt && {} git commit -m 'commit 1'",
217+ testing::timestamp_envs("Tue Dec 16 20:00:00 2023 +0000")
218+ )
219+ .as_str(),
220+ ]);
221+ let (name, path) = test_repo.build().expect("failed to init repo");
222+ let templates =
223+ Tera::new("themes/default/templates/*.html").expect("failed to load templates");
224+ let context = Context::new();
225+ let builder = Builder {
226+ templates,
227+ context,
228+ origin: String::from("localhost:8080"),
229+ title: String::from("test"),
230+ time_to_live: Some(Duration::HOUR),
231+ current_time: OffsetDateTime::parse(CURRENT_TIME, &Rfc2822).unwrap(),
232+ };
233+ let channel = builder
234+ .summary(vec![(path, name)], Timeframe::DAILY)
235+ .expect("failed to build items");
236+ assert!(channel.items.len() == 0);
237+ assert!(channel.ttl.as_ref().is_some_and(|ttl| ttl == "60"))
238+ }
239+
240+ #[test]
241 fn test_timeframe_1d() {
242 let now = datetime!(2021-03-05 13:00:55 UTC);
243 let (start, end) = Timeframe::DAILY.clamp(now);