Skip to content

Commit fd35ab8

Browse files
committed
using services for connection
1 parent c05b18c commit fd35ab8

19 files changed

+87
-106
lines changed

packages/mcp-provider-devops/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"@salesforce/core": "^8.24.3",
1919
"@salesforce/source-deploy-retrieve": "^12.31.7",
2020
"@salesforce/ts-types": "^2.0.12",
21-
"axios": "^1.10.0",
2221
"zod": "^3.25.76"
2322
},
2423
"devDependencies": {

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getConnection } from "./shared/auth.js";
1+
import type { Connection } from "@salesforce/core";
22

33
export interface DevopsPipelineRecordMP {
44
Id: string;
@@ -11,9 +11,8 @@ export interface DevopsPipelineRecordMP {
1111
* Fetch the Managed Package DevOps pipeline for a given Project Id.
1212
* Returns the first matching pipeline or null if none found.
1313
*/
14-
export async function getPipelineMP(username: string, projectId: string): Promise<DevopsPipelineRecordMP | null | any> {
14+
export async function getPipelineMP(connection: Connection, projectId: string): Promise<DevopsPipelineRecordMP | null | any> {
1515
try {
16-
const connection = await getConnection(username);
1716
const query = `
1817
SELECT Id, Name, sf_devops__Activated__c, sf_devops__Project__c
1918
FROM sf_devops__Pipeline__c

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getConnection } from "./shared/auth.js";
1+
import type { Connection } from "@salesforce/core";
22

33
export interface PipelineStageRecordMP {
44
Id: string;
@@ -15,9 +15,8 @@ export interface PipelineStageRecordMP {
1515
* Fetch Pipeline Stages for a Managed Package pipeline (sf_devops__Pipeline_Stage__c).
1616
* Includes current stage's branch and the next stage's name/branch.
1717
*/
18-
export async function fetchPipelineStagesMP(username: string, pipelineId: string): Promise<PipelineStageRecordMP[] | any> {
18+
export async function fetchPipelineStagesMP(connection: Connection, pipelineId: string): Promise<PipelineStageRecordMP[] | any> {
1919
try {
20-
const connection = await getConnection(username);
2120
const query = `
2221
SELECT
2322
Id,

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
import { getConnection } from "./shared/auth.js";
1+
import type { Connection } from "@salesforce/core";
22

33
export interface DevopsProjectRecord {
44
Id: string;
55
Name: string;
66
Description?: string;
77
}
88

9-
export async function fetchProjects(username: string): Promise<DevopsProjectRecord[]> {
10-
const connection = await getConnection(username);
9+
export async function fetchProjects(connection: Connection): Promise<DevopsProjectRecord[]> {
1110
const query = "SELECT Id, Name, Description FROM DevopsProject";
1211
const result = await connection.query<DevopsProjectRecord>(query);
1312
return result.records ?? [];

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { type Connection } from "@salesforce/core";
2-
import { getConnection } from "./shared/auth.js";
32
import { computeFirstStageId, fetchPipelineStages, getBranchNameFromStage, getPipelineIdForProject, findStageById, resolveTargetStageId } from "./shared/pipelineUtils.js";
43
import type { WorkItem } from "./types/WorkItem.js";
54

@@ -75,9 +74,8 @@ function mapRawItemToWorkItem(item: any, ctx: ProjectStagesContext): WorkItem {
7574
return mapped;
7675
}
7776

78-
export async function fetchWorkItems(username: string, projectId: string): Promise<WorkItem[] | any> {
77+
export async function fetchWorkItems(connection: Connection, projectId: string): Promise<WorkItem[] | any> {
7978
try {
80-
const connection = await getConnection(username);
8179
const query = `
8280
SELECT
8381
Id,
@@ -171,9 +169,8 @@ export async function fetchWorkItemByNameWithConnection(
171169
}
172170
}
173171

174-
export async function fetchWorkItemByName(username: string, workItemName: string): Promise<WorkItem | null | any> {
172+
export async function fetchWorkItemByName(connection: Connection, workItemName: string): Promise<WorkItem | null | any> {
175173
try {
176-
const connection = await getConnection(username);
177174
const query = `
178175
SELECT
179176
Id,
@@ -213,17 +210,14 @@ export async function fetchWorkItemByName(username: string, workItemName: string
213210
}
214211
}
215212

216-
export async function fetchWorkItemsByNames(username: string, workItemNames: string[]): Promise<WorkItem[] | any> {
213+
export async function fetchWorkItemsByNames(connection: Connection, workItemNames: string[]): Promise<WorkItem[] | any> {
217214
try {
218215
if (!Array.isArray(workItemNames) || workItemNames.length === 0) {
219216
return [];
220217
}
221218

222-
223219
const escapeName = (name: string) => String(name).replace(/'/g, "\\'");
224220
const namesList = workItemNames.map(n => `'${escapeName(n)}'`).join(", ");
225-
226-
const connection = await getConnection(username);
227221
const query = `
228222
SELECT
229223
Id,

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
1-
import { getConnection } from "./shared/auth.js";
1+
import type { Connection } from "@salesforce/core";
22
import type { WorkItem } from "./types/WorkItem.js";
33
import { getPipelineMP } from "./getPipelineMP.js";
44
import { fetchPipelineStagesMP } from "./getPipelineStagesMP.js";
55

66

7-
export async function fetchWorkItemByNameMP(username: string, workItemName: string): Promise<WorkItem | null | any> {
7+
export async function fetchWorkItemByNameMP(connection: Connection, workItemName: string): Promise<WorkItem | null | any> {
88
try {
9-
const connection = await getConnection(username);
10-
119
const item = await queryWorkItemByName(connection, workItemName);
1210
if (!item) {
1311
return { error: { message: `Work Item '${workItemName}' not found. Please verify the Work Item Name/Number and try again.` } };
1412
}
1513
if (item?.sf_devops__Concluded__c && String(item.sf_devops__Concluded__c).trim().length > 0) {
1614
return { error: { message: `Work Item '${workItemName}' is concluded. No further actions required.` } };
1715
}
18-
const pipeline = await ensurePipelineForProject(username, item?.sf_devops__Project__c, workItemName);
16+
const pipeline = await ensurePipelineForProject(connection, item?.sf_devops__Project__c, workItemName);
1917
if ((pipeline as any)?.error) {
2018
return { error: { message: `Pipeline not found for project ${item?.sf_devops__Project__c}. Please verify the Project Name and try again.` } };
2119
}
2220

23-
const stages = await ensureStagesForPipeline(username, (pipeline as any).Id, (pipeline as any).Name);
21+
const stages = await ensureStagesForPipeline(connection, (pipeline as any).Id, (pipeline as any).Name);
2422
if ((stages as any)?.error) {
2523
return { error: { message: `Stages not found for pipeline ${pipeline?.Name}. Please verify the Pipeline Name and try again.` } };
2624
}
@@ -65,16 +63,16 @@ async function queryWorkItemByName(connection: any, workItemName: string): Promi
6563
return (result?.records || [])[0] || null;
6664
}
6765

68-
async function ensurePipelineForProject(username: string, projectId: string, workItemName: string): Promise<any> {
69-
const pipeline = await getPipelineMP(username, projectId);
66+
async function ensurePipelineForProject(connection: Connection, projectId: string, workItemName: string): Promise<any> {
67+
const pipeline = await getPipelineMP(connection, projectId);
7068
if (!pipeline) {
7169
return { error: { message: `Work item ${workItemName} is not mapped to a pipeline` } };
7270
}
7371
return pipeline;
7472
}
7573

76-
async function ensureStagesForPipeline(username: string, pipelineId: string, pipelineName?: string): Promise<any[] | any> {
77-
const stages = await fetchPipelineStagesMP(username, pipelineId);
74+
async function ensureStagesForPipeline(connection: Connection, pipelineId: string, pipelineName?: string): Promise<any[] | any> {
75+
const stages = await fetchPipelineStagesMP(connection, pipelineId);
7876
if (!stages) {
7977
return { error: { message: `Stages not found for pipeline ${pipelineName || pipelineId}` } };
8078
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ export class DevOpsMcpProvider extends McpProvider {
2626
new SfDevopsListWorkItems(services),
2727
new SfDevopsCreateWorkItem(services),
2828
new SfDevopsPromoteWorkItem(services),
29-
new SfDevopsDetectConflict(telemetryService),
30-
new SfDevopsResolveConflict(telemetryService),
29+
new SfDevopsDetectConflict(services),
30+
new SfDevopsResolveConflict(services),
3131

3232
new SfDevopsCheckoutWorkItem(services),
3333
new SfDevopsCommitWorkItem(services),

packages/mcp-provider-devops/src/shared/orgType.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { getConnection } from "./auth.js";
2-
import { Connection } from "@salesforce/core";
1+
import type { Connection } from "@salesforce/core";
32

43
/**
54
* Check whether the given org uses the Managed Package DevOps model.
@@ -11,17 +10,7 @@ import { Connection } from "@salesforce/core";
1110
* This can be extended later (e.g., check installed packages or additional
1211
* objects) without changing the call sites.
1312
*/
14-
export async function isManagedPackageDevopsOrg(username?: string, alias?: string): Promise<boolean> {
15-
let connection: Connection;
16-
try {
17-
const usernameOrAlias = username ?? alias;
18-
if (!usernameOrAlias) {
19-
throw new Error("Username or alias of valid DevOps Center org is required");
20-
}
21-
connection = await getConnection(usernameOrAlias);
22-
} catch (error: any) {
23-
throw error;
24-
}
13+
export async function isManagedPackageDevopsOrg(connection: Connection): Promise<boolean> {
2514
try {
2615
await connection.query("SELECT Id FROM sf_devops__Project__c LIMIT 1");
2716
return true;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ This tool takes the DevOps Center org username and the exact Work Item Name, loo
9595

9696
let workItem: any;
9797
try {
98-
workItem = await fetchWorkItemByName(input.usernameOrAlias, input.workItemName);
98+
const connection = await this.services.getOrgService().getConnection(input.usernameOrAlias);
99+
workItem = await fetchWorkItemByName(connection, input.workItemName);
99100
} catch (e: any) {
100101
const executionTime = Date.now() - startTime;
101102

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ export class SfDevopsCommitWorkItem extends McpTool<InputArgsShape, OutputArgsSh
8282

8383
let workItem: any;
8484
try {
85-
workItem = await fetchWorkItemByName(input.usernameOrAlias, input.workItemName);
85+
const connection = await this.services.getOrgService().getConnection(input.usernameOrAlias);
86+
workItem = await fetchWorkItemByName(connection, input.workItemName);
8687
} catch (e: any) {
8788
return {
8889
error: {

0 commit comments

Comments
 (0)