Make changes to 15 git repositories all at once
- Utvikling
I needed to update the CODEOWNERS
file for our the git repositories my team owns. Instead of going through each one and doing the same change over and over I knew that this could be automated. For this I used these two tools Mani and Github CLI
🏗️ Setup repositories
# Setup repositories for mani
mkdir ~/posten/team-repoes
cd ~/posten/team-repoes
mani init
code mani.yaml
The mani config file needs to know about my repositories in it’s config file, looking something like this:
projects:
your-app-backend:
url: git@github.com:your-org/your-app-backend.git
your-app-frontend:
url: git@github.com:your-org/your-app-frontend.gitIf you have added your team name as a topic to your repositories you can get them as a list using the github cli as so
Instead of manually typing them I used the Github CLI to fetch the names, and then using some multi cursor editing I quickly created the config file
gh repo list bring --topic notifications-open-tracking --json name
Then I used mani sync
to get it clone all the repositories.
📝 Make the change
My change was quite simple, so I just created the correct file I wanted and then for each repository I copied it over.
code CODEOWNERS # Edit the file the way you want it to be
mani exec --all "mkdir -p ./github && cp ../CODEOWNERS .github"
🚀 Commit, push, and make PR’s
mani exec --all 'git switch -c update-codeowners'
mani exec --all 'git add .github/CODEOWNERS'
mani exec --all 'git commit -m "update CODEOWNERS file"'
mani exec --all 'git push --set-upstream origin update-codeowners'
# Finally open the PR's with the approriate reviewers
mani exec --all 'gh pr create --fill --reviewer bring/notifications-open-tracking'
Note: You might need to run the last command a few times, as the github api rate limits how many PR’s you can create