From 68297f4389ad257bf9d5714426a1ad0e440ca78c Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Fri, 18 Jul 2025 07:26:08 -0700 Subject: [PATCH] basic infra for tag support --- src/atom.zig | 7 +++++++ src/integration_tests.zig | 2 ++ src/main.zig | 5 +++++ src/providers/Codeberg.zig | 3 +++ src/providers/GitHub.zig | 2 ++ src/providers/GitLab.zig | 3 +++ src/providers/SourceHut.zig | 2 ++ src/timestamp_tests.zig | 3 +++ src/utils.zig | 2 ++ 9 files changed, 29 insertions(+) diff --git a/src/atom.zig b/src/atom.zig index 1a13eb5..535df8d 100644 --- a/src/atom.zig +++ b/src/atom.zig @@ -190,6 +190,9 @@ pub fn generateFeed(allocator: Allocator, releases: []const Release) ![]u8 { try escapeXml(writer, release.repo_name); try writer.writeAll(" - "); try escapeXml(writer, release.tag_name); + if (release.is_tag) { + try writer.writeAll(" (tag)"); + } try writer.writeAll("\n"); try writer.writeAll(" chars & symbols", .provider = "github", + .is_tag = false, }, }; diff --git a/src/integration_tests.zig b/src/integration_tests.zig index ef5b13a..6e83558 100644 --- a/src/integration_tests.zig +++ b/src/integration_tests.zig @@ -28,6 +28,7 @@ test "Atom feed validates against W3C validator" { .html_url = "https://github.com/ziglang/zig/releases/tag/0.14.0", .description = "Zig 0.14.0 release with many improvements", .provider = "github", + .is_tag = false, }, Release{ .repo_name = "example/test", @@ -36,6 +37,7 @@ test "Atom feed validates against W3C validator" { .html_url = "https://github.com/example/test/releases/tag/v1.2.3", .description = "Bug fixes and performance improvements", .provider = "github", + .is_tag = false, }, }; diff --git a/src/main.zig b/src/main.zig index d83f159..caeb059 100644 --- a/src/main.zig +++ b/src/main.zig @@ -66,6 +66,7 @@ pub const Release = struct { html_url: []const u8, description: []const u8, provider: []const u8, + is_tag: bool = false, pub fn deinit(self: Release, allocator: Allocator) void { allocator.free(self.repo_name); @@ -363,6 +364,7 @@ test "atom feed generation" { .html_url = "https://github.com/test/repo/releases/tag/v1.0.0", .description = "Test release", .provider = "github", + .is_tag = false, }, }; @@ -427,6 +429,7 @@ test "Age-based release filtering" { .html_url = "https://github.com/test/recent/releases/tag/v1.0.0", .description = "Recent release", .provider = "github", + .is_tag = false, }; const old_release = Release{ @@ -436,6 +439,7 @@ test "Age-based release filtering" { .html_url = "https://github.com/test/old/releases/tag/v0.1.0", .description = "Old release", .provider = "github", + .is_tag = false, }; const borderline_release = Release{ @@ -445,6 +449,7 @@ test "Age-based release filtering" { .html_url = "https://github.com/test/borderline/releases/tag/v0.5.0", .description = "Borderline release", .provider = "github", + .is_tag = false, }; const releases = [_]Release{ recent_release, old_release, borderline_release }; diff --git a/src/providers/Codeberg.zig b/src/providers/Codeberg.zig index ef9d469..ab54612 100644 --- a/src/providers/Codeberg.zig +++ b/src/providers/Codeberg.zig @@ -37,6 +37,7 @@ pub fn fetchReleases(self: *Self, allocator: Allocator) !ArrayList(Release) { // Get releases for each repo for (starred_repos.items) |repo| { + // TODO: Investigate the tags/releases situation similar to GitHub const repo_releases = getRepoReleases(allocator, &client, self.token, repo) catch |err| { const stderr = std.io.getStdErr().writer(); stderr.print("Error fetching Codeberg releases for {s}: {}\n", .{ repo, err }) catch {}; @@ -239,6 +240,7 @@ fn getRepoReleases(allocator: Allocator, client: *http.Client, token: []const u8 .html_url = try allocator.dupe(u8, html_url_value.string), .description = try allocator.dupe(u8, body_str), .provider = try allocator.dupe(u8, "codeberg"), + .is_tag = false, }; releases.append(release) catch |err| { @@ -317,6 +319,7 @@ test "codeberg release parsing with live data snapshot" { .html_url = try allocator.dupe(u8, html_url_value.string), .description = try allocator.dupe(u8, body_str), .provider = try allocator.dupe(u8, "codeberg"), + .is_tag = false, }; try releases.append(release); diff --git a/src/providers/GitHub.zig b/src/providers/GitHub.zig index df214c8..b9d7bce 100644 --- a/src/providers/GitHub.zig +++ b/src/providers/GitHub.zig @@ -414,6 +414,7 @@ fn getRepoReleases(allocator: Allocator, client: *http.Client, token: []const u8 .html_url = try allocator.dupe(u8, obj.get("html_url").?.string), .description = try allocator.dupe(u8, body_str), .provider = try allocator.dupe(u8, "github"), + .is_tag = false, }; try releases.append(release); @@ -564,6 +565,7 @@ test "github release parsing with live data snapshot" { .html_url = try allocator.dupe(u8, obj.get("html_url").?.string), .description = try allocator.dupe(u8, body_str), .provider = try allocator.dupe(u8, "github"), + .is_tag = false, }; try releases.append(release); diff --git a/src/providers/GitLab.zig b/src/providers/GitLab.zig index 651676a..de3522d 100644 --- a/src/providers/GitLab.zig +++ b/src/providers/GitLab.zig @@ -36,6 +36,7 @@ pub fn fetchReleases(self: *Self, allocator: Allocator) !ArrayList(Release) { } // Get releases for each project + // TODO: Investigate tags similar to GitHub for (starred_projects.items) |project_id| { const project_releases = getProjectReleases(allocator, &client, self.token, project_id) catch |err| { const stderr = std.io.getStdErr().writer(); @@ -226,6 +227,7 @@ fn getProjectReleases(allocator: Allocator, client: *http.Client, token: []const .html_url = try allocator.dupe(u8, obj.get("_links").?.object.get("self").?.string), .description = try allocator.dupe(u8, desc_str), .provider = try allocator.dupe(u8, "gitlab"), + .is_tag = false, }; releases.append(release) catch |err| { @@ -322,6 +324,7 @@ test "gitlab release parsing with live data snapshot" { .html_url = try allocator.dupe(u8, obj.get("_links").?.object.get("self").?.string), .description = try allocator.dupe(u8, desc_str), .provider = try allocator.dupe(u8, "gitlab"), + .is_tag = false, }; try releases.append(release); diff --git a/src/providers/SourceHut.zig b/src/providers/SourceHut.zig index bddc564..da2560f 100644 --- a/src/providers/SourceHut.zig +++ b/src/providers/SourceHut.zig @@ -150,6 +150,7 @@ fn fetchReleasesMultiRepo(allocator: Allocator, client: *http.Client, token: []c else "1970-01-01T00:00:00Z"; + // TODO: Investigate annotated tags as the description here const release = Release{ .repo_name = try std.fmt.allocPrint(allocator, "~{s}/{s}", .{ tag_data.username, tag_data.reponame }), .tag_name = try allocator.dupe(u8, tag_data.tag_name), @@ -157,6 +158,7 @@ fn fetchReleasesMultiRepo(allocator: Allocator, client: *http.Client, token: []c .html_url = try std.fmt.allocPrint(allocator, "https://git.sr.ht/~{s}/{s}/refs/{s}", .{ tag_data.username, tag_data.reponame, tag_data.tag_name }), .description = try std.fmt.allocPrint(allocator, "Tag {s} (commit: {s})", .{ tag_data.tag_name, tag_data.commit_id }), .provider = try allocator.dupe(u8, "sourcehut"), + .is_tag = false, // Well, this is a lie. However, sourcehut doesn't have "releases", so it is a little weird to always set this true }; releases.append(release) catch |err| { diff --git a/src/timestamp_tests.zig b/src/timestamp_tests.zig index d9ba5b7..054d1a4 100644 --- a/src/timestamp_tests.zig +++ b/src/timestamp_tests.zig @@ -79,6 +79,7 @@ test "compareReleasesByDate with various timestamp formats" { .html_url = "https://github.com/test/iso-early/releases/tag/v1.0.0", .description = "Early ISO format", .provider = "github", + .is_tag = false, }; const release_iso_late = Release{ @@ -91,6 +92,7 @@ test "compareReleasesByDate with various timestamp formats" { .html_url = "https://github.com/test/iso-late/releases/tag/v2.0.0", .description = "Late ISO format", .provider = "github", + .is_tag = false, }; const release_invalid = Release{ @@ -100,6 +102,7 @@ test "compareReleasesByDate with various timestamp formats" { .html_url = "https://github.com/test/invalid/releases/tag/v3.0.0", .description = "Invalid format", .provider = "github", + .is_tag = false, }; // Later date should come before earlier date (more recent first) diff --git a/src/utils.zig b/src/utils.zig index ba9983b..ba1c5f8 100644 --- a/src/utils.zig +++ b/src/utils.zig @@ -53,6 +53,7 @@ test "compareReleasesByDate" { .html_url = "https://github.com/test/repo1/releases/tag/v1.0.0", .description = "First release", .provider = "github", + .is_tag = false, }; const release2 = Release{ @@ -65,6 +66,7 @@ test "compareReleasesByDate" { .html_url = "https://github.com/test/repo2/releases/tag/v2.0.0", .description = "Second release", .provider = "github", + .is_tag = false, }; // release2 should come before release1 (more recent first)