-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_github_trending.sh
More file actions
executable file
·107 lines (83 loc) · 2.73 KB
/
check_github_trending.sh
File metadata and controls
executable file
·107 lines (83 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#! /bin/bash
# Features:
# When passed a list of github repos, find out the ones I have never checked and the ones that I have checked in the past, but the last time was more than N months ago.
# Those are the ones that I should check, so I should open them in the browser.
# I should create/update them in in the database and set their timestamp to today.
# Cases:
# - never checked -> insert them w/date to today, open in browser
# - already checked, less than N months ago -> nothing
# - already checked, more than N months ago -> update them w/date to today, open in browser
set -e
set -o errtrace
trap 'echo -e "${RED}💥 Script failed at line $LINENO: $BASH_COMMAND${RESET}"' ERR
CURRENTLY_TRENDING_REPOS_FILE="currently_trending_repos.txt"
DB_FILE="$HOME/.check_github_trending.db.txt"
MONTHS_TO_CONSIDER_REPO_STALE=4
GREEN="\033[1;32m"
YELLOW="\033[1;33m"
BLUE="\033[1;34m"
RESET="\033[0m"
MAX_REPOS_TO_OPEN=10
declare -i opened_count=0
today() {
date +"%Y-%m-%d"
}
months_ago() {
date -d "-${1} month" +"%Y-%m-%d"
}
repo_was_never_reviewed() {
local repo="$1"
! grep -q "$1$" "$DB_FILE"
}
find_last_review_date() {
local repo="$1"
grep "$1$" "$DB_FILE" | tail -1 | cut -d ' ' -f 1
}
repo_was_reviewed_a_long_time_ago() {
local repo="$1"
[[ "$(find_last_review_date "$repo")" < "$(months_ago "$MONTHS_TO_CONSIDER_REPO_STALE")" ]]
}
review_repo() {
local repo="$1"
mark_repo_as_reviewed "$repo"
open_repo_in_browser "$repo"
}
open_repo_in_browser() {
local repo="$1"
$BROWSER "$repo" >&/dev/null
((opened_count++)) || true
}
mark_repo_as_reviewed() {
local repo="$1"
echo "$(today) $repo" >>$DB_FILE
}
check() {
local repo="$1"
local short_name="${repo#https://github.com/}"
if repo_was_never_reviewed "$repo"; then
echo -e "${GREEN}🟢 NEW → $short_name (never reviewed)${RESET}"
review_repo "$repo"
elif repo_was_reviewed_a_long_time_ago "$repo"; then
echo -e "${YELLOW}🟡 STALE → $short_name (reviewed a long time ago)${RESET}"
review_repo "$repo"
else
echo -e "${BLUE}🔵 OK → $short_name (already reviewed recently)${RESET}"
fi
}
create_database_if_not_present() {
if [[ ! -f $DB_FILE ]]; then
echo "New database file created with path: $DB_FILE"
touch "$DB_FILE"
fi
}
check_github_trending_repos() {
create_database_if_not_present
while read -r currently_trending_repo; do
check "$currently_trending_repo"
if [[ $opened_count -ge $MAX_REPOS_TO_OPEN ]]; then
echo -e "${RESET}${YELLOW}🔚 Reached limit of $MAX_REPOS_TO_OPEN opened repos. Exiting.${RESET}"
break
fi
done <"$CURRENTLY_TRENDING_REPOS_FILE"
}
check_github_trending_repos