Created
November 2, 2023 18:05
-
-
Save pepijndevos/a26b77b43a37cdf16592e4e413441891 to your computer and use it in GitHub Desktop.
Automatically refactor the code in an entire github organization
This file contains 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
#!/bin/bash | |
set -ex | |
# Define your GitHub username and organization name | |
YOUR_USERNAME="pepijndevos" | |
ORG_NAME="SciML" | |
# Iterate through the organization's repositories | |
REPO_LIST=$(gh repo list $ORG_NAME --json name --limit 1000 --no-archived) | |
for repo in $(echo "$REPO_LIST" | jq -r '.[].name'); do | |
if [ -d "$repo" ]; then | |
echo "Skipping $repo. Directory already exists." | |
continue | |
fi | |
git clone "https://github.com/$ORG_NAME/$repo.git" | |
cd "$repo" | |
# Run the specified command | |
git ls-files -z | xargs -0 sed -i -e 's/typeof(\([^)]*\)) <:/\1 isa/g' | |
# Check if the diff is empty | |
if [[ -z $(git diff --color) ]]; then | |
echo "No changes in $repo. Skipping pull request." | |
else | |
# Ask for confirmation before creating the pull request | |
read -p "Do you want to create a pull request for $repo? (y/n): " confirm | |
if [[ $confirm == "y" ]]; then | |
git branch new-branch | |
git checkout new-branch | |
# Commit changes | |
git commit -am "Change typeof(x) <: y to x isa y" | |
# Fork the repository to your account | |
gh repo fork "$ORG_NAME/$repo" --clone=false | |
sleep 5 # let it finish or something? | |
# Push changes to a new branch | |
git remote add fork [email protected]:$YOUR_USERNAME/$repo.git | |
git push fork new-branch | |
# Create a pull request in the original repository | |
gh repo set-default "$ORG_NAME/$repo" | |
gh pr create --head "$YOUR_USERNAME:new-branch" --title "Change typeof(x) <: y to x isa y" --body "This PR has been automatically generated by a script co-authored by ChatGPT" | |
fi | |
fi | |
# Go back to the original directory | |
cd .. | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment