upleb.uk

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

summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2026-02-17 10:42:33 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2026-02-17 11:38:26 +0000
commitfe5addc2a61022824e83c3523a83fce7690ca8e8 (patch)
treeb9791bd9447828ebd77b69c3989b53bb47c0cd70 /tests
parentf84b658530c0c0eaaaa0473add8c8c359fa6b09e (diff)
feat: add push-options for title and description to git-remote-nostr
Allows setting PR title and description via git push options: git push --push-option=title="My PR" \ --push-option=description="Details" origin pr/branch
Diffstat (limited to 'tests')
-rw-r--r--tests/git_remote_nostr/push.rs121
1 files changed, 121 insertions, 0 deletions
diff --git a/tests/git_remote_nostr/push.rs b/tests/git_remote_nostr/push.rs
index 404d07f..38b1f8c 100644
--- a/tests/git_remote_nostr/push.rs
+++ b/tests/git_remote_nostr/push.rs
@@ -1,4 +1,5 @@
1use git2::Signature; 1use git2::Signature;
2use ngit::git_events::KIND_PULL_REQUEST;
2use rstest::*; 3use rstest::*;
3 4
4use super::*; 5use super::*;
@@ -1774,6 +1775,126 @@ async fn push_new_pr_branch_creates_proposal() -> Result<()> {
1774 Ok(()) 1775 Ok(())
1775} 1776}
1776 1777
1778#[tokio::test]
1779#[serial]
1780async fn push_new_pr_branch_with_title_description_options_creates_pr_with_custom_title_description()
1781-> Result<()> {
1782 let (events, source_git_repo) = prep_source_repo_and_events_including_proposals().await?;
1783 let _source_path = source_git_repo.dir.to_str().unwrap().to_string();
1784
1785 let (mut r51, mut r52, mut r53, mut r55, mut r56, mut r57) = (
1786 Relay::new(8051, None, None),
1787 Relay::new(8052, None, None),
1788 Relay::new(8053, None, None),
1789 Relay::new(8055, None, None),
1790 Relay::new(8056, None, None),
1791 Relay::new(8057, None, None),
1792 );
1793 r51.events = events.clone();
1794 r55.events = events.clone();
1795
1796 #[allow(clippy::mutable_key_type)]
1797 let before = r55.events.iter().cloned().collect::<HashSet<Event>>();
1798 let branch_name = "pr/my-pr-with-title";
1799
1800 let cli_tester_handle = std::thread::spawn(move || -> Result<String> {
1801 let mut git_repo = clone_git_repo_with_nostr_url()?;
1802 git_repo.delete_dir_on_drop = false;
1803 git_repo.create_branch(branch_name)?;
1804 git_repo.checkout(branch_name)?;
1805
1806 let large_content = "x".repeat(70 * 1024);
1807 std::fs::write(git_repo.dir.join("large_file.txt"), large_content)?;
1808 git_repo.stage_and_commit("large_file.txt")?;
1809
1810 let mut p = CliTester::new_git_with_remote_helper_from_dir(
1811 &git_repo.dir,
1812 [
1813 "push",
1814 "--push-option=title=Custom PR Title",
1815 "--push-option=description=Custom PR description here",
1816 "-u",
1817 "origin",
1818 branch_name,
1819 ],
1820 );
1821 cli_expect_nostr_fetch(&mut p)?;
1822 p.expect("git servers: listing refs...\r\n")?;
1823 p.expect_eventually_and_print(format!("To {}\r\n", get_nostr_remote_url()?).as_str())?;
1824 let output = p.expect_end_eventually()?;
1825
1826 for p in [51, 52, 53, 55, 56, 57] {
1827 relay::shutdown_relay(8000 + p)?;
1828 }
1829
1830 Ok(output)
1831 });
1832 let _ = join!(
1833 r51.listen_until_close(),
1834 r52.listen_until_close(),
1835 r53.listen_until_close(),
1836 r55.listen_until_close(),
1837 r56.listen_until_close(),
1838 r57.listen_until_close(),
1839 );
1840
1841 let output = cli_tester_handle.join().unwrap()?;
1842
1843 assert_eq!(
1844 output,
1845 format!(" * [new branch] {branch_name} -> {branch_name}\r\nbranch '{branch_name}' set up to track 'origin/{branch_name}'.\r\n").as_str(),
1846 );
1847
1848 let new_events = r55
1849 .events
1850 .iter()
1851 .cloned()
1852 .collect::<HashSet<Event>>()
1853 .difference(&before)
1854 .cloned()
1855 .collect::<Vec<Event>>();
1856 assert_eq!(new_events.len(), 1, "should create exactly 1 PR event");
1857
1858 let pr_event = new_events.first().unwrap();
1859
1860 assert!(
1861 pr_event.kind.eq(&KIND_PULL_REQUEST),
1862 "event should be a PR event"
1863 );
1864
1865 let title_tag = pr_event.tags.iter().find(|t| t.as_slice()[0].eq("subject"));
1866 assert!(
1867 title_tag.is_some(),
1868 "PR event should have a subject tag for title"
1869 );
1870 assert_eq!(
1871 title_tag.unwrap().as_slice()[1],
1872 "Custom PR Title",
1873 "title should match push-option"
1874 );
1875
1876 assert_eq!(
1877 pr_event.content, "Custom PR description here",
1878 "description should match push-option"
1879 );
1880
1881 let branch_name_tag = pr_event
1882 .tags
1883 .iter()
1884 .find(|t| t.as_slice()[0].eq("branch-name"));
1885 assert!(
1886 branch_name_tag.is_some(),
1887 "PR event should have a branch-name tag"
1888 );
1889 assert_eq!(
1890 branch_name_tag.unwrap().as_slice()[1],
1891 branch_name.replace("pr/", ""),
1892 "branch-name tag should match"
1893 );
1894
1895 Ok(())
1896}
1897
1777mod push_from_another_maintainer { 1898mod push_from_another_maintainer {
1778 1899
1779 // TODO that has issued announcement 1900 // TODO that has issued announcement