Last active
October 17, 2018 19:12
-
-
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!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- 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 "Recipients:", ", ".join(members) | |
| print "Subject: Changes to tink-ab Github permissions" | |
| 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