@atomist/sdm-pack-aspect
Version:
an Atomist SDM Extension Pack for visualizing drift across an organization
106 lines • 5.56 kB
JavaScript
;
/*
* Copyright © 2019 Atomist, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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 automation_client_1 = require("@atomist/automation-client");
const configuration_1 = require("@atomist/automation-client/lib/configuration");
const StableDirectoryManager_1 = require("@atomist/automation-client/lib/spi/clone/StableDirectoryManager");
const tmpDirectoryManager_1 = require("@atomist/automation-client/lib/spi/clone/tmpDirectoryManager");
const _ = require("lodash");
const pgClientFactory_1 = require("../persist/pgClientFactory");
const PostgresProjectAnalysisResultStore_1 = require("../persist/PostgresProjectAnalysisResultStore");
const common_1 = require("./common");
const GitCommandGitProjectCloner_1 = require("./github/GitCommandGitProjectCloner");
const GitHubSpider_1 = require("./github/GitHubSpider");
const LocalSpider_1 = require("./local/LocalSpider");
/**
* Spider a GitHub.com org
*/
function spider(params, analyzer, analysisTracking) {
return __awaiter(this, void 0, void 0, function* () {
const { search, workspaceId } = params;
const org = params.owner;
const searchInRepoName = search ? ` ${search} in:name` : "";
const spiderYo = params.source === "GitHub" ?
new GitHubSpider_1.GitHubSpider(params.cloneUnder ?
new GitCommandGitProjectCloner_1.GitCommandGitProjectCloner(new StableDirectoryManager_1.StableDirectoryManager({
baseDir: params.cloneUnder,
cleanOnExit: false,
// Use previous clones if possible
reuseDirectories: true,
})) :
new GitCommandGitProjectCloner_1.GitCommandGitProjectCloner(tmpDirectoryManager_1.TmpDirectoryManager)) :
new LocalSpider_1.LocalSpider(params.localDirectory);
const persister = new PostgresProjectAnalysisResultStore_1.PostgresProjectAnalysisResultStore(pgClientFactory_1.sdmConfigClientFactory(configuration_1.loadUserConfiguration()));
const query = params.query || `org:${org}` + searchInRepoName;
const criteria = {
// See the GitHub search API documentation at
// https://developer.github.com/v3/search/
// You can query for many other things here, beyond org
githubQueries: [query],
maxRetrieved: 1500,
maxReturned: 1500,
projectTest: (p) => __awaiter(this, void 0, void 0, function* () {
// You can also perform a computation here to return false if a project should not
// be analyzed and persisted, based on its contents. For example,
// this enables you to analyze only projects containing a particular file
// through calling getFile()
return true;
}),
};
const arr = new Array(JSON.stringify(criteria).length + 20);
_.fill(arr, "-");
const sep = arr.join("");
automation_client_1.logger.debug("%s\nOptions: %j\nSpider criteria: %j\n%s\n", sep, params, criteria, sep);
let keepExistingPersisted = neverKeepExisting; // default
if (params.update !== undefined && params.update !== null) { // parameter is defined
keepExistingPersisted = params.update ? neverKeepExisting : alwaysKeepExisting;
}
return spiderYo.spider(criteria, analyzer, analysisTracking, {
persister,
keepExistingPersisted,
// Controls promise usage in Node
poolSize: params.poolSize || common_1.DefaultPoolSize,
workspaceId,
});
});
}
exports.spider = spider;
function alwaysKeepExisting(existing) {
return __awaiter(this, void 0, void 0, function* () {
if (!existing || !existing.analysis) {
return false;
}
automation_client_1.logger.debug(`Retaining existing analysis for ${existing.analysis.id.url}:${existing.analysis.id.sha}`);
return true;
});
}
function neverKeepExisting(existing) {
return __awaiter(this, void 0, void 0, function* () {
automation_client_1.logger.debug(`Computing analysis for ${existing.analysis.id.url}:${existing.analysis.id.sha}`);
return false;
});
}
//# sourceMappingURL=spiderCall.js.map