Skip to content

Commit 265b9b6

Browse files
authored
fix(devops): fix commit status tool issue (salesforcecli#286)
* update commit status logic * Revert "update commit status logic" This reverts commit 0fd2a5a. * fix commit status issue
1 parent 15d0f43 commit 265b9b6

File tree

2 files changed

+49
-23
lines changed

2 files changed

+49
-23
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ export async function commitWorkItem({
113113
.split('\n').map(l => l.trim()).filter(Boolean);
114114
const untrackedRel = execFileSync('git', ['ls-files', '--others', '--exclude-standard'], { cwd: workingDir, encoding: 'utf8' })
115115
.split('\n').map(l => l.trim()).filter(Boolean);
116+
const stagedRel = execFileSync('git', ['diff', '--cached', '--name-only'], { cwd: workingDir, encoding: 'utf8' })
117+
.split('\n').map(l => l.trim()).filter(Boolean);
116118

117119

118120

@@ -135,6 +137,11 @@ export async function commitWorkItem({
135137
if (isModified) operation = 'modify';
136138
}
137139

140+
if (!operation) {
141+
const isStaged = stagedRel.some(p => isMatch(fileName, p));
142+
if (isStaged) operation = 'modify';
143+
}
144+
138145
if (operation && componentType) {
139146
computedChanges.push({ fullName, type: componentType, operation });
140147
}

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

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,51 @@ 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];
25-
return {
26-
requestId,
27-
status: record.Status__c,
28-
recordId: record.Id,
29-
message: `Request ${requestId} has status: ${record.Status__c}`
30-
};
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.');
3126
}
3227

33-
return {
34-
requestId,
35-
status: 'NOT_FOUND',
36-
message: `No record found for request ID: ${requestId}`
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'
3734
};
38-
}
3935

36+
try {
37+
const response = await axios.get(url, { headers });
38+
const records = response.data.records || [];
4039

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;
49+
return {
50+
requestId,
51+
status,
52+
recordId: records[0].Id,
53+
message: `Commit status for request ID ${requestId}: ${status}`
54+
};
55+
} catch (error: any) {
56+
const errorMessage = error.response?.data?.[0]?.message || error.message;
57+
throw new Error(`Error checking commit status: ${errorMessage}`);
58+
}
59+
}

0 commit comments

Comments
 (0)