From de539d776b84288e8014d34dcfa10ba544dce027 Mon Sep 17 00:00:00 2001 From: mohammad5305 Date: Mon, 5 Feb 2024 17:59:48 +0330 Subject: [PATCH] refactor: one line if-else --- crawl_news.sh | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/crawl_news.sh b/crawl_news.sh index 0d1f3e9..0ff12fc 100644 --- a/crawl_news.sh +++ b/crawl_news.sh @@ -30,15 +30,10 @@ push_news() { export -f push_news export SHORT_COMMITS URL CHANNEL_ID -if [ -f "$OLD_FEED" ] -then - jq -s -r '(.[0] - .[1])[] | ( (.commit.message / "\n\n") as $msg | if ( $msg | length ) > 1 then ""+ $msg[0] + "", $msg[1:][], .html_url else "" + $msg[0] + "" end), "----"' "$CURRENT_FEED" "$OLD_FEED" | tac -s '----' | sed 's/----/\x0/' | xargs -0 -I{} -- bash -c 'push_news "$@"' _ {} -else - jq -r '.[] | ( (.commit.message / "\n\n") as $msg | if ( $msg | length ) > 1 then ""+ $msg[0] + "", $msg[1:][], .html_url else "" + $msg[0] + "" end), "----"' "$CURRENT_FEED" | tac -s '----' | sed 's/----/\x0/' | xargs -0 -I{} -- bash -c 'push_news "$@"' _ {} -fi - -if [ -s "$SHORT_COMMITS" ]; then - curl -s -X POST $URL -d chat_id=$CHANNEL_ID -d parse_mode="HTML" -d text="minor changes:"$'\n'"$(cat $SHORT_COMMITS)" -fi +[ -f "$OLD_FEED" ] && jq -s -r '(.[0] - .[1])[] | ( (.commit.message / "\n\n") as $msg | if ( $msg | length ) > 1 then ""+ $msg[0] + "", $msg[1:][], .html_url else "" + $msg[0] + "" end), "----"' "$CURRENT_FEED" "$OLD_FEED" \ + || jq -r '.[] | ( (.commit.message / "\n\n") as $msg | if ( $msg | length ) > 1 then ""+ $msg[0] + "", $msg[1:][], .html_url else "" + $msg[0] + "" end), "----"' "$CURRENT_FEED" \ + | tac -s '----' | sed 's/----/\x0/' | xargs -0 -I{} -- bash -c 'push_news "$@"' _ {} + +[ -s "$SHORT_COMMITS" ] && curl -s -X POST $URL -d chat_id=$CHANNEL_ID -d parse_mode="HTML" -d text="minor changes:"$'\n'"$(cat $SHORT_COMMITS)" mv "$CURRENT_FEED" "$OLD_FEED"