upleb.uk

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

summaryrefslogtreecommitdiff
path: root/test_utils/src/lib.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-07-23 16:36:06 +0100
committerDanConwayDev <DanConwayDev@protonmail.com>2024-07-23 16:36:06 +0100
commitb67376ff54abeab31422921ba5f4883d5d3dccdb (patch)
treed4f4194fdf2d285332dd7aacea31678042389b00 /test_utils/src/lib.rs
parent643fa17fde858c2d6f934dcc435eb84843cc172e (diff)
feat(list): unique proposal branch names
to prevent accidental name conflicts. also moved to prs/* namespace `pull` and `push` integration tests are intermitantly failing to end at least for `push` they work when run individually but not when run together
Diffstat (limited to 'test_utils/src/lib.rs')
-rw-r--r--test_utils/src/lib.rs60
1 files changed, 59 insertions, 1 deletions
diff --git a/test_utils/src/lib.rs b/test_utils/src/lib.rs
index a2ed5f2..de7aee5 100644
--- a/test_utils/src/lib.rs
+++ b/test_utils/src/lib.rs
@@ -1,9 +1,17 @@
1use std::{ffi::OsStr, path::PathBuf, str::FromStr}; 1use std::{
2 ffi::OsStr,
3 path::{Path, PathBuf},
4 str::FromStr,
5};
2 6
3use anyhow::{bail, ensure, Context, Result}; 7use anyhow::{bail, ensure, Context, Result};
4use dialoguer::theme::{ColorfulTheme, Theme}; 8use dialoguer::theme::{ColorfulTheme, Theme};
9use futures::executor::block_on;
10use git::GitTestRepo;
5use nostr::{self, nips::nip65::RelayMetadata, Kind, Tag}; 11use nostr::{self, nips::nip65::RelayMetadata, Kind, Tag};
12use nostr_database::{NostrDatabase, Order};
6use nostr_sdk::{serde_json, NostrSigner, TagStandard}; 13use nostr_sdk::{serde_json, NostrSigner, TagStandard};
14use nostr_sqlite::SQLiteDatabase;
7use once_cell::sync::Lazy; 15use once_cell::sync::Lazy;
8use rexpect::session::{Options, PtySession}; 16use rexpect::session::{Options, PtySession};
9use strip_ansi_escapes::strip_str; 17use strip_ansi_escapes::strip_str;
@@ -935,3 +943,53 @@ where
935 }, 943 },
936 ) 944 )
937} 945}
946
947/** copied from client.rs */
948async fn get_local_cache_database(git_repo_path: &Path) -> Result<SQLiteDatabase> {
949 SQLiteDatabase::open(git_repo_path.join(".git/nostr-cache.sqlite"))
950 .await
951 .context("cannot open or create nostr cache database at .git/nostr-cache.sqlite")
952}
953
954/** copied from client.rs */
955pub async fn get_events_from_cache(
956 git_repo_path: &Path,
957 filters: Vec<nostr::Filter>,
958) -> Result<Vec<nostr::Event>> {
959 get_local_cache_database(git_repo_path)
960 .await?
961 .query(filters.clone(), Order::Asc)
962 .await
963 .context(
964 "cannot execute query on opened git repo nostr cache database .git/nostr-cache.sqlite",
965 )
966}
967
968pub fn get_proposal_branch_name(
969 test_repo: &GitTestRepo,
970 branch_name_in_event: &str,
971) -> Result<String> {
972 let events = block_on(get_events_from_cache(
973 &test_repo.dir,
974 vec![
975 nostr::Filter::default()
976 .kind(nostr_sdk::Kind::GitPatch)
977 .hashtag("root"),
978 ],
979 ))?;
980 for event in events {
981 if event.iter_tags().any(|t| {
982 !t.as_vec()[1].eq("revision-root")
983 && event.iter_tags().any(|t| {
984 t.as_vec()[0].eq("branch-name") && t.as_vec()[1].eq(branch_name_in_event)
985 })
986 }) {
987 return Ok(format!(
988 "prs/{}({})",
989 branch_name_in_event,
990 &event.id.to_hex().as_str()[..8],
991 ));
992 }
993 }
994 bail!("cannot find proposal root with branch-name tag matching title")
995}