Skip to content

Commit

Permalink
Add Visual Studio Code Marketplace
Browse files Browse the repository at this point in the history
  • Loading branch information
Th3Whit3Wolf authored and lilydjwg committed Jul 14, 2021
1 parent ad2dc19 commit 25d7a74
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,17 @@ Check `Open Vsx <https://open-vsx.org/>`_ for updates.
openvsx
The extension's Unique Identifier on open-vsx.org, e.g. ``ritwickdey.LiveServer``.

Check Visual Studio Code Marketplace
~~~~~~~~~~~~~~~
::

source = "vsmarketplace"

Check `Visual Studio Code Marketplace <https://marketplace.visualstudio.com/vscode/>`_ for updates.

vsmarketplace
The extension's Unique Identifier on marketplace.visualstudio.com/vscode, e.g. ``ritwickdey.LiveServer``.

Combine others' results
~~~~~~~~~~~~~~~~~~~~~~~
::
Expand Down
54 changes: 54 additions & 0 deletions nvchecker_source/vsmarketplace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# MIT licensed
# Copyright (c) 2013-2021 Th3Whit3Wolf <the.white.wolf.is.1337@gmail.com>, et al.

from nvchecker.api import (
VersionResult, Entry, AsyncCache, KeyManager,
TemporaryError, session, GetVersionError,
)

API_URL = 'https://marketplace.visualstudio.com/_apis/public/gallery/extensionquery'

HEADERS = {
'Accept': 'application/json;api-version=6.1-preview.1',
'Content-Type': 'application/json'
}

async def get_version(name: str, conf: Entry, *, cache: AsyncCache, **kwargs):
name = conf.get('vsmarketplace') or name

q = {
'filters': [
{
'criteria': [
{
'filterType': 8,
'value': 'Microsoft.VisualStudio.Code'
},
{
'filterType': 10,
'value': name
},
{
'filterType': 12,
'value': '4096'
}
],
'pageNumber': 1,
'pageSize': 2,
'sortBy': 0,
'sortOrder': 0
}
],
'assetTypes': [],
'flags': 946
}

res = await session.post(
API_URL,
headers = HEADERS,
json = q,
)
j = res.json()

version = j['results'][0]['extensions'][0]['versions'][0]['version']
return version
10 changes: 10 additions & 0 deletions tests/test_vsmarketplace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# MIT licensed
# Copyright (c) 2013-2021 Th3Whit3Wolf <the.white.wolf.is.1337@gmail.com>, et al.

import pytest
pytestmark = [pytest.mark.asyncio, pytest.mark.needs_net]

async def test_vsmarketplace(get_version):
assert await get_version("usernamehw.indent-one-space", {
"source": "vsmarketplace",
}) == "0.2.6"

0 comments on commit 25d7a74

Please sign in to comment.