╭ event.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1 const std = @import("std"); 2 const builtin = @import("builtin"); 3 const xit = @import("xit"); 4 const rp = xit.repo; 5 6 test "simple" { 7 const io = std.testing.io; 8 const allocator = std.testing.allocator; 9 const temp_dir_name = "temp-event-simple"; 10 11 // create the temp dir 12 const cwd = std.Io.Dir.cwd(); 13 var temp_dir_or_err = cwd.openDir(io, temp_dir_name, .{}); 14 if (temp_dir_or_err) |*temp_dir| { 15 temp_dir.close(io); 16 try cwd.deleteTree(io, temp_dir_name); 17 } else |_| {} 18 var temp_dir = try cwd.createDirPathOpen(io, temp_dir_name, .{}); 19 defer cwd.deleteTree(io, temp_dir_name) catch {}; 20 defer temp_dir.close(io); 21 22 const cwd_path = try std.process.currentPathAlloc(io, allocator); 23 defer allocator.free(cwd_path); 24 25 const work_path = try std.fs.path.join(allocator, &.{ cwd_path, temp_dir_name }); 26 defer allocator.free(work_path); 27 28 var repo = try rp.Repo(.xit, .{ .is_test = true }).init(io, allocator, .{ .path = work_path }); 29 defer repo.deinit(io, allocator); 30 31 const id_size: usize = 20; 32 const AddIssueEvent = struct { 33 id: [2 * id_size]u8, 34 kind: []const u8, 35 data: struct { 36 title: []const u8, 37 description: []const u8, 38 tags: []const []const u8, 39 }, 40 }; 41 42 var json: std.Io.Writer.Allocating = .init(std.testing.allocator); 43 defer json.deinit(); 44 45 // create event as json 46 { 47 var prng = std.Random.DefaultPrng.init(std.testing.random_seed); 48 var entropy: [id_size]u8 = undefined; 49 prng.random().bytes(&entropy); 50 51 const event = AddIssueEvent{ 52 .id = std.fmt.bytesToHex(entropy, .lower), 53 .kind = "add-issue", 54 .data = .{ 55 .title = "Login form clears password on validation error", 56 .description = "Submitting an invalid email address resets the password field. Preserve the field value and show an inline validation message.", 57 .tags = &[_][]const u8{ "bug", "priority-high", "ui" }, 58 }, 59 }; 60 61 try std.json.Stringify.value(event, .{}, &json.writer); 62 } 63 64 _ = try repo.commitAtRef(io, allocator, .{ .message = json.written() }, null, .{ .kind = .head, .name = "haxy/meta" }); 65 } 66