Skip to content

Commit 0fd2a5a

Browse files
committed
update commit status logic
1 parent 95bd83f commit 0fd2a5a

File tree

2 files changed

+72
-34
lines changed

2 files changed

+72
-34
lines changed

packages/mcp-provider-devops/src/getCommitStatus.ts

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,52 @@ export interface CommitStatusResult {
99
}
1010

1111
export async function fetchCommitStatus(username: string, requestId: string): Promise<CommitStatusResult> {
12+
if (!username || username.trim().length === 0) {
13+
throw new Error('Username is required. Please provide the DevOps Center org username.');
14+
}
15+
1216
const connection = await getConnection(username);
13-
const query = `SELECT Id, Status__c, RequestToken__c FROM DevopsRequestInfo WHERE RequestToken__c = '${requestId}' LIMIT 1`;
14-
15-
const response = await axios.get(`${connection.instanceUrl}/services/data/v65.0/query`, {
16-
headers: {
17-
'Authorization': `Bearer ${connection.accessToken}`,
18-
'Content-Type': 'application/json'
19-
},
20-
params: { q: query }
21-
});
22-
23-
if (response.data.records && response.data.records.length > 0) {
24-
const record = response.data.records[0];
17+
const accessToken = connection.accessToken;
18+
const instanceUrl = connection.instanceUrl;
19+
20+
if (!accessToken || !instanceUrl) {
21+
throw new Error('Missing access token or instance URL. Please check if you are authenticated to the org.');
22+
}
23+
24+
if (!requestId || requestId.trim().length === 0) {
25+
throw new Error('Request ID is required to check commit status.');
26+
}
27+
28+
const soqlQuery = `SELECT Status FROM DevopsRequestInfo WHERE RequestToken = '${requestId}'`;
29+
const encodedQuery = encodeURIComponent(soqlQuery);
30+
const url = `${instanceUrl}/services/data/v65.0/query/?q=${encodedQuery}`;
31+
const headers = {
32+
'Authorization': `Bearer ${accessToken}`,
33+
'Content-Type': 'application/json'
34+
};
35+
36+
try {
37+
const response = await axios.get(url, { headers });
38+
const records = response.data.records || [];
39+
40+
if (records.length === 0) {
41+
return {
42+
requestId,
43+
status: 'NOT_FOUND',
44+
message: `No commit status found for request ID: ${requestId}`
45+
};
46+
}
47+
48+
const status = records[0].Status;
2549
return {
2650
requestId,
27-
status: record.Status__c,
28-
recordId: record.Id,
29-
message: `Request ${requestId} has status: ${record.Status__c}`
51+
status,
52+
recordId: records[0].Id,
53+
message: `Commit status for request ID ${requestId}: ${status}`
3054
};
55+
} catch (error: any) {
56+
const errorMessage = error.response?.data?.[0]?.message || error.message;
57+
throw new Error(`Error checking commit status: ${errorMessage}`);
3158
}
32-
33-
return {
34-
requestId,
35-
status: 'NOT_FOUND',
36-
message: `No record found for request ID: ${requestId}`
37-
};
3859
}
3960

40-

packages/mcp-provider-devops/src/tools/checkCommitStatus.ts

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,45 @@ export class CheckCommitStatus extends McpTool<InputArgsShape, OutputArgsShape>
3434
public getConfig(): McpToolConfig<InputArgsShape, OutputArgsShape> {
3535
return {
3636
title: "Check Commit Status",
37-
description: `Check the current status of a work item committed to DevOps Center.
37+
description: `Checks the status of a specific commit by querying the "DevopsRequestInfo" Salesforce object using the RequestToken field.
3838
39-
**Use this tool to:**
40-
- Check the status of a specific commit using its Request Id
41-
- Verify commit processing completion before creating a pull request
42-
- Ensure commits are ready for PR creation
39+
**Use this tool to:**
40+
- Check the status of a specific commit using its Request Token
41+
- Verify commit processing completion before creating a pull request
42+
- Ensure commits are ready for PR creation
4343
44-
**Input Parameters:**
45-
- username: The username of the DevOps Center org to authenticate with
46-
- requestId: The specific request Id to check status for (REQUIRED)
44+
**Input Parameters:**
45+
- username: The username of the DevOps Center org to authenticate with
46+
- requestId: The specific request token to check status for (REQUIRED)
4747
48-
**Output:**
49-
- Status field value for the specified request Id
50-
- Request Id and associated status information`,
48+
**Output:**
49+
- Status field value for the specified request token
50+
- Request token and associated status information`,
5151
inputSchema: inputSchema.shape,
5252
outputSchema: undefined,
5353
};
5454
}
5555

5656
public async exec(input: InputArgs): Promise<CallToolResult> {
5757
try {
58+
if (!input.username || input.username.trim().length === 0) {
59+
return {
60+
content: [{
61+
type: "text",
62+
text: `Error: Username is required. Please provide the DevOps Center org username.`
63+
}]
64+
};
65+
}
66+
67+
if (!input.requestId || input.requestId.trim().length === 0) {
68+
return {
69+
content: [{
70+
type: "text",
71+
text: `Error: Request ID is required to check commit status.`
72+
}]
73+
};
74+
}
75+
5876
const status = await fetchCommitStatus(input.username, input.requestId);
5977
return {
6078
content: [{
@@ -66,7 +84,7 @@ export class CheckCommitStatus extends McpTool<InputArgsShape, OutputArgsShape>
6684
return {
6785
content: [{
6886
type: "text",
69-
text: `Failed to check commit status: ${error.message}`
87+
text: `Error checking commit status: ${error.message}`
7088
}],
7189
isError: true
7290
};

0 commit comments

Comments
 (0)