Skip to content

Instantly share code, notes, and snippets.

@3stacks 3stacks/argus-test.js
Last active Dec 14, 2016

Embed
What would you like to do?
Automating Argus Eyes
'use strict';
const Git = require("nodegit");
const shell = require('shelljs');
const colors = require('colors');
const pathToRepo = require("path").resolve("./.git");
// This will be set to the name of our feature branch
let featureBranch;
/**
* @param {string} path - path to the repository (.git)
* @returns {Promise}
*/
function openRepository(path) {
return Git.Repository.open(path);
}
/**
* @param {Repository} repo - The reference to the repository object
* @returns {Promise}
*/
function getBranchName(repo) {
return repo.getCurrentBranch();
}
/**
* @param {Repository} repo - The reference to the repository object
* @param {string} branchName - The name of the branch to clone
* @returns {Promise}
*/
function switchBranch(repo, branchName) {
return repo.checkoutBranch(branchName);
}
function init() {
// Delete the .argus-eyes directory if it exists
shell.rm('-r', '.argus-eyes');
// Initialise the repository
openRepository(pathToRepo).then(repo => {
console.log('Ensure you have committed or stashed any outstanding changes'.bgRed);
// set featureBranch var to the name of the current branch
getBranchName(repo).then(reference => {
// set featureBranch variable
featureBranch = reference.name();
console.log(colors.bgGreen('current branch is: ' + featureBranch));
console.log('capturing feature branch'.bgRed);
shell.exec('node node_modules/argus-eyes/bin/argus-eyes.js capture ' + featureBranch);
console.log('switching to develop'.bgGreen);
switchBranch(repo, 'test').then(
() => {
console.log('switched to develop'.bgGreen);
console.log('capturing develop branch'.bgRed);
// Capture the develop branch (synchronous)
shell.exec('node node_modules/argus-eyes/bin/argus-eyes.js capture develop');
console.log('comparing branches'.bgRed);
// Compare the develop branch with feature branch
shell.exec('node node_modules/argus-eyes/bin/argus-eyes.js compare develop ' + featureBranch);
},
error => {
console.error(error);
}
)
});
});
}
init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.