Skip to content
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

GitHub Cleanup Process #9

Open
pavaniankam92 opened this issue Aug 15, 2023 · 2 comments
Open

GitHub Cleanup Process #9

pavaniankam92 opened this issue Aug 15, 2023 · 2 comments

Comments

@pavaniankam92
Copy link
Collaborator

Currently GitHub is on a legacy plan and pre-requisite is to trim down the user list on GitHub before it can be upgraded to the right plan. Trying to archive or delete unused repos by coordinating with the team.
@benjwadams @patrick-tripp @mpiannucci @jonmjoyce @DonaldMoretti

@pavaniankam92
Copy link
Collaborator Author

pavaniankam92 commented Aug 15, 2023

Plan is to archive all the unused repositories to Azure Devops

Genetrated a spreadsheet of github unused repositories with respective owners(last updated)
I have used gitapi here
#!/bin/bash

ACCESS_TOKEN="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

API_ENDPOINT="https://api.github.com/user/repos?type=private&page=1&per_page=100"

CSV_FILE="github_repos.csv"

$CSV_FILE

get_last_updated_date() {
local repo_full_name="$1"
local response=$(curl -s -H "Authorization: token $ACCESS_TOKEN" "https://api.github.com/repos/$repo_full_name")
local last_updated_date=$(echo "$response" | ./jq -r '.pushed_at')
echo "$last_updated_date"
}

echo "Git Repo Name,Last Updated,Owner,Last Updated By" > "$CSV_FILE"

repos_response=$(curl -s -H "Authorization: token $ACCESS_TOKEN" "$API_ENDPOINT")
repos_list=$(echo "$repos_response" | ./jq -r '.[] | [.full_name, .owner.login] | @TSV')

while IFS=$'\t' read -r repo_full_name owner; do
last_updated_date=$(get_last_updated_date "$repo_full_name")
API_URL="https://api.github.com/repos/$repo_full_name/commits?per_page=1"

response=$(curl -s -H "Authorization: token ${ACCESS_TOKEN}" ${API_URL})

#if [[ $? -eq 0 && ! $(echo $response | ./jq -r '. | has("message")') ]]; then
author="Not Found"
if [[ $? -eq 0 && $(echo $response | ./jq 'type == "array" and length > 0') == true ]]; then
	author=$(echo $response | ./jq -r '.[0].commit.author.name')
	#echo "Latest commit author: ${author}"
fi

echo "$repo_full_name,$last_updated_date,$owner,$author" >> "$CSV_FILE"

done <<< "$repos_list"

@pavaniankam92
Copy link
Collaborator Author

Generated spreadsheet for outside collaborators

ACCESS_TOKEN="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
ORG="asascience"
CSV_FILE="github_collabuserslist.csv"

$CSV_FILE

echo "Collab User" > $CSV_FILE
collaborators_response=$(curl -s -H "Authorization: Bearer ${ACCESS_TOKEN}" "https://api.github.com/orgs/${ORG}/outside_collaborators?per_page=100")
collab_user=$(echo $collaborators_response | ./jq -r '.[] | .login')
echo "$collab_user" >> $CSV_FILE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant