Last active
December 2, 2025 15:34
-
-
Save safeamiiir/3bc6b737b8cbfa352a0a56767bcfb1d7 to your computer and use it in GitHub Desktop.
when-repo-created
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| ########################### | |
| ### AI GENERATED SCRIPT ### | |
| ########################### | |
| # Usage: | |
| # curl -s <your-gist-raw-url> | bash -s "<owner>/<repo>" | |
| # example: curl -s https://gist.githubusercontent.com/safeamiiir/3bc6b737b8cbfa352a0a56767bcfb1d7/raw/69096fccaf3a96a876bef560f1767b2db6336f1b/when-repo-created | bash -s "octocat/Hello-World" | |
| set -e | |
| # Colors | |
| CYAN="\033[96m" | |
| GREEN="\033[92m" | |
| YELLOW="\033[93m" | |
| MAGENTA="\033[95m" | |
| RESET="\033[0m" | |
| if [ -z "$1" ]; then | |
| echo -e "${YELLOW}Error:${RESET} expected argument <owner>/<repo>" | |
| exit 1 | |
| fi | |
| REPO="$1" | |
| # Fetch general repo info | |
| repo_json=$(curl -s "https://api.github.com/repos/$REPO") | |
| created_raw=$(echo "$repo_json" | grep '"created_at"' | head -1 | cut -d '"' -f 4) | |
| default_branch=$(echo "$repo_json" | grep '"default_branch"' | cut -d '"' -f 4) | |
| if [ -z "$created_raw" ] || [ -z "$default_branch" ]; then | |
| echo -e "${YELLOW}Error:${RESET} Could not fetch repository info. Check repo name." | |
| exit 1 | |
| fi | |
| # Split created_at into date + time | |
| created_date=${created_raw%%T*} | |
| created_time=$(echo "$created_raw" | cut -d 'T' -f 2 | sed 's/Z//') | |
| echo -e "${CYAN}Repository:${RESET} ${MAGENTA}$REPO${RESET}" | |
| echo -e "${CYAN}Default branch:${RESET} ${MAGENTA}$default_branch${RESET}" | |
| echo -e "${CYAN}Created:${RESET} ${GREEN}$created_date${RESET} at ${GREEN}$created_time${RESET}" | |
| # Today's date | |
| now=$(date +%Y-%m-%d) | |
| # --- Compute age since creation --- | |
| age=$(python3 - <<PY | |
| from datetime import datetime | |
| c = datetime.strptime("$created_date", "%Y-%m-%d") | |
| n = datetime.strptime("$now", "%Y-%m-%d") | |
| d = n - c | |
| years = d.days // 365 | |
| months = (d.days % 365) // 30 | |
| days = (d.days % 365) % 30 | |
| print(f"{years} years, {months} months, {days} days") | |
| PY | |
| ) | |
| echo -e "${CYAN}Age since creation:${RESET} ${YELLOW}$age${RESET}" | |
| # --- Fetch the most recent commit date --- | |
| commit_json=$(curl -s "https://api.github.com/repos/$REPO/commits/$default_branch") | |
| latest_commit_raw=$(echo "$commit_json" | grep '"date"' | head -1 | cut -d '"' -f 4) | |
| if [ -z "$latest_commit_raw" ]; then | |
| echo -e "${YELLOW}Error:${RESET} Could not fetch latest commit info." | |
| exit 1 | |
| fi | |
| latest_commit_date=${latest_commit_raw%%T*} | |
| latest_commit_time=$(echo "$latest_commit_raw" | cut -d 'T' -f 2 | sed 's/Z//') | |
| echo -e "${CYAN}Latest commit:${RESET} ${GREEN}$latest_commit_date${RESET} at ${GREEN}$latest_commit_time${RESET}" | |
| # --- Compute how long since last update --- | |
| last_update=$(python3 - <<PY | |
| from datetime import datetime | |
| c = datetime.strptime("$latest_commit_date", "%Y-%m-%d") | |
| n = datetime.strptime("$now", "%Y-%m-%d") | |
| d = n - c | |
| years = d.days // 365 | |
| months = (d.days % 365) // 30 | |
| days = (d.days % 365) % 30 | |
| print(f"{years} years, {months} months, {days} days") | |
| PY | |
| ) | |
| echo -e "${CYAN}Time since last update:${RESET} ${YELLOW}$last_update${RESET}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment