Skip to content

Create Inactive-branches.sh #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Inactive-branches.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh
echo "Enter repository to check inactive branches: "
read repo_name
echo "Enter username: "
read user_name
echo "Enter password: "
read -s password
presentdate=`date +'%s'`
list_of_branches=$(curl -s -u $user_name:$password https://api.github.com/repos/$user_name/$repo_name/branches | jq '.[].name')
for branch in $list_of_branches; do 
api_branch_name=$(echo $branch | cut -d'"' -f 2)
last_updated_date=$(curl -s -u $user_name:$password https://api.github.com/repos/$user_name/$repo_name/branches/$api_branch_name | jq '.commit.commit.author.date')
api_last_updated_date=$(echo $last_updated_date | cut -d'"' -f 2)
last_updated_date_sec=$(date -d $api_last_updated_date +%s)
numberofdays=$(( ($presentdate - $last_updated_date_sec)/(60*60*24) ))
if [ $numberofdays -gt 60 ] ; then
       echo "Branch $api_branch_name was last updated $numberofdays days ago."
    fi
done