From: Matthias Kruk Date: Sat, 22 Jan 2022 09:11:43 +0000 (+0900) Subject: watchbot: Add support for smart git-over-http protocol X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=45271807b25bc042a0fc2206b2f41c0b827c15b8;p=foundry watchbot: Add support for smart git-over-http protocol Watchbot does not support the smart git-over-http protocol, making it unable to watch repositories hosted by Github and other services. This commit adds support for the smart git-over-http protocol to watchbot. --- diff --git a/watchbot.sh b/watchbot.sh index 8b5c476..a1317fe 100755 --- a/watchbot.sh +++ b/watchbot.sh @@ -37,7 +37,33 @@ watch_to_branch() { return 0 } -fetch_head_remote() { +fetch_head_smart_http() { + local watch="$1" + + local repository + local branch + local url + local re + local data + local ref + + repository=$(watch_to_repository "$watch") + branch=$(watch_to_branch "$watch") + + re="00[0-9a-f]{2}\\K[0-9a-f]{40} refs/heads/$branch" + url="$repository/info/refs?service=git-upload-pack" + + if ! data=$(curl --get --silent --location "$url" 2>/dev/null | + grep -oP "$re" --binary-files=text); then + return 1 + fi + + ref="${data%% *}" + echo "$ref" + return 0 +} + +fetch_head_dumb_http() { local watch="$1" local repository @@ -69,6 +95,21 @@ fetch_head_remote() { return 0 } +fetch_head_remote() { + local watch="$1" + + local head + + if ! head=$(fetch_head_smart_http "$watch"); then + if ! head=$(fetch_head_dumb_http "$watch"); then + return 1 + fi + fi + + echo "$head" + return 0 +} + fetch_head_local() { local watch="$1"