git-repo-info
Advanced tools
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(); | ||
} |
{ | ||
"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 @@ |
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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 11 instances in 1 package
28
0
8224
3
195