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

github_user should override namespace.name for legacy roles. #1923

Merged
merged 1 commit into from
Oct 9, 2023
Merged
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
26 changes: 25 additions & 1 deletion galaxy_ng/app/api/v1/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,27 @@ def get_avatar_url(self, obj):

class LegacyRoleSerializer(serializers.ModelSerializer):

# core cli uses this field to emit the list of
# results from a role search so it must exit
username = serializers.SerializerMethodField()

# this has to be the real github org/user so that
# role installs will work
github_user = serializers.SerializerMethodField()

# this has to be the real github repository name
# so that role installs will work
github_repo = serializers.SerializerMethodField()

# this is the default or non-default branch
# the cli will use will installing the role.
# in old galaxy this was internall renamed to
# import_branch.
github_branch = serializers.SerializerMethodField()

commit = serializers.SerializerMethodField()
commit_message = serializers.SerializerMethodField()

description = serializers.SerializerMethodField()
summary_fields = serializers.SerializerMethodField()
upstream_id = serializers.SerializerMethodField()
Expand All @@ -191,6 +207,7 @@ class Meta:
'github_repo',
'github_branch',
'commit',
'commit_message',
'name',
'description',
'summary_fields',
Expand Down Expand Up @@ -229,6 +246,8 @@ def get_github_user(self, obj):
of the role in the form of:
https://github.com/<github_user>/<github_repo>/...
"""
if obj.full_metadata.get('github_user'):
return obj.full_metadata['github_user']
return obj.namespace.name

def get_username(self, obj):
Expand All @@ -252,11 +271,16 @@ def get_github_branch(self, obj):
at install time. If not branch is given, the cli will default to
the "master" branch.
"""
return obj.full_metadata.get('github_reference')
if obj.full_metadata.get('github_reference'):
return obj.full_metadata.get('github_reference')
return obj.full_metadata.get('github_branch')

def get_commit(self, obj):
return obj.full_metadata.get('commit')

def get_commit_message(self, obj):
return obj.full_metadata.get('commit_message')

def get_description(self, obj):
return obj.full_metadata.get('description')

Expand Down
15 changes: 9 additions & 6 deletions galaxy_ng/app/api/v1/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def legacy_role_import(
'clone_url': clone_url,
'tags': galaxy_info["galaxy_tags"],
'commit': github_commit,
'github_user': github_user,
'github_repo': github_repo,
'github_reference': github_reference,
'issue_tracker_url': galaxy_info["issue_tracker_url"] or clone_url + "/issues",
Expand Down Expand Up @@ -253,17 +254,18 @@ def legacy_sync_from_upstream(
else:
namespace, v3_namespace = nsmap[ns_data['name']]

ruser = rdata.get('github_user')
rname = rdata.get('name')
github_user = rdata.get('github_user')
role_name = rdata.get('name')

logger.info(f'POPULATE {ruser}.{rname}')
logger.info(f'POPULATE {github_user}.{role_name}')

rkey = (ruser, rname)
rkey = (github_user, role_name)
remote_id = rdata['id']
role_versions = rversions[:]
# github_user = rdata['github_user']
github_repo = rdata['github_repo']
jctanner marked this conversation as resolved.
Show resolved Hide resolved
github_branch = rdata['github_branch']
clone_url = f'https://github.com/{ruser}/{github_repo}'
clone_url = f'https://github.com/{github_user}/{github_repo}'
sfields = rdata.get('summary_fields', {})
role_tags = sfields.get('tags', [])
commit_hash = rdata.get('commit')
Expand All @@ -288,7 +290,7 @@ def legacy_sync_from_upstream(
logger.debug(f'SYNC create initial role for {rkey}')
this_role, _ = LegacyRole.objects.get_or_create(
namespace=namespace,
name=rname
name=role_name
)
rmap[rkey] = this_role
else:
Expand All @@ -305,6 +307,7 @@ def legacy_sync_from_upstream(
'commit': commit_hash,
'commit_message': commit_msg,
'commit_url': commit_url,
'github_user': github_user,
'github_repo': github_repo,
'github_branch': github_branch,
# 'github_reference': github_reference,
Expand Down
15 changes: 8 additions & 7 deletions galaxy_ng/tests/integration/api/test_community.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ def test_v1_autocomplete_search(ansible_config):
# query by user
resp = api_client(f'/api/v1/roles/?owner__username={github_user}')
assert resp['count'] > 0
usernames = sorted(set([x['username'] for x in resp['results']]))
usernames = sorted(set([x['github_user'] for x in resp['results']]))
assert usernames == [github_user]

# validate autocomplete search only finds the relevant roles
Expand Down Expand Up @@ -566,11 +566,11 @@ def get_roles(page_size=1, order_by='created'):
urls, all_roles = get_roles(page_size=1, order_by='created')
roles = [[x['created'], x['id']] for x in all_roles]

# make sure all 10 show up ...
assert len(roles) == 10
total_count = len(urls)
assert total_count >= 10

# make sure all pages were visited
assert len(urls) == 10
# make sure all 10 show up ...
assert len(roles) == total_count

# make sure no duplicates found
assert [x[1] for x in roles] == sorted(set([x[1] for x in roles]))
Expand All @@ -581,9 +581,10 @@ def get_roles(page_size=1, order_by='created'):
# repeat with ordered by name ...
urls, all_roles = get_roles(page_size=1, order_by='name')
roles = [x['name'] for x in all_roles]

assert roles == sorted(roles)
assert len(roles) == 10
assert len(sorted(set(roles))) == 10
assert len(roles) == total_count
assert len(sorted(set(roles))) == total_count

# cleanup
clean_all_roles(ansible_config)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ def test_community_hijacking(ansible_config):

usermap = {
'jctannerTESTME': {
'uid': 1000,
'uid': 2000,
'login': 'jctannerTESTME',
# 'email': '[email protected]',
'email': '',
},
'drod0258X': {
'uid': 1001,
'uid': 2001,
'login': 'drod0258X',
# 'email': '[email protected]',
'email': ''
Expand Down
2 changes: 1 addition & 1 deletion galaxy_ng/tests/integration/utils/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def clean_all_roles(ansible_config):
break
next_url = resp['next']

usernames = [x['username'] for x in pre_existing]
usernames = [x['github_user'] for x in pre_existing]
usernames = sorted(set(usernames))
for username in usernames:
cleanup_social_user(username, ansible_config)
Expand Down
Loading