Skip to content
This repository was archived by the owner on Sep 12, 2019. It is now read-only.

Commit a7f3c74

Browse files
author
sw-yx
committed
fix borked safeJoin
1 parent 58f6772 commit a7f3c74

File tree

3 files changed

+22
-34
lines changed

3 files changed

+22
-34
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
"inquirer": "^6.2.2",
1717
"netlify": "ssh+git://[email protected]:netlify/js-client-private",
1818
"netlify-rules-proxy": "git+ssh://[email protected]/netlify/netlify-rules-proxy.git",
19-
"safe-join": "^0.1.1",
2019
"node-fetch": "^2.3.0",
2120
"opn": "^5.5.0",
21+
"safe-join": "^0.1.2",
2222
"static-dev-server": "^1.0.0",
2323
"wait-port": "^0.2.2"
2424
},

src/utils/readRepoURL.js

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
const url = require("url");
2-
const fetch = require("node-fetch");
3-
const safeJoin = require("safe-join");
1+
const url = require('url')
2+
const fetch = require('node-fetch')
3+
const { safeJoin } = require('safe-join')
44

55
// supported repo host types
6-
const GITHUB = Symbol("GITHUB");
6+
const GITHUB = Symbol('GITHUB')
77
// const BITBUCKET = Symbol('BITBUCKET')
88
// const GITLAB = Symbol('GITLAB')
99

@@ -12,52 +12,40 @@ const GITHUB = Symbol("GITHUB");
1212
* and returns https://api.github.com/repos/netlify-labs/all-the-functions/contents/functions/9-using-middleware
1313
*/
1414
async function readRepoURL(_url) {
15-
const URL = url.parse(_url);
16-
const repoHost = validateRepoURL(URL);
17-
const [owner_and_repo, contents_path] = parseRepoURL(repoHost, URL);
18-
const folderContents = await getRepoURLContents(
19-
repoHost,
20-
owner_and_repo,
21-
contents_path
22-
);
23-
return folderContents;
15+
const URL = url.parse(_url)
16+
const repoHost = validateRepoURL(URL)
17+
const [owner_and_repo, contents_path] = parseRepoURL(repoHost, URL)
18+
const folderContents = await getRepoURLContents(repoHost, owner_and_repo, contents_path)
19+
return folderContents
2420
}
2521

2622
async function getRepoURLContents(repoHost, owner_and_repo, contents_path) {
2723
// naive joining strategy for now
2824
if (repoHost === GITHUB) {
2925
// https://developer.github.com/v3/repos/contents/#get-contents
30-
const APIURL = safeJoin(
31-
"https://api.github.com/repos",
32-
owner_and_repo,
33-
"contents",
34-
contents_path
35-
);
26+
const APIURL = safeJoin('https://api.github.com/repos', owner_and_repo, 'contents', contents_path)
3627
return fetch(APIURL)
3728
.then(x => x.json())
38-
.catch(err =>
39-
console.error("Error occurred while fetching ", APIURL, err)
40-
);
29+
.catch(err => console.error('Error occurred while fetching ', APIURL, err))
4130
} else {
42-
throw new Error("unsupported host ", repoHost);
31+
throw new Error('unsupported host ', repoHost)
4332
}
4433
}
4534

4635
function validateRepoURL(URL) {
47-
if (URL.host !== "github.com")
48-
throw new Error("only github repos are supported for now");
36+
if (URL.host !== 'github.com') throw new Error('only github repos are supported for now')
4937
// other validation logic here
50-
return GITHUB;
38+
return GITHUB
5139
}
5240
function parseRepoURL(repoHost, URL) {
5341
// naive splitting strategy for now
5442
if (repoHost === GITHUB) {
5543
// https://developer.github.com/v3/repos/contents/#get-contents
56-
const [owner_and_repo, contents_path] = URL.path.split("/tree/master"); // what if it's not master? note that our contents retrieval may assume it is master
57-
return [owner_and_repo, contents_path];
44+
const [owner_and_repo, contents_path] = URL.path.split('/tree/master') // what if it's not master? note that our contents retrieval may assume it is master
45+
return [owner_and_repo, contents_path]
5846
} else {
59-
throw new Error("unsupported host ", repoHost);
47+
throw new Error('unsupported host ', repoHost)
6048
}
6149
}
6250

63-
module.exports = readRepoURL;
51+
module.exports = readRepoURL

0 commit comments

Comments
 (0)