1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | import {
|
18 | Configuration,
|
19 | HandlerContext,
|
20 | } from "@atomist/automation-client";
|
21 | import {
|
22 | ProgressLog,
|
23 | SdmGoalEvent,
|
24 | } from "@atomist/sdm";
|
25 | import * as _ from "lodash";
|
26 | import { RolarProgressLog } from "./RolarProgressLog";
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | export 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 |
|
72 | export 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 | }
|