Skip to content

Instantly share code, notes, and snippets.

@dctucker
Created April 19, 2018 23:13
Show Gist options
  • Save dctucker/a20e3106ecb848bf842e05530cb74689 to your computer and use it in GitHub Desktop.
Save dctucker/a20e3106ecb848bf842e05530cb74689 to your computer and use it in GitHub Desktop.
This uses the GitHub API to mark notifications as read if they meet a certain criteria (closed/merged/OoO/Backport/etc)
#!/bin/bash
mark_read() {
id=$1
curl -H "$CURLH" -s -X PATCH $API/notifications/threads/$id
}
CURLH="Authorization: token $GITHUB_TOKEN"
API=https://api.github.com
pages=$(curl -isH "Authorization: token $GITHUB_TOKEN" -I $API/notifications | grep '^Link: ' | egrep -o 'page=[0-9]+' | tail -n 1 | egrep -o '[0-9]+')
for page in `seq 1 $pages` ; do
echo Page $page >&2
urls=$(curl -H "$CURLH" -s "$API/notifications?page=$page" | jq -r '.[] | .id + " " + .subject.url')
echo -e "$urls" | while read -r id url ; do
echo -n $url
data=$(curl -H "$CURLH" -s $url)
state=$(echo $data | jq -r ".state")
title=$(echo $data | jq -r ".title")
ooo=" OoO "
if [ "$state" == "closed" ] || [ "$state" == "merged" ] ; then
echo " $state" >&2
mark_read $id
elif [[ "$title" =~ ^Backport ]] ; then
echo " $title" >&2
mark_read $id
elif [[ "$title" =~ $ooo ]] || [[ "$title" =~ ^configuration\.sh ]] ; then
echo " $title" >&2
mark_read $id
else
echo
fi
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment