default-branch
Advanced tools
Comparing version 1.0.3 to 1.0.4
29
index.js
@@ -5,8 +5,13 @@ 'use strict'; | ||
function getDefaultBranch(path) { | ||
if (!path.includes('github.com')) { | ||
module.exports = path => { | ||
if (!(path.startsWith('https://github.com/') || path.startsWith('http://github.com/'))) { | ||
path = 'https://github.com/' + path; | ||
} | ||
return new Promise( (resolve, reject) => { | ||
if (path.startsWith('http://github.com/')) { | ||
// Force https connection | ||
path = path.substr(0, 4) + 's' + path.substr(4); | ||
} | ||
return new Promise((resolve, reject) => { | ||
https.get(path + '/branches', (response) => { | ||
@@ -26,6 +31,10 @@ if (response.statusCode < 200 || response.statusCode > 299) { | ||
response.on('end', function() { | ||
//TODO: try, catch? | ||
const regexMatch = data.match(regexp); | ||
// The first item (0) will be at the top and will be the default branch | ||
resolve(regexMatch[0].split('>')[1].split('<')[0]); | ||
try { | ||
const regexMatch = data.match(regexp); | ||
// The first item (0) will be at the top and will be the default branch | ||
resolve(regexMatch[0].split('>')[1].split('<')[0]); | ||
} catch (err) { | ||
reject(new Error('Failed to get default branch: ' + err)); | ||
return; | ||
} | ||
}); | ||
@@ -36,6 +45,2 @@ }).on('error', (error) => { | ||
}); | ||
} | ||
module.exports = path => { | ||
return getDefaultBranch(path); | ||
}; |
{ | ||
"name": "default-branch", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Get the default branch of a GitHub repository", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -28,3 +28,7 @@ # default-branch | ||
## Related | ||
- [has-license](https://github.com/Knutakir/has-license) - Check if a repository has a license | ||
- [gh-repo-has-license](https://github.com/Knutakir/gh-repo-has-license) - Check if a GitHub repository has a license | ||
## License | ||
MIT © [Knut Kirkhorn](LICENSE) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5066
5
36
34