From 0fd2a5a2303f9bdaa7776e1f13d71726681b3ddc Mon Sep 17 00:00:00 2001 From: manan-dey Date: Mon, 6 Oct 2025 12:59:24 +0530 Subject: [PATCH 1/3] update commit status logic --- .../src/getCommitStatus.ts | 64 ++++++++++++------- .../src/tools/checkCommitStatus.ts | 42 ++++++++---- 2 files changed, 72 insertions(+), 34 deletions(-) diff --git a/packages/mcp-provider-devops/src/getCommitStatus.ts b/packages/mcp-provider-devops/src/getCommitStatus.ts index 7b3a78dd..a80a96c4 100644 --- a/packages/mcp-provider-devops/src/getCommitStatus.ts +++ b/packages/mcp-provider-devops/src/getCommitStatus.ts @@ -9,32 +9,52 @@ export interface CommitStatusResult { } export async function fetchCommitStatus(username: string, requestId: string): Promise { + 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 query = `SELECT Id, Status__c, RequestToken__c FROM DevopsRequestInfo WHERE RequestToken__c = '${requestId}' LIMIT 1`; - - const response = await axios.get(`${connection.instanceUrl}/services/data/v65.0/query`, { - headers: { - 'Authorization': `Bearer ${connection.accessToken}`, - 'Content-Type': 'application/json' - }, - params: { q: query } - }); - - if (response.data.records && response.data.records.length > 0) { - const record = response.data.records[0]; + 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 commit 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 commit status found for request ID: ${requestId}` + }; + } + + const status = records[0].Status; return { requestId, - status: record.Status__c, - recordId: record.Id, - message: `Request ${requestId} has status: ${record.Status__c}` + status, + recordId: records[0].Id, + message: `Commit status for request ID ${requestId}: ${status}` }; + } catch (error: any) { + const errorMessage = error.response?.data?.[0]?.message || error.message; + throw new Error(`Error checking commit status: ${errorMessage}`); } - - return { - requestId, - status: 'NOT_FOUND', - message: `No record found for request ID: ${requestId}` - }; } - diff --git a/packages/mcp-provider-devops/src/tools/checkCommitStatus.ts b/packages/mcp-provider-devops/src/tools/checkCommitStatus.ts index 8b939b95..3edacf8e 100644 --- a/packages/mcp-provider-devops/src/tools/checkCommitStatus.ts +++ b/packages/mcp-provider-devops/src/tools/checkCommitStatus.ts @@ -34,20 +34,20 @@ export class CheckCommitStatus extends McpTool public getConfig(): McpToolConfig { return { title: "Check Commit Status", - description: `Check the current status of a work item committed to DevOps Center. + description: `Checks the status of a specific commit by querying the "DevopsRequestInfo" Salesforce object using the RequestToken field. - **Use this tool to:** - - Check the status of a specific commit using its Request Id - - Verify commit processing completion before creating a pull request - - Ensure commits are ready for PR creation +**Use this tool to:** +- Check the status of a specific commit using its Request Token +- Verify commit processing completion before creating a pull request +- Ensure commits are ready for PR creation - **Input Parameters:** - - username: The username of the DevOps Center org to authenticate with - - requestId: The specific request Id to check status for (REQUIRED) +**Input Parameters:** +- username: The username of the DevOps Center org to authenticate with +- requestId: The specific request token to check status for (REQUIRED) - **Output:** - - Status field value for the specified request Id - - Request Id and associated status information`, +**Output:** +- Status field value for the specified request token +- Request token and associated status information`, inputSchema: inputSchema.shape, outputSchema: undefined, }; @@ -55,6 +55,24 @@ export class CheckCommitStatus extends McpTool public async exec(input: InputArgs): Promise { try { + if (!input.username || input.username.trim().length === 0) { + return { + content: [{ + type: "text", + text: `Error: Username is required. Please provide the DevOps Center org username.` + }] + }; + } + + if (!input.requestId || input.requestId.trim().length === 0) { + return { + content: [{ + type: "text", + text: `Error: Request ID is required to check commit status.` + }] + }; + } + const status = await fetchCommitStatus(input.username, input.requestId); return { content: [{ @@ -66,7 +84,7 @@ export class CheckCommitStatus extends McpTool return { content: [{ type: "text", - text: `Failed to check commit status: ${error.message}` + text: `Error checking commit status: ${error.message}` }], isError: true }; From 0b0f39f022da07387e248ff030ea2d9948d7adbe Mon Sep 17 00:00:00 2001 From: manan-dey Date: Mon, 6 Oct 2025 13:40:07 +0530 Subject: [PATCH 2/3] Revert "update commit status logic" This reverts commit 0fd2a5a2303f9bdaa7776e1f13d71726681b3ddc. --- .../src/getCommitStatus.ts | 64 +++++++------------ .../src/tools/checkCommitStatus.ts | 42 ++++-------- 2 files changed, 34 insertions(+), 72 deletions(-) diff --git a/packages/mcp-provider-devops/src/getCommitStatus.ts b/packages/mcp-provider-devops/src/getCommitStatus.ts index a80a96c4..7b3a78dd 100644 --- a/packages/mcp-provider-devops/src/getCommitStatus.ts +++ b/packages/mcp-provider-devops/src/getCommitStatus.ts @@ -9,52 +9,32 @@ export interface CommitStatusResult { } export async function fetchCommitStatus(username: string, requestId: string): Promise { - 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 commit 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 commit status found for request ID: ${requestId}` - }; - } - - const status = records[0].Status; + const query = `SELECT Id, Status__c, RequestToken__c FROM DevopsRequestInfo WHERE RequestToken__c = '${requestId}' LIMIT 1`; + + const response = await axios.get(`${connection.instanceUrl}/services/data/v65.0/query`, { + headers: { + 'Authorization': `Bearer ${connection.accessToken}`, + 'Content-Type': 'application/json' + }, + params: { q: query } + }); + + if (response.data.records && response.data.records.length > 0) { + const record = response.data.records[0]; return { requestId, - status, - recordId: records[0].Id, - message: `Commit status for request ID ${requestId}: ${status}` + status: record.Status__c, + recordId: record.Id, + message: `Request ${requestId} has status: ${record.Status__c}` }; - } catch (error: any) { - const errorMessage = error.response?.data?.[0]?.message || error.message; - throw new Error(`Error checking commit status: ${errorMessage}`); } + + return { + requestId, + status: 'NOT_FOUND', + message: `No record found for request ID: ${requestId}` + }; } + diff --git a/packages/mcp-provider-devops/src/tools/checkCommitStatus.ts b/packages/mcp-provider-devops/src/tools/checkCommitStatus.ts index 3edacf8e..8b939b95 100644 --- a/packages/mcp-provider-devops/src/tools/checkCommitStatus.ts +++ b/packages/mcp-provider-devops/src/tools/checkCommitStatus.ts @@ -34,20 +34,20 @@ export class CheckCommitStatus extends McpTool public getConfig(): McpToolConfig { return { title: "Check Commit Status", - description: `Checks the status of a specific commit by querying the "DevopsRequestInfo" Salesforce object using the RequestToken field. + description: `Check the current status of a work item committed to DevOps Center. -**Use this tool to:** -- Check the status of a specific commit using its Request Token -- Verify commit processing completion before creating a pull request -- Ensure commits are ready for PR creation + **Use this tool to:** + - Check the status of a specific commit using its Request Id + - Verify commit processing completion before creating a pull request + - Ensure commits are ready for PR creation -**Input Parameters:** -- username: The username of the DevOps Center org to authenticate with -- requestId: The specific request token to check status for (REQUIRED) + **Input Parameters:** + - username: The username of the DevOps Center org to authenticate with + - requestId: The specific request Id to check status for (REQUIRED) -**Output:** -- Status field value for the specified request token -- Request token and associated status information`, + **Output:** + - Status field value for the specified request Id + - Request Id and associated status information`, inputSchema: inputSchema.shape, outputSchema: undefined, }; @@ -55,24 +55,6 @@ export class CheckCommitStatus extends McpTool public async exec(input: InputArgs): Promise { try { - if (!input.username || input.username.trim().length === 0) { - return { - content: [{ - type: "text", - text: `Error: Username is required. Please provide the DevOps Center org username.` - }] - }; - } - - if (!input.requestId || input.requestId.trim().length === 0) { - return { - content: [{ - type: "text", - text: `Error: Request ID is required to check commit status.` - }] - }; - } - const status = await fetchCommitStatus(input.username, input.requestId); return { content: [{ @@ -84,7 +66,7 @@ export class CheckCommitStatus extends McpTool return { content: [{ type: "text", - text: `Error checking commit status: ${error.message}` + text: `Failed to check commit status: ${error.message}` }], isError: true }; From b1e0260b6bafee53943b4408a87d8addd8c2b955 Mon Sep 17 00:00:00 2001 From: manan-dey Date: Mon, 6 Oct 2025 13:48:30 +0530 Subject: [PATCH 3/3] fix commit status issue --- .../mcp-provider-devops/src/commitWorkItem.ts | 7 ++ .../src/getCommitStatus.ts | 65 ++++++++++++------- 2 files changed, 49 insertions(+), 23 deletions(-) diff --git a/packages/mcp-provider-devops/src/commitWorkItem.ts b/packages/mcp-provider-devops/src/commitWorkItem.ts index e7ac9ff7..02804622 100644 --- a/packages/mcp-provider-devops/src/commitWorkItem.ts +++ b/packages/mcp-provider-devops/src/commitWorkItem.ts @@ -113,6 +113,8 @@ export async function commitWorkItem({ .split('\n').map(l => l.trim()).filter(Boolean); const untrackedRel = execFileSync('git', ['ls-files', '--others', '--exclude-standard'], { cwd: workingDir, encoding: 'utf8' }) .split('\n').map(l => l.trim()).filter(Boolean); + const stagedRel = execFileSync('git', ['diff', '--cached', '--name-only'], { cwd: workingDir, encoding: 'utf8' }) + .split('\n').map(l => l.trim()).filter(Boolean); @@ -135,6 +137,11 @@ export async function commitWorkItem({ if (isModified) operation = 'modify'; } + if (!operation) { + const isStaged = stagedRel.some(p => isMatch(fileName, p)); + if (isStaged) operation = 'modify'; + } + if (operation && componentType) { computedChanges.push({ fullName, type: componentType, operation }); } diff --git a/packages/mcp-provider-devops/src/getCommitStatus.ts b/packages/mcp-provider-devops/src/getCommitStatus.ts index 7b3a78dd..85466754 100644 --- a/packages/mcp-provider-devops/src/getCommitStatus.ts +++ b/packages/mcp-provider-devops/src/getCommitStatus.ts @@ -9,32 +9,51 @@ export interface CommitStatusResult { } export async function fetchCommitStatus(username: string, requestId: string): Promise { + 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 query = `SELECT Id, Status__c, RequestToken__c FROM DevopsRequestInfo WHERE RequestToken__c = '${requestId}' LIMIT 1`; - - const response = await axios.get(`${connection.instanceUrl}/services/data/v65.0/query`, { - headers: { - 'Authorization': `Bearer ${connection.accessToken}`, - 'Content-Type': 'application/json' - }, - params: { q: query } - }); - - if (response.data.records && response.data.records.length > 0) { - const record = response.data.records[0]; - return { - requestId, - status: record.Status__c, - recordId: record.Id, - message: `Request ${requestId} has status: ${record.Status__c}` - }; + 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 commit status.'); } - return { - requestId, - status: 'NOT_FOUND', - message: `No record found for request ID: ${requestId}` + 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 commit status found for request ID: ${requestId}` + }; + } + + const status = records[0].Status; + return { + requestId, + status, + recordId: records[0].Id, + message: `Commit status for request ID ${requestId}: ${status}` + }; + } catch (error: any) { + const errorMessage = error.response?.data?.[0]?.message || error.message; + throw new Error(`Error checking commit status: ${errorMessage}`); + } +} \ No newline at end of file