@salesforce/plugin-devops-center 1.2.26 → 1.2.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (225) hide show
  1. package/LICENSE.txt +200 -6
  2. package/README.md +430 -19
  3. package/bin/dev.js +15 -0
  4. package/bin/run.js +5 -0
  5. package/lib/commands/devops/pipeline/activate.d.ts +14 -0
  6. package/lib/commands/devops/pipeline/activate.js +82 -0
  7. package/lib/commands/devops/pipeline/activate.js.map +1 -0
  8. package/lib/commands/devops/pipeline/attach-project.d.ts +15 -0
  9. package/lib/commands/devops/pipeline/attach-project.js +82 -0
  10. package/lib/commands/devops/pipeline/attach-project.js.map +1 -0
  11. package/lib/commands/devops/pipeline/create.d.ts +23 -0
  12. package/lib/commands/devops/pipeline/create.js +136 -0
  13. package/lib/commands/devops/pipeline/create.js.map +1 -0
  14. package/lib/commands/devops/pipeline/stage/add.d.ts +16 -0
  15. package/lib/commands/devops/pipeline/stage/add.js +94 -0
  16. package/lib/commands/devops/pipeline/stage/add.js.map +1 -0
  17. package/lib/commands/devops/project/create.d.ts +15 -0
  18. package/lib/commands/devops/project/create.js +72 -0
  19. package/lib/commands/devops/project/create.js.map +1 -0
  20. package/lib/commands/devops/project/list.d.ts +20 -0
  21. package/lib/commands/devops/project/list.js +59 -0
  22. package/lib/commands/devops/project/list.js.map +1 -0
  23. package/lib/commands/devops/pull-request/create.d.ts +17 -0
  24. package/lib/commands/devops/pull-request/create.js +104 -0
  25. package/lib/commands/devops/pull-request/create.js.map +1 -0
  26. package/lib/commands/devops/work-item/create.d.ts +16 -0
  27. package/lib/commands/devops/work-item/create.js +76 -0
  28. package/lib/commands/devops/work-item/create.js.map +1 -0
  29. package/lib/commands/devops/work-item/list.d.ts +17 -0
  30. package/lib/commands/devops/work-item/list.js +72 -0
  31. package/lib/commands/devops/work-item/list.js.map +1 -0
  32. package/lib/commands/devops/work-item/status/update.d.ts +16 -0
  33. package/lib/commands/devops/work-item/status/update.js +90 -0
  34. package/lib/commands/devops/work-item/status/update.js.map +1 -0
  35. package/lib/commands/project/deploy/pipeline/quick.d.ts +2 -2
  36. package/lib/commands/project/deploy/pipeline/quick.js +24 -21
  37. package/lib/commands/project/deploy/pipeline/quick.js.map +1 -1
  38. package/lib/commands/project/deploy/pipeline/report.d.ts +4 -4
  39. package/lib/commands/project/deploy/pipeline/report.js +38 -35
  40. package/lib/commands/project/deploy/pipeline/report.js.map +1 -1
  41. package/lib/commands/project/deploy/pipeline/resume.d.ts +2 -2
  42. package/lib/commands/project/deploy/pipeline/resume.js +24 -21
  43. package/lib/commands/project/deploy/pipeline/resume.js.map +1 -1
  44. package/lib/commands/project/deploy/pipeline/start.d.ts +3 -3
  45. package/lib/commands/project/deploy/pipeline/start.js +26 -23
  46. package/lib/commands/project/deploy/pipeline/start.js.map +1 -1
  47. package/lib/commands/project/deploy/pipeline/validate.d.ts +3 -3
  48. package/lib/commands/project/deploy/pipeline/validate.js +24 -21
  49. package/lib/commands/project/deploy/pipeline/validate.js.map +1 -1
  50. package/lib/common/base/abstractAsyncOperation.d.ts +3 -3
  51. package/lib/common/base/abstractAsyncOperation.js +31 -23
  52. package/lib/common/base/abstractAsyncOperation.js.map +1 -1
  53. package/lib/common/base/abstractPromote.d.ts +5 -4
  54. package/lib/common/base/abstractPromote.js +52 -38
  55. package/lib/common/base/abstractPromote.js.map +1 -1
  56. package/lib/common/base/abstractQuick.d.ts +4 -3
  57. package/lib/common/base/abstractQuick.js +44 -43
  58. package/lib/common/base/abstractQuick.js.map +1 -1
  59. package/lib/common/base/abstractReportOnPromote.d.ts +2 -1
  60. package/lib/common/base/abstractReportOnPromote.js +31 -24
  61. package/lib/common/base/abstractReportOnPromote.js.map +1 -1
  62. package/lib/common/base/abstractResume.d.ts +3 -2
  63. package/lib/common/base/abstractResume.js +40 -33
  64. package/lib/common/base/abstractResume.js.map +1 -1
  65. package/lib/common/constants.js +19 -13
  66. package/lib/common/constants.js.map +1 -1
  67. package/lib/common/deployPipelineCache.js +20 -15
  68. package/lib/common/deployPipelineCache.js.map +1 -1
  69. package/lib/common/flags/flags.d.ts +2 -2
  70. package/lib/common/flags/flags.js +34 -29
  71. package/lib/common/flags/flags.js.map +1 -1
  72. package/lib/common/flags/promote/promoteFlags.d.ts +3 -3
  73. package/lib/common/flags/promote/promoteFlags.js +26 -20
  74. package/lib/common/flags/promote/promoteFlags.js.map +1 -1
  75. package/lib/common/index.d.ts +3 -2
  76. package/lib/common/index.js +2 -17
  77. package/lib/common/index.js.map +1 -1
  78. package/lib/common/outputColumns.d.ts +3 -13
  79. package/lib/common/outputColumns.js +23 -19
  80. package/lib/common/outputColumns.js.map +1 -1
  81. package/lib/common/outputService/aorOutputService.d.ts +4 -4
  82. package/lib/common/outputService/aorOutputService.js +27 -20
  83. package/lib/common/outputService/aorOutputService.js.map +1 -1
  84. package/lib/common/outputService/deployCommandOutputService.d.ts +2 -2
  85. package/lib/common/outputService/deployCommandOutputService.js +17 -12
  86. package/lib/common/outputService/deployCommandOutputService.js.map +1 -1
  87. package/lib/common/outputService/deploySummaryBuilder.d.ts +1 -1
  88. package/lib/common/outputService/deploySummaryBuilder.js +45 -31
  89. package/lib/common/outputService/deploySummaryBuilder.js.map +1 -1
  90. package/lib/common/outputService/deploymentResultOutputService.d.ts +4 -4
  91. package/lib/common/outputService/deploymentResultOutputService.js +16 -10
  92. package/lib/common/outputService/deploymentResultOutputService.js.map +1 -1
  93. package/lib/common/outputService/index.d.ts +8 -6
  94. package/lib/common/outputService/index.js +5 -19
  95. package/lib/common/outputService/index.js.map +1 -1
  96. package/lib/common/outputService/outputService.d.ts +6 -4
  97. package/lib/common/outputService/outputService.js +20 -14
  98. package/lib/common/outputService/outputService.js.map +1 -1
  99. package/lib/common/outputService/outputServiceFactory.d.ts +8 -8
  100. package/lib/common/outputService/outputServiceFactory.js +21 -16
  101. package/lib/common/outputService/outputServiceFactory.js.map +1 -1
  102. package/lib/common/outputService/outputUtils.d.ts +1 -1
  103. package/lib/common/outputService/outputUtils.js +24 -19
  104. package/lib/common/outputService/outputUtils.js.map +1 -1
  105. package/lib/common/outputService/promoteOutputService.d.ts +4 -5
  106. package/lib/common/outputService/promoteOutputService.js +19 -13
  107. package/lib/common/outputService/promoteOutputService.js.map +1 -1
  108. package/lib/common/outputService/reportOutputService.d.ts +5 -6
  109. package/lib/common/outputService/reportOutputService.js +32 -27
  110. package/lib/common/outputService/reportOutputService.js.map +1 -1
  111. package/lib/common/outputService/resumeCommandOutputService.d.ts +3 -3
  112. package/lib/common/outputService/resumeCommandOutputService.js +19 -13
  113. package/lib/common/outputService/resumeCommandOutputService.js.map +1 -1
  114. package/lib/common/outputService/resumeOutputService.d.ts +3 -3
  115. package/lib/common/outputService/resumeOutputService.js +23 -17
  116. package/lib/common/outputService/resumeOutputService.js.map +1 -1
  117. package/lib/common/selectors/asyncOperationResultsSelector.d.ts +1 -1
  118. package/lib/common/selectors/asyncOperationResultsSelector.js +16 -10
  119. package/lib/common/selectors/asyncOperationResultsSelector.js.map +1 -1
  120. package/lib/common/selectors/deployComponentsSelector.d.ts +1 -1
  121. package/lib/common/selectors/deployComponentsSelector.js +18 -13
  122. package/lib/common/selectors/deployComponentsSelector.js.map +1 -1
  123. package/lib/common/selectors/deployProgressSummarySelector.d.ts +2 -2
  124. package/lib/common/selectors/deployProgressSummarySelector.js +16 -10
  125. package/lib/common/selectors/deployProgressSummarySelector.js.map +1 -1
  126. package/lib/common/selectors/deploymentResultsSelector.d.ts +2 -2
  127. package/lib/common/selectors/deploymentResultsSelector.js +20 -16
  128. package/lib/common/selectors/deploymentResultsSelector.js.map +1 -1
  129. package/lib/common/selectors/environmentSelector.d.ts +2 -2
  130. package/lib/common/selectors/environmentSelector.js +16 -10
  131. package/lib/common/selectors/environmentSelector.js.map +1 -1
  132. package/lib/common/selectors/namedCredentialSelector.d.ts +1 -1
  133. package/lib/common/selectors/namedCredentialSelector.js +16 -10
  134. package/lib/common/selectors/namedCredentialSelector.js.map +1 -1
  135. package/lib/common/selectors/pipelineStageSelector.d.ts +1 -1
  136. package/lib/common/selectors/pipelineStageSelector.js +18 -13
  137. package/lib/common/selectors/pipelineStageSelector.js.map +1 -1
  138. package/lib/common/selectors/selectorUtils.d.ts +1 -1
  139. package/lib/common/selectors/selectorUtils.js +17 -11
  140. package/lib/common/selectors/selectorUtils.js.map +1 -1
  141. package/lib/common/selectors/validateDeploySelector.d.ts +1 -1
  142. package/lib/common/selectors/validateDeploySelector.js +16 -10
  143. package/lib/common/selectors/validateDeploySelector.js.map +1 -1
  144. package/lib/common/selectors/workItemSelector.d.ts +2 -2
  145. package/lib/common/selectors/workItemSelector.js +16 -10
  146. package/lib/common/selectors/workItemSelector.js.map +1 -1
  147. package/lib/common/types.d.ts +4 -4
  148. package/lib/common/types.js +4 -7
  149. package/lib/common/types.js.map +1 -1
  150. package/lib/common/utils.d.ts +4 -4
  151. package/lib/common/utils.js +42 -43
  152. package/lib/common/utils.js.map +1 -1
  153. package/lib/configMeta.js +21 -15
  154. package/lib/configMeta.js.map +1 -1
  155. package/lib/streamer/doceMonitor.d.ts +3 -2
  156. package/lib/streamer/doceMonitor.js +14 -6
  157. package/lib/streamer/doceMonitor.js.map +1 -1
  158. package/lib/streamer/doceStream.d.ts +1 -1
  159. package/lib/streamer/doceStream.js +19 -11
  160. package/lib/streamer/doceStream.js.map +1 -1
  161. package/lib/streamer/processors/asyncOpStream.d.ts +2 -2
  162. package/lib/streamer/processors/asyncOpStream.js +22 -15
  163. package/lib/streamer/processors/asyncOpStream.js.map +1 -1
  164. package/lib/streamer/sObjectStream.d.ts +1 -1
  165. package/lib/streamer/sObjectStream.js +9 -10
  166. package/lib/streamer/sObjectStream.js.map +1 -1
  167. package/lib/utils/activatePipeline.d.ts +17 -0
  168. package/lib/utils/activatePipeline.js +35 -0
  169. package/lib/utils/activatePipeline.js.map +1 -0
  170. package/lib/utils/addPipelineStage.d.ts +20 -0
  171. package/lib/utils/addPipelineStage.js +43 -0
  172. package/lib/utils/addPipelineStage.js.map +1 -0
  173. package/lib/utils/attachProject.d.ts +21 -0
  174. package/lib/utils/attachProject.js +44 -0
  175. package/lib/utils/attachProject.js.map +1 -0
  176. package/lib/utils/createPipeline.d.ts +34 -0
  177. package/lib/utils/createPipeline.js +77 -0
  178. package/lib/utils/createPipeline.js.map +1 -0
  179. package/lib/utils/createProject.d.ts +17 -0
  180. package/lib/utils/createProject.js +39 -0
  181. package/lib/utils/createProject.js.map +1 -0
  182. package/lib/utils/createPullRequest.d.ts +49 -0
  183. package/lib/utils/createPullRequest.js +204 -0
  184. package/lib/utils/createPullRequest.js.map +1 -0
  185. package/lib/utils/createWorkItem.d.ts +19 -0
  186. package/lib/utils/createWorkItem.js +58 -0
  187. package/lib/utils/createWorkItem.js.map +1 -0
  188. package/lib/utils/pipelineUtils.d.ts +8 -0
  189. package/lib/utils/pipelineUtils.js +51 -0
  190. package/lib/utils/pipelineUtils.js.map +1 -0
  191. package/lib/utils/types.d.ts +57 -0
  192. package/lib/utils/types.js +17 -0
  193. package/lib/utils/types.js.map +1 -0
  194. package/lib/utils/updateWorkItemStatus.d.ts +34 -0
  195. package/lib/utils/updateWorkItemStatus.js +71 -0
  196. package/lib/utils/updateWorkItemStatus.js.map +1 -0
  197. package/lib/utils/workItems.d.ts +3 -0
  198. package/lib/utils/workItems.js +181 -0
  199. package/lib/utils/workItems.js.map +1 -0
  200. package/messages/commonErrors.md +5 -1
  201. package/messages/devops.pipeline.activate.md +29 -0
  202. package/messages/devops.pipeline.attach-project.md +29 -0
  203. package/messages/devops.pipeline.create.md +81 -0
  204. package/messages/devops.pipeline.stage.add.md +37 -0
  205. package/messages/devops.project.create.md +29 -0
  206. package/messages/devops.project.list.md +17 -0
  207. package/messages/devops.pull-request.create.md +57 -0
  208. package/messages/devops.work-item.create.md +29 -0
  209. package/messages/devops.work-item.list.md +21 -0
  210. package/messages/devops.work-item.status.update.md +29 -0
  211. package/npm-shrinkwrap.json +4594 -4552
  212. package/oclif.lock +3513 -3194
  213. package/oclif.manifest.json +863 -11
  214. package/package.json +56 -26
  215. package/schemas/devops-pipeline-activate.json +28 -0
  216. package/schemas/devops-pipeline-attach__project.json +25 -0
  217. package/schemas/devops-pipeline-create.json +50 -0
  218. package/schemas/devops-pipeline-stage-add.json +31 -0
  219. package/schemas/devops-project-create.json +28 -0
  220. package/schemas/devops-project-list.json +35 -0
  221. package/schemas/devops-pull__request-create.json +34 -0
  222. package/schemas/devops-work__item-create.json +28 -0
  223. package/schemas/devops-work__item-list.json +75 -0
  224. package/schemas/devops-work__item-status-update.json +28 -0
  225. package/schemas/project-deploy-pipeline-report.json +2 -2
