Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

free category #68

Merged
merged 2 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions core/omg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1566,3 +1566,15 @@ void omg_free_discussion(omg_discussion *discussion) {
}
}
}

void omg_free_repo_discussion_category(omg_repo_discussion_category *category) {
if (category != NULL) {
free(category->id);
for (size_t i = 0; i < category->len; i++) {
free(category->categories[i].id);
free(category->categories[i].name);
}

free(category->categories);
}
}
6 changes: 6 additions & 0 deletions core/omg.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,12 @@ typedef struct {
size_t len;
} omg_repo_discussion_category;

void omg_free_repo_discussion_category(omg_repo_discussion_category *);

#define omg_auto_repo_discussion_category \
omg_repo_discussion_category \
__attribute__((cleanup(omg_free_repo_discussion_category)))

omg_error omg_query_repo_discussion_category(omg_context, const char *owner,
const char *name,
omg_repo_discussion_category *);
Expand Down
2 changes: 1 addition & 1 deletion tests/core.zig
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ fn test_create_pull(ctx: ?*clib.struct_omg_context) anyerror!void {
}

fn test_star_repo(ctx: ?*clib.struct_omg_context) anyerror!void {
try check_error(clib.omg_star_repo(ctx, "jiacai2050/oh-my-github"));
try check_error(clib.omg_star_repo(ctx, "xigua2023/xigua2023"));
}

pub fn main() anyerror!void {
Expand Down
5 changes: 3 additions & 2 deletions tests/discussion.zig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const testing = std.testing;
const time = std.time;

pub fn main() !void {
const ctx = try util.init_ctx();
var ctx = try util.init_ctx();
defer c.omg_free_context(&ctx);

// https://github.com/xigua2023/test-github-api/discussions
try create(ctx);
Expand All @@ -23,7 +24,7 @@ fn query(ctx: c.omg_context) !void {
};
try util.check_error(c.omg_query_repo_discussion_category(ctx, "xigua2023", "test-github-api", &out));
defer {
// TODO: free out
c.omg_free_repo_discussion_category(&out);
}
}

Expand Down