Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
lots of beutification of getting ready for first release
  • Loading branch information
garbas committed Jul 2, 2011
1 parent 53997e4 commit b6d8f64
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 36 deletions.
54 changes: 52 additions & 2 deletions README.rst
Expand Up @@ -9,6 +9,9 @@ Approach that ``github-collective`` tool takes is that you edit central
configuration (for now only ini-like file) from where configuration is read and
updated respectivly.

Initially purposo of this scrip is to manage Plone's collective organisation on
github: https://collective.github.com


.. contents
Expand All @@ -35,6 +38,32 @@ name.
::

% bin/github-collective --help
usage: github-collective [-h] -c CONFIG [-M MAILER] [-C CACHE] -o GITHUB_ORG
-u GITHUB_USERNAME -P GITHUB_PASSWORD [-v] [-p]
This tool will let you automate tedious tasks of creating teams granting
permission and creating repositories.
optional arguments:
-h, --help show this help message and exit
-c CONFIG, --config CONFIG
path to configuration file (could also be remote
location). eg.
http://collective.github.com/permissions.cfg (default:
None)
-M MAILER, --mailer MAILER
TODO (default: None)
-C CACHE, --cache CACHE
path to file where to cache results from github.
(default: None)
-o GITHUB_ORG, --github-org GITHUB_ORG
github organisation. (default: None)
-u GITHUB_USERNAME, --github-username GITHUB_USERNAME
github account username. (default: None)
-P GITHUB_PASSWORD, --github-password GITHUB_PASSWORD
github account password. (default: None)
-v, --verbose
-p, --pretend


Example of configuration stored locally
Expand All @@ -43,8 +72,8 @@ Example of configuration stored locally
::

% bin/github-collective \
-c example.cfg \ # path to configuration file
-o collective \ # organization that we are
-c example.cfg \ # path to configuration file
-o vim-addons \ # organization that we are
-u garbas \ # account that has management right for organization
-P PASSWORD # account password

Expand All @@ -60,6 +89,27 @@ Example of configuration stored on github
-u garbas \ # account that has management right for organization
-P PASSWORD # account password

Example of cached configuration
-------------------------------

::

% bin/github-collective \
-c https://raw.github.com/garbas/github-collective/master/example.cfg \
# url to configuration file
-C .cache # file where store and read cached results from github
-o collective \ # organization that we are
-u garbas \ # account that has management right for organization
-P PASSWORD # account password


Todo
====

- Send emails to owners about removing repos
- better logging mechanism (eg. logbook)


Credits
=======

Expand Down
24 changes: 17 additions & 7 deletions githubcollective/__init__.py
Expand Up @@ -29,16 +29,26 @@ def send(self, to, msg):

def run():
parser = argparse.ArgumentParser(
prog=Sync.__name__,
prog='github-collective',
description='This tool will let you automate tedious tasks of '
'creating teams granting permission and creating '
'repositories.',
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)

parser.add_argument('-c', '--config', type=select_config, required=True)
parser.add_argument('-M', '--mailer', type=lambda x: Mailer(x))
parser.add_argument('-C', '--cache', type=str)
parser.add_argument('-o', '--github-org', type=str, required=True)
parser.add_argument('-u', '--github-username', type=str, required=True)
parser.add_argument('-P', '--github-password', type=str, required=True)
parser.add_argument('-c', '--config', type=select_config, required=True,
help="path to configuration file (could also be remote location). "
"eg. http://collective.github.com/permissions.cfg")
parser.add_argument('-M', '--mailer', type=lambda x: Mailer(x),
help="TODO")
parser.add_argument('-C', '--cache', type=str,
help="path to file where to cache results from github.")
parser.add_argument('-o', '--github-org', type=str, required=True,
help="github organisation.")
parser.add_argument('-u', '--github-username', type=str, required=True,
help="github account username.")
parser.add_argument('-P', '--github-password', type=str, required=True,
help="github account password.")
parser.add_argument('-v', '--verbose', action='store_true')
parser.add_argument('-p', '--pretend', action='store_true')

Expand Down
5 changes: 2 additions & 3 deletions githubcollective/github.py
Expand Up @@ -7,10 +7,7 @@
import base64
import requests

from githubcollective.team import Team
from githubcollective.repo import Repo
from githubcollective.config import BASE_URL
from githubcollective.config import TEAM_PREFIX


class Github(object):
Expand All @@ -36,6 +33,8 @@ def __init__(self, organization, username, password, verbose, pretend):
# requests library helpers

def _request(self, method, url, data=None):
if self.pretend:
return
kw = {'url': BASE_URL+url+'?per_page=10000',
'headers': self.headers}
if data:
Expand Down
24 changes: 0 additions & 24 deletions githubcollective/sync.py
Expand Up @@ -3,10 +3,6 @@


class Sync(object):
"""
"""

__name__ = 'githubcollective-sync'

def __init__(self, github, mailer=None, verbose=False, pretend=False):
self.github = github
Expand Down Expand Up @@ -127,27 +123,19 @@ def run(self, new, old):

def add_repo(self, config, repo):
config._repos[repo.name] = repo
if self.pretend:
return
return self.github._gh_org_create_repo(repo.name)

def remove_repo(self, config, repo):
del config._repos[repo.name]
if self.pretend:
return
if self.mailer:
raise NotImplemented

def fork_repo(self, config, fork_url, repo):
config._repos[repo.name] = repo
if self.pretend:
return
return self._gh_org_fork_repo(fork_url)

def add_team(self, config, team):
config._teams[team.name] = Team(team.name, team.permission)
if self.pretend:
return
return self._gh_org_create_team(
name=team.name,
permission=team.permission,
Expand All @@ -156,8 +144,6 @@ def add_team(self, config, team):
def edit_team(self, config, team):
config._teams[team.name].name = team.name
config._teams[team.name].permission = team.permission
if self.pretend:
return
return self._gh_org_edit_team(
id=team.id,
name=team.name,
Expand All @@ -166,34 +152,24 @@ def edit_team(self, config, team):

def remove_team(self, config, team):
del config._teams[team.name]
if self.pretend:
return
return self._gh_org_delete_team(team.id)

def add_team_member(self, config, team, member):
team = config.get_team(team.name)
team.members.update([member])
if self.pretend:
return
return self._gh_org_add_team_member(team.id, member)

def remove_team_member(self, config, team, member):
team = config.get_team(team.name)
team.members.remove(member)
if self.pretend:
return
return self._gh_org_remove_team_member(team.id, member)

def add_team_repo(self, config, team, repo):
team = config.get_team(team.name)
team.repos.update([repo])
if self.pretend:
return
return self._gh_org_add_team_repo(team.id, repo)

def remove_team_repo(self, config, team, repo):
team = config.get_team(team.name)
team.repos.remove(repo)
if self.pretend:
return
return self._gh_org_remove_team_repo(team.id, repo)

0 comments on commit b6d8f64

Please sign in to comment.