UNPKG

@atomist/sdm-pack-aspect

Version:

an Atomist SDM Extension Pack for visualizing drift across an organization

92 lines 5.01 kB
"use strict"; /* * 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) { 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) : new P(function (resolve) { resolve(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 machine_1 = require("../../../machine/machine"); const PostgresProjectAnalysisResultStore_1 = require("../persist/PostgresProjectAnalysisResultStore"); 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) { 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(machine_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); return spiderYo.spider(criteria, analyzer, { persister, keepExistingPersisted: (existing) => __awaiter(this, void 0, void 0, function* () { // Perform a computation here to return true if an existing analysis seems valid const keep = !params.update; automation_client_1.logger.debug(keep ? `Retaining existing analysis for ${existing.analysis.id.url}:${existing.analysis.id.sha}` : `Recomputing analysis for ${existing.analysis.id.url}:${existing.analysis.id.sha}`); return keep; }), // Controls promise usage in Node poolSize: 40, workspaceId, }); }); } exports.spider = spider; //# sourceMappingURL=spiderCall.js.map