Add dependency badge for Pipenv applications [GithubPipenv] (#4096)
I recently published https://github.com/metabolize/rq-dashboard-on-heroku and want to add badges to show the locked version of Python and rq-dashboard, the main dependency it’s wrapping. This is along the lines of #2259, which was for package.json-based applications, and also included some discussion of a Python application that used `requirements.txt`. It’s useful for showing the pinned version of any dependency in a Python application that uses a lockfile. In the future, as an alternative to reading Pipfile.lock, I could see expanding this to read Pipfile. However for my purposes I prefer to show the locked dependency, since that’s the version that a user of my package would actually get if they ran it on Heroku.
This commit is contained in:
@@ -24,9 +24,9 @@ const contentSchema = Joi.object({
|
||||
encoding: Joi.equal('base64').required(),
|
||||
}).required()
|
||||
|
||||
async function fetchJsonFromRepo(
|
||||
async function fetchRepoContent(
|
||||
serviceInstance,
|
||||
{ schema, user, repo, branch = 'master', filename }
|
||||
{ user, repo, branch = 'master', filename }
|
||||
) {
|
||||
const errorMessages = errorMessagesFor(
|
||||
`repo not found, branch not found, or ${filename} missing`
|
||||
@@ -41,13 +41,32 @@ async function fetchJsonFromRepo(
|
||||
errorMessages,
|
||||
})
|
||||
|
||||
let decoded
|
||||
try {
|
||||
decoded = Buffer.from(content, 'base64').toString('utf-8')
|
||||
return Buffer.from(content, 'base64').toString('utf-8')
|
||||
} catch (e) {
|
||||
throw new InvalidResponse({ prettyMessage: 'undecodable content' })
|
||||
}
|
||||
const json = serviceInstance._parseJson(decoded)
|
||||
} else {
|
||||
const url = `https://raw.githubusercontent.com/${user}/${repo}/${branch}/${filename}`
|
||||
return serviceInstance._request({
|
||||
url,
|
||||
errorMessages,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchJsonFromRepo(
|
||||
serviceInstance,
|
||||
{ schema, user, repo, branch = 'master', filename }
|
||||
) {
|
||||
if (serviceInstance.staticAuthConfigured) {
|
||||
const buffer = await fetchRepoContent(serviceInstance, {
|
||||
user,
|
||||
repo,
|
||||
branch,
|
||||
filename,
|
||||
})
|
||||
const json = serviceInstance._parseJson(buffer)
|
||||
return serviceInstance.constructor._validate(json, schema)
|
||||
} else {
|
||||
const url = `https://raw.githubusercontent.com/${user}/${repo}/${branch}/${filename}`
|
||||
|
||||
Reference in New Issue
Block a user