mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Fix some bugs with the github functionality
This commit is contained in:
parent
82b4a51cb7
commit
1014b780b5
@ -748,43 +748,43 @@ def get_repo_info(repo_name, profile='github'):
|
||||
org_name = _get_config_value(profile, 'org_name')
|
||||
client = _get_client(profile)
|
||||
|
||||
repo = client.get_repo('/'.join([org_name, repo_name]))
|
||||
if repo:
|
||||
# client.get_repo will return a github.Repository.Repository object,
|
||||
# even if the repo is invalid. We need to catch the exception when
|
||||
# we try to perform actions on the repo object, rather than above
|
||||
# the if statement.
|
||||
try:
|
||||
try:
|
||||
repo = client.get_repo('/'.join([org_name, repo_name]))
|
||||
if repo:
|
||||
# client.get_repo can return a github.Repository.Repository object,
|
||||
# even if the repo is invalid. We need to catch the exception when
|
||||
# we try to perform actions on the repo object, rather than above
|
||||
# the if statement.
|
||||
ret['id'] = repo.id
|
||||
except github.UnknownObjectException:
|
||||
raise CommandExecutionError(
|
||||
'The \'{0}\' repository under the \'{1}\' organization could not '
|
||||
'be found.'.format(
|
||||
repo_name,
|
||||
org_name
|
||||
)
|
||||
)
|
||||
ret['name'] = repo.name
|
||||
ret['full_name'] = repo.full_name
|
||||
ret['owner'] = repo.owner.login
|
||||
ret['private'] = repo.private
|
||||
ret['html_url'] = repo.html_url
|
||||
ret['description'] = repo.description
|
||||
ret['fork'] = repo.fork
|
||||
ret['homepage'] = repo.homepage
|
||||
ret['size'] = repo.size
|
||||
ret['stargazers_count'] = repo.stargazers_count
|
||||
ret['watchers_count'] = repo.watchers_count
|
||||
ret['language'] = repo.language
|
||||
ret['open_issues_count'] = repo.open_issues_count
|
||||
ret['forks'] = repo.forks
|
||||
ret['open_issues'] = repo.open_issues
|
||||
ret['watchers'] = repo.watchers
|
||||
ret['default_branch'] = repo.default_branch
|
||||
ret['has_issues'] = repo.has_issues
|
||||
ret['has_wiki'] = repo.has_wiki
|
||||
ret['has_downloads'] = repo.has_downloads
|
||||
|
||||
ret['name'] = repo.name
|
||||
ret['full_name'] = repo.full_name
|
||||
ret['owner'] = repo.owner.login
|
||||
ret['private'] = repo.private
|
||||
ret['html_url'] = repo.html_url
|
||||
ret['description'] = repo.description
|
||||
ret['fork'] = repo.fork
|
||||
ret['homepage'] = repo.homepage
|
||||
ret['size'] = repo.size
|
||||
ret['stargazers_count'] = repo.stargazers_count
|
||||
ret['watchers_count'] = repo.watchers_count
|
||||
ret['language'] = repo.language
|
||||
ret['open_issues_count'] = repo.open_issues_count
|
||||
ret['forks'] = repo.forks
|
||||
ret['open_issues'] = repo.open_issues
|
||||
ret['watchers'] = repo.watchers
|
||||
ret['default_branch'] = repo.default_branch
|
||||
ret['has_issues'] = repo.has_issues
|
||||
ret['has_wiki'] = repo.has_wiki
|
||||
ret['has_downloads'] = repo.has_downloads
|
||||
except github.UnknownObjectException:
|
||||
raise CommandExecutionError(
|
||||
'The \'{0}\' repository under the \'{1}\' organization could not '
|
||||
'be found.'.format(
|
||||
repo_name,
|
||||
org_name
|
||||
)
|
||||
)
|
||||
return ret
|
||||
|
||||
|
||||
@ -1436,8 +1436,15 @@ def list_members_without_mfa(profile="github", ignore_cache=False):
|
||||
organization = client.get_organization(
|
||||
_get_config_value(profile, 'org_name')
|
||||
)
|
||||
|
||||
filter_key = 'filter'
|
||||
# Silly hack to see if we're past PyGithub 1.26.0, where the name of
|
||||
# the filter kwarg changed
|
||||
if hasattr(github.Team.Team, 'membership'):
|
||||
filter_key = 'filter_'
|
||||
|
||||
__context__[key] = [m.login.lower() for m in
|
||||
_get_members(organization, {'filter': '2fa_disabled'})]
|
||||
_get_members(organization, {filter_key: '2fa_disabled'})]
|
||||
return __context__[key]
|
||||
|
||||
|
||||
@ -1502,9 +1509,6 @@ def add_team_member(name, team_name, profile="github"):
|
||||
log.exception('Resource not found: {0}'.format(team['id']))
|
||||
return False
|
||||
|
||||
if not hasattr(team, 'add_membership'):
|
||||
return (False, 'PyGithub 1.26.0 or greater is required for team '
|
||||
'management, please upgrade.')
|
||||
try:
|
||||
# Can't use team.add_membership due to this bug that hasn't made it into
|
||||
# a PyGithub release yet https://github.com/PyGithub/PyGithub/issues/363
|
||||
@ -1592,18 +1596,15 @@ def list_teams(profile="github", ignore_cache=False):
|
||||
organization = client.get_organization(
|
||||
_get_config_value(profile, 'org_name')
|
||||
)
|
||||
headers, teams_data = organization._requester.requestJsonAndCheck(
|
||||
'GET',
|
||||
organization.url + '/teams'
|
||||
)
|
||||
teams_data = organization.get_teams()
|
||||
teams = {}
|
||||
for team in teams_data:
|
||||
teams[team['name']] = {
|
||||
'id': team['id'],
|
||||
'slug': team['slug'],
|
||||
'description': team['description'],
|
||||
'permission': team['permission'],
|
||||
'privacy': team['privacy']
|
||||
teams[team.name] = {
|
||||
'id': team.id,
|
||||
'slug': team.slug,
|
||||
'description': team.raw_data['description'],
|
||||
'permission': team.permission,
|
||||
'privacy': team.raw_data['privacy']
|
||||
}
|
||||
__context__[key] = teams
|
||||
|
||||
|
@ -160,7 +160,7 @@ def absent(name, profile="github", **kwargs):
|
||||
|
||||
def team_present(
|
||||
name,
|
||||
description='',
|
||||
description=None,
|
||||
repo_names=None,
|
||||
privacy='secret',
|
||||
permission='pull',
|
||||
@ -247,7 +247,8 @@ def team_present(
|
||||
|
||||
if len(parameters) > 0:
|
||||
if __opts__['test']:
|
||||
test_comments.append('Team properties are set to be edited.')
|
||||
test_comments.append('Team properties are set to be edited: {0}'
|
||||
.format(parameters))
|
||||
ret['result'] = None
|
||||
else:
|
||||
result = __salt__['github.edit_team'](name, profile=profile,
|
||||
@ -262,11 +263,12 @@ def team_present(
|
||||
ret['comment'] = 'Failed to update team properties.'
|
||||
return ret
|
||||
|
||||
manage_repos = repo_names is not None
|
||||
current_repos = set(__salt__['github.list_team_repos'](name, profile=profile))
|
||||
repo_names = set(repo_names or [])
|
||||
|
||||
repos_to_add = repo_names - current_repos
|
||||
repos_to_remove = current_repos - repo_names
|
||||
repos_to_remove = current_repos - repo_names if repo_names else []
|
||||
|
||||
if repos_to_add:
|
||||
if __opts__['test']:
|
||||
@ -332,12 +334,14 @@ def team_present(
|
||||
ret['comment'] = 'Failed to create team {0}.'.format(name)
|
||||
return ret
|
||||
|
||||
manage_members = members is not None
|
||||
|
||||
mfa_deadline = datetime.datetime.utcnow() - datetime.timedelta(seconds=no_mfa_grace_seconds)
|
||||
members_no_mfa = __salt__['github.list_members_without_mfa'](profile=profile)
|
||||
|
||||
members_lower = {}
|
||||
for name, info in six.iteritems(members):
|
||||
members_lower[name.lower()] = info
|
||||
for member_name, info in six.iteritems(members or {}):
|
||||
members_lower[member_name.lower()] = info
|
||||
|
||||
member_change = False
|
||||
current_members = __salt__['github.list_team_members'](name, profile=profile)
|
||||
@ -378,7 +382,8 @@ def team_present(
|
||||
if member in members_lower:
|
||||
mfa_violation = _member_violates_mfa(member, members_lower[member],
|
||||
mfa_deadline, members_no_mfa)
|
||||
if member not in members_lower or (enforce_mfa and mfa_violation):
|
||||
if (manage_members and member not in members_lower or
|
||||
(enforce_mfa and mfa_violation)):
|
||||
# Remove from team
|
||||
member_change = True
|
||||
if __opts__['test']:
|
||||
@ -476,7 +481,7 @@ def team_absent(name, profile="github", **kwargs):
|
||||
|
||||
def repo_present(
|
||||
name,
|
||||
description='',
|
||||
description=None,
|
||||
homepage=None,
|
||||
private=False,
|
||||
has_issues=True,
|
||||
@ -562,7 +567,7 @@ def repo_present(
|
||||
parameters = {}
|
||||
old_parameters = {}
|
||||
for param_name, param_value in six.iteritems(given_params):
|
||||
if (param_name not in ignore_params and
|
||||
if (param_value is not None and param_name not in ignore_params and
|
||||
target[param_name] is not param_value and
|
||||
target[param_name] != param_value):
|
||||
parameters[param_name] = param_value
|
||||
|
Loading…
Reference in New Issue
Block a user