Skip to content

Commit

Permalink
Command to search extensions in marketplace (#488)
Browse files Browse the repository at this point in the history
  • Loading branch information
gauravsaralMs committed Mar 20, 2019
1 parent 916318e commit 57cb782
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 1 deletion.
16 changes: 16 additions & 0 deletions azure-devops/azext_devops/dev/team/_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@
from azext_devops.dev.common.format import trim_for_display, date_time_to_only_date


def transform_extension_search_results_table_output(result):
table_output = []
for item in result:
table_output.append(_transform_extension_search_result_row(item))
return table_output


def _transform_extension_search_result_row(row):
table_row = OrderedDict()
table_row['Publisher Id'] = row['publisher']['publisherName']
table_row['Extension Id'] = row['extensionName']
table_row['Name'] = row['displayName']

return table_row


def transform_extension_table_output(result):
table_output = [_transform_extension_row(result)]
return table_output
Expand Down
1 change: 1 addition & 0 deletions azure-devops/azext_devops/dev/team/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def load_team_arguments(self, _):
help='Include disabled extensions.')
context.argument('publisher_id', help='Publisher ID')
context.argument('extension_id', help='Extension ID')
context.argument('search_query', options_list=('--search-query', '-q'), help='Search term')

with self.argument_context('devops') as context:
load_global_args(context)
Expand Down
4 changes: 3 additions & 1 deletion azure-devops/azext_devops/dev/team/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
transform_users_table_output,
transform_user_table_output,
transform_extension_table_output,
transform_extensions_table_output)
transform_extensions_table_output,
transform_extension_search_results_table_output)


projectOps = CliCommandType(
Expand Down Expand Up @@ -101,3 +102,4 @@ def load_team_commands(self, _):
g.command('show', 'get_extension', table_transformer=transform_extension_table_output)
g.command('enable', 'enable_extension', table_transformer=transform_extension_table_output)
g.command('disable', 'disable_extension', table_transformer=transform_extension_table_output)
g.command('search', 'search_extensions', table_transformer=transform_extension_search_results_table_output)
79 changes: 79 additions & 0 deletions azure-devops/azext_devops/dev/team/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,85 @@
logger = get_logger(__name__)


def search_extensions(search_query):
""" Search extensions from marketplace
"""
from msrest.universal_http import ClientRequest
from msrest.service_client import ServiceClient
from msrest import Configuration
from azext_devops.version import VERSION
config = Configuration(base_url=None)
config.add_user_agent('devOpsCli/{}'.format(VERSION))
client = ServiceClient(creds=None, config=config)
request = ClientRequest(method='POST',
url='https://marketplace.visualstudio.com/_apis/public/gallery/extensionquery')

search_request = {
'assetTypes': [
'Microsoft.VisualStudio.Services.Icons.Default',
'Microsoft.VisualStudio.Services.Icons.Branding',
'Microsoft.VisualStudio.Services.Icons.Small'
],
'filters': [
{
'criteria': [
{
'filterType': 8,
'value': 'Microsoft.VisualStudio.Services'
},
{
'filterType': 8,
'value': 'Microsoft.VisualStudio.Services.Integration'
},
{
'filterType': 8,
'value': 'Microsoft.VisualStudio.Services.Cloud'
},
{
'filterType': 8,
'value': 'Microsoft.TeamFoundation.Server'
},
{
'filterType': 8,
'value': 'Microsoft.TeamFoundation.Server.Integration'
},
{
'filterType': 8,
'value': 'Microsoft.VisualStudio.Services.Cloud.Integration'
},
{
'filterType': 8,
'value': 'Microsoft.VisualStudio.Services.Resource.Cloud'
},
{
'filterType': 10,
'value': search_query
},
{
'filterType': 12,
'value': '37888'
}
],
'direction': 2,
'pageSize': 50,
'pageNumber': 1,
'sortBy': 0,
'sortOrder': 0,
'pagingToken': None
}
],
'flags': 870
}

headers = {'Content-Type': 'application/json' + '; charset=utf-8',
'Accept': 'application/json' + ';api-version=' + '5.0-preview.1'}

response = client.send(request=request, headers=headers, content=search_request)

response_json = response.json()
return response_json['results'][0]['extensions']


def list_extensions(include_built_in='true', include_disabled='true', organization=None, detect=None):
""" List extensions installed in an organization
"""
Expand Down
Loading

0 comments on commit 57cb782

Please sign in to comment.