-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathgetStatus.ts
More file actions
59 lines (50 loc) · 1.8 KB
/
getStatus.ts
File metadata and controls
59 lines (50 loc) · 1.8 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
import axios from "axios";
import { getConnection } from "./shared/auth.js";
export interface StatusResult {
requestId: string;
status: string;
recordId?: string;
message: string;
}
export async function fetchStatus(username: string, requestId: string): Promise<StatusResult> {
if (!username || username.trim().length === 0) {
throw new Error('Username is required. Please provide the DevOps Center org username.');
}
const connection = await getConnection(username);
const accessToken = connection.accessToken;
const instanceUrl = connection.instanceUrl;
if (!accessToken || !instanceUrl) {
throw new Error('Missing access token or instance URL. Please check if you are authenticated to the org.');
}
if (!requestId || requestId.trim().length === 0) {
throw new Error('Request ID is required to check status.');
}
const soqlQuery = `SELECT Status FROM DevopsRequestInfo WHERE RequestToken = '${requestId}'`;
const encodedQuery = encodeURIComponent(soqlQuery);
const url = `${instanceUrl}/services/data/v65.0/query/?q=${encodedQuery}`;
const headers = {
'Authorization': `Bearer ${accessToken}`,
'Content-Type': 'application/json'
};
try {
const response = await axios.get(url, { headers });
const records = response.data.records || [];
if (records.length === 0) {
return {
requestId,
status: 'NOT_FOUND',
message: `No status found for request ID: ${requestId}`
};
}
const status = records[0].Status;
return {
requestId,
status,
recordId: records[0].Id,
message: `Status for request ID ${requestId}: ${status}`
};
} catch (error: any) {
const errorMessage = error.response?.data?.[0]?.message || error.message;
throw new Error(`Error checking status: ${errorMessage}`);
}
}