Skip to content

Instantly share code, notes, and snippets.

@basepi
Created January 29, 2019 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save basepi/08acfdd5dc3ca4c06aea394b96a65342 to your computer and use it in GitHub Desktop.
Save basepi/08acfdd5dc3ca4c06aea394b96a65342 to your computer and use it in GitHub Desktop.
Unsubscribing from all issues in a repo
'''
This requires the google chrome web driver on your PATH:
http://chromedriver.chromium.org/downloads
Start google chrome like this (make sure you fix the user-data-dir path):
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --user-data-dir=/Users/<user>/Library/Application\ Support/Google/Chrome --profile-directory=Default --remote-debugging-port=20480
Then add your user, token, and org/repo to the code below and this script will
connect to the running chrome instance (make sure you're logged into Github)
and unsubscribe from all the issues for that org/repo.
(Note: pretty sure you have to be a collaborator on the repo for the API
call to work. You could pretty easily modify this to just hit every issue
on a repo if you needed to.)
'''
import requests
from requests.auth import HTTPBasicAuth
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
auth = '<user>', '<token_or_password>'
page = 0
urls = []
while True:
r = requests.get('https://api.github.com/issues?filter=subscribed&state=all&page={0}'.format(page), auth=auth)
count = 0
for result in r.json():
count += 1
if result['repository']['full_name'] == '<org>/<repo':
urls.append(result['html_url'])
if count == 0:
break
page += 1
driver = webdriver.Chrome(desired_capabilities={'chromeOptions': {'debuggerAddress': '127.0.0.1:20480'}, 'detach': False})
for url in urls:
try:
driver.get(url)
wait = WebDriverWait(driver, 10)
wait.until(EC.presence_of_element_located((By.XPATH, "//button[preceding-sibling::input[@value='unsubscribe' or @value='mute' or @value='subscribe']]")))
element = driver.find_element_by_xpath("//button[preceding-sibling::input[@value='unsubscribe' or @value='mute']]")
element.submit()
wait = WebDriverWait(driver, 10)
wait.until(EC.presence_of_element_located((By.XPATH, "//button[preceding-sibling::input[@value='subscribe']]")))
print(url, 'succeeded')
except:
print(url, 'failed')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment