mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Allow setting alternate_role_name for galaxy CLI (#17418)
When using the ansible-galaxy CLI to import roles, it's not possible to specify an alternate_role_name, even though the REST API seems to allow such a thing (at least on investigation of the interactions the web app makes) That makes importing things like: openstack/openstack-ansible-os_cloudkitty wind up with roles named "openstack-ansible-os_cloudkitty" instead of "os_cloudkitty". Also, the web ui is smart and imports "openstack-infra/ansible-role-puppet" as openstack-infra.puppet ... but the CLI imports it as openstack-infra.ansible-role-puppet. Add that filtering as well. Issue ansible/galaxy-issues:#185
This commit is contained in:
parent
d60bc492b6
commit
bd9ca5ef28
2 changed files with 10 additions and 5 deletions
|
@ -80,6 +80,7 @@ class GalaxyCLI(CLI):
|
||||||
self.parser.set_usage("usage: %prog import [options] github_user github_repo")
|
self.parser.set_usage("usage: %prog import [options] github_user github_repo")
|
||||||
self.parser.add_option('--no-wait', dest='wait', action='store_false', default=True, help='Don\'t wait for import results.')
|
self.parser.add_option('--no-wait', dest='wait', action='store_false', default=True, help='Don\'t wait for import results.')
|
||||||
self.parser.add_option('--branch', dest='reference', help='The name of a branch to import. Defaults to the repository\'s default branch (usually master)')
|
self.parser.add_option('--branch', dest='reference', help='The name of a branch to import. Defaults to the repository\'s default branch (usually master)')
|
||||||
|
self.parser.add_option('--role-name', dest='role_name', help='The name the role should have, if different than the repo name')
|
||||||
self.parser.add_option('--status', dest='check_status', action='store_true', default=False, help='Check the status of the most recent import request for given github_user/github_repo.')
|
self.parser.add_option('--status', dest='check_status', action='store_true', default=False, help='Check the status of the most recent import request for given github_user/github_repo.')
|
||||||
elif self.action == "info":
|
elif self.action == "info":
|
||||||
self.parser.set_usage("usage: %prog info [options] role_name[,version]")
|
self.parser.set_usage("usage: %prog info [options] role_name[,version]")
|
||||||
|
@ -567,7 +568,7 @@ class GalaxyCLI(CLI):
|
||||||
task = self.api.get_import_task(github_user=github_user, github_repo=github_repo)
|
task = self.api.get_import_task(github_user=github_user, github_repo=github_repo)
|
||||||
else:
|
else:
|
||||||
# Submit an import request
|
# Submit an import request
|
||||||
task = self.api.create_import_task(github_user, github_repo, reference=self.options.reference)
|
task = self.api.create_import_task(github_user, github_repo, reference=self.options.reference, role_name=self.options.role_name)
|
||||||
|
|
||||||
if len(task) > 1:
|
if len(task) > 1:
|
||||||
# found multiple roles associated with github_user/github_repo
|
# found multiple roles associated with github_user/github_repo
|
||||||
|
|
|
@ -140,17 +140,21 @@ class GalaxyAPI(object):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@g_connect
|
@g_connect
|
||||||
def create_import_task(self, github_user, github_repo, reference=None):
|
def create_import_task(self, github_user, github_repo, reference=None, role_name=None):
|
||||||
"""
|
"""
|
||||||
Post an import request
|
Post an import request
|
||||||
"""
|
"""
|
||||||
url = '%s/imports/' % self.baseurl
|
url = '%s/imports/' % self.baseurl
|
||||||
args = urlencode({
|
args = {
|
||||||
"github_user": github_user,
|
"github_user": github_user,
|
||||||
"github_repo": github_repo,
|
"github_repo": github_repo,
|
||||||
"github_reference": reference if reference else ""
|
"github_reference": reference if reference else ""
|
||||||
})
|
}
|
||||||
data = self.__call_galaxy(url, args=args)
|
if role_name:
|
||||||
|
args['alternate_role_name'] = role_name
|
||||||
|
elif github_repo.startswith('ansible-role'):
|
||||||
|
args['alternate_role_name'] = github_repo[len('ansible-role')+1:]
|
||||||
|
data = self.__call_galaxy(url, args=urlencode(args))
|
||||||
if data.get('results', None):
|
if data.get('results', None):
|
||||||
return data['results']
|
return data['results']
|
||||||
return data
|
return data
|
||||||
|
|
Loading…
Reference in a new issue