Skip to content

Commit 2c97125

Browse files
committed
Fix PR label extraction for non-PR GitHub URLs
1 parent 2087fee commit 2c97125

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

Sources/agentd/ActivitySummary.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ struct ActivitySummary: Codable, Sendable {
275275
}
276276

277277
private static func githubPullRequestExtractedLabel(_ raw: String) -> String? {
278-
guard let match = raw.firstMatch(of: #/([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+)#([0-9]+)/#) else {
278+
guard let match = raw.wholeMatch(of: #/([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+)#([0-9]+)/#) else {
279279
return nil
280280
}
281281
return "\(match.1)/\(match.2)#\(match.3)"

Tests/agentdTests/DiagnosticCLITests.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,37 @@ final class DiagnosticCLITests: XCTestCase {
270270
XCTAssertEqual(summary.artifacts.first?.foregroundSeconds, 45)
271271
}
272272

273+
func testActivitySummaryIgnoresNonPullRequestGitHubDocumentPath() async throws {
274+
let root = try temporaryDirectory()
275+
defer { try? FileManager.default.removeItem(at: root) }
276+
let now = Date(timeIntervalSince1970: 21_600)
277+
try writeBatch(
278+
ActivitySummaryTests.batch(
279+
id: "batch_non_pr_url",
280+
startedAt: Date(timeIntervalSince1970: 7_000),
281+
endedAt: Date(timeIntervalSince1970: 7_030),
282+
frames: [
283+
ActivitySummaryTests.frame(
284+
appName: "Google Chrome",
285+
bundleId: "com.google.Chrome",
286+
windowTitle: "cerebro",
287+
documentPath: "https://github.com/evalops/cerebro#123",
288+
capturedAt: Date(timeIntervalSince1970: 7_000),
289+
displayId: 42
290+
)
291+
]
292+
),
293+
to: root.appendingPathComponent("batch_non_pr_url.json")
294+
)
295+
296+
let summary = try await ActivitySummary.run(
297+
options: ActivityOptions(sinceHours: 6, batchDirectory: root, windowLabel: "6h"),
298+
now: now
299+
)
300+
301+
XCTAssertTrue(summary.artifacts.isEmpty)
302+
}
303+
273304
func testActivitySummaryArtifactsWriteInstructionsAndResource() async throws {
274305
let batchRoot = try temporaryDirectory()
275306
let artifactRoot = try temporaryDirectory()

0 commit comments

Comments
 (0)