1- import axios from 'axios' ;
2- import { getConnection , getRequiredOrgs } from './shared/auth.js' ;
1+ import { type Connection } from '@salesforce/core' ;
32import { execFileSync } from 'child_process' ;
43import { normalizeAndValidateRepoPath } from './shared/pathUtils.js' ;
54import path from 'path' ;
@@ -8,68 +7,60 @@ import * as os from 'os';
87import { RegistryAccess } from '@salesforce/source-deploy-retrieve' ;
98import { convertToSourceComponents } from './shared/sfdxService.js' ;
109
10+ const API_VERSION = 'v65.0' ;
11+
1112interface Change {
1213 fullName : string ;
1314 type : string ;
1415 operation : string ;
1516}
1617
17- interface CommitWorkItemParams {
18+ export interface CommitWorkItemParams {
19+ connection : Connection ;
1820 workItem : { id : string } ;
1921 requestId : string ;
2022 commitMessage : string ;
21- username : string ;
2223 repoPath ?: string ;
2324}
2425
25-
26+ /**
27+ * Commits work item changes (lite flow) using the provided Connection.
28+ * API: POST /services/data/v65.0/connect/devops/workItems/<id>/commitlite
29+ */
2630export async function commitWorkItem ( {
31+ connection,
2732 workItem,
2833 requestId,
2934 commitMessage,
30- username,
3135 repoPath
3236} : CommitWorkItemParams ) : Promise < any > {
33- const connection = await getConnection ( username ) ;
34- const accessToken = connection . accessToken ;
35- const instanceUrl = connection . instanceUrl ;
36-
37- if ( ! accessToken || ! instanceUrl ) {
38- throw new Error ( 'Missing access token or instance URL. Please check if you are authenticated to the org.' ) ;
39- }
40-
41-
4237 const workingDir = normalizeAndValidateRepoPath ( repoPath ) ;
43-
4438 const computedChanges = buildComputedChanges ( workingDir ) ;
45-
46- const { commitSha, branch } = AddAndCommitChanges ( workingDir , commitMessage ) ;
47-
48- const url = `${ instanceUrl } /services/data/v65.0/connect/devops/workItems/${ workItem . id } /commitlite` ;
49-
50- const headers = {
51- 'Authorization' : `Bearer ${ accessToken } ` ,
52- 'Content-Type' : 'application/json'
53- } ;
39+ const { commitSha } = AddAndCommitChanges ( workingDir , commitMessage ) ;
5440
41+ const pathUrl = `/services/data/${ API_VERSION } /connect/devops/workItems/${ workItem . id } /commitlite` ;
5542 const requestBody = {
5643 requestId,
5744 commitMessage,
58- ' commitId' : commitSha ,
45+ commitId : commitSha ,
5946 changes : computedChanges
6047 } ;
6148
6249 try {
63- const response = await axios . post ( url , requestBody , { headers } ) ;
64-
65- return {
50+ await connection . request ( {
51+ method : 'POST' ,
52+ url : pathUrl ,
53+ body : JSON . stringify ( requestBody ) ,
54+ headers : { 'Content-Type' : 'application/json' }
55+ } ) ;
56+ return {
6657 content : [ {
67- type : "text" ,
68- text : `Changes committed successfully.
58+ type : "text" ,
59+ text : `Changes committed successfully.
6960 Commit SHA: ${ commitSha }
7061 Agent execution guide (perform these steps now)
7162 - Push the commit: 'git push'` ,
72- actionRequired : true
63+ actionRequired : true
7364 } ] ,
7465 isError : false
7566 } ;
0 commit comments