From 40a2464cb16e318b17723a72cef857842ee16c91 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Fri, 5 Aug 2022 21:50:04 -0300 Subject: git: Add `get_keyword_cb` getter callbacks --- git.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/git.c b/git.c index 447d9fe..e20cfd6 100644 --- a/git.c +++ b/git.c @@ -377,6 +377,34 @@ pull_request *get_pull_request(index_t *idx, const char *root, const char *repo) } } +int has_remote_branch(void *ctx, void *data, const keyword *key, keyword_val *val) { + pull_request *pr = (pull_request *)data; + return (pr->pr_type) ? 0 : -1; +} + +int get_patch_list(void *ctx, void *data, const keyword *key, keyword_val *val) { + pull_request *pr = (pull_request *)data; + + if (key->type == TYPE_STRING && !pr->pr_type && pr->patches != NULL) { + int len = 0; + char *tmp; + + for (int i = 0; pr->patches[i] != NULL; i++) { + len += format_len("% *s", !i, pr->patches[i]->name); + } + + val->str = calloc(len+1, sizeof(char)); + tmp = val->str; + + for (int i = 0; pr->patches[i] != NULL; i++) { + tmp += sprintf(tmp, "%*s", !i, pr->patches[i]->name); + } + return 2; + } else { + return -1; + } +} + int get_info_len(pull_request *pr) { struct tm tm; int len = format_len("title: %s\n", pr->title); @@ -489,6 +517,26 @@ int create_info_file(pull_request *pr, const char *pr_root) { return 1; } +int get_comment_reply(void *ctx, void *data, const keyword *key, keyword_val *val) { + comment *comm = (comment *)data; + + if (comm->reply != NULL) { + /* Which keyword do we have? */ + switch (key->type) { + /* reply-to */ + case TYPE_INT : val->i = comm->reply->id; break; + /* reply-author */ + case TYPE_STRING: val->str = comm->reply->author; break; + /* reply-date */ + case TYPE_TIME : val->t = comm->reply->date; break; + default : return -1; break; + } + return 1; + } else { + return -1; + } +} + int get_comment_len(comment *comment) { struct tm tm; int len = format_len("id: %i\n", comment->id); -- cgit v1.2.3-13-gbd6f