UNPKG

@atomist/org-visualizer

Version:

Organization Visualizer using Atomist project scanning

144 lines 7.06 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 sdm_1 = require("@atomist/sdm"); const sdm_pack_fingerprints_1 = require("@atomist/sdm-pack-fingerprints"); const runner_1 = require("@atomist/sdm-pack-fingerprints/lib/machine/runner"); const _ = require("lodash"); function calculateFingerprintTask(fingerprinters, handlers) { return { name: "CalculateFingerprintTask", description: "Trigger calculation of fingerprints on the provided repository", parameters: { providerId: { description: "Id of the SCMProvider" }, repoId: { description: "Id of the Repo" }, owner: { uri: automation_client_1.MappedParameters.GitHubOwner, declarationType: sdm_1.DeclarationType.Mapped }, name: { uri: automation_client_1.MappedParameters.GitHubRepository, declarationType: sdm_1.DeclarationType.Mapped }, branch: { description: "Name of the branch" }, }, listener: (ci) => __awaiter(this, void 0, void 0, function* () { const provider = _.get(yield ci.context.graphClient.query({ name: "ScmProviderById", variables: { providerId: ci.parameters.providerId, }, options: automation_client_1.QueryNoCacheOptions, }), "SCMProvider[0]"); const app = _.get(yield ci.context.graphClient.query({ name: "GitHubAppInstallationByOwner", variables: { name: ci.parameters.owner, }, options: automation_client_1.QueryNoCacheOptions, }), "GitHubAppInstallation[0]"); const token = _.get(provider, "credential.secret") || _.get(app, "token.secret"); if (!token) { return; } const id = automation_client_1.GitHubRepoRef.from({ owner: ci.parameters.owner, repo: ci.parameters.name, branch: ci.parameters.branch, rawApiBase: provider.apiUrl, }); const credentials = { token }; yield ci.configuration.sdm.projectLoader.doWithProject(Object.assign({}, ci, { id, credentials }), (p) => __awaiter(this, void 0, void 0, function* () { if (sdm_1.isLazyProjectLoader(ci.configuration.sdm.projectLoader)) { yield p.materialize(); } // git rev-parse HEAD = sha const sha = (yield sdm_1.execPromise("git", ["rev-parse", "HEAD"], { cwd: p.baseDir })).stdout.trim(); // const author = (await execPromise("git", ["show", "-s", "--format=%an"], { cwd: p.baseDir })).stdout.trim(); const email = (yield sdm_1.execPromise("git", ["show", "-s", "--format=%ae"], { cwd: p.baseDir })).stdout.trim(); const ts = (yield sdm_1.execPromise("git", ["show", "-s", "--format=%at"], { cwd: p.baseDir })).stdout.trim(); const message = (yield sdm_1.execPromise("git", ["show", "-s", "--format=%B"], { cwd: p.baseDir })).stdout.trim(); // Ingest initial commit const commit = { repoId: ci.parameters.repoId, branchName: ci.parameters.branch, timestamp: new Date(+ts * 1000).toISOString(), email: { address: email, }, sha, message, }; yield ci.context.graphClient.mutate({ name: "IngestScmCommit", variables: { providerId: provider.id, commit, }, }); // Run the fingerprint code const pi = { context: ci.context, configuration: ci.configuration, project: p, addressChannels: ci.addressChannels, preferences: ci.preferences, credentials: ci.credentials, id, impactedSubProject: p, filesChanged: undefined, commit: { sha, message, }, push: { repo: { defaultBranch: ci.parameters.branch, channels: [], name: ci.parameters.name, owner: ci.parameters.owner, org: { owner: ci.parameters.owner, provider: { apiUrl: provider.apiUrl, providerId: ci.parameters.providerId, providerType: sdm_1.ProviderType.github_com, }, }, }, after: { sha, message, }, commits: [{ sha, message, }], branch: ci.parameters.branch, timestamp: ts, }, }; yield sdm_pack_fingerprints_1.fingerprintRunner(fingerprinters, handlers, runner_1.computeFingerprints)(pi); })); }), }; } exports.calculateFingerprintTask = calculateFingerprintTask; //# sourceMappingURL=fingerprintTask.js.map