|
1 | | -import { getConnection } from "./shared/auth.js"; |
| 1 | +import type { Connection } from "@salesforce/core"; |
2 | 2 | import type { WorkItem } from "./types/WorkItem.js"; |
3 | 3 | import { getPipelineMP } from "./getPipelineMP.js"; |
4 | 4 | import { fetchPipelineStagesMP } from "./getPipelineStagesMP.js"; |
5 | 5 |
|
6 | 6 |
|
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> { |
8 | 8 | try { |
9 | | - const connection = await getConnection(username); |
10 | | - |
11 | 9 | const item = await queryWorkItemByName(connection, workItemName); |
12 | 10 | if (!item) { |
13 | 11 | return { error: { message: `Work Item '${workItemName}' not found. Please verify the Work Item Name/Number and try again.` } }; |
14 | 12 | } |
15 | 13 | if (item?.sf_devops__Concluded__c && String(item.sf_devops__Concluded__c).trim().length > 0) { |
16 | 14 | return { error: { message: `Work Item '${workItemName}' is concluded. No further actions required.` } }; |
17 | 15 | } |
18 | | - const pipeline = await ensurePipelineForProject(username, item?.sf_devops__Project__c, workItemName); |
| 16 | + const pipeline = await ensurePipelineForProject(connection, item?.sf_devops__Project__c, workItemName); |
19 | 17 | if ((pipeline as any)?.error) { |
20 | 18 | return { error: { message: `Pipeline not found for project ${item?.sf_devops__Project__c}. Please verify the Project Name and try again.` } }; |
21 | 19 | } |
22 | 20 |
|
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); |
24 | 22 | if ((stages as any)?.error) { |
25 | 23 | return { error: { message: `Stages not found for pipeline ${pipeline?.Name}. Please verify the Pipeline Name and try again.` } }; |
26 | 24 | } |
@@ -65,16 +63,16 @@ async function queryWorkItemByName(connection: any, workItemName: string): Promi |
65 | 63 | return (result?.records || [])[0] || null; |
66 | 64 | } |
67 | 65 |
|
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); |
70 | 68 | if (!pipeline) { |
71 | 69 | return { error: { message: `Work item ${workItemName} is not mapped to a pipeline` } }; |
72 | 70 | } |
73 | 71 | return pipeline; |
74 | 72 | } |
75 | 73 |
|
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); |
78 | 76 | if (!stages) { |
79 | 77 | return { error: { message: `Stages not found for pipeline ${pipelineName || pipelineId}` } }; |
80 | 78 | } |
|
0 commit comments