@@ -0,0 +1,17 @@
1
+ import { Connection } from '@salesforce/core';
2
+ export type CreateProjectParams = {
3
+ connection: Connection;
4
+ name: string;
5
+ description: string;
6
+ };
7
+ export type CreateProjectResult = {
8
+ success: boolean;
9
+ projectId?: string;
10
+ name?: string;
11
+ description?: string;
12
+ error?: string;
13
+ };
14
+ /**
15
+ * Creates a new DevOps Center project via sObject create on DevopsProject.
16
+ */
17
+ export declare function createProject(params: CreateProjectParams): Promise<CreateProjectResult>;
@@ -0,0 +1,39 @@
1
+ /*
2
+ * Copyright 2026, Salesforce, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * Creates a new DevOps Center project via sObject create on DevopsProject.
18
+ */
19
+ export async function createProject(params) {
20
+ const { connection, name, description } = params;
21
+ const result = await connection.sobject('DevopsProject').create({
22
+ Name: name,
23
+ Description: description || null,
24
+ });
25
+ if (result.success) {
26
+ return {
27
+ success: true,
28
+ projectId: result.id,
29
+ name,
30
+ description: description || undefined,
31
+ };
32
+ }
33
+ const errorMessages = result.errors?.map((e) => (typeof e === 'string' ? e : JSON.stringify(e))).join('; ');
34
+ return {
35
+ success: false,
36
+ error: errorMessages ?? 'Unknown error',
37
+ };
38
+ }
39
+ //# sourceMappingURL=createProject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createProject.js","sourceRoot":"","sources":["../../src/utils/createProject.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAkBH;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,MAA2B;IAC7D,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC;IAEjD,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC;QAC9D,IAAI,EAAE,IAAI;QACV,WAAW,EAAE,WAAW,IAAI,IAAI;KACjC,CAAC,CAAC;IAEH,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACnB,OAAO;YACL,OAAO,EAAE,IAAI;YACb,SAAS,EAAE,MAAM,CAAC,EAAE;YACpB,IAAI;YACJ,WAAW,EAAE,WAAW,IAAI,SAAS;SACtC,CAAC;IACJ,CAAC;IAED,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5G,OAAO;QACL,OAAO,EAAE,KAAK;QACd,KAAK,EAAE,aAAa,IAAI,eAAe;KACxC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,49 @@
1
+ import { Connection } from '@salesforce/core';
2
+ export type WorkItemDetail = {
3
+ workItemId: string;
4
+ workItemName: string;
5
+ subject: string;
6
+ branchName?: string;
7
+ targetBranch?: string;
8
+ projectId: string;
9
+ repoOwner?: string;
10
+ repoName?: string;
11
+ provider?: string;
12
+ };
13
+ export type CreatePullRequestParams = {
14
+ owner: string;
15
+ repo: string;
16
+ head: string;
17
+ base: string;
18
+ title: string;
19
+ body?: string;
20
+ provider: string;
21
+ token: string;
22
+ };
23
+ export type CreatePullRequestResult = {
24
+ success: boolean;
25
+ workItemName?: string;
26
+ title?: string;
27
+ url?: string;
28
+ sourceBranch?: string;
29
+ targetBranch?: string;
30
+ error?: string;
31
+ };
32
+ /**
33
+ * Queries a work item (by Name or Id) and resolves all info needed
34
+ * to create a pull request: branch, repo, owner, provider, and target branch.
35
+ */
36
+ export declare function fetchWorkItemDetail(connection: Connection, filter: {
37
+ name: string;
38
+ } | {
39
+ id: string;
40
+ }): Promise<WorkItemDetail>;
41
+ /**
42
+ * Creates a pull request on GitHub or Bitbucket using their REST APIs.
43
+ */
44
+ export declare function createPullRequest(params: CreatePullRequestParams): Promise<CreatePullRequestResult>;
45
+ /**
46
+ * Attempts to resolve a VCS authentication token from the environment
47
+ * or the `gh` CLI (for GitHub).
48
+ */
49
+ export declare function resolveGitHubToken(): Promise<string | undefined>;
@@ -0,0 +1,204 @@
1
+ /*
2
+ * Copyright 2026, Salesforce, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { getPipelineIdForProject, fetchPipelineStages, computeFirstStageId, findStageById, getBranchNameFromStage, resolveTargetStageId, } from './pipelineUtils.js';
17
+ function normalizeProvider(provider) {
18
+ if (!provider)
19
+ return undefined;
20
+ const normalized = String(provider).toLowerCase();
21
+ if (normalized === 'bitbucketcloud')
22
+ return 'bitbucket';
23
+ return normalized;
24
+ }
25
+ function providerToVcsType(provider) {
26
+ const normalized = normalizeProvider(provider);
27
+ if (normalized === 'github')
28
+ return 'GITHUB';
29
+ if (normalized === 'bitbucket')
30
+ return 'BITBUCKET';
31
+ return undefined;
32
+ }
33
+ function extractOwnerFromVcsPayload(payload) {
34
+ if (!payload)
35
+ return undefined;
36
+ if (typeof payload === 'string')
37
+ return payload.trim() || undefined;
38
+ const obj = payload;
39
+ if (typeof obj.owner === 'string' && obj.owner.trim())
40
+ return obj.owner.trim();
41
+ const list = (obj.owners ?? obj.items ?? obj.records);
42
+ if (Array.isArray(list)) {
43
+ for (const candidate of list) {
44
+ if (typeof candidate === 'string' && candidate.trim())
45
+ return candidate.trim();
46
+ if (candidate && typeof candidate === 'object') {
47
+ const ownerVal = candidate.owner;
48
+ if (typeof ownerVal === 'string' && ownerVal.trim())
49
+ return ownerVal.trim();
50
+ }
51
+ }
52
+ }
53
+ return undefined;
54
+ }
55
+ async function fetchOwnerByVcsType(connection, vcsType) {
56
+ const path = `/services/data/v${connection.getApiVersion()}/connect/devops/vcs/${vcsType}`;
57
+ const response = await connection.request({ method: 'GET', url: path });
58
+ return extractOwnerFromVcsPayload(response);
59
+ }
60
+ /**
61
+ * Queries a work item (by Name or Id) and resolves all info needed
62
+ * to create a pull request: branch, repo, owner, provider, and target branch.
63
+ */
64
+ export async function fetchWorkItemDetail(connection, filter) {
65
+ const whereClause = 'name' in filter ? `Name = '${filter.name}'` : `Id = '${filter.id}'`;
66
+ const identifier = 'name' in filter ? filter.name : filter.id;
67
+ const result = await connection.query(`SELECT Id, Name, Subject, DevopsProjectId, DevopsPipelineStageId,
68
+ SourceCodeRepositoryBranch.Name,
69
+ SourceCodeRepositoryBranch.SourceCodeRepository.Name,
70
+ SourceCodeRepositoryBranch.SourceCodeRepository.RepositoryOwner,
71
+ SourceCodeRepositoryBranch.SourceCodeRepository.Provider
72
+ FROM WorkItem
73
+ WHERE ${whereClause}
74
+ LIMIT 1`);
75
+ const record = (result.records ?? [])[0];
76
+ if (!record) {
77
+ throw new Error(`Work item '${identifier}' not found.`);
78
+ }
79
+ const provider = normalizeProvider(record.SourceCodeRepositoryBranch?.SourceCodeRepository?.Provider);
80
+ let repoOwner = record.SourceCodeRepositoryBranch?.SourceCodeRepository?.RepositoryOwner ?? undefined;
81
+ const vcsType = providerToVcsType(provider);
82
+ if (vcsType && !repoOwner) {
83
+ try {
84
+ repoOwner = (await fetchOwnerByVcsType(connection, vcsType)) ?? undefined;
85
+ }
86
+ catch {
87
+ // owner lookup is best-effort
88
+ }
89
+ }
90
+ const detail = {
91
+ workItemId: record.Id,
92
+ workItemName: record.Name,
93
+ subject: record.Subject ?? '',
94
+ branchName: record.SourceCodeRepositoryBranch?.Name ?? undefined,
95
+ projectId: record.DevopsProjectId,
96
+ repoOwner,
97
+ repoName: record.SourceCodeRepositoryBranch?.SourceCodeRepository?.Name ?? undefined,
98
+ provider,
99
+ };
100
+ const pipelineId = await getPipelineIdForProject(connection, record.DevopsProjectId);
101
+ if (pipelineId) {
102
+ const stages = await fetchPipelineStages(connection, pipelineId);
103
+ if (stages.length) {
104
+ let targetStageId = resolveTargetStageId(record.DevopsPipelineStageId ?? undefined, stages);
105
+ if (!targetStageId) {
106
+ targetStageId = computeFirstStageId(stages);
107
+ }
108
+ detail.targetBranch = getBranchNameFromStage(findStageById(stages, targetStageId));
109
+ }
110
+ }
111
+ return detail;
112
+ }
113
+ /**
114
+ * Creates a pull request on GitHub or Bitbucket using their REST APIs.
115
+ */
116
+ export async function createPullRequest(params) {
117
+ const { owner, repo, head, base, title, body, provider, token } = params;
118
+ if (provider === 'github') {
119
+ return createGitHubPullRequest({ owner, repo, head, base, title, body, token });
120
+ }
121
+ else if (provider === 'bitbucket') {
122
+ return createBitbucketPullRequest({ owner, repo, head, base, title, body, token });
123
+ }
124
+ throw new Error(`Unsupported VCS provider: ${provider ?? 'unknown'}. Supported providers are GitHub and Bitbucket.`);
125
+ }
126
+ async function createGitHubPullRequest(params) {
127
+ const { owner, repo, head, base, title, body, token } = params;
128
+ const url = `https://api.github.com/repos/${owner}/${repo}/pulls`;
129
+ const response = await fetch(url, {
130
+ method: 'POST',
131
+ headers: {
132
+ Authorization: `Bearer ${token}`,
133
+ Accept: 'application/vnd.github+json',
134
+ 'Content-Type': 'application/json',
135
+ 'X-GitHub-Api-Version': '2022-11-28',
136
+ },
137
+ body: JSON.stringify({ title, body: body ?? '', head, base }),
138
+ });
139
+ const data = (await response.json());
140
+ if (!response.ok) {
141
+ const errors = Array.isArray(data.errors)
142
+ ? data.errors.map((e) => e.message ?? JSON.stringify(e)).join('; ')
143
+ : undefined;
144
+ const msg = data.message ?? `HTTP ${response.status}`;
145
+ throw new Error(errors ? `${msg}: ${errors}` : msg);
146
+ }
147
+ return {
148
+ success: true,
149
+ title: data.title,
150
+ url: data.html_url,
151
+ sourceBranch: head,
152
+ targetBranch: base,
153
+ };
154
+ }
155
+ async function createBitbucketPullRequest(params) {
156
+ const { owner, repo, head, base, title, body, token } = params;
157
+ const url = `https://api.bitbucket.org/2.0/repositories/${owner}/${repo}/pullrequests`;
158
+ const response = await fetch(url, {
159
+ method: 'POST',
160
+ headers: {
161
+ Authorization: `Bearer ${token}`,
162
+ 'Content-Type': 'application/json',
163
+ },
164
+ body: JSON.stringify({
165
+ title,
166
+ description: body ?? '',
167
+ source: { branch: { name: head } },
168
+ destination: { branch: { name: base } },
169
+ }),
170
+ });
171
+ const data = (await response.json());
172
+ if (!response.ok) {
173
+ const errorMsg = data.error?.message ?? data.message ?? `HTTP ${response.status}`;
174
+ throw new Error(String(errorMsg));
175
+ }
176
+ const links = data.links;
177
+ return {
178
+ success: true,
179
+ title: data.title,
180
+ url: links?.html?.href ?? data.url ?? '',
181
+ sourceBranch: head,
182
+ targetBranch: base,
183
+ };
184
+ }
185
+ /**
186
+ * Attempts to resolve a VCS authentication token from the environment
187
+ * or the `gh` CLI (for GitHub).
188
+ */
189
+ export async function resolveGitHubToken() {
190
+ const envToken = process.env.GITHUB_TOKEN ?? process.env.GH_TOKEN;
191
+ if (envToken)
192
+ return envToken;
193
+ try {
194
+ const { execSync } = await import('node:child_process');
195
+ const token = execSync('gh auth token', { encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'] }).trim();
196
+ if (token)
197
+ return token;
198
+ }
199
+ catch {
200
+ // gh CLI not installed or not authenticated
201
+ }
202
+ return undefined;
203
+ }
204
+ //# sourceMappingURL=createPullRequest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createPullRequest.js","sourceRoot":"","sources":["../../src/utils/createPullRequest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EACL,uBAAuB,EACvB,mBAAmB,EACnB,mBAAmB,EACnB,aAAa,EACb,sBAAsB,EACtB,oBAAoB,GACrB,MAAM,oBAAoB,CAAC;AA2C5B,SAAS,iBAAiB,CAAC,QAAiB;IAC1C,IAAI,CAAC,QAAQ;QAAE,OAAO,SAAS,CAAC;IAChC,MAAM,UAAU,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC;IAClD,IAAI,UAAU,KAAK,gBAAgB;QAAE,OAAO,WAAW,CAAC;IACxD,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,SAAS,iBAAiB,CAAC,QAAiB;IAC1C,MAAM,UAAU,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IAC/C,IAAI,UAAU,KAAK,QAAQ;QAAE,OAAO,QAAQ,CAAC;IAC7C,IAAI,UAAU,KAAK,WAAW;QAAE,OAAO,WAAW,CAAC;IACnD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,0BAA0B,CAAC,OAAgB;IAClD,IAAI,CAAC,OAAO;QAAE,OAAO,SAAS,CAAC;IAC/B,IAAI,OAAO,OA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AAQ,CAAC,MAAM,EAAE,CAAC;QAC/G,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;IACpC,CAAC;IAED,MAAM,KAAK,GAAG,IAAI,CAAC,KAA2D,CAAC;IAC/E,OAAO;QACL,OAAO,EAAE,IAAI;QACb,KAAK,EAAE,IAAI,CAAC,KAAe;QAC3B,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,IAAK,IAAI,CAAC,GAAc,IAAI,EAAE;QACpD,YAAY,EAAE,IAAI;QAClB,YAAY,EAAE,IAAI;KACnB,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB;IACtC,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClE,IAAI,QAAQ;QAAE,OAAO,QAAQ,CAAC;IAE9B,IAAI,CAAC;QACH,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC,oBAAoB,CAAC,CAAC;QACxD,MAAM,KAAK,GAAG,QAAQ,CAAC,eAAe,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QACvG,IAAI,KAAK;YAAE,OAAO,KAAK,CAAC;IAC1B,CAAC;IAAC,MAAM,CAAC;QACP,4CAA4C;IAC9C,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { Connection } from '@salesforce/core';
2
+ export type CreateWorkItemParams = {
3
+ connection: Connection;
4
+ projectId: string;
5
+ subject: string;
6
+ description: string;
7
+ };
8
+ export type CreateWorkItemResult = {
9
+ success: boolean;
10
+ workItemId?: string;
11
+ workItemName?: string;
12
+ subject?: string;
13
+ error?: string;
14
+ };
15
+ /**
16
+ * Creates a new DevOps Center Work Item in the specified project.
17
+ * API: POST /services/data/v65.0/connect/devops/projects/<ProjectID>/workitem
18
+ */
19
+ export declare function createWorkItem(params: CreateWorkItemParams): Promise<CreateWorkItemResult>;
@@ -0,0 +1,58 @@
1
+ /*
2
+ * Copyright 2026, Salesforce, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * Creates a new DevOps Center Work Item in the specified project.
18
+ * API: POST /services/data/v65.0/connect/devops/projects/<ProjectID>/workitem
19
+ */
20
+ export async function createWorkItem(params) {
21
+ const { connection, projectId, subject, description } = params;
22
+ const path = `/services/data/v${connection.getApiVersion()}/connect/devops/projects/${projectId}/workitem`;
23
+ const body = JSON.stringify({ subject, description: description ?? '' });
24
+ try {
25
+ const response = await connection.request({
26
+ method: 'POST',
27
+ url: path,
28
+ body,
29
+ headers: { 'Content-Type': 'application/json' },
30
+ });
31
+ const data = response ?? {};
32
+ return {
33
+ success: true,
34
+ workItemId: (data.id ?? data.Id),
35
+ workItemName: (data.name ?? data.Name),
36
+ subject: (data.subject ?? data.Subject ?? subject),
37
+ };
38
+ }
39
+ catch (error) {
40
+ const err = error;
41
+ const data = (err.response?.data ?? err.body ?? err);
42
+ const message = (typeof data === 'object' &&
43
+ data !== null &&
44
+ (data.message ??
45
+ data.error ??
46
+ data.errorDescription)) ||
47
+ err.message ||
48
+ 'Unknown error';
49
+ const details = typeof data === 'object' && data !== null && Array.isArray(data.body)
50
+ ? data.body.join('; ')
51
+ : undefined;
52
+ return {
53
+ success: false,
54
+ error: details ? `${String(message)}: ${details}` : String(message),
55
+ };
56
+ }
57
+ }
58
+ //# sourceMappingURL=createWorkItem.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createWorkItem.js","sourceRoot":"","sources":["../../src/utils/createWorkItem.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAmBH;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,MAA4B;IAC/D,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC;IAE/D,MAAM,IAAI,GAAG,mBAAmB,UAAU,CAAC,aAAa,EAAE,4BAA4B,SAAS,WAAW,CAAC;IAC3G,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,IAAI,EAAE,EAAE,CAAC,CAAC;IAEzE,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC;YACxC,MAAM,EAAE,MAAM;YACd,GAAG,EAAE,IAAI;YACT,IAAI;YACJ,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;SAChD,CAAC,CAAC;QACH,MAAM,IAAI,GAAI,QAAoC,IAAI,EAAE,CAAC;QACzD,OAAO;YACL,OAAO,EAAE,IAAI;YACb,UAAU,EAAE,CAAC,IAAI,CAAC,EAAE,IAAI,IAAI,CAAC,EAAE,CAAuB;YACtD,YAAY,EAAE,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAuB;YAC5D,OAAO,EAAE,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,IAAI,OAAO,CAAW;SAC7D,CAAC;IACJ,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,MAAM,GAAG,GAAG,KAAuG,CAAC;QACpH,MAAM,IAAI,GAAY,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,CAAY,CAAC;QACzE,MAAM,OAAO,GACX,CAAC,OAAO,IAAI,KAAK,QAAQ;YACvB,IAAI,KAAK,IAAI;YACb,CAAE,IAAgC,CAAC,OAAO;gBACvC,IAAgC,CAAC,KAAK;gBACtC,IAAgC,CAAC,gBAAgB,CAAC,CAAC;YACxD,GAAG,CAAC,OAAO;YACX,eAAe,CAAC;QAClB,MAAM,OAAO,GACX,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAE,IAAgC,CAAC,IAAI,CAAC;YAChG,CAAC,CAAG,IAAkC,CAAC,IAAiB,CAAC,IAAI,CAAC,IAAI,CAAC;YACnE,CAAC,CAAC,SAAS,CAAC;QAChB,OAAO;YACL,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,OAAO,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC;SACpE,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { Connection } from '@salesforce/core';
2
+ import { PipelineStageRecord } from './types.js';
3
+ export declare function getPipelineIdForProject(connection: Connection, projectId: string): Promise<string | undefined>;
4
+ export declare function fetchPipelineStages(connection: Connection, pipelineId: string): Promise<PipelineStageRecord[]>;
5
+ export declare function computeFirstStageId(stages: PipelineStageRecord[]): string | undefined;
6
+ export declare function resolveTargetStageId(currentStageId: string | undefined, stages: PipelineStageRecord[]): string | undefined;
7
+ export declare function findStageById(stages: PipelineStageRecord[], stageId: string | undefined): PipelineStageRecord | undefined;
8
+ export declare function getBranchNameFromStage(stage: PipelineStageRecord | undefined): string | undefined;
@@ -0,0 +1,51 @@
1
+ /*
2
+ * Copyright 2026, Salesforce, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export async function getPipelineIdForProject(connection, projectId) {
17
+ const query = `SELECT DevopsPipelineId FROM DevopsProjectPipeline WHERE DevopsProjectId = '${projectId}' LIMIT 1`;
18
+ const result = await connection.query(query);
19
+ return (result.records ?? [])[0]?.DevopsPipelineId;
20
+ }
21
+ export async function fetchPipelineStages(connection, pipelineId) {
22
+ const stageQuery = `SELECT Id, Name, NextStageId, SourceCodeRepositoryBranch.Name FROM DevopsPipelineStage WHERE DevopsPipelineId = '${pipelineId}'`;
23
+ const stageResult = await connection.query(stageQuery);
24
+ return stageResult.records ?? [];
25
+ }
26
+ export function computeFirstStageId(stages) {
27
+ const allStageIds = new Set(stages.map((s) => s.Id));
28
+ const nextStageIds = new Set(stages.map((s) => s.NextStageId).filter(Boolean));
29
+ const firstStageIds = Array.from(allStageIds).filter((id) => !nextStageIds.has(id));
30
+ if (firstStageIds.length !== 1)
31
+ return undefined;
32
+ return firstStageIds[0];
33
+ }
34
+ export function resolveTargetStageId(currentStageId, stages) {
35
+ if (!stages.length)
36
+ return undefined;
37
+ if (currentStageId) {
38
+ const current = stages.find((s) => s.Id === currentStageId);
39
+ return current?.NextStageId ?? undefined;
40
+ }
41
+ return undefined;
42
+ }
43
+ export function findStageById(stages, stageId) {
44
+ if (!stageId)
45
+ return undefined;
46
+ return stages.find((s) => s.Id === stageId);
47
+ }
48
+ export function getBranchNameFromStage(stage) {
49
+ return stage?.SourceCodeRepositoryBranch?.Name ?? undefined;
50
+ }
51
+ //# sourceMappingURL=pipelineUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pipelineUtils.js","sourceRoot":"","sources":["../../src/utils/pipelineUtils.ts"],"names":[],"m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AkC,EAClC,MAA6B;IAE7B,IAAI,CAAC,MAAM,CAAC,MAAM;QAAE,OAAO,SAAS,CAAC;IACrC,IAAI,cAAc,EAAE,CAAC;QACnB,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,cAAc,CAAC,CAAC;QAC5D,OAAO,OAAO,EAAE,WAAW,IAAI,SAAS,CAAC;IAC3C,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,aAAa,CAC3B,MAA6B,EAC7B,OAA2B;IAE3B,IAAI,CAAC,OAAO;QAAE,OAAO,SAAS,CAAC;IAC/B,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,OAAO,CAAC,CAAC;AAC9C,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,KAAsC;IAC3E,OAAO,KAAK,EAAE,0BAA0B,EAAE,IAAI,IAAI,SAAS,CAAC;AAC9D,CAAC"}
@@ -0,0 +1,57 @@
1
+ export type WorkItem = {
2
+ id: string;
3
+ name: string;
4
+ subject?: string;
5
+ description?: string;
6
+ status: string;
7
+ owner: string;
8
+ DevopsProjectId: string;
9
+ PipelineId?: string;
10
+ PipelineStageId?: string;
11
+ SourceCodeRepository?: {
12
+ repoUrl: string;
13
+ repoType: string;
14
+ };
15
+ WorkItemBranch?: string;
16
+ TargetStageId?: string;
17
+ TargetBranch?: string;
18
+ };
19
+ export type PipelineStageRecord = {
20
+ Id: string;
21
+ Name?: string;
22
+ NextStageId?: string | null;
23
+ SourceCodeRepositoryBranch?: {
24
+ Name?: string;
25
+ } | null;
26
+ };
27
+ export type ProjectStagesContext = {
28
+ pipelineId: string;
29
+ stages: PipelineStageRecord[];
30
+ firstStageId: string | undefined;
31
+ };
32
+ export type VcsType = 'GITHUB' | 'BITBUCKET';
33
+ export type SourceCodeRepositoryQueryRecord = {
34
+ Name: string | null;
35
+ RepositoryOwner: string | null;
36
+ Provider: string | null;
37
+ };
38
+ export type SourceCodeRepositoryBranchQueryRecord = {
39
+ Name: string | null;
40
+ SourceCodeRepositoryId: string | null;
41
+ SourceCodeRepository: SourceCodeRepositoryQueryRecord | null;
42
+ };
43
+ export type WorkItemQueryRecord = {
44
+ Id: string;
45
+ Name: string;
46
+ Subject: string | null;
47
+ Description: string | null;
48
+ Status: string;
49
+ AssignedToId: string | null;
50
+ SourceCodeRepositoryBranchId: string | null;
51
+ SourceCodeRepositoryBranch: SourceCodeRepositoryBranchQueryRecord | null;
52
+ DevopsPipelineStageId: string | null;
53
+ DevopsProjectId: string;
54
+ };
55
+ export type DevopsProjectPipelineQueryRecord = {
56
+ DevopsPipelineId: string;
57
+ };
@@ -0,0 +1,17 @@
1
+ /*
2
+ * Copyright 2026, Salesforce, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export {};
17
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG"}
@@ -0,0 +1,34 @@
1
+ import { Connection } from '@salesforce/core';
2
+ export type WorkItemContext = {
3
+ workItemId: string;
4
+ projectId: string;
5
+ };
6
+ export type UpdateWorkItemStatusParams = {
7
+ connection: Connection;
8
+ workItemId: string;
9
+ projectId: string;
10
+ status: string;
11
+ };
12
+ export type UpdateWorkItemStatusResult = {
13
+ success: boolean;
14
+ workItemId: string;
15
+ workItemName?: string;
16
+ status?: string;
17
+ error?: string;
18
+ };
19
+ /**
20
+ * Resolves a work item's Salesforce ID and project ID from its Name (e.g. WI-000001) via SOQL.
21
+ */
22
+ export declare function resolveWorkItemByName(connection: Connection, workItemName: string): Promise<WorkItemContext>;
23
+ /**
24
+ * Fetches the project ID for a given work item ID via SOQL.
25
+ */
26
+ export declare function resolveProjectIdForWorkItem(connection: Connection, workItemId: string): Promise<string>;
27
+ export declare const ALLOWED_STATUSES: readonly ["In Progress", "Ready to Promote"];
28
+ export type AllowedStatus = (typeof ALLOWED_STATUSES)[number];
29
+ export declare function toApiStatus(status: string): string;
30
+ /**
31
+ * Updates the status of a DevOps Center work item via the Connect API.
32
+ * API: PATCH /services/data/v{version}/connect/devops/projects/{projectId}/workitem/{workItemId}
33
+ */
34
+ export declare function updateWorkItemStatus(params: UpdateWorkItemStatusParams): Promise<UpdateWorkItemStatusResult>;
@@ -0,0 +1,71 @@
1
+ /*
2
+ * Copyright 2026, Salesforce, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * Resolves a work item's Salesforce ID and project ID from its Name (e.g. WI-000001) via SOQL.
18
+ */
19
+ export async function resolveWorkItemByName(connection, workItemName) {
20
+ const result = await connection.query(`SELECT Id, DevopsProjectId FROM WorkItem WHERE Name = '${workItemName}' LIMIT 1`);
21
+ const record = (result.records ?? [])[0];
22
+ if (!record) {
23
+ throw new Error(`Work item with name '${workItemName}' not found.`);
24
+ }
25
+ return { workItemId: record.Id, projectId: record.DevopsProjectId };
26
+ }
27
+ /**
28
+ * Fetches the project ID for a given work item ID via SOQL.
29
+ */
30
+ export async function resolveProjectIdForWorkItem(connection, workItemId) {
31
+ const result = await connection.query(`SELECT DevopsProjectId FROM WorkItem WHERE Id = '${workItemId}' LIMIT 1`);
32
+ const record = (result.records ?? [])[0];
33
+ if (!record) {
34
+ throw new Error(`Work item with ID '${workItemId}' not found.`);
35
+ }
36
+ return record.DevopsProjectId;
37
+ }
38
+ export const ALLOWED_STATUSES = ['In Progress', 'Ready to Promote'];
39
+ const STATUS_LABEL_TO_API = {
40
+ 'in progress': 'IN_PROGRESS',
41
+ 'ready to promote': 'READY_TO_PROMOTE',
42
+ };
43
+ export function toApiStatus(status) {
44
+ const apiStatus = STATUS_LABEL_TO_API[status.toLowerCase()];
45
+ if (!apiStatus) {
46
+ throw new Error(`Invalid status "${status}". Allowed values: ${ALLOWED_STATUSES.join(', ')}`);
47
+ }
48
+ return apiStatus;
49
+ }
50
+ /**
51
+ * Updates the status of a DevOps Center work item via the Connect API.
52
+ * API: PATCH /services/data/v{version}/connect/devops/projects/{projectId}/workitem/{workItemId}
53
+ */
54
+ export async function updateWorkItemStatus(params) {
55
+ const { connection, workItemId, projectId, status } = params;
56
+ const path = `/services/data/v${connection.getApiVersion()}/connect/devops/projects/${projectId}/workitem/${workItemId}`;
57
+ const body = JSON.stringify({ status: toApiStatus(status) });
58
+ const response = await connection.request({
59
+ method: 'PATCH',
60
+ url: path,
61
+ body,
62
+ headers: { 'Content-Type': 'application/json' },
63
+ });
64
+ const data = response ?? {};
65
+ return {
66
+ success: true,
67
+ workItemId,
68
+ status: (data.status ?? data.Status ?? status),
69
+ };
70
+ }
71
+ //# sourceMappingURL=updateWorkItemStatus.js.map