UNPKG

@atomist/sdm-pack-aspect

Version:

an Atomist SDM Extension Pack for visualizing drift across an organization

147 lines 7.39 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) { 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 spiderCall_1 = require("./spiderCall"); const AnalyzeCommandParameterDefinitions = { workspaceId: { description: "Atomist workspace ID to save analysis in. Defaults to 'local'", defaultValue: "local", required: false, }, update: { type: "boolean", description: "Overwrite existing analyses? (default is yes)", required: false, }, poolSize: { type: "number", description: "How many analyses to run in parallel", required: false, }, }; const AnalyzeGitHubCommandParametersDefinition = Object.assign(Object.assign({}, AnalyzeCommandParameterDefinitions), { source: { description: "find repositories on GitHub, by organization or query", defaultValue: "GitHub", displayable: false, required: false, pattern: /GitHub/, validInput: "'GitHub'", }, search: { description: "To narrow which repositories within an owner, provide a substring to look for in the repo name", required: false, }, cloneUnder: { description: "A local directory to clone repositories in", required: false, } }); const AnalyzeGitHubOrganizationCommandParametersDefinition = Object.assign(Object.assign({}, AnalyzeGitHubCommandParametersDefinition), { owner: { description: "GitHub owner of repositories to analyze", required: true, } }); const AnalyzeGitHubByQueryCommandParametersDefinition = Object.assign(Object.assign({}, AnalyzeGitHubCommandParametersDefinition), { query: { description: "A GitHub search query to choose repositories", required: true, } }); const AnalyzeLocalCommandParametersDefinition = Object.assign(Object.assign({}, AnalyzeCommandParameterDefinitions), { source: { description: "find repositories on the local filesystem", defaultValue: "local", displayable: false, required: false, pattern: /local/, validInput: "'local'", }, localDirectory: { description: "absolute path to find repositories in", required: true, } }); function analyzeFromGitHubOrganization(analyzer, analysisTracking) { return (d) => __awaiter(this, void 0, void 0, function* () { const spiderAppOptions = d.parameters; automation_client_1.logger.info("analyze github org invoked with " + JSON.stringify(spiderAppOptions)); yield d.addressChannels("Check the progress of your analysis: http://localhost:" + d.configuration.http.port + "/analysis"); const result = yield spiderCall_1.spider(spiderAppOptions, analyzer, analysisTracking); yield d.addressChannels(`Analysis result: ` + JSON.stringify(result, undefined, 2)); return { code: 0 }; }); } function analyzeFromGitHubByQuery(analyzer, analysisTracking) { return (d) => __awaiter(this, void 0, void 0, function* () { const spiderAppOptions = d.parameters; automation_client_1.logger.info("analyze github by query invoked with " + JSON.stringify(spiderAppOptions)); yield d.addressChannels("Check the progress of your analysis: http://localhost:" + d.configuration.http.port + "/analysis"); const result = yield spiderCall_1.spider(spiderAppOptions, analyzer, analysisTracking); yield d.addressChannels(`Analysis result: ` + JSON.stringify(result, undefined, 2)); return { code: 0 }; }); } function analyzeGitHubOrganizationCommandRegistration(analyzer, analysisTracking) { return { name: "analyzeRepositoriesFromGitHubOrganization", intent: ["analyze github organization"], description: "analyze repositories from one GitHub organization (or user)", parameters: AnalyzeGitHubOrganizationCommandParametersDefinition, listener: analyzeFromGitHubOrganization(analyzer, analysisTracking), }; } exports.analyzeGitHubOrganizationCommandRegistration = analyzeGitHubOrganizationCommandRegistration; function analyzeGitHubByQueryCommandRegistration(analyzer, analysisTracking) { return { name: "analyzeRepositoriesFromGitHubByQuery", intent: ["analyze github by query"], description: "choose repositories to analyze by GitHub query", parameters: AnalyzeGitHubByQueryCommandParametersDefinition, listener: analyzeFromGitHubByQuery(analyzer, analysisTracking), }; } exports.analyzeGitHubByQueryCommandRegistration = analyzeGitHubByQueryCommandRegistration; const path = require("path"); function analyzeFromLocal(analyzer, analysisTracking) { return (d) => __awaiter(this, void 0, void 0, function* () { if (!path.isAbsolute(d.parameters.localDirectory)) { yield d.addressChannels("Please provide an absolute path. You provided: " + d.parameters.localDirectory); return { code: 1, error: new Error("Please provide an absolute path") }; } const spiderAppOptions = d.parameters; automation_client_1.logger.info("analyze local invoked with " + JSON.stringify(spiderAppOptions)); yield d.addressChannels("Check the progress of your analysis: http://localhost:" + d.configuration.http.port + "/analysis"); const result = yield spiderCall_1.spider(spiderAppOptions, analyzer, analysisTracking); yield d.addressChannels(`Analysis result: ` + JSON.stringify(result, undefined, 2)); return { code: 0 }; }); } function analyzeLocalCommandRegistration(analyzer, analysisTracking) { return { name: "analyzeRepositoriesFromLocalFilesystem", intent: ["analyze local repositories"], description: "choose repositories to analyze, by parent directory", parameters: AnalyzeLocalCommandParametersDefinition, listener: analyzeFromLocal(analyzer, analysisTracking), }; } exports.analyzeLocalCommandRegistration = analyzeLocalCommandRegistration; //# sourceMappingURL=analyzeCommand.js.map