upleb.uk

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

summaryrefslogtreecommitdiff
path: root/tests/common
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2026-01-07 15:50:50 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2026-01-07 15:50:50 +0000
commit049cff14fa731c95b9b0074f67469df3af19870b (patch)
tree78f87b52385eaaaa1d221745cdf367ee81b598ba /tests/common
parent1db877d53c4ff45971c69fecc5165c352ec316c9 (diff)
test: add test_pr_event_syncs_from_remote
Diffstat (limited to 'tests/common')
-rw-r--r--tests/common/purgatory_helpers.rs67
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/common/purgatory_helpers.rs b/tests/common/purgatory_helpers.rs
index e61e2e2..7d8e908 100644
--- a/tests/common/purgatory_helpers.rs
+++ b/tests/common/purgatory_helpers.rs
@@ -529,6 +529,73 @@ pub fn push_to_relay(
529 Ok(()) 529 Ok(())
530} 530}
531 531
532/// Push a specific ref to a relay.
533///
534/// This is used for pushing to refs/nostr/<event-id> for PR events.
535/// Unlike `push_to_relay` which pushes all refs, this pushes a specific
536/// commit to a specific ref name.
537///
538/// # Arguments
539/// * `local_path` - Path to local git repository
540/// * `relay_domain` - The relay domain (e.g., "127.0.0.1:8080")
541/// * `npub` - Owner's npub
542/// * `repo_id` - Repository identifier
543/// * `commit_hash` - The commit to push
544/// * `ref_name` - The ref name to push to (e.g., "refs/nostr/<event-id>")
545///
546/// # Returns
547/// * `Ok(())` - Push successful
548/// * `Err(String)` - Push failed
549pub fn push_ref_to_relay(
550 local_path: &Path,
551 relay_domain: &str,
552 npub: &str,
553 repo_id: &str,
554 commit_hash: &str,
555 ref_name: &str,
556) -> Result<(), String> {
557 let remote_url = format!("http://{}/{}/{}.git", relay_domain, npub, repo_id);
558
559 // Check if origin already exists
560 let check_output = Command::new("git")
561 .args(["remote", "get-url", "origin"])
562 .current_dir(local_path)
563 .output()
564 .map_err(|e| format!("Failed to check remote: {}", e))?;
565
566 if check_output.status.success() {
567 // Remote exists, update it
568 let _ = Command::new("git")
569 .args(["remote", "set-url", "origin", &remote_url])
570 .current_dir(local_path)
571 .output();
572 } else {
573 // Add new remote
574 let _ = Command::new("git")
575 .args(["remote", "add", "origin", &remote_url])
576 .current_dir(local_path)
577 .output();
578 }
579
580 // Push specific commit to specific ref
581 // Format: git push origin <commit>:<ref>
582 let refspec = format!("{}:{}", commit_hash, ref_name);
583 let output = Command::new("git")
584 .args(["push", "origin", &refspec])
585 .current_dir(local_path)
586 .output()
587 .map_err(|e| format!("Failed to run git push: {}", e))?;
588
589 if !output.status.success() {
590 return Err(format!(
591 "git push failed: {}",
592 String::from_utf8_lossy(&output.stderr)
593 ));
594 }
595
596 Ok(())
597}
598
532#[cfg(test)] 599#[cfg(test)]
533mod tests { 600mod tests {
534 use super::*; 601 use super::*;