* Build(deps-dev): bump eslint-plugin-import from 2.20.1 to 2.20.2 Bumps [eslint-plugin-import](https://github.com/benmosher/eslint-plugin-import) from 2.20.1 to 2.20.2. - [Release notes](https://github.com/benmosher/eslint-plugin-import/releases) - [Changelog](https://github.com/benmosher/eslint-plugin-import/blob/master/CHANGELOG.md) - [Commits](https://github.com/benmosher/eslint-plugin-import/compare/v2.20.1...v2.20.2) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> * Fixes * refactor: combine imports * refactor: combine imports * refactor: combine imports * refactor: update import ordering Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com> Co-authored-by: Paul Melnikow <email@paulmelnikow.com> Co-authored-by: Caleb Cartwright <calebcartwright@users.noreply.github.com> Co-authored-by: Caleb Cartwright <caleb.cartwright@outlook.com>
85 lines
2.3 KiB
JavaScript
85 lines
2.3 KiB
JavaScript
'use strict'
|
|
|
|
const Joi = require('@hapi/joi')
|
|
const { InvalidResponse } = require('..')
|
|
const { errorMessagesFor } = require('./github-helpers')
|
|
|
|
const issueSchema = Joi.object({
|
|
head: Joi.object({
|
|
sha: Joi.string().required(),
|
|
}).required(),
|
|
}).required()
|
|
|
|
async function fetchIssue(serviceInstance, { user, repo, number }) {
|
|
return serviceInstance._requestJson({
|
|
schema: issueSchema,
|
|
url: `/repos/${user}/${repo}/pulls/${number}`,
|
|
errorMessages: errorMessagesFor('pull request or repo not found'),
|
|
})
|
|
}
|
|
|
|
const contentSchema = Joi.object({
|
|
// https://github.com/hapijs/joi/issues/1430
|
|
content: Joi.string().required(),
|
|
encoding: Joi.equal('base64').required(),
|
|
}).required()
|
|
|
|
async function fetchRepoContent(
|
|
serviceInstance,
|
|
{ user, repo, branch = 'master', filename }
|
|
) {
|
|
const errorMessages = errorMessagesFor(
|
|
`repo not found, branch not found, or ${filename} missing`
|
|
)
|
|
if (serviceInstance.staticAuthConfigured) {
|
|
const { content } = await serviceInstance._requestJson({
|
|
schema: contentSchema,
|
|
url: `/repos/${user}/${repo}/contents/${filename}`,
|
|
options: { qs: { ref: branch } },
|
|
errorMessages,
|
|
})
|
|
|
|
try {
|
|
return Buffer.from(content, 'base64').toString('utf-8')
|
|
} catch (e) {
|
|
throw new InvalidResponse({ prettyMessage: 'undecodable content' })
|
|
}
|
|
} else {
|
|
const { buffer } = await serviceInstance._request({
|
|
url: `https://raw.githubusercontent.com/${user}/${repo}/${branch}/${filename}`,
|
|
errorMessages,
|
|
})
|
|
return buffer
|
|
}
|
|
}
|
|
|
|
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 {
|
|
return serviceInstance._requestJson({
|
|
schema,
|
|
url: `https://raw.githubusercontent.com/${user}/${repo}/${branch}/${filename}`,
|
|
errorMessages: errorMessagesFor(
|
|
`repo not found, branch not found, or ${filename} missing`
|
|
),
|
|
})
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
fetchIssue,
|
|
fetchRepoContent,
|
|
fetchJsonFromRepo,
|
|
}
|