Skip to content

Instantly share code, notes, and snippets.

@JensRantil
Last active October 17, 2018 19:12
Show Gist options
  • Save JensRantil/5cf27605709fd456778acc7c7410671c to your computer and use it in GitHub Desktop.
Save JensRantil/5cf27605709fd456778acc7c7410671c to your computer and use it in GitHub Desktop.
Script that inform Github users of removal of a Github team. Modify for your organization and copy-paste the generated text into your favourite mail client!
# -*- coding: utf-8 -*-
import requests
import os
import pprint
def request(url):
return requests.get(url, auth=('JensRantil', os.environ['APIKEY']), headers={"Accept": "application/vnd.github.hellcat-preview+json"})
teams = dict([(e['id'], e['name']) for e in request('https://api.github.com/orgs/tink-ab/teams').json()])
pprint.pprint(teams)
team = raw_input('Which team id to remove? ')
team = int(team)
repos = request('https://api.github.com/teams/{}/repos'.format(team)).json()
repos = [" * " + repo['full_name'] for repo in repos]
repos = "\n".join(repos)
members = request('https://api.github.com/teams/{}/members'.format(team)).json()
members = [request(e['url']).json() for e in members]
members = [(e['name'], e['email'], e['login']) for e in members]
def email(e):
if e[1]:
return e[1]
proposal = e[0].lower().replace(' ', '.') + "@tink.se" if e[0] else e[2]
try:
q = 'What is e-mail for "{}"? [{}] '.format(e[0], proposal)
a = raw_input(q).strip()
except:
a = None
if not a:
return proposal
return a
members = [email(m) for m in members]
pprint.pprint(members)
print
print "Recipients:", ", ".join(members)
print "Subject: Changes to tink-ab Github permissions"
print
print """Hello,
This is an automated e-mail.
I am writing to you to let you know that I might have removed write access to the following repositories:
{}
If you believe you have lost the access, please request the permission from your team lead.
Cheers,
Jens Rantil, Github admin at Tink""".format(repos)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment