github_manage_collaborators allows you to change access for all repositories

of an github.com account.

    $ github_manage_collaborators --login company --apitoken 02...66 list
    huSoftM: hudora mdornseif cklein
    huTools: hudora cklein
    pyJasper: hudora

    $ github_manage_collaborators --login company --apitoken 02...66 add nerxs
    added 'nerxs' to 'huSoftM'
    added 'nerxs' to 'huTools'
    added 'nerxs' to 'pyJasper'

    $ github_manage_collaborators --login company --apitoken 02...66 remove nerxs
    removed 'nerxs' from 'huSoftM'
    removed 'nerxs' from 'huTools'
    removed 'nerxs' from 'pyJasper'

    $ github_manage_collaborators --login company --apitoken 02...66 list
    huSoftM: hudora mdornseif cklein nerxs
    huTools: hudora cklein nerxs
    pyJasper: hudora nerxs

Use it only on workstations where you are the single user, because the `ps`
command would reveal your secret API-token to everybody on the host
running `github_manage_collaborators`.
This commit is contained in:
Maximillian Dornseif
2009-12-31 23:34:38 +01:00
parent b8463cc8df
commit b44bcf82d6
+82
View File
@@ -0,0 +1,82 @@
#!/usr/bin/env python
# encoding: utf-8
"""github_manage_collaborators - add/remove collaborators to all github
projects of an account.
Typically used with company accounts where all coders should have
R/W access to all private repositories of the company account.
"""
# Created by Maximillian Dornseif on 2009-12-31 for HUDORA.
# Copyright (c) 2009 HUDORA. All rights reserved.
# BSD licensed
from optparse import OptionParser
import github2.client
import time
def parse_commandline():
"""Parse the comandline and return parsed options."""
parser = OptionParser(version=True)
parser.description = __doc__
parser.set_usage('usage: %prog [options] (list|add|remove) [collaborator]. Try %prog --help for details.')
parser.add_option('-d', '--debug', action='store_true',
help='Enables debugging mode')
parser.add_option('-l', '--login',
help='Username to login with')
parser.add_option('-a', '--account',
help='User owning the repositories to be changed [default: same as --login]')
parser.add_option('-t', '--apitoken',
help='API Token - can be found on the lower right of https://github.com/account')
options, args = parser.parse_args()
if len(args) not in [1, 2]:
parser.error('wrong number of arguments')
if (len(args) == 1 and args[0] in ['add', 'remove']):
parser.error('%r needs a collaborator name as second parameter\n' % args[0])
elif (len(args) == 1 and args[0] != 'list'):
parser.error('unknown command %r. Try "list", "add" or "remove"\n' % args[0])
if (len(args) == 2 and args[0] not in ['add', 'remove']):
parser.error('unknown command %r. Try "list", "add" or "remove"\n' % args[0])
if not options.login:
parser.error('you must provide --login information\n')
return options, args
def main(options, args):
"""This implements the actual program functionality"""
if not options.account:
options.account = options.login
github = github2.client.Github(username=options.login,
api_token=options.apitoken,
debug=options.debug)
if len(args) == 1:
for repos in github.repos.list(options.account):
fullreposname = github.project_for_user_repo(options.account, repos.name)
print "%s: %s" % (repos.name, ' '.join(github.repos.list_collaborators(fullreposname)))
time.sleep(0.5) # to keep github from overloading
elif len(args) == 2:
command, collaborator = args
for repos in github.repos.list(options.account):
fullreposname = github.project_for_user_repo(options.account, repos.name)
if collaborator in github.repos.list_collaborators(fullreposname):
if command == 'remove':
github.repos.remove_collaborator(repos.name, collaborator)
print "removed %r from %r" % (collaborator, repos.name)
else:
if command == 'add':
github.repos.add_collaborator(repos.name, collaborator)
print "added %r to %r" % (collaborator, repos.name)
time.sleep(0.5) # to keep github from overloading
if __name__ == '__main__':
main(*parse_commandline())