diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2023-10-01 00:00:00 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2023-10-01 00:00:00 +0100 |
| commit | b9a88672b8734448615354e3f46748d2fdc2f647 (patch) | |
| tree | fd9b55c4ea8a132ab31abec3b6b8a4833c9bd8ff | |
| parent | 5dce8a09f0f980b878bd02b7e96fc001155492ec (diff) | |
feat(prs-create) send commit to relay
- add client
- use client to send event
- add async functionality - enabler for relay interaction whilst
getting cli input
| -rw-r--r-- | Cargo.lock | 215 | ||||
| -rw-r--r-- | Cargo.toml | 6 | ||||
| -rw-r--r-- | src/client.rs | 65 | ||||
| -rw-r--r-- | src/main.rs | 6 | ||||
| -rw-r--r-- | src/sub_commands/prs/create.rs | 20 | ||||
| -rw-r--r-- | src/sub_commands/prs/mod.rs | 4 | ||||
| -rw-r--r-- | test_utils/Cargo.toml | 2 |
7 files changed, 305 insertions, 13 deletions
| @@ -268,6 +268,29 @@ dependencies = [ | |||
| 268 | ] | 268 | ] |
| 269 | 269 | ||
| 270 | [[package]] | 270 | [[package]] |
| 271 | name = "async-utility" | ||
| 272 | version = "0.1.1" | ||
| 273 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 274 | checksum = "3716c0d3970fe92d79a8f4cda2caf91113574505dff5b18e455e549d4b078e98" | ||
| 275 | dependencies = [ | ||
| 276 | "futures-util", | ||
| 277 | "gloo-timers", | ||
| 278 | "tokio", | ||
| 279 | "wasm-bindgen-futures", | ||
| 280 | ] | ||
| 281 | |||
| 282 | [[package]] | ||
| 283 | name = "async_io_stream" | ||
| 284 | version = "0.3.3" | ||
| 285 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 286 | checksum = "b6d7b9decdf35d8908a7e3ef02f64c5e9b1695e230154c0e8de3969142d9b94c" | ||
| 287 | dependencies = [ | ||
| 288 | "futures", | ||
| 289 | "pharos", | ||
| 290 | "rustc_version", | ||
| 291 | ] | ||
| 292 | |||
| 293 | [[package]] | ||
| 271 | name = "atomic-waker" | 294 | name = "atomic-waker" |
| 272 | version = "1.1.2" | 295 | version = "1.1.2" |
| 273 | source = "registry+https://github.com/rust-lang/crates.io-index" | 296 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| @@ -334,6 +357,7 @@ dependencies = [ | |||
| 334 | "bitcoin_hashes 0.12.0", | 357 | "bitcoin_hashes 0.12.0", |
| 335 | "hex_lit", | 358 | "hex_lit", |
| 336 | "secp256k1", | 359 | "secp256k1", |
| 360 | "serde", | ||
| 337 | ] | 361 | ] |
| 338 | 362 | ||
| 339 | [[package]] | 363 | [[package]] |
| @@ -651,6 +675,12 @@ dependencies = [ | |||
| 651 | ] | 675 | ] |
| 652 | 676 | ||
| 653 | [[package]] | 677 | [[package]] |
| 678 | name = "data-encoding" | ||
| 679 | version = "2.4.0" | ||
| 680 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 681 | checksum = "c2e66c9d817f1720209181c316d28635c050fa304f9c79e47a520882661b7308" | ||
| 682 | |||
| 683 | [[package]] | ||
| 654 | name = "derivative" | 684 | name = "derivative" |
| 655 | version = "2.2.0" | 685 | version = "2.2.0" |
| 656 | source = "registry+https://github.com/rust-lang/crates.io-index" | 686 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| @@ -1002,6 +1032,18 @@ dependencies = [ | |||
| 1002 | ] | 1032 | ] |
| 1003 | 1033 | ||
| 1004 | [[package]] | 1034 | [[package]] |
| 1035 | name = "gloo-timers" | ||
| 1036 | version = "0.2.6" | ||
| 1037 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1038 | checksum = "9b995a66bb87bebce9a0f4a95aed01daca4872c050bfcb21653361c03bc35e5c" | ||
| 1039 | dependencies = [ | ||
| 1040 | "futures-channel", | ||
| 1041 | "futures-core", | ||
| 1042 | "js-sys", | ||
| 1043 | "wasm-bindgen", | ||
| 1044 | ] | ||
| 1045 | |||
| 1046 | [[package]] | ||
| 1005 | name = "h2" | 1047 | name = "h2" |
| 1006 | version = "0.3.21" | 1048 | version = "0.3.21" |
| 1007 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1049 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| @@ -1444,15 +1486,18 @@ version = "0.0.1" | |||
| 1444 | dependencies = [ | 1486 | dependencies = [ |
| 1445 | "anyhow", | 1487 | "anyhow", |
| 1446 | "assert_cmd", | 1488 | "assert_cmd", |
| 1489 | "async-trait", | ||
| 1447 | "chacha20poly1305", | 1490 | "chacha20poly1305", |
| 1448 | "clap", | 1491 | "clap", |
| 1449 | "dialoguer", | 1492 | "dialoguer", |
| 1450 | "directories", | 1493 | "directories", |
| 1451 | "duplicate", | 1494 | "duplicate", |
| 1495 | "futures", | ||
| 1452 | "git2", | 1496 | "git2", |
| 1453 | "keyring", | 1497 | "keyring", |
| 1454 | "mockall", | 1498 | "mockall", |
| 1455 | "nostr", | 1499 | "nostr", |
| 1500 | "nostr-sdk", | ||
| 1456 | "once_cell", | 1501 | "once_cell", |
| 1457 | "passwords", | 1502 | "passwords", |
| 1458 | "rexpect 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", | 1503 | "rexpect 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", |
| @@ -1461,6 +1506,7 @@ dependencies = [ | |||
| 1461 | "serde_json", | 1506 | "serde_json", |
| 1462 | "serial_test", | 1507 | "serial_test", |
| 1463 | "test_utils", | 1508 | "test_utils", |
| 1509 | "tokio", | ||
| 1464 | "zeroize", | 1510 | "zeroize", |
| 1465 | ] | 1511 | ] |
| 1466 | 1512 | ||
| @@ -1499,25 +1545,56 @@ checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" | |||
| 1499 | 1545 | ||
| 1500 | [[package]] | 1546 | [[package]] |
| 1501 | name = "nostr" | 1547 | name = "nostr" |
| 1502 | version = "0.23.0" | 1548 | version = "0.24.0" |
| 1503 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1549 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1504 | checksum = "525a8f75106f4eeb1fedaacadc61547548fe4715c3edde7d03eed2900b467952" | 1550 | checksum = "df0af088a37ea0026bf96dcd66db8bf21ed7ff528b7cbe34b7f32f6af3ae14a0" |
| 1505 | dependencies = [ | 1551 | dependencies = [ |
| 1506 | "aes 0.8.3", | 1552 | "aes 0.8.3", |
| 1507 | "base64", | 1553 | "base64", |
| 1508 | "bech32", | ||
| 1509 | "bip39", | 1554 | "bip39", |
| 1510 | "bitcoin", | 1555 | "bitcoin", |
| 1511 | "bitcoin_hashes 0.12.0", | ||
| 1512 | "cbc", | 1556 | "cbc", |
| 1557 | "chacha20", | ||
| 1513 | "getrandom", | 1558 | "getrandom", |
| 1514 | "instant", | 1559 | "instant", |
| 1560 | "once_cell", | ||
| 1515 | "reqwest", | 1561 | "reqwest", |
| 1516 | "secp256k1", | ||
| 1517 | "serde", | 1562 | "serde", |
| 1518 | "serde_json", | 1563 | "serde_json", |
| 1519 | "tracing", | 1564 | "tracing", |
| 1520 | "url", | 1565 | "url-fork", |
| 1566 | ] | ||
| 1567 | |||
| 1568 | [[package]] | ||
| 1569 | name = "nostr-sdk" | ||
| 1570 | version = "0.24.0" | ||
| 1571 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1572 | checksum = "5facab78c73baf3853f8c807006e23567dd3825392ef13a3a07122f4ce18b56d" | ||
| 1573 | dependencies = [ | ||
| 1574 | "async-utility", | ||
| 1575 | "nostr", | ||
| 1576 | "nostr-sdk-net", | ||
| 1577 | "once_cell", | ||
| 1578 | "thiserror", | ||
| 1579 | "tokio", | ||
| 1580 | "tracing", | ||
| 1581 | ] | ||
| 1582 | |||
| 1583 | [[package]] | ||
| 1584 | name = "nostr-sdk-net" | ||
| 1585 | version = "0.24.0" | ||
| 1586 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1587 | checksum = "fa4058b0267a1537c25b4674db9ed7a18152fc4c33df246dd4a88701007084ee" | ||
| 1588 | dependencies = [ | ||
| 1589 | "futures-util", | ||
| 1590 | "thiserror", | ||
| 1591 | "tokio", | ||
| 1592 | "tokio-rustls", | ||
| 1593 | "tokio-socks", | ||
| 1594 | "tokio-tungstenite", | ||
| 1595 | "url-fork", | ||
| 1596 | "webpki-roots", | ||
| 1597 | "ws_stream_wasm", | ||
| 1521 | ] | 1598 | ] |
| 1522 | 1599 | ||
| 1523 | [[package]] | 1600 | [[package]] |
| @@ -1597,6 +1674,16 @@ dependencies = [ | |||
| 1597 | ] | 1674 | ] |
| 1598 | 1675 | ||
| 1599 | [[package]] | 1676 | [[package]] |
| 1677 | name = "num_cpus" | ||
| 1678 | version = "1.16.0" | ||
| 1679 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1680 | checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" | ||
| 1681 | dependencies = [ | ||
| 1682 | "hermit-abi", | ||
| 1683 | "libc", | ||
| 1684 | ] | ||
| 1685 | |||
| 1686 | [[package]] | ||
| 1600 | name = "object" | 1687 | name = "object" |
| 1601 | version = "0.32.1" | 1688 | version = "0.32.1" |
| 1602 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1689 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| @@ -1717,6 +1804,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
| 1717 | checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" | 1804 | checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" |
| 1718 | 1805 | ||
| 1719 | [[package]] | 1806 | [[package]] |
| 1807 | name = "pharos" | ||
| 1808 | version = "0.5.3" | ||
| 1809 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1810 | checksum = "e9567389417feee6ce15dd6527a8a1ecac205ef62c2932bcf3d9f6fc5b78b414" | ||
| 1811 | dependencies = [ | ||
| 1812 | "futures", | ||
| 1813 | "rustc_version", | ||
| 1814 | ] | ||
| 1815 | |||
| 1816 | [[package]] | ||
| 1720 | name = "pin-project-lite" | 1817 | name = "pin-project-lite" |
| 1721 | version = "0.2.13" | 1818 | version = "0.2.13" |
| 1722 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1819 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| @@ -2085,6 +2182,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
| 2085 | checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" | 2182 | checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" |
| 2086 | 2183 | ||
| 2087 | [[package]] | 2184 | [[package]] |
| 2185 | name = "rustc_version" | ||
| 2186 | version = "0.4.0" | ||
| 2187 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2188 | checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" | ||
| 2189 | dependencies = [ | ||
| 2190 | "semver", | ||
| 2191 | ] | ||
| 2192 | |||
| 2193 | [[package]] | ||
| 2088 | name = "rustix" | 2194 | name = "rustix" |
| 2089 | version = "0.37.24" | 2195 | version = "0.37.24" |
| 2090 | source = "registry+https://github.com/rust-lang/crates.io-index" | 2196 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| @@ -2249,6 +2355,18 @@ dependencies = [ | |||
| 2249 | ] | 2355 | ] |
| 2250 | 2356 | ||
| 2251 | [[package]] | 2357 | [[package]] |
| 2358 | name = "semver" | ||
| 2359 | version = "1.0.20" | ||
| 2360 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2361 | checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" | ||
| 2362 | |||
| 2363 | [[package]] | ||
| 2364 | name = "send_wrapper" | ||
| 2365 | version = "0.6.0" | ||
| 2366 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2367 | checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73" | ||
| 2368 | |||
| 2369 | [[package]] | ||
| 2252 | name = "serde" | 2370 | name = "serde" |
| 2253 | version = "1.0.188" | 2371 | version = "1.0.188" |
| 2254 | source = "registry+https://github.com/rust-lang/crates.io-index" | 2372 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| @@ -2555,12 +2673,25 @@ dependencies = [ | |||
| 2555 | "bytes", | 2673 | "bytes", |
| 2556 | "libc", | 2674 | "libc", |
| 2557 | "mio", | 2675 | "mio", |
| 2676 | "num_cpus", | ||
| 2558 | "pin-project-lite", | 2677 | "pin-project-lite", |
| 2559 | "socket2 0.5.4", | 2678 | "socket2 0.5.4", |
| 2679 | "tokio-macros", | ||
| 2560 | "windows-sys 0.48.0", | 2680 | "windows-sys 0.48.0", |
| 2561 | ] | 2681 | ] |
| 2562 | 2682 | ||
| 2563 | [[package]] | 2683 | [[package]] |
| 2684 | name = "tokio-macros" | ||
| 2685 | version = "2.1.0" | ||
| 2686 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2687 | checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" | ||
| 2688 | dependencies = [ | ||
| 2689 | "proc-macro2", | ||
| 2690 | "quote", | ||
| 2691 | "syn 2.0.38", | ||
| 2692 | ] | ||
| 2693 | |||
| 2694 | [[package]] | ||
| 2564 | name = "tokio-rustls" | 2695 | name = "tokio-rustls" |
| 2565 | version = "0.24.1" | 2696 | version = "0.24.1" |
| 2566 | source = "registry+https://github.com/rust-lang/crates.io-index" | 2697 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| @@ -2583,6 +2714,21 @@ dependencies = [ | |||
| 2583 | ] | 2714 | ] |
| 2584 | 2715 | ||
| 2585 | [[package]] | 2716 | [[package]] |
| 2717 | name = "tokio-tungstenite" | ||
| 2718 | version = "0.20.1" | ||
| 2719 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2720 | checksum = "212d5dcb2a1ce06d81107c3d0ffa3121fe974b73f068c8282cb1c32328113b6c" | ||
| 2721 | dependencies = [ | ||
| 2722 | "futures-util", | ||
| 2723 | "log", | ||
| 2724 | "rustls", | ||
| 2725 | "tokio", | ||
| 2726 | "tokio-rustls", | ||
| 2727 | "tungstenite", | ||
| 2728 | "webpki-roots", | ||
| 2729 | ] | ||
| 2730 | |||
| 2731 | [[package]] | ||
| 2586 | name = "tokio-util" | 2732 | name = "tokio-util" |
| 2587 | version = "0.7.9" | 2733 | version = "0.7.9" |
| 2588 | source = "registry+https://github.com/rust-lang/crates.io-index" | 2734 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| @@ -2658,6 +2804,26 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
| 2658 | checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" | 2804 | checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" |
| 2659 | 2805 | ||
| 2660 | [[package]] | 2806 | [[package]] |
| 2807 | name = "tungstenite" | ||
| 2808 | version = "0.20.1" | ||
| 2809 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2810 | checksum = "9e3dac10fd62eaf6617d3a904ae222845979aec67c615d1c842b4002c7666fb9" | ||
| 2811 | dependencies = [ | ||
| 2812 | "byteorder", | ||
| 2813 | "bytes", | ||
| 2814 | "data-encoding", | ||
| 2815 | "http", | ||
| 2816 | "httparse", | ||
| 2817 | "log", | ||
| 2818 | "rand", | ||
| 2819 | "rustls", | ||
| 2820 | "sha1", | ||
| 2821 | "thiserror", | ||
| 2822 | "url", | ||
| 2823 | "utf-8", | ||
| 2824 | ] | ||
| 2825 | |||
| 2826 | [[package]] | ||
| 2661 | name = "typenum" | 2827 | name = "typenum" |
| 2662 | version = "1.17.0" | 2828 | version = "1.17.0" |
| 2663 | source = "registry+https://github.com/rust-lang/crates.io-index" | 2829 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| @@ -2725,10 +2891,28 @@ dependencies = [ | |||
| 2725 | "form_urlencoded", | 2891 | "form_urlencoded", |
| 2726 | "idna", | 2892 | "idna", |
| 2727 | "percent-encoding", | 2893 | "percent-encoding", |
| 2894 | ] | ||
| 2895 | |||
| 2896 | [[package]] | ||
| 2897 | name = "url-fork" | ||
| 2898 | version = "3.0.0" | ||
| 2899 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2900 | checksum = "956afc9d7e101f0b718a6776489cd7998d0b17fc79f4cdb6ee6761fb72d1c2ce" | ||
| 2901 | dependencies = [ | ||
| 2902 | "form_urlencoded", | ||
| 2903 | "percent-encoding", | ||
| 2728 | "serde", | 2904 | "serde", |
| 2905 | "unicode-bidi", | ||
| 2906 | "unicode-normalization", | ||
| 2729 | ] | 2907 | ] |
| 2730 | 2908 | ||
| 2731 | [[package]] | 2909 | [[package]] |
| 2910 | name = "utf-8" | ||
| 2911 | version = "0.7.6" | ||
| 2912 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2913 | checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" | ||
| 2914 | |||
| 2915 | [[package]] | ||
| 2732 | name = "utf8parse" | 2916 | name = "utf8parse" |
| 2733 | version = "0.2.1" | 2917 | version = "0.2.1" |
| 2734 | source = "registry+https://github.com/rust-lang/crates.io-index" | 2918 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| @@ -3052,6 +3236,25 @@ dependencies = [ | |||
| 3052 | ] | 3236 | ] |
| 3053 | 3237 | ||
| 3054 | [[package]] | 3238 | [[package]] |
| 3239 | name = "ws_stream_wasm" | ||
| 3240 | version = "0.7.4" | ||
| 3241 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 3242 | checksum = "7999f5f4217fe3818726b66257a4475f71e74ffd190776ad053fa159e50737f5" | ||
| 3243 | dependencies = [ | ||
| 3244 | "async_io_stream", | ||
| 3245 | "futures", | ||
| 3246 | "js-sys", | ||
| 3247 | "log", | ||
| 3248 | "pharos", | ||
| 3249 | "rustc_version", | ||
| 3250 | "send_wrapper", | ||
| 3251 | "thiserror", | ||
| 3252 | "wasm-bindgen", | ||
| 3253 | "wasm-bindgen-futures", | ||
| 3254 | "web-sys", | ||
| 3255 | ] | ||
| 3256 | |||
| 3257 | [[package]] | ||
| 3055 | name = "xdg-home" | 3258 | name = "xdg-home" |
| 3056 | version = "1.0.0" | 3259 | version = "1.0.0" |
| 3057 | source = "registry+https://github.com/rust-lang/crates.io-index" | 3260 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| @@ -13,17 +13,21 @@ categories = ["command-line-utilities","git"] | |||
| 13 | 13 | ||
| 14 | [dependencies] | 14 | [dependencies] |
| 15 | anyhow = "1.0.75" | 15 | anyhow = "1.0.75" |
| 16 | async-trait = "0.1.73" | ||
| 16 | chacha20poly1305 = "0.10.1" | 17 | chacha20poly1305 = "0.10.1" |
| 17 | clap = { version = "4.3.19", features = ["derive"] } | 18 | clap = { version = "4.3.19", features = ["derive"] } |
| 18 | dialoguer = "0.10.4" | 19 | dialoguer = "0.10.4" |
| 19 | directories = "5.0.1" | 20 | directories = "5.0.1" |
| 21 | futures = "0.3.28" | ||
| 20 | git2 = "0.18.1" | 22 | git2 = "0.18.1" |
| 21 | keyring = "2.0.5" | 23 | keyring = "2.0.5" |
| 22 | nostr = "0.23.0" | 24 | nostr = "0.24.0" |
| 25 | nostr-sdk = "0.24.0" | ||
| 23 | passwords = "3.1.13" | 26 | passwords = "3.1.13" |
| 24 | scrypt = "0.11.0" | 27 | scrypt = "0.11.0" |
| 25 | serde = { version = "1.0.181", features = ["derive"] } | 28 | serde = { version = "1.0.181", features = ["derive"] } |
| 26 | serde_json = "1.0.105" | 29 | serde_json = "1.0.105" |
| 30 | tokio = "1.33.0" | ||
| 27 | zeroize = "1.6.0" | 31 | zeroize = "1.6.0" |
| 28 | 32 | ||
| 29 | [dev-dependencies] | 33 | [dev-dependencies] |
diff --git a/src/client.rs b/src/client.rs new file mode 100644 index 0000000..a6f7dda --- /dev/null +++ b/src/client.rs | |||
| @@ -0,0 +1,65 @@ | |||
| 1 | // have you considered | ||
| 2 | |||
| 3 | // TO USE ASYNC | ||
| 4 | |||
| 5 | // in traits (required for mocking unit tests) | ||
| 6 | // https://rust-lang.github.io/async-book/07_workarounds/05_async_in_traits.html | ||
| 7 | // https://github.com/dtolnay/async-trait | ||
| 8 | // see https://blog.rust-lang.org/inside-rust/2022/11/17/async-fn-in-trait-nightly.html | ||
| 9 | // I think we can use the async-trait crate and switch to the native feature | ||
| 10 | // which is currently in nightly. alternatively we can use nightly as it looks | ||
| 11 | // certain that the implementation is going to make it to stable but we don't | ||
| 12 | // want to inadvertlty use other features of nightly that might be removed. | ||
| 13 | use anyhow::Result; | ||
| 14 | use async_trait::async_trait; | ||
| 15 | #[cfg(test)] | ||
| 16 | use mockall::*; | ||
| 17 | use nostr::Event; | ||
| 18 | |||
| 19 | pub struct Client { | ||
| 20 | client: nostr_sdk::Client, | ||
| 21 | } | ||
| 22 | |||
| 23 | #[async_trait] | ||
| 24 | #[cfg_attr(test, automock)] | ||
| 25 | pub trait Connect { | ||
| 26 | fn default() -> Self; | ||
| 27 | fn new(opts: Params) -> Self; | ||
| 28 | async fn connect(&self) -> Result<()>; | ||
| 29 | async fn send_event_to(&self, url: &str, event: nostr::event::Event) -> Result<nostr::EventId>; | ||
| 30 | } | ||
| 31 | |||
| 32 | #[async_trait] | ||
| 33 | impl Connect for Client { | ||
| 34 | fn default() -> Self { | ||
| 35 | Client { | ||
| 36 | client: nostr_sdk::Client::new(&nostr::Keys::generate()), | ||
| 37 | } | ||
| 38 | } | ||
| 39 | fn new(opts: Params) -> Self { | ||
| 40 | Client { | ||
| 41 | client: nostr_sdk::Client::new(&opts.keys.unwrap_or(nostr::Keys::generate())), | ||
| 42 | } | ||
| 43 | } | ||
| 44 | async fn connect(&self) -> Result<()> { | ||
| 45 | self.client.add_relay("ws://localhost:8080", None).await?; | ||
| 46 | self.client.connect().await; | ||
| 47 | // self.client.s | ||
| 48 | Ok(()) | ||
| 49 | } | ||
| 50 | async fn send_event_to(&self, url: &str, event: Event) -> Result<nostr::EventId> { | ||
| 51 | Ok(self.client.send_event_to(url, event).await?) | ||
| 52 | } | ||
| 53 | } | ||
| 54 | |||
| 55 | #[derive(Default)] | ||
| 56 | pub struct Params { | ||
| 57 | pub keys: Option<nostr::Keys>, | ||
| 58 | } | ||
| 59 | |||
| 60 | impl Params { | ||
| 61 | pub fn with_keys(mut self, keys: nostr::Keys) -> Self { | ||
| 62 | self.keys = Some(keys); | ||
| 63 | self | ||
| 64 | } | ||
| 65 | } | ||
diff --git a/src/main.rs b/src/main.rs index 5094c11..9c37aa7 100644 --- a/src/main.rs +++ b/src/main.rs | |||
| @@ -5,6 +5,7 @@ use anyhow::Result; | |||
| 5 | use clap::{Parser, Subcommand}; | 5 | use clap::{Parser, Subcommand}; |
| 6 | 6 | ||
| 7 | mod cli_interactor; | 7 | mod cli_interactor; |
| 8 | mod client; | ||
| 8 | mod config; | 9 | mod config; |
| 9 | mod git; | 10 | mod git; |
| 10 | mod key_handling; | 11 | mod key_handling; |
| @@ -33,10 +34,11 @@ enum Commands { | |||
| 33 | Prs(sub_commands::prs::SubCommandArgs), | 34 | Prs(sub_commands::prs::SubCommandArgs), |
| 34 | } | 35 | } |
| 35 | 36 | ||
| 36 | fn main() -> Result<()> { | 37 | #[tokio::main] |
| 38 | async fn main() -> Result<()> { | ||
| 37 | let cli = Cli::parse(); | 39 | let cli = Cli::parse(); |
| 38 | match &cli.command { | 40 | match &cli.command { |
| 39 | Commands::Login(args) => sub_commands::login::launch(&cli, args), | 41 | Commands::Login(args) => sub_commands::login::launch(&cli, args), |
| 40 | Commands::Prs(args) => sub_commands::prs::launch(&cli, args), | 42 | Commands::Prs(args) => futures::executor::block_on(sub_commands::prs::launch(&cli, args)), |
| 41 | } | 43 | } |
| 42 | } | 44 | } |
diff --git a/src/sub_commands/prs/create.rs b/src/sub_commands/prs/create.rs index dd32c65..89ea652 100644 --- a/src/sub_commands/prs/create.rs +++ b/src/sub_commands/prs/create.rs | |||
| @@ -3,6 +3,7 @@ use nostr::{prelude::sha1::Hash as Sha1Hash, EventBuilder, Marker, Tag, TagKind} | |||
| 3 | 3 | ||
| 4 | use crate::{ | 4 | use crate::{ |
| 5 | cli_interactor::{Interactor, InteractorPrompt, PromptConfirmParms, PromptInputParms}, | 5 | cli_interactor::{Interactor, InteractorPrompt, PromptConfirmParms, PromptInputParms}, |
| 6 | client::{Client, Connect, Params as ClientParams}, | ||
| 6 | git::{Repo, RepoActions}, | 7 | git::{Repo, RepoActions}, |
| 7 | login, Cli, | 8 | login, Cli, |
| 8 | }; | 9 | }; |
| @@ -23,7 +24,7 @@ pub struct SubCommandArgs { | |||
| 23 | to_branch: Option<String>, | 24 | to_branch: Option<String>, |
| 24 | } | 25 | } |
| 25 | 26 | ||
| 26 | pub fn launch( | 27 | pub async fn launch( |
| 27 | cli_args: &Cli, | 28 | cli_args: &Cli, |
| 28 | _pr_args: &super::SubCommandArgs, | 29 | _pr_args: &super::SubCommandArgs, |
| 29 | args: &SubCommandArgs, | 30 | args: &SubCommandArgs, |
| @@ -81,6 +82,7 @@ pub fn launch( | |||
| 81 | let root_commit = git_repo | 82 | let root_commit = git_repo |
| 82 | .get_root_commit(to_branch.as_str()) | 83 | .get_root_commit(to_branch.as_str()) |
| 83 | .context("failed to get root commit of the repository")?; | 84 | .context("failed to get root commit of the repository")?; |
| 85 | |||
| 84 | // create PR event | 86 | // create PR event |
| 85 | 87 | ||
| 86 | let keys = login::launch(&cli_args.nsec, &cli_args.password)?; | 88 | let keys = login::launch(&cli_args.nsec, &cli_args.password)?; |
| @@ -138,7 +140,23 @@ pub fn launch( | |||
| 138 | ); | 140 | ); |
| 139 | } | 141 | } |
| 140 | 142 | ||
| 143 | let client = Client::new(ClientParams::default().with_keys(keys)); | ||
| 144 | |||
| 145 | println!("connecting..."); | ||
| 146 | client.connect().await?; | ||
| 147 | println!("connected..."); | ||
| 148 | |||
| 141 | // TODO check if there is already a similarly named PR | 149 | // TODO check if there is already a similarly named PR |
| 150 | let _ = client | ||
| 151 | .send_event_to("ws://localhost:8080", pr_event) | ||
| 152 | .await?; | ||
| 153 | // TODO post each PR | ||
| 154 | // TODO report | ||
| 155 | println!("posted successfully to 4/5 of your relays and 0/4 of maintainers relays"); | ||
| 156 | // should we have a relays in Repository event? | ||
| 157 | // yes | ||
| 158 | // | ||
| 159 | |||
| 142 | // TODO connect to relays and post | 160 | // TODO connect to relays and post |
| 143 | 161 | ||
| 144 | Ok(()) | 162 | Ok(()) |
diff --git a/src/sub_commands/prs/mod.rs b/src/sub_commands/prs/mod.rs index c316e73..982e866 100644 --- a/src/sub_commands/prs/mod.rs +++ b/src/sub_commands/prs/mod.rs | |||
| @@ -15,8 +15,8 @@ pub enum Commands { | |||
| 15 | Create(create::SubCommandArgs), | 15 | Create(create::SubCommandArgs), |
| 16 | } | 16 | } |
| 17 | 17 | ||
| 18 | pub fn launch(cli_args: &Cli, pr_args: &SubCommandArgs) -> Result<()> { | 18 | pub async fn launch(cli_args: &Cli, pr_args: &SubCommandArgs) -> Result<()> { |
| 19 | match &pr_args.prs_command { | 19 | match &pr_args.prs_command { |
| 20 | Commands::Create(args) => create::launch(cli_args, pr_args, args), | 20 | Commands::Create(args) => create::launch(cli_args, pr_args, args).await, |
| 21 | } | 21 | } |
| 22 | } | 22 | } |
diff --git a/test_utils/Cargo.toml b/test_utils/Cargo.toml index 3d936b5..1773d93 100644 --- a/test_utils/Cargo.toml +++ b/test_utils/Cargo.toml | |||
| @@ -9,7 +9,7 @@ assert_cmd = "2.0.12" | |||
| 9 | dialoguer = "0.10.4" | 9 | dialoguer = "0.10.4" |
| 10 | directories = "5.0.1" | 10 | directories = "5.0.1" |
| 11 | git2 = "0.18.1" | 11 | git2 = "0.18.1" |
| 12 | nostr = "0.23.0" | 12 | nostr = "0.24.0" |
| 13 | once_cell = "1.18.0" | 13 | once_cell = "1.18.0" |
| 14 | rand = "0.8" | 14 | rand = "0.8" |
| 15 | rexpect = { git = "https://github.com/phaer/rexpect.git", branch= "skip-ansi-escape-codes" } | 15 | rexpect = { git = "https://github.com/phaer/rexpect.git", branch= "skip-ansi-escape-codes" } |