Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add parser options for team suffix/prefix #9

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions githubcollective/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ def run():
help="github account username.")
parser.add_argument('-P', '--github-password', type=str, required=True,
help="github account password.")
parser.add_argument('--no-team-prefix', dest='team_prefix',
action='store_false',
help='explicitly disable team prefix')
parser.add_argument('--team-prefix', dest='team_prefix',
help='prefix for team names',
default='--auto-')
parser.add_argument('--no-team-owner-suffix', dest='owner_suffix',
action='store_false',
help='explicitly disable team prefix')
parser.add_argument('--team-owner-suffix', dest='owner_suffix',
help='suffix for team names',
default='-owners')
parser.add_argument('-v', '--verbose', action='store_true')
parser.add_argument('-p', '--pretend', action='store_true')
parser.add_argument('-D', '--no_delete', action='store_true')
Expand All @@ -69,6 +81,8 @@ def run():
args.config[1],
args.verbose,
args.pretend,
args.team_prefix,
args.owner_suffix,
)

old = ConfigGithub(
Expand Down
32 changes: 24 additions & 8 deletions githubcollective/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@


BASE_URL = 'https://api.github.com'
TEAM_PREFIX = '--auto-'
TEAM_OWNERS_SUFFIX = '-owners'
LOCAL_SECTION_PREFIXES = ('repo',)


class Config(object):

def __init__(self, filename, verbose, pretend):
def __init__(self, filename, verbose, pretend, team_prefix, owner_suffix):
self._teams = {}
self._repos = {}
self._fork_urls = {}
Expand All @@ -32,6 +30,13 @@ def __init__(self, filename, verbose, pretend):
self.verbose = verbose
self.pretend = pretend

self.team_prefix = team_prefix
if team_prefix is False:
self.team_prefix = ''
self.owner_suffix = owner_suffix
if owner_suffix is False:
self.owner_suffix = ''

if type(filename) is file:
data = filename.read()
elif type(filename) in [str, unicode] and \
Expand Down Expand Up @@ -253,13 +258,13 @@ def parse(self, data):
fork_urls[name] = config.get(section, 'fork')
# add owners team
if config.has_option(section, 'owners'):
team_name = TEAM_PREFIX + name + TEAM_OWNERS_SUFFIX
team_name = self.team_prefix + name + self.owner_suffix
team_members = config.get(section, 'owners').split()
teams[team_name] = Team(team_name, 'admin',
members=team_members, repos=[name])
elif section.startswith('team:'):
# add team
name = TEAM_PREFIX + section[len('team:'):]
name = self.team_prefix + section[len('team:'):]
permission = 'pull'
if config.has_option(section, 'permission'):
permission = config.get(section, 'permission')
Expand All @@ -277,18 +282,25 @@ def parse(self, data):
if section.startswith('repo:'):
if config.has_option(section, 'teams'):
for team in config.get(section, 'teams').split():
teams[TEAM_PREFIX + team].repos.add(
teams[self.team_prefix + team].repos.add(
section[len('repo:'):],
)

return teams, repos, fork_urls

class ConfigGithub(Config):

def __init__(self, github, cache, verbose=False, pretend=False):
def __init__(self, github, cache, verbose=False, pretend=False, team_prefix='', owner_suffix=''):
self.github = github
self._github = {'teams': {}, 'repos': {}}

self.team_prefix = team_prefix
if team_prefix is False:
self.team_prefix = ''
self.owner_suffix = owner_suffix
if owner_suffix is False:
self.owner_suffix = ''

data = None
if cache:
data = cache.read()
Expand All @@ -303,7 +315,11 @@ def _get_teams(self):
not self._github['teams']:
self._github['teams'] = {}
for item in self.github._gh_org_teams():
if not item['name'].startswith(TEAM_PREFIX):
# TODO: whats happening here? This seems to rely on
# team prefix being used. Skips evyerthing else.
# If we are taking the no-prefix support approach
# then the script should accept all groups, ya?
if not item['name'].startswith(self.team_prefix):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that simply having this behave like this would address the issue... but definitely want some feedback.

    if self.team_prefix and not item['name'].startswith(self.team_prefix):

continue
item.update(self.github._gh_team(item['id']))
team = Team(**item)
Expand Down