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 79d9d61
Show file tree
Hide file tree
Showing 2 changed files with 84 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"
79 changes: 79 additions & 0 deletions current.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,83 @@
[
{
"sha": "672eff3212572a203b58ffd4f1e2474d8a40fcfc",
"node_id": "C_kwDOAV-JftoAKDY3MmVmZjMyMTI1NzJhMjAzYjU4ZmZkNGYxZTI0NzRkOGE0MGZjZmM",
"commit": {
"author": {
"name": "Nicholas Feinberg",
"email": "[email protected]",
"date": "2024-02-05T02:01:30Z"
},
"committer": {
"name": "Nicholas Feinberg",
"email": "[email protected]",
"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",
Expand Down

0 comments on commit 79d9d61

Please sign in to comment.