-
-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathRestClient.tsx
More file actions
105 lines (97 loc) · 2.51 KB
/
RestClient.tsx
File metadata and controls
105 lines (97 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import {
Result,
StageInfo,
} from "../pipeline-graph-view/pipeline-graph/main/PipelineGraphModel.tsx";
import { ResourceBundle } from "./i18n/messages.ts";
export interface RunStatus {
stages: StageInfo[];
complete: boolean;
}
/**
* StageInfo is the input, in the form of an Array<StageInfo> of the top-level stages of a pipeline
*/
export interface StepInfo {
name: string;
title: string;
state: Result;
completePercent: number;
id: string;
type: string;
stageId: string;
pauseDurationMillis: number;
startTimeMillis: number;
totalDurationMillis: number;
}
// Internal representation of console log.
export interface StepLogBufferInfo {
lines: string[];
startByte: number;
endByte: number;
}
// Returned from API, gets converted to 'StepLogBufferInfo'.
export interface ConsoleLogData {
text: string;
startByte: number;
endByte: number;
}
export async function getRunStatusFromPath(
url: string,
): Promise<RunStatus | null> {
try {
const response = await fetch(url + "pipeline-console/tree");
if (!response.ok) {
throw response.statusText;
}
const json = await response.json();
return json.data;
} catch (e) {
console.error(`Caught error getting tree: '${e}'`);
return null;
}
}
export async function getRunSteps(): Promise<StepInfo[] | null> {
try {
const response = await fetch("allSteps");
if (!response.ok) throw response.statusText;
const json = await response.json();
return json.data.steps;
} catch (e) {
console.warn(`Caught error getting steps: '${e}'`);
return null;
}
}
export async function getConsoleTextOffset(
stepId: string,
startByte: number,
): Promise<ConsoleLogData | null> {
try {
const response = await fetch(
`consoleOutput?nodeId=${stepId}&startByte=${startByte}`,
);
if (!response.ok) throw response.statusText;
const json = await response.json();
return json.data;
} catch (e) {
console.error(`Caught error when fetching console: '${e}'`);
return null;
}
}
export async function getResourceBundle(
resource: string,
): Promise<ResourceBundle | undefined> {
try {
const baseUrl: string = document.head.dataset.rooturl ?? "";
const response = await fetch(
`${baseUrl}/i18n/resourceBundle?baseName=${resource}`,
);
if (!response.ok) {
throw response.statusText;
}
return (await response.json()).data;
} catch (e) {
console.error(
`Caught error when fetching resource bundle ${resource}: '${e}'`,
);
return undefined;
}
}