╭ Issues.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1 const std = @import("std"); 2 const builtin = @import("builtin"); 3 const evt = @import("../../event.zig"); 4 const ui = @import("../../ui.zig"); 5 const xit = @import("xit"); 6 const rp = xit.repo; 7 const hash = xit.hash; 8 const diff3 = @import("../../diff3.zig"); 9 const Comment = @import("Comment.zig"); 10 const Attachment = @import("Attachment.zig"); 11 const thread = ui.widget.thread; 12 13 const wasm = builtin.target.cpu.arch == .wasm32; 14 15 // how many issues one window shows before a "next" link appears. 16 pub const page_size = 20; 17 18 // how many labels the labels view shows at most. 19 pub const max_labels = 1000; 20 21 // one issue from the repo's consumed event database, with its hex event id 22 // (the id lives in the event envelope, not the payload). 23 pub const IssueWithId = struct { 24 id: []const u8, 25 record: evt.Issue.Record, 26 // the creation commit's author 27 author: ui.Author = .unknown, 28 // whether the issue has an unresolved merge conflict 29 conflicted: bool = false, 30 comments: Comment.Window = .empty, 31 attachments: []const Attachment.WithId = &.{}, 32 assignees: []const ui.Assignee = &.{}, 33 // whether the viewer may change the thread, computed here so the web ui has it 34 can_modify: bool = false, 35 // the viewer's notify button, null when hidden 36 notify_action: ?ui.NotifyAction = null, 37 }; 38 39 pub const Entry = IssueWithId; 40 41 // one side of a conflicted field: its value and who set it 42 pub const Side = struct { 43 text: []const u8, 44 author: ui.Author = .unknown, 45 }; 46 47 pub const FieldConflict = struct { 48 ours: Side, 49 theirs: Side, 50 }; 51 52 // the selected issue's conflict, read for the resolve view. ours is the live 53 // record; the chunks split the description against the merge base. 54 pub const Conflict = struct { 55 title: ?FieldConflict = null, 56 labels: ?FieldConflict = null, 57 description: ?struct { 58 chunks: []const diff3.Chunk, 59 ours_author: ui.Author = .unknown, 60 theirs_author: ui.Author = .unknown, 61 } = null, 62 }; 63 64 // one status's windowed listing. 65 pub const Window = struct { 66 items: []const IssueWithId, 67 // the id of the previous window's first issue, or null when this window 68 // is already the first. 69 prev_id: ?[]const u8, 70 // the id of the next window's first issue, or null when this is the last 71 // window. 72 next_id: ?[]const u8, 73 // how many issues the listing holds across all windows. 74 count: usize, 75 // whether a search stopped counting at its cap, so `count` is a floor. 76 more: bool = false, 77 78 pub const empty: Window = .{ .items = &.{}, .prev_id = null, .next_id = null, .count = 0 }; 79 }; 80 81 // "owner:name", so the view can build /owner:name/issues/... links. 82 identity: []const u8, 83 // the url-encoded label the lists are filtered to ("" = unfiltered). 84 label: []const u8, 85 // the url-encoded name or email the lists are filtered to, as typed ("" = unfiltered). 86 assignee: []const u8, 87 // false when the assignee names no user or no assigned issue, which lists nothing 88 assignee_found: bool = true, 89 // the decoded query the lists are filtered to, or null when unfiltered. 90 search: ?[]const u8 = null, 91 // the hex event id of the issue its status's window is rooted at ("" = the 92 // first window), mirrored into the url. 93 selected_id: []const u8, 94 // the comment shown in the selected issue's detail pane. 95 comment_id: []const u8, 96 // the selected issue's comment window (0 = the first window). 97 comments_start: usize, 98 // the selected comment and its immediate replies. 99 comment_page: ?Comment.Permalink = null, 100 // who the page is built for, null when logged out 101 viewer: ?ui.Viewer = null, 102 open: Window, 103 closed: Window, 104 // the conflicted issues' listing; its count also gates the conflicts tab. 105 conflicts: Window, 106 // the selected issue's conflict, set when the page shows the resolve view. 107 conflict: ?Conflict = null, 108 // the resolve view's comma-separated fields prefilled from their side, 109 // mirrored from the url. 110 theirs_picks: []const u8 = "", 111 // the view the page shows initially (a selected issue's status overrides the route's) 112 view: ui.RoutablePage.IssuesView, 113 // the /description page: the detail pane shows the selected issue's whole 114 // description behind a back link. 115 description_page: bool = false, 116 // every label in the repo, in sorted order, for the labels view. 117 labels: []const []const u8, 118 // the on-disk repo this page was read from, for the terminal submit path 119 // (the web posts the new-issue form to the issue route instead). 120 repo_source: ?ui.RepoSource = null, 121 122 const Self = @This(); 123 124 pub const Event = evt.Issue; 125 pub const Status = evt.Issue.Status; 126 pub const ViewKind = ui.RoutablePage.IssuesView; 127 pub const thread_name = "issue"; 128 pub const header_widget_name = "repo_issues_header"; 129 130 pub fn statusKind(event: Event) Status { 131 return event.status; 132 } 133 134 pub fn listRoute(identity: []const u8, status: Status, label: []const u8, selected: []const u8) ?ui.RoutablePage { 135 return ui.RoutablePage.repoIssuesRoute(identity, status, label, selected); 136 } 137 138 pub fn conflictsRoute(identity: []const u8, selected: []const u8) ?ui.RoutablePage { 139 return ui.RoutablePage.repoIssuesConflictsRoute(identity, selected); 140 } 141 142 pub fn resolveRoute(identity: []const u8, selected: []const u8, picks: []const u8) ?ui.RoutablePage { 143 return ui.RoutablePage.repoIssuesResolveRoute(identity, selected, picks); 144 } 145 146 // `status`'s windowed listing. 147 pub fn window(self: *const Self, status: evt.Issue.Status) *const Window { 148 return switch (status) { 149 .open => &self.open, 150 .closed => &self.closed, 151 }; 152 } 153 154 // whether `field` (a field name or "d<n>" hunk name) is listed in the url's 155 // theirs: picks. 156 pub fn theirsPicked(self: *const Self, field: []const u8) bool { 157 var it = std.mem.splitScalar(u8, self.theirs_picks, ','); 158 while (it.next()) |pick| { 159 if (std.mem.eql(u8, pick, field)) return true; 160 } 161 return false; 162 } 163 164 // the issue `selected_id` names, in whichever window holds it. 165 pub fn selectedThread(self: *const Self) ?*const IssueWithId { 166 if (self.selected_id.len == 0) return null; 167 for ([_]*const Window{ &self.open, &self.closed }) |win| { 168 for (win.items) |*entry| { 169 if (std.mem.eql(u8, entry.id, self.selected_id)) return entry; 170 } 171 } 172 return null; 173 } 174 175 // an empty listing, for the wasm / no-repo paths. 176 pub fn emptyResult(aa: std.mem.Allocator, identity: []const u8, label: []const u8, assignee: []const u8, search: []const u8, selected_id: []const u8, comment_id: []const u8, comments_start: usize, theirs_picks: []const u8, view: ui.RoutablePage.IssuesView) !Self { 177 return .{ 178 .identity = try aa.dupe(u8, identity), 179 .label = try aa.dupe(u8, label), 180 .assignee = try aa.dupe(u8, assignee), 181 .search = if (search.len == 0) null else std.Uri.percentDecodeInPlace(try aa.dupe(u8, search)), 182 .selected_id = try aa.dupe(u8, selected_id), 183 .comment_id = try aa.dupe(u8, comment_id), 184 .comments_start = comments_start, 185 .open = .empty, 186 .closed = .empty, 187 .conflicts = .empty, 188 .theirs_picks = try aa.dupe(u8, theirs_picks), 189 // a description url shows a status list, the issue's own status 190 // picking it once the issue is read; conflicts and resolve urls also 191 // start there, upgraded by init when the conflict data exists. 192 .view = switch (view) { 193 .description, .conflicts, .resolve => .open, 194 else => view, 195 }, 196 .description_page = view == .description, 197 .labels = &.{}, 198 }; 199 } 200 201 // read one window per status of an opened repo's issues (filtered to `label` 202 // and `assignee` when set), ordered by creation (newest first). the window of 203 // the issue `selected_id` names starts at it ("" = the beginning). a git repo reads the 204 // event db next to it (synced from the events branch on each page build); a 205 // xit repo reads its own db. 206 pub fn init( 207 comptime repo_kind: rp.RepoKind, 208 comptime repo_opts: rp.RepoOpts(repo_kind), 209 arena: *std.heap.ArenaAllocator, 210 repo: *rp.Repo(repo_kind, repo_opts), 211 io: std.Io, 212 // the admin db's moment, for resolving author emails to user names (null 213 // in local mode, which has no users) 214 admin_moment: ?evt.AdminDB.HashMap(.read_only), 215 identity: []const u8, 216 label: []const u8, 217 assignee: []const u8, 218 search: []const u8, 219 selected_id: []const u8, 220 comment_id: []const u8, 221 comments_start: usize, 222 theirs_picks: []const u8, 223 view: ui.RoutablePage.IssuesView, 224 viewer: ?ui.Viewer, 225 ) !Self { 226 var empty = try emptyResult(arena.allocator(), identity, label, assignee, search, selected_id, comment_id, comments_start, theirs_picks, view); 227 // the early returns below still let the viewer write 228 empty.viewer = viewer; 229 230 const aa = arena.allocator(); 231 const DB = evt.EventDB(repo_opts.hash); 232 const rooted = empty.selected_id.len != 0; 233 const labeled = empty.label.len != 0; 234 // an explicitly named issue or label that doesn't exist is a bad url 235 // (NotFound -> 404); the bare route falls through to an empty listing. 236 const strict = rooted or labeled; 237 238 // a repo with no consumed events has no moment yet. 239 const gpa = arena.child_allocator; 240 var event_db_maybe: ?evt.LocalEventDB(repo_opts.hash) = if (repo_kind == .git) try evt.LocalEventDB(repo_opts.hash).openReadOnly(io, gpa, repo.core.repo_dir) else null; 241 defer if (event_db_maybe) |*event_db| event_db.deinit(io, gpa); 242 const haxy_moment = (if (event_db_maybe) |*event_db| 243 evt.currentMomentFromDb(repo_opts.hash, event_db.db) 244 else if (repo_kind == .git) 245 return empty 246 else 247 evt.currentMoment(repo_opts, repo)) catch { 248 if (strict) return error.NotFound; 249 return empty; 250 }; 251 252 // the sorted sets to window, per status: the label's sets when filtered, 253 // else the top-level per-status sets. a missing set is an empty window. 254 var open_set: ?DB.SortedSet(.read_only) = null; 255 var closed_set: ?DB.SortedSet(.read_only) = null; 256 if (labeled) { 257 const label_to_issues_cursor = try haxy_moment.getCursor(hash.hashInt(repo_opts.hash, evt.Issue.label_status_to_id_set_key)) orelse return error.NotFound; 258 const label_to_issues = try DB.SortedMap(.read_only).init(label_to_issues_cursor); 259 const decoded = std.Uri.percentDecodeInPlace(try aa.dupe(u8, empty.label)); 260 open_set = try thread.labelStatusSet(Self, DB, label_to_issues, decoded, .open); 261 closed_set = try thread.labelStatusSet(Self, DB, label_to_issues, decoded, .closed); 262 // a label no issue carries is a bad url 263 if (open_set == null and closed_set == null) return error.NotFound; 264 } else if (try haxy_moment.getCursor(hash.hashInt(repo_opts.hash, evt.Issue.status_to_id_set_key))) |status_to_issues_cursor| { 265 const status_to_issues = try DB.SortedMap(.read_only).init(status_to_issues_cursor); 266 open_set = try thread.statusSet(Self, DB, status_to_issues, .open); 267 closed_set = try thread.statusSet(Self, DB, status_to_issues, .closed); 268 } else if (rooted) return error.NotFound; 269 270 // the assignee's issues, intersected with each status's set when windowed. 271 // a name resolves to its user's email. an unknown name or an email no 272 // issue carries lists nothing and marks the box, like the assign input. 273 var assignee_set: ?DB.SortedSet(.read_only) = null; 274 const assignee_found = empty.assignee.len == 0 or found: { 275 const decoded = std.Uri.percentDecodeInPlace(try aa.dupe(u8, empty.assignee)); 276 const email = switch (try ui.assigneeEmail(admin_moment, arena, decoded)) { 277 .email => |email| email, 278 .failure => break :found false, 279 }; 280 const by_assignee_cursor = try haxy_moment.getCursor(hash.hashInt(repo_opts.hash, evt.Assignment.assignee_to_issue_id_set_key)) orelse break :found false; 281 const by_assignee = try DB.HashMap(.read_only).init(by_assignee_cursor); 282 const set_cursor = try by_assignee.getCursor(hash.hashInt(repo_opts.hash, email)) orelse break :found false; 283 assignee_set = try DB.SortedSet(.read_only).init(set_cursor); 284 break :found true; 285 }; 286 if (!assignee_found) { 287 open_set = null; 288 closed_set = null; 289 } 290 291 const event_id_to_issue_cursor = try haxy_moment.getCursor(hash.hashInt(repo_opts.hash, evt.Issue.record_map_key)) orelse { 292 if (strict) return error.NotFound; 293 return empty; 294 }; 295 const event_id_to_issue = try DB.HashMap(.read_only).init(event_id_to_issue_cursor); 296 297 // the conflicted issues' container: a set view for membership and 298 // windowing, a map view for the resolve entry, over the same cursor. 299 var conflict_set: ?DB.SortedSet(.read_only) = null; 300 var conflicts_map: ?DB.SortedMap(.read_only) = null; 301 if (try haxy_moment.getCursor(hash.hashInt(repo_opts.hash, evt.Issue.conflicts_key))) |cursor| { 302 conflict_set = try DB.SortedSet(.read_only).init(cursor); 303 conflicts_map = try DB.SortedMap(.read_only).init(cursor); 304 } 305 306 // a named issue roots its own status's window at itself (the conflicts 307 // view's window instead); the other windows start at the beginning. 308 var resolved_view = empty.view; 309 var open_root: ?[]const u8 = null; 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