╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Issues.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
310 var closed_root: ?[]const u8 = null; 311 var conflicts_root: ?[]const u8 = null; 312 var conflict_data: ?Conflict = null; 313 if (rooted) { 314 const id_bytes = evt.parseEventId(empty.selected_id) catch return error.NotFound; 315 const issue_cursor = try event_id_to_issue.getCursor(hash.hashInt(repo_opts.hash, &id_bytes)) orelse return error.NotFound; 316 const issue_map = try DB.HashMap(.read_only).init(issue_cursor); 317 const issue_event = try evt.read(evt.Issue.Record, DB, repo_opts.hash, arena, issue_map); 318 const order_key = try aa.dupe(u8, &evt.orderKeyDesc(issue_event.created_order, &id_bytes)); 319 320 if (view == .conflicts) { 321 // the id roots the conflicts window, so it must be conflicted 322 const set = conflict_set orelse return error.NotFound; 323 if (!try set.contains(order_key)) return error.NotFound; 324 conflicts_root = order_key; 325 } else { 326 // the named issue must be in its windowed set (a label url can name 327 // an issue that doesn't carry the label). 328 const set = (switch (issue_event.event.status) { 329 .open => open_set, 330 .closed => closed_set, 331 }) orelse return error.NotFound; 332 if (!try set.contains(order_key)) return error.NotFound; 333 if (assignee_set) |assignee_issues| if (!try assignee_issues.contains(order_key)) return error.NotFound; 334 335 switch (issue_event.event.status) { 336 .open => open_root = order_key, 337 .closed => closed_root = order_key, 338 } 339 // form urls keep their view; otherwise the issue's status picks it. 340 if (view != .edit and view != .new_comment and view != .edit_comment and view != .remove) resolved_view = switch (issue_event.event.status) { 341 .open => .open, 342 .closed => .closed, 343 }; 344 345 // a resolve url shows the resolve view only while the issue still 346 // has a conflict entry; otherwise the status list stands. the 347 // wasm client renders from the snapshot, so the diff machinery 348 // this pulls in is gated out of its build. 349 if (comptime !wasm) { 350 if (view == .resolve) { 351 if (conflicts_map) |map| { 352 if (try map.getCursor(order_key)) |conflict_cursor| { 353 const conflict_entry = try DB.HashMap(.read_only).init(conflict_cursor); 354 conflict_data = try thread.readConflict(Self, repo_kind, repo_opts, arena, repo, io, admin_moment, haxy_moment, &id_bytes, issue_event, conflict_entry); 355 resolved_view = .resolve; 356 } 357 } 358 } 359 } 360 } 361 } 362 363 const thread_comments_start = if (empty.comment_id.len == 0) comments_start else 0; 364 const open_window = try thread.loadWindow(Self, .issue, repo_opts.hash, arena, admin_moment, haxy_moment, event_id_to_issue, open_set, open_root, conflict_set, empty.selected_id, thread_comments_start, empty.search, assignee_set, viewer); 365 const closed_window = try thread.loadWindow(Self, .issue, repo_opts.hash, arena, admin_moment, haxy_moment, event_id_to_issue, closed_set, closed_root, conflict_set, empty.selected_id, thread_comments_start, empty.search, assignee_set, viewer); 366 const conflicts_window = try thread.loadWindow(Self, .issue, repo_opts.hash, arena, admin_moment, haxy_moment, event_id_to_issue, conflict_set, conflicts_root, conflict_set, empty.selected_id, thread_comments_start, null, null, viewer); 367 if (view == .conflicts and conflicts_window.count > 0) resolved_view = .conflicts; 368 369 const comment_page = if (empty.comment_id.len == 0) 370 null 371 else 372 try Comment.init(repo_opts.hash, arena, admin_moment, haxy_moment, empty.selected_id, empty.comment_id, comments_start, viewer); 373 374 const labels = try thread.loadLabels(Self, repo_opts.hash, arena, haxy_moment); 375 376 return .{ 377 .identity = empty.identity, 378 .label = empty.label, 379 .assignee = empty.assignee, 380 .assignee_found = assignee_found, 381 .search = empty.search, 382 .selected_id = empty.selected_id, 383 .comment_id = empty.comment_id, 384 .comments_start = comments_start, 385 .comment_page = comment_page, 386 .viewer = viewer, 387 .open = open_window, 388 .closed = closed_window, 389 .conflicts = conflicts_window, 390 .conflict = conflict_data, 391 .theirs_picks = empty.theirs_picks, 392 .view = resolved_view, 393 .description_page = empty.description_page, 394 .labels = labels, 395 }; 396 } 397 398 pub const View = thread.View(.issue, Self); 399 pub const Detail = thread.Detail(.issue, Self); 400 pub const detail_widget_name = "repo_issue_detail"; 401 402 pub const Header = thread.Header; 403 404 const open_tab_label = "open"; 405 const closed_tab_label = "closed"; 406 const labels_tab_label = "labels"; 407 const edit_tab_label = "edit"; 408 const reply_tab_label = "reply"; 409 const remove_tab_label = "remove"; 410 const resolve_tab_label = "resolve"; 411 const new_tab_label = "new"; 412 const conflicts_tab_label = "conflicts"; 413 414 // tabs switching between the issues page's views 415 pub fn initHeader(allocator: std.mem.Allocator, session: *ui.Session, data: *const Self) !Header { 416 var header = try Header.init(allocator, session, data.search, .{ 417 .label = if (data.assignee_found) " assignee " else " assignee (not found) ", 418 .text = std.Uri.percentDecodeInPlace(try session.page_arena.allocator().dupe(u8, data.assignee)), 419 }); 420 errdefer header.deinit(allocator); 421 const selected_index = View.viewIndex(data.view); 422 const page_selected = std.meta.activeTag(session.data.current_page) == .repo_issues; 423 424 // a list tab per status, labeled with its listing's issue count 425 const status_labels = [_][]const u8{ open_tab_label, closed_tab_label }; 426 for ([_]evt.Issue.Status{ .open, .closed }, status_labels, 0..) |status, status_label, index| { 427 const route = try thread.searchRoute(ui.RoutablePage.withEncodedAssignee(ui.RoutablePage.repoIssuesRoute(data.identity, status, data.label, ""), data.assignee), data.search); 428 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == index); 429 var label_buf: [64]u8 = undefined; 430 const label = try thread.countLabel(&label_buf, status_label, data.window(status).*); 431 try header.addTab(allocator, label, link, index); 432 } 433 434 // labels tab 435 { 436 const labels_route = try thread.searchRoute(ui.RoutablePage.withEncodedAssignee(ui.RoutablePage.repoThreadLabelsRoute(.issue, data.identity, data.label), data.assignee), data.search); 437 const labels_link = try ui.inPageTabLink(session, labels_route, page_selected and selected_index == View.viewIndex(.labels)); 438 try header.addTab(allocator, labels_tab_label, labels_link, View.viewIndex(.labels)); 439 } 440 441 // new-issue tab; an edit or resolve url shows its tab in this place 442 { 443 const route = switch (data.view) { 444 .edit => ui.RoutablePage.repoThreadEditRoute(.issue, data.identity, data.selected_id) orelse return error.RouteTooLong, 445 .new_comment => ui.RoutablePage.repoThreadCommentNewRoute(.issue, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 446 .edit_comment => ui.RoutablePage.repoThreadCommentEditRoute(.issue, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 447 .remove => ui.RoutablePage.repoThreadRemoveRoute(.issue, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 448 .resolve => ui.RoutablePage.repoIssuesResolveRoute(data.identity, data.selected_id, data.theirs_picks) orelse return error.RouteTooLong, 449 else => ui.RoutablePage.repoThreadNewRoute(.issue, data.identity) orelse return error.RouteTooLong, 450 }; 451 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == View.viewIndex(.new)); 452 const label: []const u8 = switch (data.view) { 453 .edit => edit_tab_label, 454 .new_comment => reply_tab_label, 455 .edit_comment => edit_tab_label, 456 .remove => remove_tab_label, 457 .resolve => resolve_tab_label, 458 else => new_tab_label, 459 }; 460 try header.addTab(allocator, label, link, View.viewIndex(.new)); 461 } 462 463 // conflicts tab, labeled with the conflict count 464 if (data.conflicts.count > 0) { 465 const route = ui.RoutablePage.repoIssuesConflictsRoute(data.identity, "") orelse return error.RouteTooLong; 466 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == View.viewIndex(.conflicts)); 467 var label_buf: [64]u8 = undefined; 468 const label = try std.fmt.bufPrint(&label_buf, conflicts_tab_label ++ " ({d})", .{data.conflicts.count}); 469 try header.addTab(allocator, label, link, View.viewIndex(.conflicts)); 470 } 471 472 header.select(View.viewIndex(data.view)); 473 return header; 474 } 475