Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use undici instead of node-fetch #30

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions lib/files.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
'use strict'
const fetch = require('node-fetch')
const { request } = require('undici')
const yaml = require('js-yaml')
const GHRAW = 'https://raw.githubusercontent.com/'

module.exports.getPackageJson = async function getPackageJson (project) {
const resp = await fetch(`${GHRAW}${project.repoOwner}/${project.repoName}/${project.repoBranch}${project.repoDirectory}package.json`)
if (resp.status !== 200) {
const e = new Error(`Non-200 Response: ${resp.status}`)
e.status = resp.status
e.body = await resp.text()
const resp = await request(`${GHRAW}${project.repoOwner}/${project.repoName}/${project.repoBranch}${project.repoDirectory}package.json`)
if (resp.statusCode !== 200) {
const e = new Error(`Non-200 Response: ${resp.statusCode}`)
e.status = resp.statusCode
e.body = await resp.body.text()
throw e
}
return resp.json()
return resp.body.json()
}

module.exports.getTravisConfig = async function getTravisConfig (project) {
const resp = await fetch(`${GHRAW}${project.repoOwner}/${project.repoName}/${project.repoBranch}${project.repoDirectory}.travis.yml`)
if (resp.status !== 200) {
const e = new Error(`Non-200 Response: ${resp.status}`)
e.status = resp.status
e.body = await resp.text()
const resp = await request(`${GHRAW}${project.repoOwner}/${project.repoName}/${project.repoBranch}${project.repoDirectory}.travis.yml`)

if (resp.statusCode !== 200) {
const e = new Error(`Non-200 Response: ${resp.statusCode}`)
e.status = resp.statusCode
e.body = await resp.body.text()
throw e
}
const travisTxt = await resp.text()

const travisTxt = await resp.body.text()

return yaml.safeLoad(travisTxt)
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
"libnpm": "^2.0.1",
"lit-element": "^2.2.1",
"nighthawk": "^2.3.0-1",
"node-fetch": "^2.6.0",
"npm": "^6.10.3",
"regenerator-runtime": "^0.13.3",
"undici": "^7.0.0",
"yargs": "^13.3.0"
},
"engines": {
Expand Down