Fixing a typo across multiple repos

Yesterday I found a typo in a pull request description while browsing another team’s project which I stumbled upon. I mentioned it to the author but it turned out that that part of the text came from the repository’s pull request template, which means every pull request will have this amusing but irritating mistake. I sent them a pull request, modifying the template, to fix the mistake at the source and avoid it in future, and thought that would be the end of it.

It turns out that template was written once and then copied across to new repos, which means this typo actually exists in almost all the pull requests in all of that team’s projects. Well that escalated quickly. This is the point where the average person probably says “OK whatever, it’s not worth it for something so small, there are too many repos, it’s just a small typo, never mind” and stop. A very determined person might actually start opening browser tabs and psyching themselves up to do pull requests. I open my terminal emulator and start writing a for loop.

xkcd: Automation
xkcd #1319: Automation

I have a really low tolerance for repetitive tasks, but unlike in the xkcd comic above, this actually worked on the second try — the first one was thwarted by a typo, which would be ironic if it wasn’t the number one cause of programming errors. Here’s the result reformatted for readability:

“`bash
for i in {android,ios}-{foo,bar,baz,many,projects}; do
git clone myorg/$i && \
cd $i && \
git checkout -b typofix && \
sed -i -e ‘s/teh tyop/the typo/’ PULL_REQUEST_TEMPLATE.md && \
git commit -am ‘Fix typo in PR template’ && \
git push origin typofix && \
git pull-request -F -<

In summary, I learnt a thing or two about the git pull-request command and relearnt the HERE document syntax (by tomorrow I’ll probably forget if it’s 2 arrows or 3) and even though this solved a really simple problem, it was fun and educationally to do. More importantly: Now you know it’s possible, so never shy away from a challenge and have fun automating ALL THE PULL REQUESTS!!!