Skip to content

Commit

Permalink
refactor: one line if-else
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammad5305 committed Feb 5, 2024
1 parent 44efa49 commit de539d7
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions crawl_news.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<b>"+ $msg[0] + "</b>", $msg[1:][], .html_url else "<a href=\"" + .html_url + "\">" + $msg[0] + "</a>" 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 "<b>"+ $msg[0] + "</b>", $msg[1:][], .html_url else "<a href=\"" + .html_url + "\">" + $msg[0] + "</a>" 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="<b>minor changes:</b>"$'\n'"$(cat $SHORT_COMMITS)"
fi
[ -f "$OLD_FEED" ] && jq -s -r '(.[0] - .[1])[] | ( (.commit.message / "\n\n") as $msg | if ( $msg | length ) > 1 then "<b>"+ $msg[0] + "</b>", $msg[1:][], .html_url else "<a href=\"" + .html_url + "\">" + $msg[0] + "</a>" end), "----"' "$CURRENT_FEED" "$OLD_FEED" \
|| jq -r '.[] | ( (.commit.message / "\n\n") as $msg | if ( $msg | length ) > 1 then "<b>"+ $msg[0] + "</b>", $msg[1:][], .html_url else "<a href=\"" + .html_url + "\">" + $msg[0] + "</a>" 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="<b>minor changes:</b>"$'\n'"$(cat $SHORT_COMMITS)"

mv "$CURRENT_FEED" "$OLD_FEED"

0 comments on commit de539d7

Please sign in to comment.