Github repo settings sync, using the Github cli
The number of Github repositories that I end up maintaining in one way or another ends up growing week by week. And keeping all of the descriptions and settings up to date in sync can be painful todo by hand.
A little while ago I migrated my addwiki project to use a monorepo, and thus needed to bulk update all of the github repository descriptions. While doing so I made use of the github cli and created a single bash script to let me configure all of the repositories at once.
Assuming you already have the github cli install and configured getting started with this is easy.
The below command is one of many in my bash script for repo configuration. This sets a description, homepage and various other flags that I want to be consistent across repositories.
gh api --method PATCH repos/addwiki/addwiki \
--field description='Monorepo containing all addwiki libraries, packages and applications'\
Multiple of these such commands can be combined into a single file to allow easy editing and syncing. Personally I have put this script in my monorepo
.github directory. https://github.com/addwiki/addwiki/blob/main/.github/bin/sync-repos
An upgrade to this approach could generate the commands from a JSON file rather than needing to copy and paste the github cli command over and over again.
For my example this could look something like this:
"description": "Monorepo containing all addwiki libraries, packages and applications",
}Code language: JSON / JSON with Comments (json)
If I ever upgrade my script I’ll be sure to link the new version to this post.
At least one Github action now exists covering general Github repository setting, but seemingly not descriptions, which were part of my main use.
The Repo Setting Sync action allows settings such as
BRANCH_PROTECTION_NAME uniformly across a a collection of repositories with little effort.
- name: Repo Setup
If this action allows setting things such as description or homepage it would be pretty easy to setup a matrix within an action to set slightly modified settings, such as descriptions per repository.