Get GitHub repositories failing on master

One problem that you may have when you have a lot of repositories with automatic updates is that from time to time your repository may fail on master and you may not notice. In order to address so I was wondering if there is an automated way to check for the ones failing on master among your user's repositories. Assuming you use GitHub actions to run your checks and have the GitHub client installed, here is a bash script in order to do so.

#!/bin/bash
gh repo list -L 1000 --json nameWithOwner --jq '.[].nameWithOwner' | while read repo ; do
	gh workflow list --repo $repo | while read workflow ; do
		workflow_id=`echo $workflow | awk '{print $NF}'`
		result=`gh workflow view $workflow_id --repo $repo | grep master | head -n 1`
		if [[ "$result" == *"failure"* ]]; then
			echo $repo is failing on master
      	fi
	done
done