0

Currently developping an autobuild for the docker image of slidev hosted at Docker Hub, I need to compare already built version with npm available version of the module

I have this code :

import requests as curl


def getreleasegh():
    url = "https://api.github.com/repos/slidevjs/slidev/tags"
    with curl.get(url) as r:
        if r.status_code == 200:
            j = r.json()
    release = j[0]['name']
    release.replace("v", "")
    return release


def getactualimage():
    url = 'https://registry.hub.docker.com/v2/repositories/stig124/slidev/tags/'
    with curl.get(url) as r:
        if r.status_code == 200:
            j = r.json()
    image = j['results'][0]['name']
    return image

The npm package I want to query the version is @slidev with every subpackages being the same version tag

I used npms.io API from a suggestion in this question

Is there any way to query subpackages?

Querying API endpoint for any subpackages (https://api.npms.io/v2/package/@slidev-cli) return

{"code":"INVALID_PARAMETER","message":"name can only contain URL-friendly characters (\"@slidev-cli\")"}

Querying https://api.npms.io/v2/package/slidev-cli returns

{"code":"NOT_FOUND","message":"Module not found"}

Is there any way is it possible?

1 Answers1

0

After some tinkering, I found a workaround by using the search function

I search for slidev using https://api.npms.io/v2/search?q=slidev then process the first entry by finding if the package scope is the name of the parent package (the one with the @) if it isn't I jump to next entry and so on, and it works great

def checknpm():
    base = 'https://api.npms.io/v2/search?q='
    package = 'slidev'
    url = base + package
    with curl.get(url) as r:
        if r.status_code == 200:
            j = r.json()
    for i in range(5):
        if package in str(j['results'][i]['package']['scope']):
            npm = str(j['results'][i]['package']['version'])
            break