Socket
Socket
Sign inDemoInstall

default-branch

Package Overview
Dependencies
0
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.3 to 1.0.4

.npmignore

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)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc