aboutsummaryrefslogtreecommitdiff
path: root/lib/fetchGitData.js
diff options
context:
space:
mode:
authorNick Merwin <[email protected]>2019-11-20 17:05:48 -0800
committerGitHub <[email protected]>2019-11-20 17:05:48 -0800
commit336123fe05e7f80d79fc8522b4ff21a60fffe77c (patch)
tree97e5b9343471fc73ddf4ffb20cd71ca58367d6c6 /lib/fetchGitData.js
parenteba01a29c69f28ffd7f50556492a43b5ba2486d7 (diff)
downloadnode-coveralls-336123fe05e7f80d79fc8522b4ff21a60fffe77c.tar.xz
node-coveralls-336123fe05e7f80d79fc8522b4ff21a60fffe77c.zip
ES6
* remove unused variables * move `require`s at the top * check for prototype built-ins * run in strict mode * always check for error values in tests * make style consistent * mark Node.js 6 as the minimum supported version in package.json * Use the arrow return syntax * logger.js: use `Boolean` to make the intention clearer. * Use the rest params instead of arguments. * test/getOptions.js: beautify git data. * Update logger.js Remove `hasDebugEnvVariable` function; it's just a `process.env` check * Create .jshintrc
Diffstat (limited to 'lib/fetchGitData.js')
-rw-r--r--lib/fetchGitData.js84
1 files changed, 48 insertions, 36 deletions
diff --git a/lib/fetchGitData.js b/lib/fetchGitData.js
index f04720e..ee69246 100644
--- a/lib/fetchGitData.js
+++ b/lib/fetchGitData.js
@@ -1,47 +1,53 @@
-var exec = require('child_process').exec;
-var logger = require('./logger')();
+'use strict';
+
+const { exec } = require('child_process');
+require('./logger')();
function fetchGitData(git, cb) {
- if (!cb){
- throw new Error("fetchGitData requires a callback");
+ if (!cb) {
+ throw new Error('fetchGitData requires a callback');
}
//-- Malformed/undefined git object
- if ('undefined' === typeof git) {
+ if (typeof git === 'undefined') {
return cb(new Error('No options passed'));
}
- if (!git.hasOwnProperty('head')) {
+
+ if (!Object.prototype.hasOwnProperty.call(git, 'head')) {
return cb(new Error('You must provide the head'));
}
- if (!git.head.hasOwnProperty('id')) {
+
+ if (!Object.prototype.hasOwnProperty.call(git.head, 'id')) {
return cb(new Error('You must provide the head.id'));
}
//-- Set required properties of git if they weren"t provided
- if (!git.hasOwnProperty("branch")) {
- git.branch = "";
+ if (!Object.prototype.hasOwnProperty.call(git, 'branch')) {
+ git.branch = '';
}
- if (!git.hasOwnProperty("remotes")) {
+
+ if (!Object.prototype.hasOwnProperty.call(git, 'remotes')) {
git.remotes = [];
}
//-- Assert the property types
- if ("string" !== typeof git.branch) {
- git.branch = "";
+ if (typeof git.branch !== 'string') {
+ git.branch = '';
}
- if (!(git.remotes instanceof Array)) {
+
+ if (!(Array.isArray(git.remotes))) {
git.remotes = [];
}
//-- Use git?
- exec("git rev-parse --verify " + git.head.id, function(err, response){
- if (err){
+ exec(`git rev-parse --verify ${git.head.id}`, err => {
+ if (err) {
// git is not available...
- git.head.author_name = git.head.author_name || "Unknown Author";
- git.head.author_email = git.head.author_email || "";
- git.head.committer_name = git.head.committer_name || "Unknown Committer";
- git.head.committer_email = git.head.committer_email || "";
- git.head.message = git.head.message || "Unknown Commit Message";
+ git.head.author_name = git.head.author_name || 'Unknown Author';
+ git.head.author_email = git.head.author_email || '';
+ git.head.committer_name = git.head.committer_name || 'Unknown Committer';
+ git.head.committer_email = git.head.committer_email || '';
+ git.head.message = git.head.message || 'Unknown Commit Message';
return cb(null, git);
}
@@ -50,25 +56,27 @@ function fetchGitData(git, cb) {
}
function fetchBranch(git, cb) {
- exec("git branch", function(err, branches){
- if (err)
+ exec('git branch', (err, branches) => {
+ if (err) {
return cb(err);
+ }
git.branch = (branches.match(/^\* (\w+)/) || [])[1];
fetchRemotes(git, cb);
});
}
-var REGEX_COMMIT_DETAILS = /\nauthor (.+?) <([^>]*)>.+\ncommitter (.+?) <([^>]*)>.+[\S\s]*?\n\n(.*)/m;
+const REGEX_COMMIT_DETAILS = /\nauthor (.+?) <([^>]*)>.+\ncommitter (.+?) <([^>]*)>.+[\S\s]*?\n\n(.*)/m;
function fetchHeadDetails(git, cb) {
- exec('git cat-file -p ' + git.head.id, function(err, response) {
- if (err)
+ exec(`git cat-file -p ${git.head.id}`, (err, response) => {
+ if (err) {
return cb(err);
+ }
- var items = response.match(REGEX_COMMIT_DETAILS).slice(1);
- var fields = ['author_name', 'author_email', 'committer_name', 'committer_email', 'message'];
- fields.forEach(function(field, index) {
+ const items = response.match(REGEX_COMMIT_DETAILS).slice(1);
+ const fields = ['author_name', 'author_email', 'committer_name', 'committer_email', 'message'];
+ fields.forEach((field, index) => {
git.head[field] = items[index];
});
@@ -81,14 +89,17 @@ function fetchHeadDetails(git, cb) {
}
function fetchRemotes(git, cb) {
- exec("git remote -v", function(err, remotes){
- if (err)
+ exec('git remote -v', (err, remotes) => {
+ if (err) {
return cb(err);
+ }
- var processed = {};
- remotes.split("\n").forEach(function(remote) {
- if (!/\s\(push\)$/.test(remote))
+ const processed = {};
+ remotes.split('\n').forEach(remote => {
+ if (!/\s\(push\)$/.test(remote)) {
return;
+ }
+
remote = remote.split(/\s+/);
saveRemote(processed, git, remote[0], remote[1]);
});
@@ -97,12 +108,13 @@ function fetchRemotes(git, cb) {
}
function saveRemote(processed, git, name, url) {
- var key = name + "-" + url;
- if (processed.hasOwnProperty(key))
+ const key = `${name}-${url}`;
+ if (Object.prototype.hasOwnProperty.call(processed, key)) {
return;
+ }
processed[key] = true;
- git.remotes.push({ name: name, url: url });
+ git.remotes.push({ name, url });
}
module.exports = fetchGitData;