don't worry, it's probably fine

Avoiding Work Commits When On Leave

13 Sep 2020

software

At the top of my GitHub wish-list is the ability to “snooze” notifications from a team or organisation while I’m on annual leave.

I like to sometimes write code during my time off but seeing commits into work projects breaks my happy little bubble.

Up until now I’ve manually gone and unsubscribed from every major repository I work on every time I go on leave (and reinstated the subscription on return).

This is manual and tedious, so I automated it - it’s good enough for my use case, at least.

github-snooze

#!/usr/bin/env bash

command -v gh >/dev/null || { echo "GitHub cli needed and not installed"; exit 1; }
command -v jq >/dev/null || { echo "jq needed and not installed"; exit 1; }

if [[ $# -ne 2 ]]; then
  echo "usage: ./github-snooze some-org some-team"
  echo "  Remove your subscription from all repositories visible to a team within an org"
  exit 1
fi

ORG=$1
TEAM=$2

TEAM_REPOS=$(gh api orgs/"$ORG"/teams/"$TEAM"/repos | jq -r '.[].name')

for REPO in $TEAM_REPOS; do
  echo "Removing subscription from ${REPO}"
  gh api -X DELETE repos/"$ORG"/"$REPO"/subscription
done