( command: string, exitCode: number, stdout?: string, )
| 187 | |
| 188 | // Exported for testing purposes |
| 189 | export function trackGitOperations( |
| 190 | command: string, |
| 191 | exitCode: number, |
| 192 | stdout?: string, |
| 193 | ): void { |
| 194 | const success = exitCode === 0 |
| 195 | if (!success) { |
| 196 | return |
| 197 | } |
| 198 | |
| 199 | if (GIT_COMMIT_RE.test(command)) { |
| 200 | logEvent('tengu_git_operation', { |
| 201 | operation: |
| 202 | 'commit' as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 203 | }) |
| 204 | if (command.match(/--amend\b/)) { |
| 205 | logEvent('tengu_git_operation', { |
| 206 | operation: |
| 207 | 'commit_amend' as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 208 | }) |
| 209 | } |
| 210 | getCommitCounter()?.add(1) |
| 211 | } |
| 212 | if (GIT_PUSH_RE.test(command)) { |
| 213 | logEvent('tengu_git_operation', { |
| 214 | operation: |
| 215 | 'push' as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 216 | }) |
| 217 | } |
| 218 | const prHit = GH_PR_ACTIONS.find(a => a.re.test(command)) |
| 219 | if (prHit) { |
| 220 | logEvent('tengu_git_operation', { |
| 221 | operation: |
| 222 | prHit.op as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 223 | }) |
| 224 | } |
| 225 | if (prHit?.action === 'created') { |
| 226 | getPrCounter()?.add(1) |
| 227 | // Auto-link session to PR if we can extract PR URL from stdout |
| 228 | if (stdout) { |
| 229 | const prInfo = findPrInStdout(stdout) |
| 230 | if (prInfo) { |
| 231 | // Import is done dynamically to avoid circular dependency |
| 232 | void import('../../utils/sessionStorage.js').then( |
| 233 | ({ linkSessionToPR }) => { |
| 234 | void import('../../bootstrap/state.js').then(({ getSessionId }) => { |
| 235 | const sessionId = getSessionId() |
| 236 | if (sessionId) { |
| 237 | void linkSessionToPR( |
| 238 | sessionId as `${string}-${string}-${string}-${string}-${string}`, |
| 239 | prInfo.prNumber, |
| 240 | prInfo.prUrl, |
| 241 | prInfo.prRepository, |
| 242 | ) |
| 243 | } |
| 244 | }) |
| 245 | }, |
| 246 | ) |
no test coverage detected