Skip to content

Commit

Permalink
use undici
Browse files Browse the repository at this point in the history
  • Loading branch information
bjohansebas committed Nov 29, 2024
1 parent 22418fc commit adf8315
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
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

0 comments on commit adf8315

Please sign in to comment.