Skip to content

Commit c97e548

Browse files
authored
CodeQL recommendations (#1218)
* url parsing based on codeql results * Update src/drivers/github.js * debug * lazy debugging * bad ternary? * lazy debugging * Revert things This reverts commit df90c98. This reverts commit f11c8ae. This reverts commit 39d0a45. * Cleanup
1 parent c83044e commit c97e548

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

bin/cml/asset/publish.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ exports.handler = async (opts) => {
1515
opts.native = true;
1616
}
1717

18-
const { file, repo, native, asset: path } = opts;
19-
const cml = new CML({ ...opts, repo: native ? repo : 'cml' });
18+
const { file, asset: path } = opts;
19+
const cml = new CML({ ...opts });
2020
const output = await cml.publish({ ...opts, path });
2121

2222
if (!file) console.log(output);

src/cml.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ const inferToken = () => {
6969
const inferDriver = (opts = {}) => {
7070
const { repo } = opts;
7171
if (repo) {
72-
if (repo.includes('github.com')) return GITHUB;
73-
if (repo.includes('gitlab.com')) return GITLAB;
74-
if (/bitbucket\.(com|org)/.test(repo)) return BB;
72+
const url = new URL(repo);
73+
if (url.hostname === 'github.com') return GITHUB;
74+
if (url.hostname === 'gitlab.com') return GITLAB;
75+
if (/bitbucket\.(com|org)/.test(url.hostname)) return BB;
7576
}
7677

7778
if (GITHUB_REPOSITORY) return GITHUB;

src/drivers/github.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,10 @@ const octokit = (token, repo) => {
6666
onAbuseLimit: throttleHandler
6767
}
6868
};
69-
70-
if (!repo.includes('github.com')) {
69+
const { host, hostname } = new url.URL(repo);
70+
if (hostname !== 'github.com') {
7171
// GitHub Enterprise, use the: repo URL host + '/api/v3' - as baseURL
7272
// as per: https://developer.github.com/enterprise/v3/enterprise-admin/#endpoint-urls
73-
const { host } = new url.URL(repo);
7473
octokitOptions.baseUrl = `https://${host}/api/v3`;
7574
}
7675

0 commit comments

Comments
 (0)