From 79d9d6182bc340ddffa4f2eacf520c88dde83f7a 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 ++++------ current.json | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 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" diff --git a/current.json b/current.json index 9fbf71b..9f213d6 100644 --- a/current.json +++ b/current.json @@ -1,4 +1,83 @@ [ + { + "sha": "672eff3212572a203b58ffd4f1e2474d8a40fcfc", + "node_id": "C_kwDOAV-JftoAKDY3MmVmZjMyMTI1NzJhMjAzYjU4ZmZkNGYxZTI0NzRkOGE0MGZjZmM", + "commit": { + "author": { + "name": "Nicholas Feinberg", + "email": "pleasingfung@gmail.com", + "date": "2024-02-05T02:01:30Z" + }, + "committer": { + "name": "Nicholas Feinberg", + "email": "pleasingfung@gmail.com", + "date": "2024-02-05T02:01:30Z" + }, + "message": "Refactor more band leader code", + "tree": { + "sha": "4cc02b9c7f7adb44a31e8047763b6b25ca53894b", + "url": "https://api.github.com/repos/crawl/crawl/git/trees/4cc02b9c7f7adb44a31e8047763b6b25ca53894b" + }, + "url": "https://api.github.com/repos/crawl/crawl/git/commits/672eff3212572a203b58ffd4f1e2474d8a40fcfc", + "comment_count": 0, + "verification": { + "verified": false, + "reason": "unsigned", + "signature": null, + "payload": null + } + }, + "url": "https://api.github.com/repos/crawl/crawl/commits/672eff3212572a203b58ffd4f1e2474d8a40fcfc", + "html_url": "https://github.com/crawl/crawl/commit/672eff3212572a203b58ffd4f1e2474d8a40fcfc", + "comments_url": "https://api.github.com/repos/crawl/crawl/commits/672eff3212572a203b58ffd4f1e2474d8a40fcfc/comments", + "author": { + "login": "PleasingFungus", + "id": 1192475, + "node_id": "MDQ6VXNlcjExOTI0NzU=", + "avatar_url": "https://avatars.githubusercontent.com/u/1192475?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/PleasingFungus", + "html_url": "https://github.com/PleasingFungus", + "followers_url": "https://api.github.com/users/PleasingFungus/followers", + "following_url": "https://api.github.com/users/PleasingFungus/following{/other_user}", + "gists_url": "https://api.github.com/users/PleasingFungus/gists{/gist_id}", + "starred_url": "https://api.github.com/users/PleasingFungus/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/PleasingFungus/subscriptions", + "organizations_url": "https://api.github.com/users/PleasingFungus/orgs", + "repos_url": "https://api.github.com/users/PleasingFungus/repos", + "events_url": "https://api.github.com/users/PleasingFungus/events{/privacy}", + "received_events_url": "https://api.github.com/users/PleasingFungus/received_events", + "type": "User", + "site_admin": false + }, + "committer": { + "login": "PleasingFungus", + "id": 1192475, + "node_id": "MDQ6VXNlcjExOTI0NzU=", + "avatar_url": "https://avatars.githubusercontent.com/u/1192475?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/PleasingFungus", + "html_url": "https://github.com/PleasingFungus", + "followers_url": "https://api.github.com/users/PleasingFungus/followers", + "following_url": "https://api.github.com/users/PleasingFungus/following{/other_user}", + "gists_url": "https://api.github.com/users/PleasingFungus/gists{/gist_id}", + "starred_url": "https://api.github.com/users/PleasingFungus/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/PleasingFungus/subscriptions", + "organizations_url": "https://api.github.com/users/PleasingFungus/orgs", + "repos_url": "https://api.github.com/users/PleasingFungus/repos", + "events_url": "https://api.github.com/users/PleasingFungus/events{/privacy}", + "received_events_url": "https://api.github.com/users/PleasingFungus/received_events", + "type": "User", + "site_admin": false + }, + "parents": [ + { + "sha": "c8c0bed1baaa000d437fa49d50c82bea69c1940a", + "url": "https://api.github.com/repos/crawl/crawl/commits/c8c0bed1baaa000d437fa49d50c82bea69c1940a", + "html_url": "https://github.com/crawl/crawl/commit/c8c0bed1baaa000d437fa49d50c82bea69c1940a" + } + ] + }, { "sha": "c8c0bed1baaa000d437fa49d50c82bea69c1940a", "node_id": "C_kwDOAV-JftoAKGM4YzBiZWQxYmFhYTAwMGQ0MzdmYTQ5ZDUwYzgyYmVhNjljMTk0MGE",