#include #include #include #include #include "github.h" #include "utils.h" int submit_issue(const char *token, const char *owner, const char *repo, const char *title, const char *analysis, const char *traceback, const char *sys_info) { char url[512]; snprintf(url, sizeof(url), "https://api.github.com/repos/%s/%s/issues", owner, repo); // Construct Body char body_content[8192]; snprintf(body_content, sizeof(body_content), "## AI Analysis\n%s\n\n## Technical Details\n```\n%s\n```\n\n## System Info\n```\n%s\n```", analysis ? analysis : "Analysis failed.", traceback, sys_info); // Construct JSON JsonBuilder *builder = json_builder_new(); json_builder_begin_object(builder); json_builder_set_member_name(builder, "title"); json_builder_add_string_value(builder, title); json_builder_set_member_name(builder, "body"); json_builder_add_string_value(builder, body_content); json_builder_set_member_name(builder, "labels"); json_builder_begin_array(builder); json_builder_add_string_value(builder, "bug"); json_builder_add_string_value(builder, "crash-report"); json_builder_end_array(builder); json_builder_end_object(builder); JsonGenerator *gen = json_generator_new(); JsonNode *root = json_builder_get_root(builder); json_generator_set_root(gen, root); char *json_body = json_generator_to_data(gen, NULL); // Headers struct curl_slist *headers = NULL; char auth_header[256]; snprintf(auth_header, sizeof(auth_header), "Authorization: token %s", token); headers = curl_slist_append(headers, auth_header); headers = curl_slist_append(headers, "Accept: application/vnd.github.v3+json"); headers = curl_slist_append(headers, "Content-Type: application/json"); char *response = perform_http_post(url, headers, json_body); int success = 0; if (response) { // Check for "id" or "number" in response to confirm creation if (strstr(response, "\"id\":")) { success = 1; } else { fprintf(stderr, "GitHub API Error: %s\n", response); } free(response); } // Cleanup curl_slist_free_all(headers); g_free(json_body); g_object_unref(gen); g_object_unref(builder); return success; }