upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-07-16 10:59:20 +0100
committerDanConwayDev <DanConwayDev@protonmail.com>2025-07-16 10:59:20 +0100
commitac53bca7e315848864ff9e51703720b5b466bc42 (patch)
tree775e425f0af2543eb12e4a4b1d4feb022611368f /src/lib
parent092b9606ff2b721d858a5c7b2b27a2f9942b4bc4 (diff)
chore: bump nightly rustfmt
to latest available and apply fmt fixes
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/client.rs132
-rw-r--r--src/lib/git/identify_ahead_behind.rs8
-rw-r--r--src/lib/git/mod.rs83
-rw-r--r--src/lib/git_events.rs16
-rw-r--r--src/lib/login/mod.rs14
-rw-r--r--src/lib/repo_ref.rs13
-rw-r--r--src/lib/repo_state.rs7
7 files changed, 156 insertions, 117 deletions
diff --git a/src/lib/client.rs b/src/lib/client.rs
index 16cfe30..9253022 100644
--- a/src/lib/client.rs
+++ b/src/lib/client.rs
@@ -1103,16 +1103,18 @@ pub async fn get_state_from_cache(
1103) -> Result<RepoState> { 1103) -> Result<RepoState> {
1104 if let Some(git_repo_path) = git_repo_path { 1104 if let Some(git_repo_path) = git_repo_path {
1105 RepoState::try_from( 1105 RepoState::try_from(
1106 get_events_from_local_cache(git_repo_path, vec![get_filter_state_events( 1106 get_events_from_local_cache(
1107 &repo_ref.coordinates(), 1107 git_repo_path,
1108 )]) 1108 vec![get_filter_state_events(&repo_ref.coordinates())],
1109 )
1109 .await?, 1110 .await?,
1110 ) 1111 )
1111 } else { 1112 } else {
1112 RepoState::try_from( 1113 RepoState::try_from(
1113 get_event_from_global_cache(git_repo_path, vec![get_filter_state_events( 1114 get_event_from_global_cache(
1114 &repo_ref.coordinates(), 1115 git_repo_path,
1115 )]) 1116 vec![get_filter_state_events(&repo_ref.coordinates())],
1117 )
1116 .await?, 1118 .await?,
1117 ) 1119 )
1118 } 1120 }
@@ -1178,17 +1180,20 @@ async fn create_relays_request(
1178 } 1180 }
1179 1181
1180 if let Some(git_repo_path) = git_repo_path { 1182 if let Some(git_repo_path) = git_repo_path {
1181 for event in &get_events_from_local_cache(git_repo_path, vec![ 1183 for event in &get_events_from_local_cache(
1182 nostr::Filter::default() 1184 git_repo_path,
1183 .kinds(vec![Kind::GitPatch]) 1185 vec![
1184 .custom_tags( 1186 nostr::Filter::default()
1185 SingleLetterTag::lowercase(nostr_sdk::Alphabet::A), 1187 .kinds(vec![Kind::GitPatch])
1186 repo_coordinates_without_relays 1188 .custom_tags(
1187 .iter() 1189 SingleLetterTag::lowercase(nostr_sdk::Alphabet::A),
1188 .map(|c| c.coordinate.to_string()) 1190 repo_coordinates_without_relays
1189 .collect::<Vec<String>>(), 1191 .iter()
1190 ), 1192 .map(|c| c.coordinate.to_string())
1191 ]) 1193 .collect::<Vec<String>>(),
1194 ),
1195 ],
1196 )
1192 .await? 1197 .await?
1193 { 1198 {
1194 if event_is_patch_set_root(event) || event_is_revision_root(event) { 1199 if event_is_patch_set_root(event) || event_is_revision_root(event) {
@@ -1198,11 +1203,11 @@ async fn create_relays_request(
1198 } 1203 }
1199 } 1204 }
1200 1205
1201 let profile_events = 1206 let profile_events = get_event_from_global_cache(
1202 get_event_from_global_cache(git_repo_path, vec![get_filter_contributor_profiles( 1207 git_repo_path,
1203 contributors.clone(), 1208 vec![get_filter_contributor_profiles(contributors.clone())],
1204 )]) 1209 )
1205 .await?; 1210 .await?;
1206 for c in &contributors { 1211 for c in &contributors {
1207 if let Some(event) = profile_events 1212 if let Some(event) = profile_events
1208 .iter() 1213 .iter()
@@ -1768,17 +1773,20 @@ pub async fn get_proposals_and_revisions_from_cache(
1768 git_repo_path: &Path, 1773 git_repo_path: &Path,
1769 repo_coordinates: HashSet<Nip19Coordinate>, 1774 repo_coordinates: HashSet<Nip19Coordinate>,
1770) -> Result<Vec<nostr::Event>> { 1775) -> Result<Vec<nostr::Event>> {
1771 let mut proposals = get_events_from_local_cache(git_repo_path, vec![ 1776 let mut proposals = get_events_from_local_cache(
1772 nostr::Filter::default() 1777 git_repo_path,
1773 .kind(nostr::Kind::GitPatch) 1778 vec![
1774 .custom_tags( 1779 nostr::Filter::default()
1775 nostr::SingleLetterTag::lowercase(nostr_sdk::Alphabet::A), 1780 .kind(nostr::Kind::GitPatch)
1776 repo_coordinates 1781 .custom_tags(
1777 .iter() 1782 nostr::SingleLetterTag::lowercase(nostr_sdk::Alphabet::A),
1778 .map(|c| c.coordinate.to_string()) 1783 repo_coordinates
1779 .collect::<Vec<String>>(), 1784 .iter()
1780 ), 1785 .map(|c| c.coordinate.to_string())
1781 ]) 1786 .collect::<Vec<String>>(),
1787 ),
1788 ],
1789 )
1782 .await? 1790 .await?
1783 .iter() 1791 .iter()
1784 .filter(|e| event_is_patch_set_root(e)) 1792 .filter(|e| event_is_patch_set_root(e))
@@ -1794,23 +1802,29 @@ pub async fn get_all_proposal_patch_events_from_cache(
1794 repo_ref: &RepoRef, 1802 repo_ref: &RepoRef,
1795 proposal_id: &nostr::EventId, 1803 proposal_id: &nostr::EventId,
1796) -> Result<Vec<nostr::Event>> { 1804) -> Result<Vec<nostr::Event>> {
1797 let mut commit_events = get_events_from_local_cache(git_repo_path, vec![ 1805 let mut commit_events = get_events_from_local_cache(
1798 nostr::Filter::default() 1806 git_repo_path,
1799 .kind(nostr::Kind::GitPatch) 1807 vec![
1800 .event(*proposal_id), 1808 nostr::Filter::default()
1801 nostr::Filter::default() 1809 .kind(nostr::Kind::GitPatch)
1802 .kind(nostr::Kind::GitPatch) 1810 .event(*proposal_id),
1803 .id(*proposal_id), 1811 nostr::Filter::default()
1804 ]) 1812 .kind(nostr::Kind::GitPatch)
1813 .id(*proposal_id),
1814 ],
1815 )
1805 .await?; 1816 .await?;
1806 1817
1807 let permissioned_users: HashSet<PublicKey> = [repo_ref.maintainers.clone(), vec![ 1818 let permissioned_users: HashSet<PublicKey> = [
1808 commit_events 1819 repo_ref.maintainers.clone(),
1809 .iter() 1820 vec![
1810 .find(|e| e.id.eq(proposal_id)) 1821 commit_events
1811 .context("proposal not in cache")? 1822 .iter()
1812 .pubkey, 1823 .find(|e| e.id.eq(proposal_id))
1813 ]] 1824 .context("proposal not in cache")?
1825 .pubkey,
1826 ],
1827 ]
1814 .concat() 1828 .concat()
1815 .iter() 1829 .iter()
1816 .copied() 1830 .copied()
@@ -1824,12 +1838,15 @@ pub async fn get_all_proposal_patch_events_from_cache(
1824 .collect(); 1838 .collect();
1825 1839
1826 if !revision_roots.is_empty() { 1840 if !revision_roots.is_empty() {
1827 for event in get_events_from_local_cache(git_repo_path, vec![ 1841 for event in get_events_from_local_cache(
1828 nostr::Filter::default() 1842 git_repo_path,
1829 .kind(nostr::Kind::GitPatch) 1843 vec![
1830 .events(revision_roots) 1844 nostr::Filter::default()
1831 .authors(permissioned_users.clone()), 1845 .kind(nostr::Kind::GitPatch)
1832 ]) 1846 .events(revision_roots)
1847 .authors(permissioned_users.clone()),
1848 ],
1849 )
1833 .await? 1850 .await?
1834 { 1851 {
1835 commit_events.push(event); 1852 commit_events.push(event);
@@ -1844,9 +1861,10 @@ pub async fn get_all_proposal_patch_events_from_cache(
1844} 1861}
1845 1862
1846pub async fn get_event_from_cache_by_id(git_repo: &Repo, event_id: &EventId) -> Result<Event> { 1863pub async fn get_event_from_cache_by_id(git_repo: &Repo, event_id: &EventId) -> Result<Event> {
1847 Ok(get_events_from_local_cache(git_repo.get_path()?, vec![ 1864 Ok(get_events_from_local_cache(
1848 nostr::Filter::default().id(*event_id), 1865 git_repo.get_path()?,
1849 ]) 1866 vec![nostr::Filter::default().id(*event_id)],
1867 )
1850 .await? 1868 .await?
1851 .first() 1869 .first()
1852 .context("failed to find event in cache")? 1870 .context("failed to find event in cache")?
diff --git a/src/lib/git/identify_ahead_behind.rs b/src/lib/git/identify_ahead_behind.rs
index baea687..d736522 100644
--- a/src/lib/git/identify_ahead_behind.rs
+++ b/src/lib/git/identify_ahead_behind.rs
@@ -184,10 +184,10 @@ mod tests {
184 identify_ahead_behind(&git_repo, &Some("feature".to_string()), &None)?; 184 identify_ahead_behind(&git_repo, &Some("feature".to_string()), &None)?;
185 185
186 assert_eq!(from_branch, "feature"); 186 assert_eq!(from_branch, "feature");
187 assert_eq!(ahead, vec![ 187 assert_eq!(
188 oid_to_sha1(&feature_oid), 188 ahead,
189 oid_to_sha1(&dev_oid_first) 189 vec![oid_to_sha1(&feature_oid), oid_to_sha1(&dev_oid_first)]
190 ]); 190 );
191 assert_eq!(to_branch, "main"); 191 assert_eq!(to_branch, "main");
192 assert_eq!(behind, vec![]); 192 assert_eq!(behind, vec![]);
193 193
diff --git a/src/lib/git/mod.rs b/src/lib/git/mod.rs
index 464990b..d4bf2f5 100644
--- a/src/lib/git/mod.rs
+++ b/src/lib/git/mod.rs
@@ -1490,10 +1490,10 @@ mod tests {
1490 &oid_to_sha1(&feature_oid), 1490 &oid_to_sha1(&feature_oid),
1491 )?; 1491 )?;
1492 assert_eq!(ahead, vec![]); 1492 assert_eq!(ahead, vec![]);
1493 assert_eq!(behind, vec![ 1493 assert_eq!(
1494 oid_to_sha1(&behind_2_oid), 1494 behind,
1495 oid_to_sha1(&behind_1_oid), 1495 vec![oid_to_sha1(&behind_2_oid), oid_to_sha1(&behind_1_oid),],
1496 ],); 1496 );
1497 Ok(()) 1497 Ok(())
1498 } 1498 }
1499 1499
@@ -1515,10 +1515,10 @@ mod tests {
1515 &oid_to_sha1(&main_oid), 1515 &oid_to_sha1(&main_oid),
1516 &oid_to_sha1(&ahead_2_oid), 1516 &oid_to_sha1(&ahead_2_oid),
1517 )?; 1517 )?;
1518 assert_eq!(ahead, vec![ 1518 assert_eq!(
1519 oid_to_sha1(&ahead_2_oid), 1519 ahead,
1520 oid_to_sha1(&ahead_1_oid), 1520 vec![oid_to_sha1(&ahead_2_oid), oid_to_sha1(&ahead_1_oid),],
1521 ],); 1521 );
1522 assert_eq!(behind, vec![]); 1522 assert_eq!(behind, vec![]);
1523 Ok(()) 1523 Ok(())
1524 } 1524 }
@@ -1547,14 +1547,14 @@ mod tests {
1547 &oid_to_sha1(&behind_2_oid), 1547 &oid_to_sha1(&behind_2_oid),
1548 &oid_to_sha1(&ahead_2_oid), 1548 &oid_to_sha1(&ahead_2_oid),
1549 )?; 1549 )?;
1550 assert_eq!(ahead, vec![ 1550 assert_eq!(
1551 oid_to_sha1(&ahead_2_oid), 1551 ahead,
1552 oid_to_sha1(&ahead_1_oid) 1552 vec![oid_to_sha1(&ahead_2_oid), oid_to_sha1(&ahead_1_oid)],
1553 ],); 1553 );
1554 assert_eq!(behind, vec![ 1554 assert_eq!(
1555 oid_to_sha1(&behind_2_oid), 1555 behind,
1556 oid_to_sha1(&behind_1_oid) 1556 vec![oid_to_sha1(&behind_2_oid), oid_to_sha1(&behind_1_oid)],
1557 ],); 1557 );
1558 Ok(()) 1558 Ok(())
1559 } 1559 }
1560 } 1560 }
@@ -2209,9 +2209,10 @@ mod tests {
2209 test_repo.populate_with_test_branch()?; 2209 test_repo.populate_with_test_branch()?;
2210 test_repo.checkout("main")?; 2210 test_repo.checkout("main")?;
2211 2211
2212 assert_eq!(git_repo.parse_starting_commits("HEAD~1")?, vec![ 2212 assert_eq!(
2213 str_to_sha1("431b84edc0d2fa118d63faa3c2db9c73d630a5ae")? 2213 git_repo.parse_starting_commits("HEAD~1")?,
2214 ],); 2214 vec![str_to_sha1("431b84edc0d2fa118d63faa3c2db9c73d630a5ae")?],
2215 );
2215 Ok(()) 2216 Ok(())
2216 } 2217 }
2217 2218
@@ -2221,9 +2222,10 @@ mod tests {
2221 let git_repo = Repo::from_path(&test_repo.dir)?; 2222 let git_repo = Repo::from_path(&test_repo.dir)?;
2222 test_repo.populate_with_test_branch()?; 2223 test_repo.populate_with_test_branch()?;
2223 2224
2224 assert_eq!(git_repo.parse_starting_commits("HEAD~1")?, vec![ 2225 assert_eq!(
2225 str_to_sha1("82ff2bcc9aa94d1bd8faee723d4c8cc190d6061c")? 2226 git_repo.parse_starting_commits("HEAD~1")?,
2226 ],); 2227 vec![str_to_sha1("82ff2bcc9aa94d1bd8faee723d4c8cc190d6061c")?],
2228 );
2227 Ok(()) 2229 Ok(())
2228 } 2230 }
2229 } 2231 }
@@ -2237,10 +2239,13 @@ mod tests {
2237 test_repo.populate_with_test_branch()?; 2239 test_repo.populate_with_test_branch()?;
2238 test_repo.checkout("main")?; 2240 test_repo.checkout("main")?;
2239 2241
2240 assert_eq!(git_repo.parse_starting_commits("HEAD~2")?, vec![ 2242 assert_eq!(
2241 str_to_sha1("431b84edc0d2fa118d63faa3c2db9c73d630a5ae")?, 2243 git_repo.parse_starting_commits("HEAD~2")?,
2242 str_to_sha1("af474d8d271490e5c635aad337abdc050034b16a")?, 2244 vec![
2243 ],); 2245 str_to_sha1("431b84edc0d2fa118d63faa3c2db9c73d630a5ae")?,
2246 str_to_sha1("af474d8d271490e5c635aad337abdc050034b16a")?,
2247 ],
2248 );
2244 Ok(()) 2249 Ok(())
2245 } 2250 }
2246 } 2251 }
@@ -2253,11 +2258,14 @@ mod tests {
2253 let git_repo = Repo::from_path(&test_repo.dir)?; 2258 let git_repo = Repo::from_path(&test_repo.dir)?;
2254 test_repo.populate_with_test_branch()?; 2259 test_repo.populate_with_test_branch()?;
2255 2260
2256 assert_eq!(git_repo.parse_starting_commits("HEAD~3")?, vec![ 2261 assert_eq!(
2257 str_to_sha1("82ff2bcc9aa94d1bd8faee723d4c8cc190d6061c")?, 2262 git_repo.parse_starting_commits("HEAD~3")?,
2258 str_to_sha1("a23e6b05aaeb7d1471b4a838b51f337d5644eeb0")?, 2263 vec![
2259 str_to_sha1("7ab82116068982671a8111f27dc10599172334b2")?, 2264 str_to_sha1("82ff2bcc9aa94d1bd8faee723d4c8cc190d6061c")?,
2260 ],); 2265 str_to_sha1("a23e6b05aaeb7d1471b4a838b51f337d5644eeb0")?,
2266 str_to_sha1("7ab82116068982671a8111f27dc10599172334b2")?,
2267 ],
2268 );
2261 Ok(()) 2269 Ok(())
2262 } 2270 }
2263 } 2271 }
@@ -2271,11 +2279,14 @@ mod tests {
2271 test_repo.populate_with_test_branch()?; 2279 test_repo.populate_with_test_branch()?;
2272 test_repo.checkout("main")?; 2280 test_repo.checkout("main")?;
2273 2281
2274 assert_eq!(git_repo.parse_starting_commits("af474d8..a23e6b0")?, vec![ 2282 assert_eq!(
2275 str_to_sha1("a23e6b05aaeb7d1471b4a838b51f337d5644eeb0")?, 2283 git_repo.parse_starting_commits("af474d8..a23e6b0")?,
2276 str_to_sha1("7ab82116068982671a8111f27dc10599172334b2")?, 2284 vec![
2277 str_to_sha1("431b84edc0d2fa118d63faa3c2db9c73d630a5ae")?, 2285 str_to_sha1("a23e6b05aaeb7d1471b4a838b51f337d5644eeb0")?,
2278 ],); 2286 str_to_sha1("7ab82116068982671a8111f27dc10599172334b2")?,
2287 str_to_sha1("431b84edc0d2fa118d63faa3c2db9c73d630a5ae")?,
2288 ],
2289 );
2279 Ok(()) 2290 Ok(())
2280 } 2291 }
2281 } 2292 }
diff --git a/src/lib/git_events.rs b/src/lib/git_events.rs
index 3ce7637..69406c1 100644
--- a/src/lib/git_events.rs
+++ b/src/lib/git_events.rs
@@ -134,14 +134,15 @@ pub async fn generate_patch_event(
134 // code that makes it into the main branch, assuming 134 // code that makes it into the main branch, assuming
135 // the commit id is correct 135 // the commit id is correct
136 Tag::from_standardized(TagStandard::Reference(commit.to_string())), 136 Tag::from_standardized(TagStandard::Reference(commit.to_string())),
137 Tag::custom(TagKind::Custom(std::borrow::Cow::Borrowed("alt")), vec![ 137 Tag::custom(
138 format!( 138 TagKind::Custom(std::borrow::Cow::Borrowed("alt")),
139 vec![format!(
139 "git patch: {}", 140 "git patch: {}",
140 git_repo 141 git_repo
141 .get_commit_message_summary(commit) 142 .get_commit_message_summary(commit)
142 .unwrap_or_default() 143 .unwrap_or_default()
143 ), 144 )],
144 ]), 145 ),
145 ], 146 ],
146 if let Some(thread_event_id) = thread_event_id { 147 if let Some(thread_event_id) = thread_event_id {
147 vec![Tag::from_standardized(nostr_sdk::TagStandard::Event { 148 vec![Tag::from_standardized(nostr_sdk::TagStandard::Event {
@@ -205,9 +206,10 @@ pub async fn generate_patch_event(
205 .collect(), 206 .collect(),
206 vec![ 207 vec![
207 // a fallback is now in place to extract this from the patch 208 // a fallback is now in place to extract this from the patch
208 Tag::custom(TagKind::Custom(std::borrow::Cow::Borrowed("commit")), vec![ 209 Tag::custom(
209 commit.to_string(), 210 TagKind::Custom(std::borrow::Cow::Borrowed("commit")),
210 ]), 211 vec![commit.to_string()],
212 ),
211 // this is required as patches cannot be relied upon to include the 'base 213 // this is required as patches cannot be relied upon to include the 'base
212 // commit' 214 // commit'
213 Tag::custom( 215 Tag::custom(
diff --git a/src/lib/login/mod.rs b/src/lib/login/mod.rs
index bfc7328..3fcd755 100644
--- a/src/lib/login/mod.rs
+++ b/src/lib/login/mod.rs
@@ -79,11 +79,15 @@ fn print_logged_in_as(
79 "failed to find your relay list. consider using another nostr client to create one to enhance your nostr experience." 79 "failed to find your relay list. consider using another nostr client to create one to enhance your nostr experience."
80 ); 80 );
81 } 81 }
82 eprintln!("logged in as {}{}", user_ref.metadata.name, match source { 82 eprintln!(
83 SignerInfoSource::CommandLineArguments => " via cli arguments", 83 "logged in as {}{}",
84 SignerInfoSource::GitLocal => " to local repository", 84 user_ref.metadata.name,
85 SignerInfoSource::GitGlobal => "", 85 match source {
86 }); 86 SignerInfoSource::CommandLineArguments => " via cli arguments",
87 SignerInfoSource::GitLocal => " to local repository",
88 SignerInfoSource::GitGlobal => "",
89 }
90 );
87 Ok(()) 91 Ok(())
88} 92}
89 93
diff --git a/src/lib/repo_ref.rs b/src/lib/repo_ref.rs
index c1fc288..0236e34 100644
--- a/src/lib/repo_ref.rs
+++ b/src/lib/repo_ref.rs
@@ -578,11 +578,14 @@ pub fn save_repo_config_to_yaml(
578 .context("failed to convert public key into npub")?, 578 .context("failed to convert public key into npub")?,
579 ); 579 );
580 } 580 }
581 serde_yaml::to_writer(file, &RepoConfigYaml { 581 serde_yaml::to_writer(
582 identifier: Some(identifier), 582 file,
583 maintainers: maintainers_npubs, 583 &RepoConfigYaml {
584 relays, 584 identifier: Some(identifier),
585 }) 585 maintainers: maintainers_npubs,
586 relays,
587 },
588 )
586 .context("failed to write maintainers to maintainers.yaml file serde_yaml") 589 .context("failed to write maintainers to maintainers.yaml file serde_yaml")
587} 590}
588 591
diff --git a/src/lib/repo_state.rs b/src/lib/repo_state.rs
index 04f3cf2..345f05c 100644
--- a/src/lib/repo_state.rs
+++ b/src/lib/repo_state.rs
@@ -56,9 +56,10 @@ impl RepoState {
56 add_head(&mut state); 56 add_head(&mut state);
57 let mut tags = vec![Tag::identifier(identifier.clone())]; 57 let mut tags = vec![Tag::identifier(identifier.clone())];
58 for (name, value) in &state { 58 for (name, value) in &state {
59 tags.push(Tag::custom(nostr_sdk::TagKind::Custom(name.into()), vec![ 59 tags.push(Tag::custom(
60 value.clone(), 60 nostr_sdk::TagKind::Custom(name.into()),
61 ])); 61 vec![value.clone()],
62 ));
62 } 63 }
63 let event = sign_event( 64 let event = sign_event(
64 EventBuilder::new(STATE_KIND, "").tags(tags), 65 EventBuilder::new(STATE_KIND, "").tags(tags),