From 40a75fa4d322753480578f2f3ffe43b8a52ea9cb Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Mon, 22 Nov 2021 16:02:07 +0000 Subject: [PATCH] Rename project --- Cargo.lock | 504 +---------------------- Cargo.toml | 2 +- Dockerfile | 12 +- README.md | 8 +- docker-compose.yml | 6 +- package.json | 6 +- registration.sample.yml | 2 +- src/AdminRoom.ts | 40 +- src/CommentProcessor.ts | 2 +- src/Connections/GenericHook.ts | 4 +- src/Connections/GithubDiscussion.ts | 8 +- src/Connections/GithubDiscussionSpace.ts | 9 +- src/Connections/GithubIssue.ts | 9 +- src/Connections/GithubProject.ts | 6 +- src/Connections/GithubRepo.ts | 11 +- src/Connections/GithubUserSpace.ts | 3 +- src/Connections/GitlabIssue.ts | 5 +- src/Connections/GitlabRepo.ts | 6 +- src/Connections/JiraProject.ts | 4 +- src/FormatUtil.rs | 4 +- src/FormatUtil.ts | 7 +- src/Github/GithubInstance.ts | 2 +- src/GithubBridge.ts | 13 +- src/Gitlab/Client.ts | 2 +- src/NotificationFilters.ts | 3 +- src/UserTokenStore.ts | 38 +- src/libRs.ts | 4 +- tests/FormatUtilTest.ts | 4 +- yarn.lock | 5 - 29 files changed, 132 insertions(+), 597 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fdca2a4c..291b5826 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,45 +2,18 @@ # 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 = "autocfg" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - [[package]] name = "bytemuck" version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72957246c41db82b8ef88a5486143830adeb8227ef9837740bdec67724cf2c5b" -[[package]] -name = "bytes" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - [[package]] name = "contrast" version = "0.1.0" @@ -51,12 +24,6 @@ dependencies = [ "rgb", ] -[[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" @@ -67,155 +34,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "futures-channel" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5da6ba8c3bb3c165d3c7319fc1cc8304facf1fb8db99c5de877183c08a273888" -dependencies = [ - "futures-core", -] - -[[package]] -name = "futures-core" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88d1c26957f23603395cd326b0ffe64124b818f4449552f960d815cfba83a53d" - -[[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-core", - "futures-macro", - "futures-task", - "pin-project-lite", - "pin-utils", - "proc-macro-hack", - "proc-macro-nested", - "slab", -] - -[[package]] -name = "h2" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fd819562fcebdac5afc5c113c3ec36f902840b70fd4fc458799c8ce4607ae55" -dependencies = [ - "bytes", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" - -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - -[[package]] -name = "http" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1323096b05d41827dadeaee54c9981958c0f94e670bc94ed80037d1a7b8b186b" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "http-body" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ff4f84919677303da5f147645dbea6b1881f368d03ac84e1dc09031ebd7b2c6" -dependencies = [ - "bytes", - "http", - "pin-project-lite", -] - -[[package]] -name = "httparse" -version = "1.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acd94fdbe1d4ff688b67b04eee2e17bd50995534a61539e45adfefb45e5e5503" - -[[package]] -name = "httpdate" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" - -[[package]] -name = "hyper" -version = "0.14.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "436ec0091e4f20e655156a30a0df3770fe2900aa301e548e08446ec794b6953c" -dependencies = [ - "bytes", - "futures-channel", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "httparse", - "httpdate", - "itoa", - "pin-project-lite", - "socket2", - "tokio", - "tower-service", - "tracing", - "want", -] - [[package]] name = "idna" version = "0.2.3" @@ -227,61 +45,12 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5" -dependencies = [ - "autocfg", - "hashbrown", -] - -[[package]] -name = "instant" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" -dependencies = [ - "cfg-if", -] - [[package]] name = "itoa" version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" -[[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.108" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119" - -[[package]] -name = "lock_api" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712a4d093c9976e24e7dbca41db895dabcbac38eb5f4045393d17a95bdfb1109" -dependencies = [ - "scopeguard", -] - -[[package]] -name = "log" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" -dependencies = [ - "cfg-if", -] - [[package]] name = "matches" version = "0.1.9" @@ -289,52 +58,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" [[package]] -name = "matrix-github" +name = "matrix-hookshot" version = "0.1.0" dependencies = [ "contrast", - "futures-util", - "hyper", "napi", "napi-build", "napi-derive", "rgb", - "routerify", "serde", "serde_derive", "serde_json", - "tokio", "url", ] -[[package]] -name = "memchr" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" - -[[package]] -name = "mio" -version = "0.7.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8067b404fe97c70829f082dec8bcf4f71225d7eaea1d8645349cb76fa06205cc" -dependencies = [ - "libc", - "log", - "miow", - "ntapi", - "winapi", -] - -[[package]] -name = "miow" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" -dependencies = [ - "winapi", -] - [[package]] name = "napi" version = "1.7.10" @@ -342,10 +79,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9050238b713b3c5dd5ae1613da1ccefe4061c03992f9e9bbe43b7d473ba4bd3c" dependencies = [ "napi-sys", - "once_cell", "serde", "serde_json", - "tokio", "winapi", ] @@ -372,15 +107,6 @@ version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67cf20e0081fea04e044aa4adf74cfea8ddc0324eec2894b1c700f4cafc72a56" -[[package]] -name = "ntapi" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" -dependencies = [ - "winapi", -] - [[package]] name = "num-traits" version = "0.2.14" @@ -390,77 +116,12 @@ dependencies = [ "autocfg", ] -[[package]] -name = "num_cpus" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "once_cell" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" - -[[package]] -name = "parking_lot" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" -dependencies = [ - "instant", - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" -dependencies = [ - "cfg-if", - "instant", - "libc", - "redox_syscall", - "smallvec", - "winapi", -] - [[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.32" @@ -479,32 +140,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "redox_syscall" -version = "0.2.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff" -dependencies = [ - "bitflags", -] - -[[package]] -name = "regex" -version = "1.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.6.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" - [[package]] name = "rgb" version = "0.8.29" @@ -514,31 +149,12 @@ dependencies = [ "bytemuck", ] -[[package]] -name = "routerify" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c6bb49594c791cadb5ccfa5f36d41b498d40482595c199d10cd318800280bd9" -dependencies = [ - "http", - "hyper", - "lazy_static", - "percent-encoding", - "regex", -] - [[package]] name = "ryu" version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" -[[package]] -name = "scopeguard" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" - [[package]] name = "serde" version = "1.0.130" @@ -567,37 +183,6 @@ dependencies = [ "serde", ] -[[package]] -name = "signal-hook-registry" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" -dependencies = [ - "libc", -] - -[[package]] -name = "slab" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9def91fd1e018fe007022791f865d0ccc9b3a0d5001e01aabb8b40e46000afb5" - -[[package]] -name = "smallvec" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ecab6c735a6bb4139c0caafd0cc3635748bbb3acf4550e8138122099251f309" - -[[package]] -name = "socket2" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dc90fe6c7be1a323296982db1836d1ea9e47b6839496dde9a541bc496df3516" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "syn" version = "1.0.81" @@ -624,83 +209,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" -[[package]] -name = "tokio" -version = "1.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70e992e41e0d2fb9f755b37446f20900f64446ef54874f40a60c78f021ac6144" -dependencies = [ - "autocfg", - "bytes", - "libc", - "memchr", - "mio", - "num_cpus", - "once_cell", - "parking_lot", - "pin-project-lite", - "signal-hook-registry", - "tokio-macros", - "winapi", -] - -[[package]] -name = "tokio-macros" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9efc1aba077437943f7515666aa2b882dfabfbfdf89c819ea75a8d6e9eaba5e" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "tokio-util" -version = "0.6.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e99e1983e5d376cd8eb4b66604d2e99e79f5bd988c3055891dcd8c9e2604cc0" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "log", - "pin-project-lite", - "tokio", -] - -[[package]] -name = "tower-service" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" - -[[package]] -name = "tracing" -version = "0.1.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "375a639232caf30edfc78e8d89b2d4c375515393e7af7e16f01cd96917fb2105" -dependencies = [ - "cfg-if", - "pin-project-lite", - "tracing-core", -] - -[[package]] -name = "tracing-core" -version = "0.1.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4ed65637b8390770814083d20756f87bfa2c21bf2f110babdc5438351746e4" -dependencies = [ - "lazy_static", -] - -[[package]] -name = "try-lock" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" - [[package]] name = "unicode-bidi" version = "0.3.7" @@ -734,16 +242,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "want" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" -dependencies = [ - "log", - "try-lock", -] - [[package]] name = "winapi" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index aded7a6b..4a331881 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "matrix-github" +name = "matrix-hookshot" version = "0.1.0" edition = "2021" diff --git a/Dockerfile b/Dockerfile index 20d17360..d3579531 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,15 +18,15 @@ RUN yarn build # Stage 1: The actual container FROM node:16 -COPY --from=builder /src/lib/ /bin/matrix-github/ -COPY --from=builder /src/public/ /bin/matrix-github/public/ -COPY --from=builder /src/package.json /bin/matrix-github/ -COPY --from=builder /src/yarn.lock /bin/matrix-github/ -WORKDIR /bin/matrix-github +COPY --from=builder /src/lib/ /bin/matrix-hookshot/ +COPY --from=builder /src/public/ /bin/matrix-hookshot/public/ +COPY --from=builder /src/package.json /bin/matrix-hookshot/ +COPY --from=builder /src/yarn.lock /bin/matrix-hookshot/ +WORKDIR /bin/matrix-hookshot RUN yarn --production VOLUME /data EXPOSE 9993 EXPOSE 7775 -CMD ["node", "/bin/matrix-github/App/BridgeApp.js", "/data/config.yml", "/data/registration.yml"] +CMD ["node", "/bin/matrix-hookshot/App/BridgeApp.js", "/data/config.yml", "/data/registration.yml"] diff --git a/README.md b/README.md index 196fa9c8..acef7ea4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ -matrix-github +matrix-hookshot ============= +*Previously matrix-github* + [![#github-bridge:half-shot.uk](https://img.shields.io/matrix/github-bridge:half-shot.uk.svg?server_fqdn=matrix.half-shot.uk&label=%23github-bridge:half-shot.uk&logo=matrix)](https://matrix.to/#/#github-bridge:half-shot.uk) @@ -12,12 +14,12 @@ This bridge requires at least Node 12, and Rust installed. If you do not have ru To set up the bridge, simply clone this repository. -` git clone git@github.com:Half-Shot/matrix-github.git` +` git clone git@github.com:Half-Shot/matrix-hookshot.git` then you will need to install the dependencies ```sh -cd matrix-github +cd matrix-hookshot yarn ``` diff --git a/docker-compose.yml b/docker-compose.yml index f373a4c8..149874e0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,7 +15,7 @@ services: environment: CFG_QUEUE_MONOLITHIC: "false" CFG_QUEUE_HOST: "redis" - command: node /bin/matrix-github/App/GithubWebhookApp.js /data/config.yml /data/registration.yml + command: node /bin/matrix-hookshot/App/GithubWebhookApp.js /data/config.yml /data/registration.yml sender: build: context: . @@ -27,7 +27,7 @@ services: environment: CFG_QUEUE_MONOLITHIC: "false" CFG_QUEUE_HOST: "redis" - command: node /bin/matrix-github/App/MatrixSenderApp.js /data/config.yml /data/registration.yml + command: node /bin/matrix-hookshot/App/MatrixSenderApp.js /data/config.yml /data/registration.yml app: build: context: . @@ -41,4 +41,4 @@ services: environment: CFG_QUEUE_MONOLITHIC: "false" CFG_QUEUE_HOST: "redis" - command: node /bin/matrix-github/App/BridgeApp.js /data/config.yml /data/registration.yml + command: node /bin/matrix-hookshot/App/BridgeApp.js /data/config.yml /data/registration.yml diff --git a/package.json b/package.json index dbfc8e71..f5b9e5a6 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,14 @@ { - "name": "matrix-github", + "name": "matrix-hookshot", "version": "0.1.0", "description": "A bridge that displays GitHub issues/PRs as rooms.", "main": "lib/app.js", - "repository": "https://github.com/Half-Shot/matrix-github", + "repository": "https://github.com/Half-Shot/matrix-hookshot", "author": "Half-Shot", "license": "MIT", "private": false, "napi": { - "name": "matrix-github-rs" + "name": "matrix-hookshot-rs" }, "engines": { "node": ">=12" diff --git a/registration.sample.yml b/registration.sample.yml index 3037e592..253101ad 100644 --- a/registration.sample.yml +++ b/registration.sample.yml @@ -1,4 +1,4 @@ -id: matrix-github # This can be anything, but must be unique within your homeserver +id: matrix-hookshot # This can be anything, but must be unique within your homeserver as_token: aaaaaaaaaa # This again can be a random string hs_token: aaaaaaaaaa # ..as can this namespaces: diff --git a/src/AdminRoom.ts b/src/AdminRoom.ts index 68877f0a..b326530a 100644 --- a/src/AdminRoom.ts +++ b/src/AdminRoom.ts @@ -26,10 +26,13 @@ type ProjectsListForUserResponseData = Endpoints["GET /users/{username}/projects const md = new markdown(); const log = new LogWrapper('AdminRoom'); -export const BRIDGE_ROOM_TYPE = "uk.half-shot.matrix-github.room"; -export const BRIDGE_NOTIF_TYPE = "uk.half-shot.matrix-github.notif_state"; -export const BRIDGE_GITLAB_NOTIF_TYPE = "uk.half-shot.matrix-github.gitlab.notif_state"; +export const LEGACY_BRIDGE_ROOM_TYPE = "uk.half-shot.matrix-github.room"; +export const LEGACY_BRIDGE_NOTIF_TYPE = "uk.half-shot.matrix-github.notif_state"; +export const LEGACY_BRIDGE_GITLAB_NOTIF_TYPE = "uk.half-shot.matrix-github.gitlab.notif_state"; +export const BRIDGE_ROOM_TYPE = "uk.half-shot.matrix-hookshot.github.room"; +export const BRIDGE_NOTIF_TYPE = "uk.half-shot.matrix-hookshot.github.notif_state"; +export const BRIDGE_GITLAB_NOTIF_TYPE = "uk.half-shot.matrix-hookshot.gitlab.notif_state"; export interface AdminAccountData { // eslint-disable-next-line camelcase admin_user: string; @@ -109,19 +112,29 @@ export class AdminRoom extends EventEmitter { public async getNotifSince(type: "github"|"gitlab", instanceName?: string) { if (type === "gitlab") { try { - const { since } = await this.botIntent.underlyingClient.getRoomAccountData( - `${BRIDGE_GITLAB_NOTIF_TYPE}:${instanceName}`, this.roomId + let accountData: null|{since: number} = await this.botIntent.underlyingClient.getSafeRoomAccountData( + `${BRIDGE_GITLAB_NOTIF_TYPE}:${instanceName}`, this.roomId, null ); - return since; + if (!accountData) { + accountData = await this.botIntent.underlyingClient.getSafeRoomAccountData( + `${LEGACY_BRIDGE_GITLAB_NOTIF_TYPE}:${instanceName}`, this.roomId, { since: 0 } + ); + } + return accountData.since; } catch { // TODO: We should look at this error. return 0; } } try { - const { since } = await this.botIntent.underlyingClient.getRoomAccountData(BRIDGE_NOTIF_TYPE, this.roomId); - log.debug(`Got ${type} notif-since to ${since}`); - return since; + let accountData: null|{since: number} = await this.botIntent.underlyingClient.getSafeRoomAccountData(BRIDGE_NOTIF_TYPE, this.roomId, { since: 0 }); + if (!accountData) { + accountData = await this.botIntent.underlyingClient.getSafeRoomAccountData( + `${LEGACY_BRIDGE_NOTIF_TYPE}:${instanceName}`, this.roomId, { since: 0 } + ); + } + log.debug(`Got ${type} notif-since to ${accountData.since}`); + return accountData.since; } catch (ex) { log.warn(`Filed to get ${type} notif-since`, ex); // TODO: We should look at this error. @@ -506,7 +519,7 @@ export class AdminRoom extends EventEmitter { const users = parameters.filter(param => param.toLowerCase().startsWith("users:")).map(param => param.toLowerCase().substring("users:".length).split(",")).flat(); const repos = parameters.filter(param => param.toLowerCase().startsWith("repos:")).map(param => param.toLowerCase().substring("repos:".length).split(",")).flat(); if (orgs.length + users.length + repos.length === 0) { - return this.sendNotice("You must specify some filter options like 'orgs:matrix-org,half-shot', 'users:Half-Shot' or 'repos:matrix-github'"); + return this.sendNotice("You must specify some filter options like 'orgs:matrix-org,half-shot', 'users:Half-Shot' or 'repos:matrix-hookshot'"); } this.notifFilter.setFilter(name, { orgs, @@ -533,9 +546,10 @@ export class AdminRoom extends EventEmitter { } private async saveAccountData(updateFn: (record: AdminAccountData) => AdminAccountData) { - const oldData: AdminAccountData = await this.botIntent.underlyingClient.getRoomAccountData( - BRIDGE_ROOM_TYPE, this.roomId, - ); + let oldData: AdminAccountData|null = await this.botIntent.underlyingClient.getSafeRoomAccountData(BRIDGE_ROOM_TYPE, this.roomId, null); + if (!oldData) { + oldData = await this.botIntent.underlyingClient.getSafeRoomAccountData(LEGACY_BRIDGE_ROOM_TYPE, this.roomId, {admin_user: this.userId}); + } const newData = updateFn(oldData); await this.botIntent.underlyingClient.setRoomAccountData(BRIDGE_ROOM_TYPE, this.roomId, newData); this.emit("settings.changed", this, oldData, newData); diff --git a/src/CommentProcessor.ts b/src/CommentProcessor.ts index a533910a..c8003e08 100644 --- a/src/CommentProcessor.ts +++ b/src/CommentProcessor.ts @@ -18,7 +18,7 @@ const log = new LogWrapper("CommentProcessor"); interface IMatrixCommentEvent extends MatrixMessageContent { // eslint-disable-next-line camelcase external_url: string; - "uk.half-shot.matrix-github.comment": { + "uk.half-shot.matrix-hookshot.github.comment": { id: number; }; } diff --git a/src/Connections/GenericHook.ts b/src/Connections/GenericHook.ts index 940d9bec..f971fbc1 100644 --- a/src/Connections/GenericHook.ts +++ b/src/Connections/GenericHook.ts @@ -19,10 +19,12 @@ const TRANSFORMATION_TIMEOUT_MS = 2000; * Handles rooms connected to a github repo. */ export class GenericHookConnection implements IConnection { - static readonly CanonicalEventType = "uk.half-shot.matrix-github.generic.hook"; + static readonly CanonicalEventType = "uk.half-shot.matrix-hookshot.generic.hook"; + static readonly LegacyCanonicalEventType = "uk.half-shot.matrix-github.generic.hook"; static readonly EventTypes = [ GenericHookConnection.CanonicalEventType, + GenericHookConnection.LegacyCanonicalEventType, ]; public get hookId() { diff --git a/src/Connections/GithubDiscussion.ts b/src/Connections/GithubDiscussion.ts index 505cb0d2..c3d357dd 100644 --- a/src/Connections/GithubDiscussion.ts +++ b/src/Connections/GithubDiscussion.ts @@ -27,10 +27,12 @@ const md = new markdown(); * Handles rooms connected to a github repo. */ export class GitHubDiscussionConnection implements IConnection { - static readonly CanonicalEventType = "uk.half-shot.matrix-github.discussion"; + static readonly CanonicalEventType = "uk.half-shot.matrix-hookshot.github.discussion"; + static readonly LegacyCanonicalEventType = "uk.half-shot.matrix-github.discussion"; static readonly EventTypes = [ - GitHubDiscussionConnection.CanonicalEventType, // Legacy event, with an awful name. + GitHubDiscussionConnection.CanonicalEventType, + GitHubDiscussionConnection.LegacyCanonicalEventType, ]; static readonly QueryRoomRegex = /#github_disc_(.+)_(.+)_(\d+):.*/; @@ -131,7 +133,7 @@ export class GitHubDiscussionConnection implements IConnection { formatted_body: md.render(data.comment.body), msgtype: 'm.text', external_url: data.comment.html_url, - 'uk.half-shot.matrix-github.discussion.comment_id': data.comment.id, + 'uk.half-shot.matrix-hookshot.github.discussion.comment_id': data.comment.id, }); } } \ No newline at end of file diff --git a/src/Connections/GithubDiscussionSpace.ts b/src/Connections/GithubDiscussionSpace.ts index 79b428d9..d2f76441 100644 --- a/src/Connections/GithubDiscussionSpace.ts +++ b/src/Connections/GithubDiscussionSpace.ts @@ -17,10 +17,12 @@ export interface GitHubDiscussionSpaceConnectionState { * Handles rooms connected to a github repo. */ export class GitHubDiscussionSpace implements IConnection { - static readonly CanonicalEventType = "uk.half-shot.matrix-github.discussion.space"; + static readonly CanonicalEventType = "uk.half-shot.matrix-hookshot.github.discussion.space"; + static readonly LegacyCanonicalEventType = "uk.half-shot.matrix-github.discussion.space"; static readonly EventTypes = [ - GitHubDiscussionSpace.CanonicalEventType, // Legacy event, with an awful name. + GitHubDiscussionSpace.CanonicalEventType, + GitHubDiscussionSpace.LegacyCanonicalEventType, ]; static readonly QueryRoomRegex = /#github_disc_(.+)_(.+):.*/; @@ -64,9 +66,6 @@ export class GitHubDiscussionSpace implements IConnection { responseType: 'arraybuffer', }); log.info(`uploading ${profile.data.avatar_url}`); - // This does exist, but headers is silly and doesn't have content-type. - // tslint:disable-next-line: no-any - console.log(res.headers); const contentType: string = res.headers["content-type"]; const mxcUrl = await opts.as.botClient.uploadContent( Buffer.from(res.data as ArrayBuffer), diff --git a/src/Connections/GithubIssue.ts b/src/Connections/GithubIssue.ts index 70c3b341..0952077b 100644 --- a/src/Connections/GithubIssue.ts +++ b/src/Connections/GithubIssue.ts @@ -38,10 +38,12 @@ interface IQueryRoomOpts { * Handles rooms connected to a github repo. */ export class GitHubIssueConnection implements IConnection { - static readonly CanonicalEventType = "uk.half-shot.matrix-github.bridge"; + static readonly CanonicalEventType = "uk.half-shot.matrix-hookshot.github.issue"; + static readonly LegacyCanonicalEventType = "uk.half-shot.matrix-github.bridge"; static readonly EventTypes = [ - GitHubIssueConnection.CanonicalEventType, // Legacy event, with an awful name. + GitHubIssueConnection.CanonicalEventType, + GitHubIssueConnection.LegacyCanonicalEventType, ]; static readonly QueryRoomRegex = /#github_(.+)_(.+)_(\d+):.*/; @@ -84,9 +86,6 @@ export class GitHubIssueConnection implements IConnection { responseType: 'arraybuffer', }); log.info(`uploading ${profile.data.avatar_url}`); - // This does exist, but headers is silly and doesn't have content-type. - // tslint:disable-next-line: no-any - console.log(res.headers); const contentType: string = res.headers["content-type"]; const mxcUrl = await opts.as.botClient.uploadContent( Buffer.from(res.data as ArrayBuffer), diff --git a/src/Connections/GithubProject.ts b/src/Connections/GithubProject.ts index a78e3316..6aa11d34 100644 --- a/src/Connections/GithubProject.ts +++ b/src/Connections/GithubProject.ts @@ -14,10 +14,12 @@ const log = new LogWrapper("GitHubProjectConnection"); * Handles rooms connected to a github repo. */ export class GitHubProjectConnection implements IConnection { - static readonly CanonicalEventType = "uk.half-shot.matrix-github.project"; + static readonly CanonicalEventType = "uk.half-shot.matrix-hookshot.github.project"; + static readonly LegacyCanonicalEventType = "uk.half-shot.matrix-github.project"; static readonly EventTypes = [ - GitHubProjectConnection.CanonicalEventType, // Legacy event, with an awful name. + GitHubProjectConnection.CanonicalEventType, + GitHubProjectConnection.LegacyCanonicalEventType, ]; static async onOpenProject(project: ProjectsGetResponseData, as: Appservice, inviteUser: string): Promise { diff --git a/src/Connections/GithubRepo.ts b/src/Connections/GithubRepo.ts index ae274ced..e79f5a80 100644 --- a/src/Connections/GithubRepo.ts +++ b/src/Connections/GithubRepo.ts @@ -58,10 +58,12 @@ function compareEmojiStrings(e0: string, e1: string, e0Index = 0) { * Handles rooms connected to a github repo. */ export class GitHubRepoConnection implements IConnection { - static readonly CanonicalEventType = "uk.half-shot.matrix-github.repository"; + static readonly CanonicalEventType = "uk.half-shot.matrix-hookshot.github.repository"; + static readonly LegacyCanonicalEventType = "uk.half-shot.matrix-github.repository"; static readonly EventTypes = [ - GitHubRepoConnection.CanonicalEventType, // Legacy event, with an awful name. + GitHubRepoConnection.CanonicalEventType, + GitHubRepoConnection.LegacyCanonicalEventType, ]; static readonly QueryRoomRegex = /#github_(.+)_(.+):.*/; @@ -101,9 +103,6 @@ export class GitHubRepoConnection implements IConnection { responseType: 'arraybuffer', }); log.info(`uploading ${profile.data.avatar_url}`); - // This does exist, but headers is silly and doesn't have content-type. - // tslint:disable-next-line: no-any - console.log(res.headers); const contentType: string = res.headers["content-type"]; const mxcUrl = await opts.as.botClient.uploadContent( Buffer.from(res.data as ArrayBuffer), @@ -481,7 +480,7 @@ ${event.release.body}`; // eslint-disable-next-line camelcase const {event_id, key} = (evt.content as MatrixReactionContent)["m.relates_to"]; const ev = await this.as.botClient.getEvent(this.roomId, event_id); - const issueContent = ev.content["uk.half-shot.matrix-github.issue"]; + const issueContent = ev.content["uk.half-shot.matrix-hookshot.github.issue"]; if (!issueContent) { log.debug('Reaction to event did not pertain to a issue'); return; // Not our event. diff --git a/src/Connections/GithubUserSpace.ts b/src/Connections/GithubUserSpace.ts index e98fc59e..3bef2c59 100644 --- a/src/Connections/GithubUserSpace.ts +++ b/src/Connections/GithubUserSpace.ts @@ -16,7 +16,8 @@ export interface GitHubUserSpaceConnectionState { * Handles rooms connected to a github repo. */ export class GitHubUserSpace implements IConnection { - static readonly CanonicalEventType = "uk.half-shot.matrix-github.user.space"; + static readonly CanonicalEventType = "uk.half-shot.matrix-hookshot.github.user.space"; + static readonly LegacyCanonicalEventType = "uk.half-shot.matrix-github.user.space"; static readonly EventTypes = [ GitHubUserSpace.CanonicalEventType, // Legacy event, with an awful name. diff --git a/src/Connections/GitlabIssue.ts b/src/Connections/GitlabIssue.ts index ae3fae42..99173156 100644 --- a/src/Connections/GitlabIssue.ts +++ b/src/Connections/GitlabIssue.ts @@ -33,10 +33,12 @@ const log = new LogWrapper("GitLabIssueConnection"); * Handles rooms connected to a github repo. */ export class GitLabIssueConnection implements IConnection { - static readonly CanonicalEventType = "uk.half-shot.matrix-github.gitlab.issue"; + static readonly CanonicalEventType = "uk.half-shot.matrix-hookshot.gitlab.issue"; + static readonly LegacyCanonicalEventType = "uk.half-shot.matrix-github.gitlab.issue"; static readonly EventTypes = [ GitLabIssueConnection.CanonicalEventType, + GitLabIssueConnection.LegacyCanonicalEventType, ]; static readonly QueryRoomRegex = /#gitlab_(.+)_(.+)_(\d+):.*/; @@ -104,7 +106,6 @@ export class GitLabIssueConnection implements IConnection { public async onCommentCreated(event: IGitLabWebhookNoteEvent) { log.info(`${this.toString()} onCommentCreated ${event.object_attributes.noteable_id}`); - console.log(event); if (event.repository) { // Delay to stop comments racing sends await new Promise((resolve) => setTimeout(resolve, 500)); diff --git a/src/Connections/GitlabRepo.ts b/src/Connections/GitlabRepo.ts index d70ebefa..b987046c 100644 --- a/src/Connections/GitlabRepo.ts +++ b/src/Connections/GitlabRepo.ts @@ -23,10 +23,12 @@ const md = new markdown(); * Handles rooms connected to a github repo. */ export class GitLabRepoConnection implements IConnection { - static readonly CanonicalEventType = "uk.half-shot.matrix-github.gitlab.repository"; + static readonly CanonicalEventType = "uk.half-shot.matrix-hookshot.gitlab.repository"; + static readonly LegacyCanonicalEventType = "uk.half-shot.matrix-github.gitlab.repository"; static readonly EventTypes = [ - GitLabRepoConnection.CanonicalEventType, // Legacy event, with an awful name. + GitLabRepoConnection.CanonicalEventType, + GitLabRepoConnection.LegacyCanonicalEventType, ]; static botCommands: BotCommands; diff --git a/src/Connections/JiraProject.ts b/src/Connections/JiraProject.ts index 3132e346..0328a9d7 100644 --- a/src/Connections/JiraProject.ts +++ b/src/Connections/JiraProject.ts @@ -22,10 +22,12 @@ const md = new markdownit(); * Handles rooms connected to a github repo. */ export class JiraProjectConnection implements IConnection { - static readonly CanonicalEventType = "uk.half-shot.matrix-github.jira.project"; + static readonly CanonicalEventType = "uk.half-shot.matrix-hookshot.jira.project"; + static readonly LegacyCanonicalEventType = "uk.half-shot.matrix-github.jira.project"; static readonly EventTypes = [ JiraProjectConnection.CanonicalEventType, + JiraProjectConnection.LegacyCanonicalEventType, ]; static getTopicString(authorName: string, state: string) { diff --git a/src/FormatUtil.rs b/src/FormatUtil.rs index 1fde5b1e..ba1a9fb6 100644 --- a/src/FormatUtil.rs +++ b/src/FormatUtil.rs @@ -152,7 +152,7 @@ pub fn get_partial_body_for_jira_issue(ctx: CallContext) -> Result { - const key = tokenKey(type, userId, instanceUrl); + public async storeUserToken(type: TokenType, userId: string, token: string, instanceUrl?: string): Promise { + const key = tokenKey(type, userId, false, instanceUrl); const data = { encrypted: publicEncrypt(this.key, Buffer.from(token)).toString("base64"), instance: instanceUrl, @@ -40,18 +49,19 @@ export class UserTokenStore { log.debug(`Stored`, data); } - public async getUserToken(type: "github"|"gitlab", userId: string, instanceUrl?: string): Promise { - const key = tokenKey(type, userId, instanceUrl); + public async getUserToken(type: TokenType, userId: string, instanceUrl?: string): Promise { + const key = tokenKey(type, userId, false, instanceUrl); const existingToken = this.userTokens.get(key); if (existingToken) { return existingToken; } try { let obj; - if (type === "github") { - obj = await this.intent.underlyingClient.getAccountData<{encrypted: string}>(key); - } else if (type === "gitlab") { - obj = await this.intent.underlyingClient.getAccountData<{encrypted: string}>(key); + if (AllowedTokenTypes.includes(type)) { + obj = await this.intent.underlyingClient.getSafeAccountData<{encrypted: string}>(key); + if (!obj) { + obj = await this.intent.underlyingClient.getAccountData<{encrypted: string}>(tokenKey(type, userId, true, instanceUrl)); + } } else { throw Error('Unknown type'); } diff --git a/src/libRs.ts b/src/libRs.ts index d187ffdb..c053ab63 100644 --- a/src/libRs.ts +++ b/src/libRs.ts @@ -6,10 +6,10 @@ import { JiraIssue } from "./Jira/Types"; let rootModule; try { // In production, we expect it co-located - rootModule = require('./matrix-github-rs.node'); + rootModule = require('./matrix-hookshot-rs.node'); } catch (ex) { // When running under ts-node, it may not be co-located. - rootModule = require('../lib/matrix-github-rs.node'); + rootModule = require('../lib/matrix-hookshot-rs.node'); } interface FormatUtil { diff --git a/tests/FormatUtilTest.ts b/tests/FormatUtilTest.ts index 7a68e5af..9f6226a3 100644 --- a/tests/FormatUtilTest.ts +++ b/tests/FormatUtilTest.ts @@ -89,12 +89,12 @@ describe("FormatUtilTest", () => { it("should correctly format a JIRA issue", () => { expect(FormatUtil.getPartialBodyForJiraIssue(SIMPLE_JIRA_ISSUE)).to.deep.equal({ "external_url": "http://example-api.url.com/browse/TEST-001", - "uk.half-shot.matrix-github.jira.issue": { + "uk.half-shot.matrix-hookshot.jira.issue": { "api_url": "http://example-api.url.com/issue-url", "id": "test-issue", "key": "TEST-001", }, - "uk.half-shot.matrix-github.jira.project": { + "uk.half-shot.matrix-hookshot.jira.project": { "api_url": "http://example-api.url.com/project-url", "id": "test-project", "key": "TEST", diff --git a/yarn.lock b/yarn.lock index c9627ebb..41a7cac4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1979,11 +1979,6 @@ content-type@1.0.4, content-type@~1.0.4: resolved "https://registry.yarnpkg.com/content-type/-/content-type-1.0.4.tgz#e138cc75e040c727b1966fe5e5f8c9aee256fe3b" integrity sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA== -contrast-color@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/contrast-color/-/contrast-color-1.0.1.tgz#15fd7b444f43ccb7d6175d7e131d095623a9f146" - integrity sha512-XeTV/LiyWrf/OWnODTqve2YGBfg32N6zlLqQjJKmEY+ffDqIfecgdmluVz7tky1D4VEaweZgoeRJJT87gDSDCQ== - convert-source-map@^1.7.0: version "1.7.0" resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-1.7.0.tgz#17a2cb882d7f77d3490585e2ce6c524424a3a442"