-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy patharchiver.sh
executable file
·33 lines (28 loc) · 1 KB
/
archiver.sh
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
#!/bin/bash
if date --version >/dev/null 2>&1; then
# GNU date (Linux)
four_years_ago=$(date -d '4 years ago' --iso-8601=seconds)
else
# BSD/macOS date
four_years_ago=$(date -v-4y +"%Y-%m-%dT%H:%M:%SZ")
fi
for repo_dir in temp/*; do
if [ -d "$repo_dir/.git" ]; then
(
cd "$repo_dir" || exit 1
remote_url=$(git config --get remote.origin.url)
repo_fullname=$(echo "$remote_url" | sed -E 's#(git@|https://)github.com[:/](.+)\.git#\2#')
second_commit_date=$(git log --pretty=format:"%cI" | sed -n '2p')
if [ -n "$second_commit_date" ]; then
if [[ "$second_commit_date" < "$four_years_ago" ]]; then
echo "Archiving repo: $repo_fullname (second last commit: $second_commit_date)"
gh api -X PATCH "repos/$repo_fullname" -f archived=true
else
echo "Skipping repo: $repo_fullname (second last commit: $second_commit_date)"
fi
else
echo "Skipping repo: $repo_fullname (only one commit found)"
fi
)
fi
done