Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

git-repo-info

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

git-repo-info - npm Package Compare versions

Comparing version 1.1.4 to 1.2.0

60

index.js

@@ -128,2 +128,7 @@ 'use strict';

tag: null,
committer: null,
committerDate: null,
author: null,
authorDate: null,
commitMessage: null,
root: null

@@ -164,2 +169,11 @@ };

// Find commit data
var commitData = getCommitData(gitPath, result.sha);
if (commitData) {
result = Object.keys(commitData).reduce(function(r, key) {
result[key] = commitData[key];
return result;
}, result);
}
// Find tag

@@ -185,1 +199,47 @@ var tag = findTag(gitPath, result.sha);

module.exports._changeGitDir = changeGitDir;
function getCommitData(gitPath, sha) {
var objectPath = path.join(gitPath, 'objects', sha.slice(0, 2), sha.slice(2));
if (zlib.inflateSync && fs.existsSync(objectPath)) {
var objectContents = zlib.inflateSync(fs.readFileSync(objectPath)).toString();
return objectContents.split(/\0|\n/)
.filter(function(item) {
return !!item;
})
.reduce(function(data, section) {
var part = section.slice(0, section.indexOf(' ')).trim();
switch(part) {
case 'commit':
case 'tag':
case 'object':
case 'type':
case 'tree':
case 'parent':
//ignore these for now
break;
case 'author':
case 'committer':
var parts = section.match(/^(?:author|committer)\s(.+)\s(\d+\s(?:\+|\-)\d{4})$/);
if (parts) {
data[part] = parts[1];
data[part + 'Date'] = parseDate(parts[2]);
}
break;
default:
//should just be the commit message left
data.commitMessage = section;
}
return data;
}, {});
}
}
function parseDate(d) {
var epoch = d.split(' ')[0];
return new Date(epoch * 1000).toISOString();
}

5

package.json
{
"name": "git-repo-info",
"version": "1.1.4",
"version": "1.2.0",
"description": "Retrieve current sha and branch name from a git repo.",
"main": "index.js",
"files": [
"index.js"
],
"scripts": {

@@ -7,0 +10,0 @@ "test": "mocha tests",

@@ -16,2 +16,7 @@ ## git-repo-info

info.tag //=> will be the tag for the current sha (or `null` if no tag exists)
info.committer //=> will be the committer for the current sha
info.committerDate //=> will be the commit date for the current sha
info.author //=> will be the author for the current sha
info.authorDate //=> will be the authored date for the current sha
info.commitMessage //=> will be the commit message for the current sha
```

@@ -18,0 +23,0 @@

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc