diff --git a/Cargo.lock b/Cargo.lock index 7c0814c3..ad77f43d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,20 +2,11 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "aho-corasick" -version = "0.7.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" -dependencies = [ - "memchr", -] - [[package]] name = "anyhow" -version = "1.0.53" +version = "1.0.54" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94a45b455c14666b85fc40a019e8ab9eb75e3a124e05494f5397122bc9eb06e0" +checksum = "7a99269dff3bc004caa411f38845c20303f1e393ca2bd6581576fa3a7f59577d" [[package]] name = "async-trait" @@ -28,22 +19,11 @@ dependencies = [ "syn", ] -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi", - "libc", - "winapi", -] - [[package]] name = "autocfg" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "base64" @@ -78,6 +58,15 @@ dependencies = [ "generic-array", ] +[[package]] +name = "block-buffer" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf7fe51849ea569fd452f37822f606a5cabb684dc918707a0193fd4664ff324" +dependencies = [ + "generic-array", +] + [[package]] name = "buf_redux" version = "0.8.4" @@ -108,9 +97,15 @@ checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" [[package]] name = "cc" -version = "1.0.72" +version = "1.0.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" + +[[package]] +name = "cfg-if" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" [[package]] name = "cfg-if" @@ -118,6 +113,55 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" +dependencies = [ + "js-sys", + "num-integer", + "num-traits", + "wasm-bindgen", +] + +[[package]] +name = "chrono-tz" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58549f1842da3080ce63002102d5bc954c7bc843d4f47818e642abdc36253552" +dependencies = [ + "chrono", + "chrono-tz-build", + "phf", +] + +[[package]] +name = "chrono-tz-build" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db058d493fb2f65f41861bfed7e3fe6335264a9f0f92710cab5bdf01fef09069" +dependencies = [ + "parse-zoneinfo", + "phf", + "phf_codegen", +] + +[[package]] +name = "cloudflare" +version = "0.1.0" +dependencies = [ + "anyhow", + "async-trait", + "cfg-if 1.0.0", + "console_error_panic_hook", + "lazy_static", + "octocat-rs", + "serde_json", + "wasm-bindgen-futures", + "worker", +] + [[package]] name = "commitsummary" version = "0.1.0" @@ -131,11 +175,21 @@ dependencies = [ "tokio", ] +[[package]] +name = "console_error_panic_hook" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" +dependencies = [ + "cfg-if 1.0.0", + "wasm-bindgen", +] + [[package]] name = "core-foundation" -version = "0.9.2" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6888e10551bb93e424d8df1d07f1a8b4fceb0001a3a4b048bfc47554946f47b3" +checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" dependencies = [ "core-foundation-sys", "libc", @@ -156,6 +210,16 @@ dependencies = [ "libc", ] +[[package]] +name = "crypto-common" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57952ca27b5e3606ff4dd79b0020231aaf9d6aa76dc05fd30137538c50bd3ce8" +dependencies = [ + "generic-array", + "typenum", +] + [[package]] name = "digest" version = "0.9.0" @@ -166,32 +230,30 @@ dependencies = [ ] [[package]] -name = "encoding_rs" -version = "0.8.30" +name = "digest" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7896dc8abb250ffdda33912550faa54c88ec8b998dec0b2c55ab224921ce11df" +checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506" dependencies = [ - "cfg-if", + "block-buffer 0.10.2", + "crypto-common", + "subtle", ] [[package]] -name = "env_logger" -version = "0.7.1" +name = "encoding_rs" +version = "0.8.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" +checksum = "7896dc8abb250ffdda33912550faa54c88ec8b998dec0b2c55ab224921ce11df" dependencies = [ - "atty", - "humantime", - "log", - "regex", - "termcolor", + "cfg-if 1.0.0", ] [[package]] name = "fastrand" -version = "1.6.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "779d043b6a0b90cc4c0ed7ee380a6504394cee7efd7db050e3774eee387324b2" +checksum = "c3fcf0cee53519c866c09b5de1f6c56ff9d647101f81c1964fa632e148896cdf" dependencies = [ "instant", ] @@ -229,9 +291,9 @@ dependencies = [ [[package]] name = "futures" -version = "0.3.19" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28560757fe2bb34e79f907794bb6b22ae8b0e5c669b638a1132f2592b19035b4" +checksum = "f73fe65f54d1e12b726f517d3e2135ca3125a437b6d998caf1962961f7172d9e" dependencies = [ "futures-channel", "futures-core", @@ -244,9 +306,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.19" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba3dda0b6588335f360afc675d0564c17a77a2bda81ca178a4b6081bd86c7f0b" +checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010" dependencies = [ "futures-core", "futures-sink", @@ -254,15 +316,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.19" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0c8ff0461b82559810cdccfde3215c3f373807f5e5232b71479bff7bb2583d7" +checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3" [[package]] name = "futures-executor" -version = "0.3.19" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29d6d2ff5bb10fb95c85b8ce46538a2e5f5e7fdc755623a7d4529ab8a4ed9d2a" +checksum = "9420b90cfa29e327d0429f19be13e7ddb68fa1cccb09d65e5706b8c7a749b8a6" dependencies = [ "futures-core", "futures-task", @@ -271,15 +333,15 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.19" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f9d34af5a1aac6fb380f735fe510746c38067c5bf16c7fd250280503c971b2" +checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b" [[package]] name = "futures-macro" -version = "0.3.19" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6dbd947adfffb0efc70599b3ddcf7b5597bb5fa9e245eb99f62b3a5f7bb8bd3c" +checksum = "33c1e13800337f4d4d7a316bf45a567dbcb6ffe087f16424852d97e97a91f512" dependencies = [ "proc-macro2", "quote", @@ -288,21 +350,21 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.19" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3055baccb68d74ff6480350f8d6eb8fcfa3aa11bdc1a1ae3afdd0514617d508" +checksum = "21163e139fa306126e6eedaf49ecdb4588f939600f0b1e770f4205ee4b7fa868" [[package]] name = "futures-task" -version = "0.3.19" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ee7c6485c30167ce4dfb83ac568a849fe53274c831081476ee13e0dce1aad72" +checksum = "57c66a976bf5909d801bbef33416c41372779507e7a6b3a5e25e4749c58f776a" [[package]] name = "futures-util" -version = "0.3.19" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b5cf40b47a271f77a8b1bec03ca09044d99d2372c0de244e66430761127164" +checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a" dependencies = [ "futures-channel", "futures-core", @@ -332,7 +394,7 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "418d37c8b1d42553c93648be529cb70f920d3baf8ef469b74b9638df426e0b4c" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "libc", "wasi", ] @@ -340,7 +402,7 @@ dependencies = [ [[package]] name = "github-api" version = "0.1.0" -source = "git+https://github.com/octocat-rs/github-api#6863a238c51ed4a142700a5158ee998b6f6e6c4c" +source = "git+https://github.com/octocat-rs/github-api#638ff4e6ce16e112d74845e04146b6d29d0543f2" dependencies = [ "serde", "serde_json", @@ -358,13 +420,14 @@ dependencies = [ "serde_json", "strum", "tokio", + "worker", ] [[package]] name = "h2" -version = "0.3.10" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c9de88456263e249e241fcd211d3954e2c9b0ef7ccfc235a444eb367cae3689" +checksum = "d9f1f717ddc7b2ba36df7e871fd88db79326551d3d6f1fc406fbfd28b582ff8e" dependencies = [ "bytes", "fnv", @@ -387,9 +450,9 @@ checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" [[package]] name = "headers" -version = "0.3.5" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4c4eb0471fcb85846d8b0690695ef354f9afb11cb03cac2e1d7c9253351afb0" +checksum = "4cff78e5788be1e0ab65b04d306b2ed5092c815ec97ec70f4ebd5aee158aa55d" dependencies = [ "base64", "bitflags", @@ -398,7 +461,7 @@ dependencies = [ "http", "httpdate", "mime", - "sha-1", + "sha-1 0.10.0", ] [[package]] @@ -428,6 +491,15 @@ dependencies = [ "libc", ] +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest 0.10.3", +] + [[package]] name = "http" version = "0.2.6" @@ -436,7 +508,7 @@ checksum = "31f4c6746584866f0feabcc69893c5b51beef3831656a968ed7ae254cdc4fd03" dependencies = [ "bytes", "fnv", - "itoa 1.0.1", + "itoa", ] [[package]] @@ -452,9 +524,9 @@ dependencies = [ [[package]] name = "httparse" -version = "1.5.1" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acd94fdbe1d4ff688b67b04eee2e17bd50995534a61539e45adfefb45e5e5503" +checksum = "9100414882e15fb7feccb4897e5f0ff0ff1ca7d1a86a23208ada4d7a18e6c6c4" [[package]] name = "httpdate" @@ -462,20 +534,11 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" -[[package]] -name = "humantime" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" -dependencies = [ - "quick-error", -] - [[package]] name = "hyper" -version = "0.14.16" +version = "0.14.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7ec3e62bdc98a2f0393a5048e4c30ef659440ea6e0e572965103e72bd836f55" +checksum = "043f0e083e9901b6cc658a77d1eb86f4fc650bbb977a4337dd63192826aa85dd" dependencies = [ "bytes", "futures-channel", @@ -486,7 +549,7 @@ dependencies = [ "http-body", "httparse", "httpdate", - "itoa 0.4.8", + "itoa", "pin-project-lite", "socket2", "tokio", @@ -535,7 +598,7 @@ version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", ] [[package]] @@ -544,12 +607,6 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68f2d64f2edebec4ce84ad108148e67e1064789bee435edc5b60ad398714a3a9" -[[package]] -name = "itoa" -version = "0.4.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" - [[package]] name = "itoa" version = "1.0.1" @@ -573,15 +630,15 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.112" +version = "0.2.118" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125" +checksum = "06e509672465a0504304aa87f9f176f2b2b716ed8fb105ebe5c02dc6dce96a94" [[package]] name = "lock_api" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712a4d093c9976e24e7dbca41db895dabcbac38eb5f4045393d17a95bdfb1109" +checksum = "88943dd7ef4a2e5a4bfa2753aaab3013e34ce2533d1996fb18ef591e315e2b3b" dependencies = [ "scopeguard", ] @@ -592,7 +649,7 @@ version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", ] [[package]] @@ -601,6 +658,12 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" +[[package]] +name = "matchit" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9376a4f0340565ad675d11fc1419227faf5f60cd7ac9cb2e7185a471f30af833" + [[package]] name = "memchr" version = "2.4.1" @@ -615,9 +678,9 @@ checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" [[package]] name = "mime_guess" -version = "2.0.3" +version = "2.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2684d4c2e97d99848d30b324b00c8fcc7e5c897b7cbb5819b09e7c90e8baf212" +checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" dependencies = [ "mime", "unicase", @@ -625,9 +688,9 @@ dependencies = [ [[package]] name = "mio" -version = "0.7.14" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8067b404fe97c70829f082dec8bcf4f71225d7eaea1d8645349cb76fa06205cc" +checksum = "ba272f85fa0b41fc91872be579b3bbe0f56b792aa361a380eb669469f68dafb2" dependencies = [ "libc", "log", @@ -683,13 +746,32 @@ dependencies = [ [[package]] name = "ntapi" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" +checksum = "c28774a7fd2fbb4f0babd8237ce554b73af68021b5f695a3cebd6c59bac0980f" dependencies = [ "winapi", ] +[[package]] +name = "num-integer" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +dependencies = [ + "autocfg", +] + [[package]] name = "num_cpus" version = "1.13.1" @@ -706,21 +788,23 @@ version = "0.0.0" dependencies = [ "anyhow", "async-trait", + "base64", "futures", "github-api", "github-rest", - "lazy_static", - "log", - "pretty_env_logger", + "hmac", "reqwest", "serde", "serde_json", + "serde_urlencoded", + "sha2", "strum", "strum_macros", "thiserror", "tokio", "toml", "warp", + "worker", ] [[package]] @@ -742,7 +826,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c7ae222234c30df141154f159066c5093ff73b63204dcda7121eb082fc56a95" dependencies = [ "bitflags", - "cfg-if", + "cfg-if 1.0.0", "foreign-types", "libc", "once_cell", @@ -770,27 +854,34 @@ dependencies = [ [[package]] name = "parking_lot" -version = "0.11.2" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" +checksum = "87f5ec2493a61ac0506c0f4199f99070cbe83857b0337006a30f3e6719b8ef58" dependencies = [ - "instant", "lock_api", "parking_lot_core", ] [[package]] name = "parking_lot_core" -version = "0.8.5" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" +checksum = "28141e0cc4143da2443301914478dc976a61ffdb3f043058310c70df2fed8954" dependencies = [ - "cfg-if", - "instant", + "cfg-if 1.0.0", "libc", "redox_syscall", "smallvec", - "winapi", + "windows-sys", +] + +[[package]] +name = "parse-zoneinfo" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c705f256449c60da65e11ff6626e0c16a0a0b96aaa348de61376b249bc340f41" +dependencies = [ + "regex", ] [[package]] @@ -805,6 +896,45 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator", + "phf_shared", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared", + "rand", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", + "uncased", +] + [[package]] name = "pin-project" version = "1.0.10" @@ -849,16 +979,6 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" -[[package]] -name = "pretty_env_logger" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "926d36b9553851b8b0005f1275891b392ee4d2d833852c417ed025477350fb9d" -dependencies = [ - "env_logger", - "log", -] - [[package]] name = "proc-macro2" version = "1.0.36" @@ -876,23 +996,22 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quote" -version = "1.0.14" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47aa80447ce4daf1717500037052af176af5d38cc3e571d9ec1c7353fc10c87d" +checksum = "864d3e96a899863136fc6e99f3d7cae289dafe43bf2c5ac19b70df7210c0a145" dependencies = [ "proc-macro2", ] [[package]] name = "rand" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", "rand_chacha", "rand_core", - "rand_hc", ] [[package]] @@ -914,15 +1033,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rand_hc" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7" -dependencies = [ - "rand_core", -] - [[package]] name = "redox_syscall" version = "0.2.10" @@ -938,8 +1048,6 @@ version = "1.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" dependencies = [ - "aho-corasick", - "memchr", "regex-syntax", ] @@ -1036,9 +1144,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "security-framework" -version = "2.4.2" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525bc1abfda2e1998d152c45cf13e696f76d0a4972310b22fac1658b05df7c87" +checksum = "2dc14f172faf8a0194a3aded622712b0de276821addc574fa54fc0a1167e10dc" dependencies = [ "bitflags", "core-foundation", @@ -1049,9 +1157,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.4.2" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9dd14d83160b528b7bfd66439110573efcfbe281b17fc2ca9f39f550d619c7e" +checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" dependencies = [ "core-foundation-sys", "libc", @@ -1059,18 +1167,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.133" +version = "1.0.136" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97565067517b60e2d1ea8b268e59ce036de907ac523ad83a0475da04e818989a" +checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.133" +version = "1.0.136" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed201699328568d8d08208fdd080e3ff594e6c422e438b6705905da01005d537" +checksum = "08597e7152fcd306f41838ed3e37be9eaeed2b61c42e2117266a554fab4662f9" dependencies = [ "proc-macro2", "quote", @@ -1079,23 +1187,23 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.74" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee2bb9cd061c5865d345bb02ca49fcef1391741b672b54a0bf7b679badec3142" +checksum = "8e8d9fa5c3b304765ce1fd9c4c8a3de2c8db365a5b91be52f186efc675681d95" dependencies = [ - "itoa 1.0.1", + "itoa", "ryu", "serde", ] [[package]] name = "serde_urlencoded" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edfa57a7f8d9c1d260a549e7224100f6c43d43f9103e06dd8b4095a9b2b43ce9" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" dependencies = [ "form_urlencoded", - "itoa 0.4.8", + "itoa", "ryu", "serde", ] @@ -1106,13 +1214,35 @@ version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "99cd6713db3cf16b6c84e06321e049a9b9f699826e16096d23bbcc44d15d51a6" dependencies = [ - "block-buffer", - "cfg-if", + "block-buffer 0.9.0", + "cfg-if 1.0.0", "cpufeatures", - "digest", + "digest 0.9.0", "opaque-debug", ] +[[package]] +name = "sha-1" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "028f48d513f9678cda28f6e4064755b3fbb2af6acd672f2c209b62323f7aea0f" +dependencies = [ + "cfg-if 1.0.0", + "cpufeatures", + "digest 0.10.3", +] + +[[package]] +name = "sha2" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55deaec60f81eefe3cce0dc50bda92d6d8e88f2a27df7c5033b42afeb1ed2676" +dependencies = [ + "cfg-if 1.0.0", + "cpufeatures", + "digest 0.10.3", +] + [[package]] name = "signal-hook-registry" version = "1.4.0" @@ -1122,6 +1252,12 @@ dependencies = [ "libc", ] +[[package]] +name = "siphasher" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a86232ab60fa71287d7f2ddae4a7073f6b7aac33631c3015abb556f08c6d0a3e" + [[package]] name = "slab" version = "0.4.5" @@ -1136,9 +1272,9 @@ checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" [[package]] name = "socket2" -version = "0.4.2" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dc90fe6c7be1a323296982db1836d1ea9e47b6839496dde9a541bc496df3516" +checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0" dependencies = [ "libc", "winapi", @@ -1166,11 +1302,17 @@ dependencies = [ "syn", ] +[[package]] +name = "subtle" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" + [[package]] name = "syn" -version = "1.0.85" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a684ac3dcd8913827e18cd09a68384ee66c1de24157e3c556c9ab16d85695fb7" +checksum = "8a65b3f4ffa0092e9887669db0eae07941f023991ab58ea44da8fe8e2d511c6b" dependencies = [ "proc-macro2", "quote", @@ -1183,7 +1325,7 @@ version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "fastrand", "libc", "redox_syscall", @@ -1191,15 +1333,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "termcolor" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" -dependencies = [ - "winapi-util", -] - [[package]] name = "thiserror" version = "1.0.30" @@ -1237,9 +1370,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.15.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbbf1c778ec206785635ce8ad57fe52b3009ae9e0c9f574a728f3049d3e55838" +checksum = "2af73ac49756f3f7c01172e34a23e5d0216f6c32333757c2c61feb2bbff5a5ee" dependencies = [ "bytes", "libc", @@ -1250,6 +1383,7 @@ dependencies = [ "parking_lot", "pin-project-lite", "signal-hook-registry", + "socket2", "tokio-macros", "winapi", ] @@ -1330,11 +1464,11 @@ checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" [[package]] name = "tracing" -version = "0.1.29" +version = "0.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "375a639232caf30edfc78e8d89b2d4c375515393e7af7e16f01cd96917fb2105" +checksum = "f6c650a8ef0cd2dd93736f033d21cbd1224c5a967aa0c258d00fcf7dafef9b9f" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "log", "pin-project-lite", "tracing-core", @@ -1342,9 +1476,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.21" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4ed65637b8390770814083d20756f87bfa2c21bf2f110babdc5438351746e4" +checksum = "03cfcb51380632a72d3111cb8d3447a8d908e577d31beeac006f836383d29a23" dependencies = [ "lazy_static", ] @@ -1368,7 +1502,7 @@ dependencies = [ "httparse", "log", "rand", - "sha-1", + "sha-1 0.9.8", "thiserror", "url", "utf-8", @@ -1389,6 +1523,15 @@ version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" +[[package]] +name = "uncased" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5baeed7327e25054889b9bd4f975f32e5f4c5d434042d59ab6cd4142c0a76ed0" +dependencies = [ + "version_check", +] + [[package]] name = "unicase" version = "2.6.0" @@ -1415,9 +1558,9 @@ dependencies = [ [[package]] name = "unicode-segmentation" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" +checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99" [[package]] name = "unicode-xid" @@ -1507,7 +1650,9 @@ version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "632f73e236b219150ea279196e54e610f5dbafa5d61786303d4da54f84e47fce" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", + "serde", + "serde_json", "wasm-bindgen-macro", ] @@ -1532,7 +1677,7 @@ version = "0.4.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e8d7523cb1f2a4c96c1317ca690031b714a51cc14e05f712446691f413f5d39" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "js-sys", "wasm-bindgen", "web-sys", @@ -1594,19 +1739,53 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] -name = "winapi-util" -version = "0.1.5" +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3df6e476185f92a12c072be4a189a0210dcdcf512a1891d6dff9edb874deadc6" dependencies = [ - "winapi", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_msvc", ] [[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" +name = "windows_aarch64_msvc" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +checksum = "d8e92753b1c443191654ec532f14c199742964a061be25d77d7a96f09db20bf5" + +[[package]] +name = "windows_i686_gnu" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a711c68811799e017b6038e0922cb27a5e2f43a2ddb609fe0b6f3eeda9de615" + +[[package]] +name = "windows_i686_msvc" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "146c11bb1a02615db74680b32a68e2d61f553cc24c4eb5b4ca10311740e44172" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c912b12f7454c6620635bbff3450962753834be2a594819bd5e945af18ec64bc" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "504a2476202769977a040c6364301a3f65d0cc9e3fb08600b2bda150a0488316" [[package]] name = "winreg" @@ -1616,3 +1795,69 @@ checksum = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69" dependencies = [ "winapi", ] + +[[package]] +name = "worker" +version = "0.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61ca7d7e62ce3c18176bafbb9efff5f2f599aefb01bf81a51e003f4fd47e2606" +dependencies = [ + "async-trait", + "chrono", + "chrono-tz", + "futures", + "http", + "js-sys", + "matchit", + "pin-project", + "serde", + "serde_json", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "worker-kv", + "worker-macros", + "worker-sys", +] + +[[package]] +name = "worker-kv" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "682cbd728f179cc810b2ab77a2534da817b973e190ab184ab8efe1058b0dba84" +dependencies = [ + "js-sys", + "serde", + "serde_json", + "thiserror", + "wasm-bindgen", + "wasm-bindgen-futures", +] + +[[package]] +name = "worker-macros" +version = "0.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69c2b482518c7ae1d3f72917864cbd068ca65f0236e5deec0039713321c68489" +dependencies = [ + "async-trait", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen", + "wasm-bindgen-futures", + "wasm-bindgen-macro-support", + "worker-sys", +] + +[[package]] +name = "worker-sys" +version = "0.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96a9f46a3d2efc59119aa60229bc00f01e5bd178ac8b3a7b5cdbe0b70909973d" +dependencies = [ + "cfg-if 0.1.10", + "js-sys", + "wasm-bindgen", + "web-sys", +] diff --git a/Cargo.toml b/Cargo.toml index 9c8423ad..5df8c1d5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ members = [ "github-rest", "examples/basic", "examples/commitsummary", + "examples/cloudflare", #"examples/config-file", ] default-members = ["octocat-rs", "github-rest"] diff --git a/examples/cloudflare/.cargo-ok b/examples/cloudflare/.cargo-ok new file mode 100644 index 00000000..e69de29b diff --git a/examples/cloudflare/.gitignore b/examples/cloudflare/.gitignore new file mode 100644 index 00000000..40e49041 --- /dev/null +++ b/examples/cloudflare/.gitignore @@ -0,0 +1,4 @@ +/target +**/*.rs.bk +wasm-pack.log +build/ \ No newline at end of file diff --git a/examples/cloudflare/Cargo.lock b/examples/cloudflare/Cargo.lock new file mode 100644 index 00000000..ce8dac3b --- /dev/null +++ b/examples/cloudflare/Cargo.lock @@ -0,0 +1,703 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aho-corasick" +version = "0.6.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81ce3d38065e618af2d7b77e10c5ad9a069859b4be3c2250f674af3840d9c8a5" +dependencies = [ + "memchr", +] + +[[package]] +name = "async-trait" +version = "0.1.51" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44318e776df68115a881de9a8fd1b9e53368d7a4a5ce4cc48517da3393233a5e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + +[[package]] +name = "bumpalo" +version = "3.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c59e7af012c713f529e7a3ee57ce9b31ddd858d4b512923602f74608b009631" + +[[package]] +name = "bytes" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chrono" +version = "0.4.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" +dependencies = [ + "libc", + "num-integer", + "num-traits", + "time", + "winapi", +] + +[[package]] +name = "chrono-tz" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa1878c18b5b01b9978d5f130fe366d434022004d12fb87c182e8459b427c4a3" +dependencies = [ + "chrono", + "parse-zoneinfo", +] + +[[package]] +name = "console_error_panic_hook" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8d976903543e0c48546a91908f21588a680a8c8f984df9a5d69feccb2b2a211" +dependencies = [ + "cfg-if 0.1.10", + "wasm-bindgen", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "form_urlencoded" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" +dependencies = [ + "matches", + "percent-encoding", +] + +[[package]] +name = "futures" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a12aa0eb539080d55c3f2d45a67c3b58b6b0773c1a3ca2dfec66d58c97fd66ca" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5da6ba8c3bb3c165d3c7319fc1cc8304facf1fb8db99c5de877183c08a273888" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88d1c26957f23603395cd326b0ffe64124b818f4449552f960d815cfba83a53d" + +[[package]] +name = "futures-executor" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45025be030969d763025784f7f355043dc6bc74093e4ecc5000ca4dc50d8745c" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "522de2a0fe3e380f1bc577ba0474108faf3f6b18321dbf60b3b9c39a75073377" + +[[package]] +name = "futures-macro" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18e4a4b95cea4b4ccbcf1c5675ca7c4ee4e9e75eb79944d07defde18068f79bb" +dependencies = [ + "autocfg", + "proc-macro-hack", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36ea153c13024fe480590b3e3d4cad89a0cfacecc24577b68f86c6ced9c2bc11" + +[[package]] +name = "futures-task" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d3d00f4eddb73e498a54394f228cd55853bdf059259e8e7bc6e69d408892e99" + +[[package]] +name = "futures-util" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36568465210a3a6ee45e1f165136d68671471a501e632e9a98d96872222b5481" +dependencies = [ + "autocfg", + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "proc-macro-hack", + "proc-macro-nested", + "slab", +] + +[[package]] +name = "http" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "527e8c9ac747e28542699a951517aa9a6945af506cd1f2e1b53a576c17b6cc11" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "idna" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" +dependencies = [ + "matches", + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "itoa" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" + +[[package]] +name = "js-sys" +version = "0.3.53" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4bf49d50e2961077d9c99f4b7997d770a1114f087c3c2e0069b36c13fc2979d" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.101" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3cb00336871be5ed2c8ed44b60ae9959dc5b9f08539422ed43f09e34ecaeba21" + +[[package]] +name = "log" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] +name = "matches" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" + +[[package]] +name = "matchit" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31cfc429bbf773f52282c32c240342a21495ce9fa1e3721998295d2027969f6a" + +[[package]] +name = "memchr" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" + +[[package]] +name = "memory_units" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" + +[[package]] +name = "name" +version = "0.1.0" +dependencies = [ + "cfg-if 0.1.10", + "console_error_panic_hook", + "serde_json", + "wee_alloc", + "worker", +] + +[[package]] +name = "num-integer" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +dependencies = [ + "autocfg", +] + +[[package]] +name = "parse-zoneinfo" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4ee19a3656dadae35a33467f9714f1228dd34766dbe49e10e656b5296867aea" +dependencies = [ + "regex", +] + +[[package]] +name = "percent-encoding" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" + +[[package]] +name = "pin-project-lite" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro-hack" +version = "0.5.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" + +[[package]] +name = "proc-macro-nested" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" + +[[package]] +name = "proc-macro2" +version = "1.0.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9f5105d4fdaab20335ca9565e106a5d9b82b6219b5ba735731124ac6711d23d" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "regex" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9329abc99e39129fcceabd24cf5d85b4671ef7c29c50e972bc5afe32438ec384" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", + "thread_local", + "utf8-ranges", +] + +[[package]] +name = "regex-syntax" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d707a4fa2637f2dca2ef9fd02225ec7661fe01a53623c1e6515b6916511f7a7" +dependencies = [ + "ucd-util", +] + +[[package]] +name = "ryu" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" + +[[package]] +name = "serde" +version = "1.0.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.67" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7f9e390c27c3c0ce8bc5d725f6e4d30a29d26659494aa4b17535f7522c5c950" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "slab" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c307a32c1c5c437f38c7fd45d753050587732ba8628319fbdf12a7e289ccc590" + +[[package]] +name = "syn" +version = "1.0.75" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7f58f7e8eaa0009c5fec437aabf511bd9933e4b2d7407bd05273c01a8906ea7" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "thread_local" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "time" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +dependencies = [ + "libc", + "wasi", + "winapi", +] + +[[package]] +name = "tinyvec" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "848a1e1181b9f6753b5e96a092749e29b11d19ede67dfbbd6c7dc7e0f49b5338" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" + +[[package]] +name = "ucd-util" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c85f514e095d348c279b1e5cd76795082cf15bd59b93207832abe0b1d8fed236" + +[[package]] +name = "unicode-bidi" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "246f4c42e67e7a4e3c6106ff716a5d067d4132a642840b242e357e468a2a0085" + +[[package]] +name = "unicode-normalization" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-xid" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" + +[[package]] +name = "url" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" +dependencies = [ + "form_urlencoded", + "idna", + "matches", + "percent-encoding", +] + +[[package]] +name = "utf8-ranges" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4ae116fef2b7fea257ed6440d3cfcff7f190865f170cdad00bb6465bf18ecba" + +[[package]] +name = "wasi" +version = "0.10.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" + +[[package]] +name = "wasm-bindgen" +version = "0.2.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ce9b1b516211d33767048e5d47fa2a381ed8b76fc48d2ce4aa39877f9f183e0" +dependencies = [ + "cfg-if 1.0.0", + "serde", + "serde_json", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfe8dc78e2326ba5f845f4b5bf548401604fa20b1dd1d365fb73b6c1d6364041" +dependencies = [ + "bumpalo", + "lazy_static", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95fded345a6559c2cfee778d562300c581f7d4ff3edb9b0d230d69800d213972" +dependencies = [ + "cfg-if 1.0.0", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44468aa53335841d9d6b6c023eaab07c0cd4bddbcfdee3e2bb1e8d2cb8069fef" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0195807922713af1e67dc66132c7328206ed9766af3858164fb583eedc25fbad" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acdb075a845574a1fa5f09fd77e43f7747599301ea3417a9fbffdeedfc1f4a29" + +[[package]] +name = "web-sys" +version = "0.3.53" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224b2f6b67919060055ef1a67807367c2066ed520c3862cc013d26cf893a783c" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "wee_alloc" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" +dependencies = [ + "cfg-if 0.1.10", + "libc", + "memory_units", + "winapi", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "worker" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c9f2133f202313d54963c4299b169cb7567e78bf7fe46d3a5fd42d2487a46bc" +dependencies = [ + "async-trait", + "chrono", + "chrono-tz", + "futures", + "http", + "js-sys", + "matchit", + "serde", + "serde_json", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "worker-kv", + "worker-macros", + "worker-sys", +] + +[[package]] +name = "worker-kv" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6efd1fb8c8e36b99d22a8f77024df57943bd79852e8842731df21292e68aaf93" +dependencies = [ + "js-sys", + "serde", + "serde_json", + "wasm-bindgen", + "wasm-bindgen-futures", +] + +[[package]] +name = "worker-macros" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffb0170a9530c0d137e38915a385837d47109b3717f2f1c83f1cbcadf246eccc" +dependencies = [ + "async-trait", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen", + "wasm-bindgen-futures", + "wasm-bindgen-macro-support", + "worker-sys", +] + +[[package]] +name = "worker-sys" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4604db1de9c0c8e9fe83a9825dbd34047d3c5741c8681f1fbccdd7cc9dd8bdb8" +dependencies = [ + "cfg-if 0.1.10", + "js-sys", + "wasm-bindgen", + "web-sys", +] diff --git a/examples/cloudflare/Cargo.toml b/examples/cloudflare/Cargo.toml new file mode 100644 index 00000000..9cea2e6e --- /dev/null +++ b/examples/cloudflare/Cargo.toml @@ -0,0 +1,31 @@ +[package] +name = "cloudflare" +version = "0.1.0" +authors = ["Tricked "] +edition = "2018" + +[lib] +crate-type = ["cdylib", "rlib"] + +[features] +default = ["console_error_panic_hook"] + +[dependencies] +lazy_static = "1.4" +serde_json = "1" +octocat-rs = { path = "../../octocat-rs", default-features = false, features = ["workers"] } +worker = "0.0.9" +cfg-if = "1" + +# The `console_error_panic_hook` crate provides better debugging of panics by +# logging them with `console.error`. This is great for development, but requires +# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for +# code size when deploying. +console_error_panic_hook = { version = "0.1.7", optional = true } +async-trait = "0.1.52" +wasm-bindgen-futures = "0.4.1" +anyhow = "1" + +[profile.release] +# Tell `rustc` to optimize for small code size. +opt-level = "s" diff --git a/examples/cloudflare/README.md b/examples/cloudflare/README.md new file mode 100644 index 00000000..6a4a5b8d --- /dev/null +++ b/examples/cloudflare/README.md @@ -0,0 +1,41 @@ +# Getting Started + +A template for kick starting a Cloudflare worker project using [`workers-rs`](https://github.com/cloudflare/workers-rs). + +This template is designed for compiling Rust to WebAssembly and publishing the resulting worker to +Cloudflare's [edge infrastructure](https://www.cloudflare.com/network/). + +## Usage + +This template starts you off with a `src/lib.rs` file, acting as an entrypoint for requests hitting +your Worker. Feel free to add more code in this file, or create Rust modules anywhere else for this +project to use. + +With `wrangler`, you can build, test, and deploy your Worker with the following commands: + +```bash +# compiles your project to WebAssembly and will warn of any issues +wrangler build + +# run your Worker in an ideal development workflow (with a local server, file watcher & more) +wrangler dev + +# deploy your Worker globally to the Cloudflare network (update your wrangler.toml file for configuration) +wrangler publish +``` + +Read the latest `worker` crate documentation here: https://docs.rs/worker + +## WebAssembly + +`workers-rs` (the Rust SDK for Cloudflare Workers used in this template) is meant to be executed as +compiled WebAssembly, and as such so **must** all the code you write and depend upon. All crates and +modules used in Rust-based Workers projects have to compile to the `wasm32-unknown-unknown` triple. + +Read more about this on the [`workers-rs` project README](https://github.com/cloudflare/workers-rs). + +## Issues + +If you have any problems with the `worker` crate, please open an issue on the upstream project +issue tracker on the [`workers-rs` repository](https://github.com/cloudflare/workers-rs). + diff --git a/examples/cloudflare/src/lib.rs b/examples/cloudflare/src/lib.rs new file mode 100644 index 00000000..1d22cd25 --- /dev/null +++ b/examples/cloudflare/src/lib.rs @@ -0,0 +1,67 @@ +use std::sync::Arc; + +use async_trait::async_trait; +use worker::{console_log, event, Env, Request, Response, Router}; + +use octocat_rs::{handler::EventHandler, rest::model::repositories::events::PushEvent, Client, ClientBuilder, Command}; + +mod utils; + +#[event(fetch)] +pub async fn main(req: Request, env: Env, _ctx: worker::Context) -> worker::Result { + utils::set_panic_hook(); + + let router = Router::new(); + let r = router + .post_async("/payload", |req, _| async { + // TODO: Don't construct this every time + let client = ClientBuilder::new().event_handler(Handler {}).build().unwrap(); + + match client.handle(req).await { + Some((msg, code)) => Response::error(msg, code), + None => Response::empty(), + } + }) + .get("/worker-version", |_, ctx| { + let version = ctx.var("WORKERS_RS_VERSION")?.to_string(); + Response::ok(version) + }); + + r.run(req, env).await +} + +#[derive(Debug)] +struct Handler {} + +#[derive(Debug)] +enum Message { + Stuff(&'static str), +} + +#[async_trait] +impl EventHandler for Handler { + type Message = Message; + type GitHubClient = Client; + + fn listener_port(&self) -> u16 { + 2022 + } + + async fn message(&self, message: Self::Message) { + match message { + Message::Stuff(s) => { + console_log!("==> Message received: {s}"); + } + } + } + + async fn commit_event( + &self, + _github_client: Arc, + _commit: PushEvent, + ) -> Command { + console_log!("Commit pushed!"); + + Command::perform(async { "Computation finished" }, Message::Stuff) + } +} diff --git a/examples/cloudflare/src/utils.rs b/examples/cloudflare/src/utils.rs new file mode 100644 index 00000000..aab768f6 --- /dev/null +++ b/examples/cloudflare/src/utils.rs @@ -0,0 +1,12 @@ +use cfg_if::cfg_if; + +cfg_if! { + // https://github.com/rustwasm/console_error_panic_hook#readme + if #[cfg(feature = "console_error_panic_hook")] { + extern crate console_error_panic_hook; + pub use self::console_error_panic_hook::set_once as set_panic_hook; + } else { + #[inline] + pub fn set_panic_hook() {} + } +} diff --git a/examples/cloudflare/wrangler.toml b/examples/cloudflare/wrangler.toml new file mode 100644 index 00000000..177b3b66 --- /dev/null +++ b/examples/cloudflare/wrangler.toml @@ -0,0 +1,22 @@ +name = "cloudflare" +type = "javascript" +workers_dev = true +compatibility_date = "2022-02-19" + +[vars] +WORKERS_RS_VERSION = "0.0.9" + +[build] +command = "cargo install -q worker-build && worker-build --release" # required + +[build.upload] +dir = "build/worker" +format = "modules" +main = "./shim.mjs" + +[[build.upload.rules]] +globs = ["**/*.wasm"] +type = "CompiledWasm" + +# read more about configuring your Worker via wrangler.toml at: +# https://developers.cloudflare.com/workers/cli-wrangler/configuration diff --git a/github-rest/Cargo.toml b/github-rest/Cargo.toml index 1ecc77fc..332e7adf 100644 --- a/github-rest/Cargo.toml +++ b/github-rest/Cargo.toml @@ -8,7 +8,6 @@ edition = "2021" [dependencies] ## HTTP github-api = { git = "https://github.com/octocat-rs/github-api" } -reqwest = { version = "0.11.8" } ## Serialization/Deserialization strum = { version = "0.23", features = ["derive"] } @@ -19,6 +18,13 @@ serde_json = "^1" async-trait = "0.1.52" paste = "1" +[target.'cfg(not(target_family = "wasm"))'.dependencies] +reqwest = { version = "0.11.8" } + +[target.'cfg(target_family = "wasm")'.dependencies] +worker = "0.0.9" + + [features] default = ["builders"] full = ["builders", "client"] @@ -26,5 +32,5 @@ builders = [] client = [] -[dev-dependencies] +[target.'cfg(not(target_family = "wasm"))'.dev-dependencies] tokio = { version = "1.15.0", features = ["macros", "rt-multi-thread"] } diff --git a/github-rest/src/builders/pull_requests.rs b/github-rest/src/builders/pull_requests.rs index 9a0b694e..28c48bfc 100644 --- a/github-rest/src/builders/pull_requests.rs +++ b/github-rest/src/builders/pull_requests.rs @@ -45,7 +45,6 @@ mod tests { #[tokio::test] async fn test_get_pulls_builder() { - // TODO: Fix the error in the model let r = GetPullsBuilder::new() .owner("microsoft") .repo("vscode") diff --git a/github-rest/src/client.rs b/github-rest/src/client.rs index 06411625..6448a31a 100644 --- a/github-rest/src/client.rs +++ b/github-rest/src/client.rs @@ -2,13 +2,11 @@ //! own client. you can still do this though by implementing the [`Requester`] //! trait -use std::fmt::Display; -//TODO: lock this behind a feature -//TODO: Replace all Strings with T: into use async_trait::async_trait; use github_api::end_points::{EndPoints, Methods}; -use reqwest::{header, Body}; +use reqwest::header; use serde::{de::DeserializeOwned, Serialize}; +use std::fmt::Display; use crate::{GithubRestError, Requester}; @@ -59,7 +57,7 @@ impl Requester for DefaultRequest { async fn raw_req(&self, url: EndPoints, query: Option<&T>, body: Option) -> Result where T: Serialize + ?Sized + std::marker::Send + std::marker::Sync, - V: Into + std::marker::Send, + V: Into + std::marker::Send, { let path = format!("https://api.github.com{}", url.path()); @@ -100,7 +98,7 @@ impl Requester for DefaultRequest { ) -> Result where T: Serialize + ?Sized + std::marker::Send + std::marker::Sync, - V: Into + std::marker::Send, + V: Into + std::marker::Send, { let r = self.raw_req(url, query, body).await?; Ok(serde_json::from_str(&r)?) diff --git a/github-rest/src/lib.rs b/github-rest/src/lib.rs index 258ff0f7..62c24aeb 100644 --- a/github-rest/src/lib.rs +++ b/github-rest/src/lib.rs @@ -1,3 +1,4 @@ +#![feature(associated_type_defaults)] #![deny(rust_2018_idioms)] use core::fmt; @@ -6,8 +7,13 @@ use std::error::Error; use async_trait::async_trait; pub use github_api::end_points; use github_api::end_points::EndPoints; + +#[cfg(not(target_family = "wasm"))] use reqwest::{Body, StatusCode}; + use serde::{de::DeserializeOwned, Serialize}; +#[cfg(target_family = "wasm")] +use worker::wasm_bindgen::JsValue; #[cfg(feature = "builders")] pub mod builders; @@ -18,8 +24,14 @@ pub mod model; #[derive(Debug)] pub enum GithubRestError { + #[cfg(not(target_family = "wasm"))] ReqwestError(reqwest::Error), + #[cfg(target_family = "wasm")] + WorkerError(worker::Error), + #[cfg(target_family = "wasm")] + ResponseError(u16, String), JsonError(serde_json::Error), + #[cfg(not(target_family = "wasm"))] ResponseError(StatusCode, String), AnyError(), } @@ -32,12 +44,20 @@ impl fmt::Display for GithubRestError { impl Error for GithubRestError {} +#[cfg(not(target_family = "wasm"))] impl From for GithubRestError { fn from(e: reqwest::Error) -> Self { GithubRestError::ReqwestError(e) } } +#[cfg(target_family = "wasm")] +impl From for GithubRestError { + fn from(e: worker::Error) -> Self { + GithubRestError::WorkerError(e) + } +} + impl From for GithubRestError { fn from(e: serde_json::Error) -> Self { GithubRestError::JsonError(e) @@ -46,6 +66,12 @@ impl From for GithubRestError { #[async_trait] pub trait Requester: Send + Sync { + #[cfg(not(target_family = "wasm"))] + type Body: From = Body; + + #[cfg(target_family = "wasm")] + type Body: From = JsValue; + async fn raw_req( &self, url: EndPoints, @@ -54,7 +80,7 @@ pub trait Requester: Send + Sync { ) -> Result where T: Serialize + ?Sized + std::marker::Send + std::marker::Sync, - V: Into + std::marker::Send; + V: Into + std::marker::Send; async fn req( &self, @@ -64,5 +90,5 @@ pub trait Requester: Send + Sync { ) -> Result where T: Serialize + ?Sized + std::marker::Send + std::marker::Sync, - V: Into + std::marker::Send; + V: Into + std::marker::Send; } diff --git a/github-rest/src/methods/misc.rs b/github-rest/src/methods/misc.rs index 9283d371..3591f7e6 100644 --- a/github-rest/src/methods/misc.rs +++ b/github-rest/src/methods/misc.rs @@ -3,6 +3,7 @@ use crate::model::organizations::AddToOrgResponse; use super::prelude::*; use serde::{Deserialize, Serialize}; +use serde_json::Value; use strum::{EnumString, EnumVariantNames}; pub async fn zen(client: &T) -> Result @@ -12,13 +13,11 @@ where client.raw_req::(EndPoints::GetZen(), None, None).await } -pub async fn api_info(client: &T) -> Result +pub async fn api_info(client: &T) -> Result where T: Requester, { - client - .req::(EndPoints::Get(), None, None) - .await + client.req::(EndPoints::Get(), None, None).await } //Role enum used for add to org function determines the function a user has diff --git a/github-rest/src/methods/mod.rs b/github-rest/src/methods/mod.rs index 0f67aa08..e63a4925 100644 --- a/github-rest/src/methods/mod.rs +++ b/github-rest/src/methods/mod.rs @@ -11,9 +11,10 @@ mod misc; mod users; pub(crate) mod util; -///Prelude mod used for methods +/// Prelude mod used for methods pub mod prelude { pub use github_api::end_points::*; + #[cfg(not(target_family = "wasm"))] pub use reqwest::Body; pub use serde::{Deserialize, Serialize}; diff --git a/github-rest/src/model/pull_requests/events.rs b/github-rest/src/model/pull_requests/events.rs index a6c00172..1fba4adf 100644 --- a/github-rest/src/model/pull_requests/events.rs +++ b/github-rest/src/model/pull_requests/events.rs @@ -49,7 +49,6 @@ pub mod nested { Unlocked, } - // TODO: Move this to some type of shared module as `IssueEvent` uses it #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct IssueChanges { pub title: Option, diff --git a/github-rest/src/model/repositories/repositories.rs b/github-rest/src/model/repositories/repositories.rs index 2ba481be..872ff8fb 100644 --- a/github-rest/src/model/repositories/repositories.rs +++ b/github-rest/src/model/repositories/repositories.rs @@ -145,7 +145,6 @@ pub struct CodeScanningAlert { pub url: String, pub html_url: String, pub instances: Vec, - // TODO: Find possible values pub state: String, // Don't know if it's unix millis or DateTime pub fixed_at: Option, diff --git a/octocat-rs/Cargo.toml b/octocat-rs/Cargo.toml index 3469310c..e667b5d9 100644 --- a/octocat-rs/Cargo.toml +++ b/octocat-rs/Cargo.toml @@ -19,12 +19,12 @@ github-rest = { path = "../github-rest" } github-api = { git = "https://github.com/octocat-rs/github-api" } ## Async -tokio = { version = "1", features = ["full"] } +tokio = { version = "1", features = ["full"], optional = true } async-trait = "0.1.52" futures = "0.3" ## Webserver -warp = "0.3" +warp = { version = "0.3", optional = true } ## Serialization/Deserialization serde = { version = "^1", features = ["derive"] } @@ -35,12 +35,17 @@ toml = "0.5.8" thiserror = "1.0.30" anyhow = "1.0.51" -## Logging -pretty_env_logger = "0.4" -log = "0.4" - ## Util -lazy_static = "1.4.0" strum_macros = "0.23" -reqwest = "^0.11.8" +reqwest = { version = "^0.11.8", optional = true } strum = "0.23.0" +worker = { version = "0.0.9", optional = true } +serde_urlencoded = { version = "0.7.1", optional = true } +base64 = { version = "0.13.0", optional = true } +hmac = { version = "0.12.1", optional = true } +sha2 = { version = "0.10.2", optional = true } + +[features] +default = [ "native" ] +native = ["warp", "tokio", "reqwest"] +workers = ["worker", "serde_urlencoded", "base64", "hmac", "sha2"] diff --git a/octocat-rs/src/github/client.rs b/octocat-rs/src/github/client.rs index 44b869ed..67130322 100644 --- a/octocat-rs/src/github/client.rs +++ b/octocat-rs/src/github/client.rs @@ -6,11 +6,20 @@ use std::{fmt::Debug, sync::Arc}; use anyhow::Result; use async_trait::async_trait; use github_api::end_points::EndPoints; -use reqwest::Body; use serde::{de::DeserializeOwned, Serialize}; + +#[cfg(feature = "native")] use tokio::sync::mpsc; +#[cfg(feature = "native")] use warp::Filter; +#[cfg(all(target_family = "wasm", feature = "workers"))] +use hmac::{Hmac, Mac}; +#[cfg(all(target_family = "wasm", feature = "workers"))] +use sha2::Sha256; +#[cfg(all(target_family = "wasm", feature = "workers"))] +use std::str::FromStr; + use github_rest::{ model::{ apps::events::{AppAuthorizationEvent, InstallationEvent, InstallationRepositoriesEvent}, @@ -44,6 +53,9 @@ use github_rest::{ use crate::github::{handler::EventHandler, util::Authorization, DefaultEventHandler, HttpClient}; +#[cfg(all(target_family = "wasm", feature = "workers"))] +type HmacSha256 = Hmac; + #[async_trait] pub trait GitHubClient: Requester + Sized { type HttpClient: Requester + Send + Sync; @@ -67,6 +79,7 @@ where T: std::fmt::Debug + EventHandler> + Send + Sync, { handler: T, + #[cfg(feature = "native")] max_payload_size: u64, http_client: HttpClient, } @@ -88,6 +101,7 @@ where &self.handler } + #[cfg(feature = "native")] fn payload_size(&self) -> u64 { self.max_payload_size } @@ -106,7 +120,7 @@ where ) -> std::result::Result where T: Serialize + ?Sized + Send + Sync, - V: Into + Send, + V: Into + Send, { self.http_client.raw_req(url, query, body).await } @@ -119,16 +133,238 @@ where ) -> std::result::Result where T: Serialize + ?Sized + Send + Sync, - V: Into + Send, + V: Into + Send, { self.http_client.req(url, query, body).await } } +macro_rules! event_handle { + ($ev:ident) => { + match $ev { + EventTypes::Push => { + event_push!(commit_event, PushEvent) + } + EventTypes::GithubAppAuthorization => { + event_push!(app_authorization_event, AppAuthorizationEvent) + } + EventTypes::Installation => { + event_push!(installation_event, InstallationEvent) + } + EventTypes::InstallationRepositories => { + event_push!(installation_repositories_event, InstallationRepositoriesEvent) + } + EventTypes::DeployKey => { + event_push!(deploy_key_event, DeployKeyEvent) + } + EventTypes::Gollum => { + event_push!(gollum_event, GollumEvent) + } + EventTypes::Member => { + event_push!(member_event, MemberEvent) + } + EventTypes::Milestone => { + event_push!(milestone_event, MilestoneEvent) + } + EventTypes::Public => { + event_push!(public_event, PublicEvent) + } + EventTypes::Release => { + event_push!(release_event, ReleaseEvent) + } + EventTypes::Repository => { + event_push!(repository_event, RepositoryEvent) + } + EventTypes::RepositoryDispatch => { + event_push!(repository_dispatch_event, RepositoryDispatchEvent) + } + EventTypes::RepositoryImport => { + event_push!(repository_import_event, RepositoryImportEvent) + } + EventTypes::RepositoryVulnerabilityAlert => { + event_push!(repository_vulnerability_alert, RepositoryVulnerabilityAlertEvent) + } + EventTypes::SecretScanningAlert => { + event_push!(secret_scanning_alert, SecretScanningAlertEvent) + } + EventTypes::SecurityAdvisory => { + event_push!(security_advisory, SecurityAdvisoryEvent) + } + EventTypes::Star => { + event_push!(star_event, StarEvent) + } + EventTypes::Watch => { + event_push!(watch_event, WatchEvent) + } + EventTypes::PullRequest => { + event_push!(pull_request_event, PullRequestEvent) + } + EventTypes::PullRequestReview => { + event_push!(pull_request_review_event, PullRequestReviewEvent) + } + EventTypes::PullRequestReviewComment => { + event_push!(pull_request_review_comment_event, PullRequestReviewCommentEvent) + } + EventTypes::CommitComment => { + event_push!(commit_comment_event, CommitCommentEvent) + } + EventTypes::Status => { + event_push!(status_event, StatusEvent) + } + EventTypes::IssueComment => { + event_push!(issue_comment_event, IssueCommentEvent) + } + EventTypes::Issues => { + event_push!(issue_event, IssueEvent) + } + EventTypes::Label => { + event_push!(label_event, LabelEvent) + } + EventTypes::Discussion => { + event_push!(discussion_event, DiscussionEvent) + } + EventTypes::DiscussionComment => { + event_push!(discussion_comment_event, DiscussionCommentEvent) + } + EventTypes::BranchProtectionRule => { + event_push!(branch_protection_rule_event, BranchProtectionRuleEvent) + } + EventTypes::Create => { + event_push!(tag_created, CreateEvent) + } + EventTypes::Delete => { + event_push!(tag_deleted, DeleteEvent) + } + EventTypes::Fork => { + event_push!(repository_forked, ForkEvent) + } + EventTypes::CheckRun => { + event_push!(check_run, CheckRunEvent) + } + EventTypes::CheckSuite => { + event_push!(check_suite_event, CheckSuiteEvent) + } + EventTypes::CodeScanningAlert => { + event_push!(code_scanning_alert_event, CodeScanningAlertEvent) + } + EventTypes::Deployment => { + event_push!(deployment_event, DeploymentEvent) + } + EventTypes::DeploymentStatus => { + event_push!(deployment_status_event, DeploymentStatusEvent) + } + EventTypes::PageBuild => { + event_push!(page_build_event, PageBuildEvent) + } + EventTypes::WorkflowDispatch => { + event_push!(workflow_dispatch_event, WorkflowDispatchEvent) + } + EventTypes::WorkflowJob => { + event_push!(workflow_job, WorkflowJobEvent) + } + EventTypes::WorkflowRun => { + event_push!(workflow_run, WorkflowRunEvent) + } + EventTypes::Membership => { + event_push!(membership_event, MembershipEvent) + } + EventTypes::OrgBlock => { + event_push!(org_block_event, OrgBlockEvent) + } + EventTypes::Organization => { + event_push!(organization_event, OrganizationEvent) + } + EventTypes::Team => { + event_push!(team_event, TeamEvent) + } + EventTypes::TeamAdd => { + event_push!(team_add_event, TeamAddEvent) + } + EventTypes::Project => { + event_push!(project_event, ProjectEvent) + } + EventTypes::ProjectCard => { + event_push!(project_card_event, ProjectCardEvent) + } + EventTypes::ProjectColumn => { + event_push!(project_column_event, ProjectColumnEvent) + } + EventTypes::MarketplacePurchase => { + event_push!(marketplace_purchase_event, MarketplacePurchaseEvent) + } + EventTypes::Meta => { + event_push!(meta_event, MetaEvent) + } + EventTypes::Package => { + event_push!(package_event, PackageEvent) + } + EventTypes::Ping => { + event_push!(ping_event, PingEvent) + } + EventTypes::Sponsorship => { + event_push!(sponsorship_event, SponsorshipEvent) + } + } + }; +} + impl Client where T: Debug + EventHandler> + Send + Sync + 'static, { + #[cfg(all(target_family = "wasm", feature = "workers"))] + pub async fn handle(self, mut req: worker::Request) -> Option<(&'static str, u16)> { + let self_arc = Arc::new(self); + let thread_self = self_arc.clone(); + let thread_self_2 = self_arc.clone(); + worker::console_log!("{:#?}", &req.headers().get("X-GitHub-Event")); + + let ev = EventTypes::from_str(req.headers().get("X-GitHub-Event").unwrap().unwrap().as_str()) + .expect("Failed to parse headers"); + + // TODO: Native support for this. + if let Some(secret) = self_arc.handler.listener_secret() { + match req.headers().get("X-Hub-Signature-256").unwrap() { + Some(hash) => { + if !secret.is_empty() { + let mut mac = HmacSha256::new_from_slice(secret).unwrap(); + mac.update(req.text().await.unwrap().as_bytes()); + + let result = mac.finalize().into_bytes(); + + if !result[..].eq_ignore_ascii_case(&hash.as_bytes()[..]) { + return Some(("Signatures don't match!", 400)); + } + } + } + None => return Some(("Missing X-Hub-Signature-256 header!", 401)), + } + } + + macro_rules! event_push { + ($f:ident, $t:ty) => { + thread_self + .event_handler() + .$f( + thread_self.clone(), + (req).json::<$t>().await.expect("Failed to parse json"), + ) + .await + }; + } + + let user_cmd = event_handle!(ev); + + let mut cmd = user_cmd.into_futures(); + + while let Some(c) = cmd.pop() { + thread_self_2.event_handler().message(c.await).await; + } + + None + } + + #[cfg(feature = "warp")] pub async fn start(self) { let _ = self.run().await.expect("Starting application: User-defined code"); @@ -156,174 +392,8 @@ where }; } - dbg!(&ev); - dbg!(&body.to_string()); - let ev_h = async { - let user_cmd = match ev { - EventTypes::Push => { - event_push!(commit_event, PushEvent) - } - EventTypes::GithubAppAuthorization => { - event_push!(app_authorization_event, AppAuthorizationEvent) - } - EventTypes::Installation => { - event_push!(installation_event, InstallationEvent) - } - EventTypes::InstallationRepositories => { - event_push!(installation_repositories_event, InstallationRepositoriesEvent) - } - EventTypes::DeployKey => { - event_push!(deploy_key_event, DeployKeyEvent) - } - EventTypes::Gollum => { - event_push!(gollum_event, GollumEvent) - } - EventTypes::Member => { - event_push!(member_event, MemberEvent) - } - EventTypes::Milestone => { - event_push!(milestone_event, MilestoneEvent) - } - EventTypes::Public => { - event_push!(public_event, PublicEvent) - } - EventTypes::Release => { - event_push!(release_event, ReleaseEvent) - } - EventTypes::Repository => { - event_push!(repository_event, RepositoryEvent) - } - EventTypes::RepositoryDispatch => { - event_push!(repository_dispatch_event, RepositoryDispatchEvent) - } - EventTypes::RepositoryImport => { - event_push!(repository_import_event, RepositoryImportEvent) - } - EventTypes::RepositoryVulnerabilityAlert => { - event_push!(repository_vulnerability_alert, RepositoryVulnerabilityAlertEvent) - } - EventTypes::SecretScanningAlert => { - event_push!(secret_scanning_alert, SecretScanningAlertEvent) - } - EventTypes::SecurityAdvisory => { - event_push!(security_advisory, SecurityAdvisoryEvent) - } - EventTypes::Star => { - event_push!(star_event, StarEvent) - } - EventTypes::Watch => { - event_push!(watch_event, WatchEvent) - } - EventTypes::PullRequest => { - event_push!(pull_request_event, PullRequestEvent) - } - EventTypes::PullRequestReview => { - event_push!(pull_request_review_event, PullRequestReviewEvent) - } - EventTypes::PullRequestReviewComment => { - event_push!(pull_request_review_comment_event, PullRequestReviewCommentEvent) - } - EventTypes::CommitComment => { - event_push!(commit_comment_event, CommitCommentEvent) - } - EventTypes::Status => { - event_push!(status_event, StatusEvent) - } - EventTypes::IssueComment => { - event_push!(issue_comment_event, IssueCommentEvent) - } - EventTypes::Issues => { - event_push!(issue_event, IssueEvent) - } - EventTypes::Label => { - event_push!(label_event, LabelEvent) - } - EventTypes::Discussion => { - event_push!(discussion_event, DiscussionEvent) - } - EventTypes::DiscussionComment => { - event_push!(discussion_comment_event, DiscussionCommentEvent) - } - EventTypes::BranchProtectionRule => { - event_push!(branch_protection_rule_event, BranchProtectionRuleEvent) - } - EventTypes::Create => { - event_push!(tag_created, CreateEvent) - } - EventTypes::Delete => { - event_push!(tag_deleted, DeleteEvent) - } - EventTypes::Fork => { - event_push!(repository_forked, ForkEvent) - } - EventTypes::CheckRun => { - event_push!(check_run, CheckRunEvent) - } - EventTypes::CheckSuite => { - event_push!(check_suite_event, CheckSuiteEvent) - } - EventTypes::CodeScanningAlert => { - event_push!(code_scanning_alert_event, CodeScanningAlertEvent) - } - EventTypes::Deployment => { - event_push!(deployment_event, DeploymentEvent) - } - EventTypes::DeploymentStatus => { - event_push!(deployment_status_event, DeploymentStatusEvent) - } - EventTypes::PageBuild => { - event_push!(page_build_event, PageBuildEvent) - } - EventTypes::WorkflowDispatch => { - event_push!(workflow_dispatch_event, WorkflowDispatchEvent) - } - EventTypes::WorkflowJob => { - event_push!(workflow_job, WorkflowJobEvent) - } - EventTypes::WorkflowRun => { - event_push!(workflow_run, WorkflowRunEvent) - } - EventTypes::Membership => { - event_push!(membership_event, MembershipEvent) - } - EventTypes::OrgBlock => { - event_push!(org_block_event, OrgBlockEvent) - } - EventTypes::Organization => { - event_push!(organization_event, OrganizationEvent) - } - EventTypes::Team => { - event_push!(team_event, TeamEvent) - } - EventTypes::TeamAdd => { - event_push!(team_add_event, TeamAddEvent) - } - EventTypes::Project => { - event_push!(project_event, ProjectEvent) - } - EventTypes::ProjectCard => { - event_push!(project_card_event, ProjectCardEvent) - } - EventTypes::ProjectColumn => { - event_push!(project_column_event, ProjectColumnEvent) - } - EventTypes::MarketplacePurchase => { - event_push!(marketplace_purchase_event, MarketplacePurchaseEvent) - } - EventTypes::Meta => { - event_push!(meta_event, MetaEvent) - } - EventTypes::Package => { - event_push!(package_event, PackageEvent) - } - EventTypes::Ping => { - event_push!(ping_event, PingEvent) - } - EventTypes::Sponsorship => { - event_push!(sponsorship_event, SponsorshipEvent) - } - }; + let user_cmd = event_handle!(ev); if !user_cmd.is_empty() { let _ = &tx.send(user_cmd).await; @@ -353,6 +423,7 @@ where } /// Creates a new [`Client`]. + #[cfg(feature = "native")] pub fn new(handler: T, auth: Option, user_agent: Option, payload_size: Option) -> Self { Self { handler, @@ -361,6 +432,14 @@ where } } + #[cfg(all(target_family = "wasm", feature = "workers"))] + pub fn new(handler: T, auth: Option, user_agent: Option) -> Self { + Self { + handler, + http_client: HttpClient::new(auth, user_agent), + } + } + /// Updates the authorization parameter in the current [`Client`] instance. pub fn set_auth(mut self, auth: Authorization) -> Self { self.http_client.set_auth(auth); @@ -372,6 +451,7 @@ impl Default for Client { fn default() -> Client { Client { handler: DefaultEventHandler, + #[cfg(feature = "native")] max_payload_size: 1024 * 8192, http_client: HttpClient::new(None, None), } diff --git a/octocat-rs/src/github/client_builder.rs b/octocat-rs/src/github/client_builder.rs index 1f98332d..53438685 100644 --- a/octocat-rs/src/github/client_builder.rs +++ b/octocat-rs/src/github/client_builder.rs @@ -14,6 +14,7 @@ where handler: Option, auth: Option, user_agent: Option, + #[cfg(feature = "native")] payload_size: Option, } @@ -25,6 +26,7 @@ where pub fn new() -> Self { Self::default() } + /// Adds an [`EventHandler`] to the current builder. pub fn event_handler(mut self, event_handler: T) -> Self { self.handler = Some(event_handler); @@ -33,6 +35,7 @@ where /// Sets the maximum payload size that the listener can receive from GitHub /// in MiB. Default: 8. + #[cfg(feature = "native")] pub fn payload_size(mut self, size: u64) -> Self { self.payload_size = Some(size); self @@ -110,6 +113,7 @@ where self.handler.unwrap(), self.auth, self.user_agent, + #[cfg(feature = "native")] self.payload_size, )) } @@ -129,6 +133,7 @@ impl ClientBuilder { DefaultEventHandler::new(), self.auth, self.user_agent, + #[cfg(feature = "native")] self.payload_size, )) } @@ -142,6 +147,7 @@ where Self { handler: None, auth: None, + #[cfg(feature = "native")] payload_size: None, user_agent: None, } diff --git a/octocat-rs/src/github/handler.rs b/octocat-rs/src/github/handler.rs index 1de25061..101d9822 100644 --- a/octocat-rs/src/github/handler.rs +++ b/octocat-rs/src/github/handler.rs @@ -52,6 +52,11 @@ pub trait EventHandler { "/payload" } + /// The webhook secret. Defaults to none. + fn listener_secret(&self) -> Option<&[u8]> { + None + } + async fn message(&self, message: Self::Message) { {} } diff --git a/octocat-rs/src/github/http.rs b/octocat-rs/src/github/http.rs index bb99fef3..ee0a9e49 100644 --- a/octocat-rs/src/github/http.rs +++ b/octocat-rs/src/github/http.rs @@ -1,14 +1,23 @@ //! Contains [`HttpClient`]. use async_trait::async_trait; +#[cfg(feature = "native")] use reqwest::{ header, header::{HeaderMap, HeaderValue}, - Body, RequestBuilder, + RequestBuilder, }; use serde::{de::DeserializeOwned, Serialize}; +#[cfg(feature = "native")] use tokio::time::Duration; +#[cfg(all(target_family = "wasm", feature = "workers"))] +use base64::write::EncoderWriter as Base64Encoder; +#[cfg(all(target_family = "wasm", feature = "workers"))] +use std::io::Write; +#[cfg(all(target_family = "wasm", feature = "workers"))] +use worker::{Fetch, Headers, Method, Request, RequestInit}; + use github_rest::{ methods::prelude::{EndPoints, Methods}, GithubRestError, @@ -23,11 +32,15 @@ const ACCEPT_HEADER_PARSE_ERROR: &str = "HttpClient: Parsing accept header"; /// /// [`Requester`]: github_rest::Requester pub struct HttpClient { + #[cfg(feature = "native")] client: reqwest::Client, + #[cfg(all(target_family = "wasm", feature = "workers"))] + user_agent: Option, auth: Option, } impl HttpClient { + #[cfg(feature = "native")] pub fn new(auth: Option, user_agent: Option) -> Self { let mut headers = HeaderMap::new(); @@ -55,12 +68,18 @@ impl HttpClient { } } + #[cfg(all(target_family = "wasm", feature = "workers"))] + pub fn new(auth: Option, user_agent: Option) -> Self { + HttpClient { user_agent, auth } + } + /// Updates the authorization used by the current client. pub fn set_auth(&mut self, auth: Authorization) { self.auth = Some(auth); } /// Set the user agent used by the current client. + #[cfg(feature = "native")] pub fn set_ua(&mut self, user_agent: String) { let mut headers = HeaderMap::new(); @@ -80,6 +99,13 @@ impl HttpClient { .unwrap() } + /// Set the user agent used by the current client. + #[cfg(all(target_family = "wasm", feature = "workers"))] + pub fn set_ua(&mut self, user_agent: String) { + self.user_agent = Some(user_agent); + } + + #[cfg(feature = "native")] fn http_auth(&self, req: RequestBuilder) -> RequestBuilder { if let Some(auth) = &self.auth { match auth { @@ -94,10 +120,11 @@ impl HttpClient { #[async_trait] impl github_rest::Requester for HttpClient { /// Returns the API response as a [`String`]. + #[cfg(feature = "native")] async fn raw_req(&self, url: EndPoints, query: Option<&T>, body: Option) -> Result where T: Serialize + ?Sized + Send + Sync, - V: Into + Send, + V: Into + Send, { let path = format!("https://api.github.com{}", url.path()); @@ -130,6 +157,75 @@ impl github_rest::Requester for HttpClient { Ok(txt) } + /// Returns the API response as a [`String`]. + #[cfg(all(target_family = "wasm", feature = "workers"))] + async fn raw_req(&self, url: EndPoints, query: Option<&T>, body: Option) -> Result + where + T: Serialize + ?Sized + Send + Sync, + V: Into + Send, + { + let mut path = format!("https://api.github.com{}", url.path()); + + if let Some(q) = query { + path.push_str(serde_urlencoded::to_string(q).expect("Invalid query").as_str()); + } + + futures::executor::block_on(async move { + let mut init = RequestInit::new(); + init.with_method(BadWrapper::new(url.method()).into()); + + let mut headers = Headers::new(); + headers + .append("accept", "application/vnd.github.v3+json") + .expect(ACCEPT_HEADER_PARSE_ERROR); + + if let Some(auth) = &self.auth { + match auth { + Authorization::PersonalToken { username, token } => { + let mut header_value = b"Basic ".to_vec(); + + { + let mut encoder = Base64Encoder::new(&mut header_value, base64::STANDARD); + + write!(encoder, "{username}:").unwrap(); + write!(encoder, "{token}").unwrap(); + } + + headers + .append( + "authorization", + std::str::from_utf8(&header_value).expect("Failed to parse header value"), + ) + .unwrap(); + } + } + } + + if let Some(ua) = &self.user_agent { + headers.append("user-agent", ua).expect(USER_AGENT_PARSE_ERROR); + } + + init.with_headers(headers); + + if let Some(body) = body { + init.with_body(Some(body.into())); + } + + let req = Request::new_with_init(path.as_str(), &init)?; + + let mut res = Fetch::Request(req).send().await?; + + match res.status_code() { + 200..=299 => {} + _ => { + return Err(GithubRestError::ResponseError(res.status_code(), res.text().await?)); + } + } + + Ok(res.text().await?) + }) + } + async fn req( &self, url: EndPoints, @@ -138,9 +234,34 @@ impl github_rest::Requester for HttpClient { ) -> Result where T: Serialize + ?Sized + Send + Sync, - V: Into + Send, + V: Into + Send, { let r = self.raw_req(url, query, body).await?; Ok(serde_json::from_str(&r)?) } } + +#[cfg(all(target_family = "wasm", feature = "workers"))] +struct BadWrapper { + pub(crate) inner: T, +} + +#[cfg(all(target_family = "wasm", feature = "workers"))] +impl BadWrapper { + fn new(inner: T) -> Self { + BadWrapper { inner } + } +} + +#[cfg(all(target_family = "wasm", feature = "workers"))] +impl From> for Method { + fn from(v: BadWrapper) -> Self { + match v.inner { + Methods::Get => Method::Get, + Methods::Post => Method::Post, + Methods::Patch => Method::Patch, + Methods::Delete => Method::Delete, + Methods::Put => Method::Put, + } + } +} diff --git a/octocat-rs/src/github/mod.rs b/octocat-rs/src/github/mod.rs index 1075d4ea..5bf2de8d 100644 --- a/octocat-rs/src/github/mod.rs +++ b/octocat-rs/src/github/mod.rs @@ -14,26 +14,21 @@ pub mod util; #[cfg(test)] mod tests { - use std::sync::Arc; - + use crate::{github::ClientBuilder, handler::EventHandler, Client, Command, DefaultEventHandler}; use async_trait::async_trait; use futures::FutureExt; - use github_rest::{ model::{commits::comments::CommitComment, repositories::events::PushEvent}, GithubRestError, }; - - use crate::{ - github::{command::Command, handler::EventHandler, ClientBuilder}, - Client, DefaultEventHandler, - }; + use std::sync::Arc; #[test] fn default_everything() { let _client = ClientBuilder::build_unconfigured(); } + #[cfg(feature = "native")] #[tokio::test] async fn standard() { #[derive(Debug)] diff --git a/octocat-rs/src/lib.rs b/octocat-rs/src/lib.rs index 93fca14a..95106fed 100644 --- a/octocat-rs/src/lib.rs +++ b/octocat-rs/src/lib.rs @@ -13,6 +13,9 @@ pub mod github; pub use github_api as api; pub use github_rest as rest; +#[cfg(all(feature = "default", feature = "workers"))] +compile_error!("feature \"default\" and feature \"workers\" cannot be enabled at the same time"); + #[cfg(test)] mod tests { #[test] diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 00000000..a25e7e06 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "nightly" +