UNPKG

@atomist/sdm-pack-fingerprints

Version:

an Atomist SDM Extension Pack for fingerprinting code

157 lines 7.91 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 __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; 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 clj_editors_1 = require("@atomist/clj-editors"); const sdm_1 = require("@atomist/sdm"); const fingerprints_1 = require("../../adhoc/fingerprints"); const preferences_1 = require("../../adhoc/preferences"); const util_1 = require("../../support/util"); let ListFingerprintParameters = class ListFingerprintParameters { }; __decorate([ automation_client_1.MappedParameter(automation_client_1.MappedParameters.GitHubOwner), __metadata("design:type", String) ], ListFingerprintParameters.prototype, "owner", void 0); __decorate([ automation_client_1.MappedParameter(automation_client_1.MappedParameters.GitHubRepository), __metadata("design:type", String) ], ListFingerprintParameters.prototype, "repo", void 0); __decorate([ automation_client_1.MappedParameter(automation_client_1.MappedParameters.GitHubRepositoryProvider), __metadata("design:type", String) ], ListFingerprintParameters.prototype, "providerId", void 0); __decorate([ automation_client_1.Parameter({ required: false, description: "pull fingerprints from a branch ref" }), __metadata("design:type", String) ], ListFingerprintParameters.prototype, "branch", void 0); ListFingerprintParameters = __decorate([ automation_client_1.Parameters() ], ListFingerprintParameters); exports.ListFingerprintParameters = ListFingerprintParameters; let ListOneFingerprintParameters = class ListOneFingerprintParameters { }; __decorate([ automation_client_1.MappedParameter(automation_client_1.MappedParameters.GitHubOwner), __metadata("design:type", String) ], ListOneFingerprintParameters.prototype, "owner", void 0); __decorate([ automation_client_1.MappedParameter(automation_client_1.MappedParameters.GitHubRepository), __metadata("design:type", String) ], ListOneFingerprintParameters.prototype, "repo", void 0); __decorate([ automation_client_1.MappedParameter(automation_client_1.MappedParameters.GitHubRepositoryProvider), __metadata("design:type", String) ], ListOneFingerprintParameters.prototype, "providerId", void 0); __decorate([ automation_client_1.Parameter({ required: true, description: "pull fingerprints from a branch ref" }), __metadata("design:type", String) ], ListOneFingerprintParameters.prototype, "branch", void 0); __decorate([ automation_client_1.Parameter({ required: true, description: "the fingerprint to render" }), __metadata("design:type", String) ], ListOneFingerprintParameters.prototype, "fingerprint", void 0); ListOneFingerprintParameters = __decorate([ automation_client_1.Parameters() ], ListOneFingerprintParameters); exports.ListOneFingerprintParameters = ListOneFingerprintParameters; function listFingerprint(sdm) { return { name: "ListFingerprint", description: "list one fingerprint", paramsMaker: ListOneFingerprintParameters, listener: (cli) => __awaiter(this, void 0, void 0, function* () { const fps = yield fingerprints_1.queryFingerprintsByBranchRef(cli.context.graphClient)(cli.parameters.repo, cli.parameters.owner, cli.parameters.branch); const { type, name } = preferences_1.fromName(cli.parameters.fingerprint); automation_client_1.logger.info(`searching for ${type} and ${name}`); automation_client_1.logger.info(`choose from ${JSON.stringify(fps)}`); const fingerprint = fps.find(x => x.name === name && x.type === type); fingerprint.data = JSON.parse(fingerprint.data); const message = { title: `fingerprint ${cli.parameters.fingerprint} currently on ${cli.parameters.owner}/${cli.parameters.repo}`, content: clj_editors_1.renderData(fingerprint), fileType: "text", }; return cli.addressChannels(message); }), }; } exports.listFingerprint = listFingerprint; function shortenName(s) { if (s.length >= 30) { return "..." + s.substring(s.length - 27); } else { return s; } } function listFingerprints(sdm) { return { name: "ListFingerprints", intent: [ `list fingerprints ${sdm.configuration.name.replace("@", "")}`, `listFingerprints ${sdm.configuration.name.replace("@", "")}`, ], description: "list the fingerprints on a particular ref", paramsMaker: ListFingerprintParameters, listener: (cli) => __awaiter(this, void 0, void 0, function* () { // this has got to be wrong. ugh const branch = cli.parameters.branch || "master"; const fps = yield fingerprints_1.queryFingerprintsByBranchRef(cli.context.graphClient)(cli.parameters.repo, cli.parameters.owner, branch); const message = sdm_1.slackQuestionMessage("Fingerprint Target", `Choose a fingerprint`, { actions: [ automation_client_1.menuForCommand({ text: "select fingerprint", options: [ ...fps.sort(util_1.comparator("name")).map(x => { return { value: preferences_1.toName(x.type, x.name), text: shortenName(x.name), }; }), ], }, listFingerprint(sdm).name, "fingerprint", { owner: cli.parameters.owner, repo: cli.parameters.repo, branch, providerId: cli.parameters.providerId, }), ], }); return cli.addressChannels(message); }), }; } exports.listFingerprints = listFingerprints; //# sourceMappingURL=list.js.map