@atomist/automation-client
Version:
Atomist API for software low-level client
40 lines • 1.91 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const _ = require("lodash");
const GitHubRepoRef_1 = require("../../operations/common/GitHubRepoRef");
const GitCommandGitProject_1 = require("../git/GitCommandGitProject");
/**
* Extracts fingerprints, diffs them, and invokes actions on Github shas that are being compared
*/
class DifferenceEngine {
constructor(githubIssueAuth, chains) {
this.githubIssueAuth = githubIssueAuth;
this.chains = chains;
}
/**
* Run configured diff chains for these shas
* @param baseSha
* @param headSha
*/
run(baseSha, headSha) {
const baseProjectPromise = this.cloneRepo(this.githubIssueAuth, baseSha);
baseProjectPromise.then(project => {
const baseFingerprintPromises = _.map(this.chains, c => c.extractor.extract(project));
Promise.all(baseFingerprintPromises).then(baseFps => {
const headProjectCheckout = project.checkout(headSha);
headProjectCheckout.then(headProjectCheckoutSuccess => {
const headFingerprintPromises = _.map(this.chains, c => c.extractor.extract(project));
Promise.all(headFingerprintPromises).then(headFps => {
const diffs = this.chains.map((c, i) => c.differ.diff(baseFps[i], headFps[i]));
diffs.map((d, i) => this.chains[i].actions.forEach(a => a.invoke(baseFps[i], headFps[i], d)));
});
});
});
});
}
cloneRepo(githubIssueAuth, sha) {
return GitCommandGitProject_1.GitCommandGitProject.cloned({ token: githubIssueAuth.githubToken }, new GitHubRepoRef_1.GitHubRepoRef(githubIssueAuth.owner, githubIssueAuth.repo, githubIssueAuth.sha));
}
}
exports.DifferenceEngine = DifferenceEngine;
//# sourceMappingURL=DifferenceEngine.js.map