UNPKG

2.55 kBPlain TextView Raw
1/*
2 * Copyright © 2019 Atomist, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import {
18 Configuration,
19 HandlerContext,
20} from "@atomist/automation-client";
21import {
22 ProgressLog,
23 SdmGoalEvent,
24} from "@atomist/sdm";
25import * as _ from "lodash";
26import { RolarProgressLog } from "./RolarProgressLog";
27
28/**
29 * Persistent Rolar log that displays in the Dashboard
30 */
31export class DashboardDisplayProgressLog implements ProgressLog {
32
33 private readonly rolarProgressLog: RolarProgressLog;
34 private readonly dashboardBaseUrl: string;
35
36 constructor(configuration: Configuration,
37 private readonly context: HandlerContext,
38 private readonly sdmGoal: SdmGoalEvent) {
39 this.dashboardBaseUrl = _.get(configuration, "sdm.rolar.webAppUrl",
40 _.get(configuration, "sdm.dashboard.url", "https://app.atomist.com"));
41 this.rolarProgressLog =
42 new RolarProgressLog(constructLogPath(context, sdmGoal), configuration);
43 }
44
45 get name(): string {
46 return this.rolarProgressLog.name;
47 }
48
49 get url(): string {
50 const path = constructLogPath(this.context, this.sdmGoal);
51 return `${this.dashboardBaseUrl}/workspace/${path[0]}/logs/${path.slice(1).join("/")}`;
52 }
53
54 public async isAvailable(): Promise<boolean> {
55 return this.rolarProgressLog.isAvailable();
56 }
57
58 public write(msg: string, ...args: string[]): void {
59 this.rolarProgressLog.write(msg, ...args);
60 }
61
62 public flush(): Promise<any> {
63 return this.rolarProgressLog.flush();
64 }
65
66 public close(): Promise<any> {
67 return this.rolarProgressLog.close();
68 }
69
70}
71
72export function constructLogPath(context: HandlerContext, sdmGoal: SdmGoalEvent): string[] {
73 return [
74 context.workspaceId,
75 sdmGoal.repo.owner,
76 sdmGoal.repo.name,
77 sdmGoal.sha,
78 sdmGoal.environment,
79 sdmGoal.uniqueName,
80 sdmGoal.goalSetId,
81 context.correlationId,
82 ].map(encodeURIComponent);
83}