@aaronshaf/ger 0.2.0 → 0.2.1
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.
- package/README.md +9 -2
- package/package.json +1 -1
- package/src/cli/commands/review.ts +5 -131
- package/src/cli/commands/setup.ts +2 -1
- package/src/cli/index.ts +1 -1
- package/src/services/git-worktree.ts +0 -17
- package/src/utils/review-prompt-builder.ts +0 -1
- package/src/utils/url-parser.test.ts +149 -1
- package/src/utils/url-parser.ts +27 -0
- package/tests/change-id-formats.test.ts +1 -1
- package/tests/setup.test.ts +7 -11
- package/tests/unit/git-branch-detection.test.ts +1 -2
- package/tests/unit/services/review-strategy.test.ts +2 -2
package/README.md
CHANGED
|
@@ -199,7 +199,7 @@ ger comments 12345 --pretty
|
|
|
199
199
|
Extract URLs from change messages and comments for automation and scripting:
|
|
200
200
|
|
|
201
201
|
```bash
|
|
202
|
-
# Extract
|
|
202
|
+
# Extract URLs from current HEAD commit's change (auto-detect)
|
|
203
203
|
ger extract-url "build-summary-report"
|
|
204
204
|
|
|
205
205
|
# Get the latest build URL (using tail)
|
|
@@ -208,9 +208,15 @@ ger extract-url "build-summary-report" | tail -1
|
|
|
208
208
|
# Get the first/oldest build URL (using head)
|
|
209
209
|
ger extract-url "jenkins" | head -1
|
|
210
210
|
|
|
211
|
-
# For a specific change
|
|
211
|
+
# For a specific change (using change number)
|
|
212
212
|
ger extract-url "build-summary" 12345
|
|
213
213
|
|
|
214
|
+
# For a specific change (using Change-ID)
|
|
215
|
+
ger extract-url "build-summary" If5a3ae8cb5a107e187447802358417f311d0c4b1
|
|
216
|
+
|
|
217
|
+
# Chain with other tools for specific change
|
|
218
|
+
ger extract-url "build-summary-report" 12345 | tail -1 | jk failures --smart --xml
|
|
219
|
+
|
|
214
220
|
# Use regex for precise matching
|
|
215
221
|
ger extract-url "job/Canvas/job/main/\d+/" --regex
|
|
216
222
|
|
|
@@ -225,6 +231,7 @@ ger extract-url "jenkins" --xml
|
|
|
225
231
|
```
|
|
226
232
|
|
|
227
233
|
#### How it works:
|
|
234
|
+
- **Change detection**: Auto-detects Change-ID from HEAD commit if not specified, or accepts explicit change number/Change-ID
|
|
228
235
|
- **Pattern matching**: Substring match by default, regex with `--regex`
|
|
229
236
|
- **Sources**: Searches messages by default, add `--include-comments` to include inline comments
|
|
230
237
|
- **Ordering**: URLs are output in chronological order (oldest first)
|
package/package.json
CHANGED
|
@@ -1,22 +1,8 @@
|
|
|
1
|
-
import { Effect, pipe, Schema
|
|
2
|
-
import {
|
|
3
|
-
ReviewStrategyService,
|
|
4
|
-
type ReviewStrategy,
|
|
5
|
-
ReviewStrategyError,
|
|
6
|
-
} from '@/services/review-strategy'
|
|
1
|
+
import { Effect, pipe, Schema } from 'effect'
|
|
2
|
+
import { ReviewStrategyService, ReviewStrategyError } from '@/services/review-strategy'
|
|
7
3
|
import { commentCommandWithInput } from './comment'
|
|
8
4
|
import { Console } from 'effect'
|
|
9
|
-
import {
|
|
10
|
-
import type { CommentInfo } from '@/schemas/gerrit'
|
|
11
|
-
import { sanitizeCDATA, escapeXML } from '@/utils/shell-safety'
|
|
12
|
-
import { formatDiffPretty } from '@/utils/diff-formatters'
|
|
13
|
-
import { formatDate } from '@/utils/formatters'
|
|
14
|
-
import {
|
|
15
|
-
formatChangeAsXML,
|
|
16
|
-
formatCommentsAsXML,
|
|
17
|
-
formatMessagesAsXML,
|
|
18
|
-
flattenComments,
|
|
19
|
-
} from '@/utils/review-formatters'
|
|
5
|
+
import { GerritApiService } from '@/api/gerrit'
|
|
20
6
|
import { buildEnhancedPrompt } from '@/utils/review-prompt-builder'
|
|
21
7
|
import * as fs from 'node:fs/promises'
|
|
22
8
|
import * as fsSync from 'node:fs'
|
|
@@ -25,7 +11,7 @@ import * as path from 'node:path'
|
|
|
25
11
|
import { fileURLToPath } from 'node:url'
|
|
26
12
|
import { dirname } from 'node:path'
|
|
27
13
|
import * as readline from 'node:readline'
|
|
28
|
-
import { GitWorktreeService
|
|
14
|
+
import { GitWorktreeService } from '@/services/git-worktree'
|
|
29
15
|
|
|
30
16
|
// Get the directory of this module
|
|
31
17
|
const __filename = fileURLToPath(import.meta.url)
|
|
@@ -126,7 +112,7 @@ const validateAndFixInlineComments = (
|
|
|
126
112
|
for (const rawComment of rawComments) {
|
|
127
113
|
// Validate comment structure using Effect Schema
|
|
128
114
|
const parseResult = yield* Schema.decodeUnknown(InlineCommentSchema)(rawComment).pipe(
|
|
129
|
-
Effect.catchTag('ParseError', (
|
|
115
|
+
Effect.catchTag('ParseError', (_parseError) =>
|
|
130
116
|
Effect.gen(function* () {
|
|
131
117
|
yield* Console.warn('Skipping comment with invalid structure')
|
|
132
118
|
return yield* Effect.succeed(null)
|
|
@@ -192,118 +178,6 @@ const validateAndFixInlineComments = (
|
|
|
192
178
|
return validComments
|
|
193
179
|
})
|
|
194
180
|
|
|
195
|
-
// Legacy helper for backward compatibility (will be removed)
|
|
196
|
-
const getChangeDataAsXml = (changeId: string): Effect.Effect<string, ApiError, GerritApiService> =>
|
|
197
|
-
Effect.gen(function* () {
|
|
198
|
-
const gerritApi = yield* GerritApiService
|
|
199
|
-
|
|
200
|
-
// Fetch all data
|
|
201
|
-
const change = yield* gerritApi.getChange(changeId)
|
|
202
|
-
const diffResult = yield* gerritApi.getDiff(changeId)
|
|
203
|
-
const diff = typeof diffResult === 'string' ? diffResult : JSON.stringify(diffResult)
|
|
204
|
-
const commentsMap = yield* gerritApi.getComments(changeId)
|
|
205
|
-
const messages = yield* gerritApi.getMessages(changeId)
|
|
206
|
-
|
|
207
|
-
const comments = flattenComments(commentsMap)
|
|
208
|
-
|
|
209
|
-
// Build XML string using helper functions
|
|
210
|
-
const xmlLines: string[] = []
|
|
211
|
-
xmlLines.push(`<?xml version="1.0" encoding="UTF-8"?>`)
|
|
212
|
-
xmlLines.push(`<show_result>`)
|
|
213
|
-
xmlLines.push(` <status>success</status>`)
|
|
214
|
-
xmlLines.push(...formatChangeAsXML(change))
|
|
215
|
-
xmlLines.push(` <diff><![CDATA[${sanitizeCDATA(diff)}]]></diff>`)
|
|
216
|
-
xmlLines.push(...formatCommentsAsXML(comments))
|
|
217
|
-
xmlLines.push(...formatMessagesAsXML(messages))
|
|
218
|
-
xmlLines.push(`</show_result>`)
|
|
219
|
-
|
|
220
|
-
return xmlLines.join('\n')
|
|
221
|
-
})
|
|
222
|
-
|
|
223
|
-
// Helper to get change data and format as pretty string
|
|
224
|
-
const getChangeDataAsPretty = (
|
|
225
|
-
changeId: string,
|
|
226
|
-
): Effect.Effect<string, ApiError, GerritApiService> =>
|
|
227
|
-
Effect.gen(function* () {
|
|
228
|
-
const gerritApi = yield* GerritApiService
|
|
229
|
-
|
|
230
|
-
// Fetch all data
|
|
231
|
-
const change = yield* gerritApi.getChange(changeId)
|
|
232
|
-
const diffResult = yield* gerritApi.getDiff(changeId)
|
|
233
|
-
const diff = typeof diffResult === 'string' ? diffResult : JSON.stringify(diffResult)
|
|
234
|
-
const commentsMap = yield* gerritApi.getComments(changeId)
|
|
235
|
-
const messages = yield* gerritApi.getMessages(changeId)
|
|
236
|
-
|
|
237
|
-
const comments = flattenComments(commentsMap)
|
|
238
|
-
|
|
239
|
-
// Build pretty string
|
|
240
|
-
const lines: string[] = []
|
|
241
|
-
|
|
242
|
-
// Change details header
|
|
243
|
-
lines.push('━'.repeat(80))
|
|
244
|
-
lines.push(`📋 Change ${change._number}: ${change.subject}`)
|
|
245
|
-
lines.push('━'.repeat(80))
|
|
246
|
-
lines.push('')
|
|
247
|
-
|
|
248
|
-
// Metadata
|
|
249
|
-
lines.push('📝 Details:')
|
|
250
|
-
lines.push(` Project: ${change.project}`)
|
|
251
|
-
lines.push(` Branch: ${change.branch}`)
|
|
252
|
-
lines.push(` Status: ${change.status}`)
|
|
253
|
-
lines.push(` Owner: ${change.owner?.name || change.owner?.email || 'Unknown'}`)
|
|
254
|
-
lines.push(` Created: ${change.created ? formatDate(change.created) : 'Unknown'}`)
|
|
255
|
-
lines.push(` Updated: ${change.updated ? formatDate(change.updated) : 'Unknown'}`)
|
|
256
|
-
lines.push(` Change-Id: ${change.change_id}`)
|
|
257
|
-
lines.push('')
|
|
258
|
-
|
|
259
|
-
// Diff section
|
|
260
|
-
lines.push('🔍 Diff:')
|
|
261
|
-
lines.push('─'.repeat(40))
|
|
262
|
-
lines.push(formatDiffPretty(diff))
|
|
263
|
-
lines.push('')
|
|
264
|
-
|
|
265
|
-
// Comments section
|
|
266
|
-
if (comments.length > 0) {
|
|
267
|
-
lines.push('💬 Inline Comments:')
|
|
268
|
-
lines.push('─'.repeat(40))
|
|
269
|
-
for (const comment of comments) {
|
|
270
|
-
const author = comment.author?.name || 'Unknown'
|
|
271
|
-
const date = comment.updated ? formatDate(comment.updated) : 'Unknown'
|
|
272
|
-
lines.push(`📅 ${date} - ${author}`)
|
|
273
|
-
if (comment.path) lines.push(` File: ${comment.path}`)
|
|
274
|
-
if (comment.line) lines.push(` Line: ${comment.line}`)
|
|
275
|
-
lines.push(` ${comment.message}`)
|
|
276
|
-
if (comment.unresolved) lines.push(` ⚠️ Unresolved`)
|
|
277
|
-
lines.push('')
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
// Messages section
|
|
282
|
-
if (messages.length > 0) {
|
|
283
|
-
lines.push('📝 Review Activity:')
|
|
284
|
-
lines.push('─'.repeat(40))
|
|
285
|
-
for (const message of messages) {
|
|
286
|
-
const author = message.author?.name || 'Unknown'
|
|
287
|
-
const date = formatDate(message.date)
|
|
288
|
-
const cleanMessage = message.message.trim()
|
|
289
|
-
|
|
290
|
-
// Skip very short automated messages
|
|
291
|
-
if (
|
|
292
|
-
cleanMessage.length < 10 &&
|
|
293
|
-
(cleanMessage.includes('Build') || cleanMessage.includes('Patch'))
|
|
294
|
-
) {
|
|
295
|
-
continue
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
lines.push(`📅 ${date} - ${author}`)
|
|
299
|
-
lines.push(` ${cleanMessage}`)
|
|
300
|
-
lines.push('')
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
return lines.join('\n')
|
|
305
|
-
})
|
|
306
|
-
|
|
307
181
|
// Helper function to prompt user for confirmation
|
|
308
182
|
const promptUser = (message: string): Effect.Effect<boolean, never> =>
|
|
309
183
|
Effect.async<boolean, never>((resume) => {
|
|
@@ -11,6 +11,7 @@ import { AppConfig } from '@/schemas/config'
|
|
|
11
11
|
import { Schema } from '@effect/schema'
|
|
12
12
|
import { input, password } from '@inquirer/prompts'
|
|
13
13
|
import { spawn } from 'node:child_process'
|
|
14
|
+
import { normalizeGerritHost } from '@/utils/url-parser'
|
|
14
15
|
|
|
15
16
|
// Check if a command exists on the system
|
|
16
17
|
const checkCommandExists = (command: string): Promise<boolean> =>
|
|
@@ -209,7 +210,7 @@ const setupEffect = (configService: ConfigServiceImpl) =>
|
|
|
209
210
|
|
|
210
211
|
// Build flat config
|
|
211
212
|
const configData = {
|
|
212
|
-
host: host
|
|
213
|
+
host: normalizeGerritHost(host),
|
|
213
214
|
username: username.trim(),
|
|
214
215
|
password: passwordValue,
|
|
215
216
|
...(aiToolCommand && {
|
package/src/cli/index.ts
CHANGED
|
@@ -56,7 +56,7 @@ function getVersion(): string {
|
|
|
56
56
|
const packageJsonPath = join(__dirname, '..', '..', 'package.json')
|
|
57
57
|
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'))
|
|
58
58
|
return packageJson.version || '0.0.0'
|
|
59
|
-
} catch
|
|
59
|
+
} catch {
|
|
60
60
|
// Fallback version if package.json can't be read
|
|
61
61
|
return '0.0.0'
|
|
62
62
|
}
|
|
@@ -156,23 +156,6 @@ const validateGitRepo = (): Effect.Effect<void, NotGitRepoError, never> =>
|
|
|
156
156
|
Effect.map(() => undefined),
|
|
157
157
|
)
|
|
158
158
|
|
|
159
|
-
// Check if working directory is clean
|
|
160
|
-
const validateCleanRepo = (): Effect.Effect<void, DirtyRepoError, never> =>
|
|
161
|
-
pipe(
|
|
162
|
-
runGitCommand(['status', '--porcelain']),
|
|
163
|
-
Effect.mapError(() => new DirtyRepoError({ message: 'Failed to check repository status' })),
|
|
164
|
-
Effect.flatMap((output) =>
|
|
165
|
-
output.trim() === ''
|
|
166
|
-
? Effect.succeed(undefined)
|
|
167
|
-
: Effect.fail(
|
|
168
|
-
new DirtyRepoError({
|
|
169
|
-
message:
|
|
170
|
-
'Working directory has uncommitted changes. Please commit or stash changes before review.',
|
|
171
|
-
}),
|
|
172
|
-
),
|
|
173
|
-
),
|
|
174
|
-
)
|
|
175
|
-
|
|
176
159
|
// Generate unique worktree path
|
|
177
160
|
const generateWorktreePath = (changeId: string): string => {
|
|
178
161
|
const timestamp = Date.now()
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, test } from 'bun:test'
|
|
2
|
-
import { extractChangeNumber, isValidChangeId } from './url-parser'
|
|
2
|
+
import { extractChangeNumber, isValidChangeId, normalizeGerritHost } from './url-parser'
|
|
3
3
|
|
|
4
4
|
describe('extractChangeNumber', () => {
|
|
5
5
|
test('extracts change number from standard Gerrit URL', () => {
|
|
@@ -121,3 +121,151 @@ describe('isValidChangeId', () => {
|
|
|
121
121
|
expect(isValidChangeId('-abc')).toBe(false)
|
|
122
122
|
})
|
|
123
123
|
})
|
|
124
|
+
|
|
125
|
+
describe('normalizeGerritHost', () => {
|
|
126
|
+
describe('adding protocol', () => {
|
|
127
|
+
test('adds https:// when no protocol is provided', () => {
|
|
128
|
+
expect(normalizeGerritHost('gerrit.example.com')).toBe('https://gerrit.example.com')
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
test('adds https:// to hostname with port', () => {
|
|
132
|
+
expect(normalizeGerritHost('gerrit.example.com:8080')).toBe('https://gerrit.example.com:8080')
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
test('adds https:// to localhost', () => {
|
|
136
|
+
expect(normalizeGerritHost('localhost:8080')).toBe('https://localhost:8080')
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
test('adds https:// to IP address', () => {
|
|
140
|
+
expect(normalizeGerritHost('192.168.1.100')).toBe('https://192.168.1.100')
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
test('adds https:// to IP address with port', () => {
|
|
144
|
+
expect(normalizeGerritHost('192.168.1.100:8080')).toBe('https://192.168.1.100:8080')
|
|
145
|
+
})
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
describe('preserving existing protocol', () => {
|
|
149
|
+
test('preserves https:// when already present', () => {
|
|
150
|
+
expect(normalizeGerritHost('https://gerrit.example.com')).toBe('https://gerrit.example.com')
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
test('preserves http:// when explicitly provided', () => {
|
|
154
|
+
expect(normalizeGerritHost('http://gerrit.example.com')).toBe('http://gerrit.example.com')
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
test('preserves https:// with port', () => {
|
|
158
|
+
expect(normalizeGerritHost('https://gerrit.example.com:8080')).toBe(
|
|
159
|
+
'https://gerrit.example.com:8080',
|
|
160
|
+
)
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
test('preserves http:// with port', () => {
|
|
164
|
+
expect(normalizeGerritHost('http://gerrit.example.com:8080')).toBe(
|
|
165
|
+
'http://gerrit.example.com:8080',
|
|
166
|
+
)
|
|
167
|
+
})
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
describe('removing trailing slashes', () => {
|
|
171
|
+
test('removes single trailing slash', () => {
|
|
172
|
+
expect(normalizeGerritHost('https://gerrit.example.com/')).toBe('https://gerrit.example.com')
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
test('removes trailing slash from URL without protocol', () => {
|
|
176
|
+
expect(normalizeGerritHost('gerrit.example.com/')).toBe('https://gerrit.example.com')
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
test('removes trailing slash from URL with port', () => {
|
|
180
|
+
expect(normalizeGerritHost('https://gerrit.example.com:8080/')).toBe(
|
|
181
|
+
'https://gerrit.example.com:8080',
|
|
182
|
+
)
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
test('handles URL without trailing slash', () => {
|
|
186
|
+
expect(normalizeGerritHost('https://gerrit.example.com')).toBe('https://gerrit.example.com')
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
test('does not remove slash from path', () => {
|
|
190
|
+
expect(normalizeGerritHost('https://gerrit.example.com/gerrit')).toBe(
|
|
191
|
+
'https://gerrit.example.com/gerrit',
|
|
192
|
+
)
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
test('removes trailing slash from path', () => {
|
|
196
|
+
expect(normalizeGerritHost('https://gerrit.example.com/gerrit/')).toBe(
|
|
197
|
+
'https://gerrit.example.com/gerrit',
|
|
198
|
+
)
|
|
199
|
+
})
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
describe('whitespace handling', () => {
|
|
203
|
+
test('trims leading whitespace', () => {
|
|
204
|
+
expect(normalizeGerritHost(' gerrit.example.com')).toBe('https://gerrit.example.com')
|
|
205
|
+
})
|
|
206
|
+
|
|
207
|
+
test('trims trailing whitespace', () => {
|
|
208
|
+
expect(normalizeGerritHost('gerrit.example.com ')).toBe('https://gerrit.example.com')
|
|
209
|
+
})
|
|
210
|
+
|
|
211
|
+
test('trims whitespace from URL with protocol', () => {
|
|
212
|
+
expect(normalizeGerritHost(' https://gerrit.example.com ')).toBe(
|
|
213
|
+
'https://gerrit.example.com',
|
|
214
|
+
)
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
test('trims whitespace and removes trailing slash', () => {
|
|
218
|
+
expect(normalizeGerritHost(' gerrit.example.com/ ')).toBe('https://gerrit.example.com')
|
|
219
|
+
})
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
describe('combined scenarios', () => {
|
|
223
|
+
test('adds protocol and removes trailing slash', () => {
|
|
224
|
+
expect(normalizeGerritHost('gerrit.example.com/')).toBe('https://gerrit.example.com')
|
|
225
|
+
})
|
|
226
|
+
|
|
227
|
+
test('trims, adds protocol, and removes trailing slash', () => {
|
|
228
|
+
expect(normalizeGerritHost(' gerrit.example.com/ ')).toBe('https://gerrit.example.com')
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
test('handles subdomain with port', () => {
|
|
232
|
+
expect(normalizeGerritHost('review.git.example.com:8443')).toBe(
|
|
233
|
+
'https://review.git.example.com:8443',
|
|
234
|
+
)
|
|
235
|
+
})
|
|
236
|
+
|
|
237
|
+
test('handles complex URL with path', () => {
|
|
238
|
+
expect(normalizeGerritHost('gerrit.example.com/gerrit')).toBe(
|
|
239
|
+
'https://gerrit.example.com/gerrit',
|
|
240
|
+
)
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
test('normalizes complete real-world example', () => {
|
|
244
|
+
expect(normalizeGerritHost('gerrit-review.example.org')).toBe(
|
|
245
|
+
'https://gerrit-review.example.org',
|
|
246
|
+
)
|
|
247
|
+
})
|
|
248
|
+
})
|
|
249
|
+
|
|
250
|
+
describe('edge cases', () => {
|
|
251
|
+
test('handles empty string', () => {
|
|
252
|
+
// Empty string becomes 'https:/' after normalization (protocol added, then trailing slash removed)
|
|
253
|
+
expect(normalizeGerritHost('')).toBe('https:/')
|
|
254
|
+
})
|
|
255
|
+
|
|
256
|
+
test('handles whitespace-only string', () => {
|
|
257
|
+
// Whitespace-only string becomes 'https:/' after normalization
|
|
258
|
+
expect(normalizeGerritHost(' ')).toBe('https:/')
|
|
259
|
+
})
|
|
260
|
+
|
|
261
|
+
test('handles just a slash', () => {
|
|
262
|
+
// Just a slash becomes 'https://' (protocol added to '/', then trailing slash removed leaving '//')
|
|
263
|
+
expect(normalizeGerritHost('/')).toBe('https://')
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
test('handles protocol only', () => {
|
|
267
|
+
// Protocol only becomes 'https:/' (trailing slash removed)
|
|
268
|
+
expect(normalizeGerritHost('https://')).toBe('https:/')
|
|
269
|
+
})
|
|
270
|
+
})
|
|
271
|
+
})
|
package/src/utils/url-parser.ts
CHANGED
|
@@ -53,6 +53,33 @@ export const extractChangeNumber = (input: string): string => {
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Normalizes a Gerrit host URL by adding https:// if no protocol is provided
|
|
58
|
+
* and removing trailing slashes
|
|
59
|
+
*
|
|
60
|
+
* @param host - The host URL to normalize (e.g., "gerrit.example.com" or "https://gerrit.example.com")
|
|
61
|
+
* @returns The normalized URL with protocol and without trailing slash
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* normalizeGerritHost("gerrit.example.com") // returns "https://gerrit.example.com"
|
|
65
|
+
* normalizeGerritHost("gerrit.example.com:8080") // returns "https://gerrit.example.com:8080"
|
|
66
|
+
* normalizeGerritHost("http://gerrit.example.com") // returns "http://gerrit.example.com"
|
|
67
|
+
* normalizeGerritHost("https://gerrit.example.com/") // returns "https://gerrit.example.com"
|
|
68
|
+
*/
|
|
69
|
+
export const normalizeGerritHost = (host: string): string => {
|
|
70
|
+
let normalized = host.trim()
|
|
71
|
+
|
|
72
|
+
// Add https:// if no protocol provided
|
|
73
|
+
if (!normalized.startsWith('http://') && !normalized.startsWith('https://')) {
|
|
74
|
+
normalized = `https://${normalized}`
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Remove trailing slash
|
|
78
|
+
normalized = normalized.replace(/\/$/, '')
|
|
79
|
+
|
|
80
|
+
return normalized
|
|
81
|
+
}
|
|
82
|
+
|
|
56
83
|
/**
|
|
57
84
|
* Validates if a string is a valid Gerrit change identifier
|
|
58
85
|
*
|
|
@@ -76,7 +76,7 @@ ${JSON.stringify(mockChange)}`)
|
|
|
76
76
|
return HttpResponse.text('Not Found', { status: 404 })
|
|
77
77
|
}),
|
|
78
78
|
|
|
79
|
-
http.post('*/a/changes/:changeId/revisions/current/review', async ({ params
|
|
79
|
+
http.post('*/a/changes/:changeId/revisions/current/review', async ({ params }) => {
|
|
80
80
|
const { changeId } = params
|
|
81
81
|
if (changeId === CHANGE_NUMBER || changeId === CHANGE_ID) {
|
|
82
82
|
return HttpResponse.text(`)]}'
|
package/tests/setup.test.ts
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
import { describe, test, expect } from 'bun:test'
|
|
2
|
+
import { normalizeGerritHost } from '@/utils/url-parser'
|
|
2
3
|
|
|
3
4
|
describe('Setup Command', () => {
|
|
4
|
-
describe('URL
|
|
5
|
-
test('should
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
expect(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
test('should handle URLs without trailing slashes', () => {
|
|
12
|
-
const url = 'https://gerrit.example.com'
|
|
13
|
-
const normalized = url.replace(/\/$/, '')
|
|
14
|
-
expect(normalized).toBe('https://gerrit.example.com')
|
|
5
|
+
describe('URL normalization integration', () => {
|
|
6
|
+
test('should normalize host URL using normalizeGerritHost', () => {
|
|
7
|
+
// Test that the utility function is working as expected
|
|
8
|
+
expect(normalizeGerritHost('gerrit.example.com')).toBe('https://gerrit.example.com')
|
|
9
|
+
expect(normalizeGerritHost('https://gerrit.example.com/')).toBe('https://gerrit.example.com')
|
|
10
|
+
expect(normalizeGerritHost('gerrit.example.com:8080')).toBe('https://gerrit.example.com:8080')
|
|
15
11
|
})
|
|
16
12
|
})
|
|
17
13
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, test, expect } from 'bun:test'
|
|
2
2
|
import { Effect, Layer } from 'effect'
|
|
3
|
-
import { GitWorktreeService
|
|
3
|
+
import { GitWorktreeService } from '@/services/git-worktree'
|
|
4
4
|
|
|
5
5
|
describe('Git Worktree Creation', () => {
|
|
6
6
|
test('should handle commit-based worktree creation in service interface', async () => {
|
|
@@ -11,7 +11,6 @@ describe('Git Worktree Creation', () => {
|
|
|
11
11
|
validatePreconditions: () => Effect.succeed(undefined),
|
|
12
12
|
createWorktree: (changeId: string) => {
|
|
13
13
|
// Simulate commit-based worktree creation (detached HEAD)
|
|
14
|
-
const currentCommit = 'abc123def456' // Mock commit hash
|
|
15
14
|
return Effect.succeed({
|
|
16
15
|
path: `/tmp/test-worktree-${changeId}`,
|
|
17
16
|
changeId,
|
|
@@ -100,7 +100,7 @@ describe('Review Strategy', () => {
|
|
|
100
100
|
}
|
|
101
101
|
})
|
|
102
102
|
|
|
103
|
-
mockChildProcess.stderr.on.mockImplementation((
|
|
103
|
+
mockChildProcess.stderr.on.mockImplementation((_event: string, _callback: Function) => {
|
|
104
104
|
// No stderr for success
|
|
105
105
|
})
|
|
106
106
|
|
|
@@ -112,7 +112,7 @@ describe('Review Strategy', () => {
|
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
const setupFailedExecution = (exitCode = 1, stderr = 'Command failed') => {
|
|
115
|
-
mockChildProcess.stdout.on.mockImplementation((
|
|
115
|
+
mockChildProcess.stdout.on.mockImplementation((_event: string, _callback: Function) => {
|
|
116
116
|
// No stdout for failure
|
|
117
117
|
})
|
|
118
118
|
|