Badge request: GitHub Package Registry, NPM variants
- Dominant language
- JavaScript
- Stars
- 27.2k
- Forks
- 5.6k
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 46
Description
:clipboard: **Description**
Recently, GitHub has launched a new beta feature: the [GitHub Package Registry (GPR)](https://github.com/features/package-registry)! :tada:
It currently supports alternative registries for NPM, Docker, Maven, NuGet, and RubyGems. For this issue, I would like to focus specifically on the NPM registry variant of GPR.
Ideally, Shields would support GPR support for all NPM-based badge URLs, including those that start with `/npm/`, `/node/`, `/jsdelivr/npm/`, `/snyk/vulnerabilities/npm/`, etc.
:link: **Data**
As far as I know, the GitHub Package Registry for NPM supports all of the usual NPM Registry API endpoints (as it is fully compliant with the NPM CLI). This might lead one to believe that we could make use of the `registry_uri` query param that is available on some of the NPM services, e.g. https://img.shields.io/npm/v/@octokit/webhooks.svg?label=GPR&logo=github®istry_uri=https%3A%2F%2Fnpm.pkg.github.com (→ https://github.com/octokit/webhooks.js/packages)
However, the GitHub Package Registry's API does not support anonymous access, and so that approach fails with `404` responses.
Looking through the Shields code for the `npm-base` service, I see there is [already support for a Bearer token](https://github.com/badges/shields/blob/8621fe42d76b809e9ba4ae844920f8ed0373817a/services/npm/npm-base.js#L80-L82), so I believe you could establish a new set of `/npm`-equivalent URIs for a separate instance of the `npm-*` services with a [GitHub Personal Access Token (PAT)](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line) as the Bearer token (`npm_token`).
However, you may instead want to consider modifying the code to detect when `registry_uri` is set to `https%3A%2F%2Fnpm.pkg.github.com` and use an alternative secret name like `gpr_token`. This may feel less clean but it should still require minimal changes and would prevent the need to add and maintain alternative URLs — instead just ensuring that the support for `registry_uri` is available on all NPM-related endpoints.
:microphone: **Motivation**
GitHub Package Registry is likely to become a popular alternative to the NPM registry due to its focus on security, traceability, and mandatory package `@scope`. If a package author chooses to publish their packages to both GPR and NPM, then they could just get badges using the existing NPM endpoints. However, if they only chose to publish to GPR, then the existing endpoints will not suffice.
Contributor guide
Research direction
Start in services/npm/npm-base.js, especially the existing Bearer-token handling, and trace how registry_uri reaches the NPM-related badge services. Compare the proposed separate endpoints with conditional GitHub Package Registry handling; done means supported NPM badge URLs can query the GPR registry with the required token without breaking the standard registry path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- github, javascript, node.js
- Domain
- api, authentication, backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100