@atomist/automation-client
Version:
Atomist API for software low-level client
42 lines • 2.24 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
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) {
return __awaiter(this, void 0, void 0, function* () {
const project = yield this.cloneRepo(this.githubIssueAuth, baseSha);
const baseFps = yield Promise.all(this.chains.map(c => c.extractor.extract(project)));
yield project.checkout(headSha);
const headFps = yield Promise.all(this.chains.map(c => c.extractor.extract(project)));
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