From ef7b5453c1e76a66770c5da6c2770157a19327cc Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Wed, 30 Jun 2021 09:47:23 -0400 Subject: Add `get_comment_len()`. --- git.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'git.c') diff --git a/git.c b/git.c index d5b1661..3cb7656 100644 --- a/git.c +++ b/git.c @@ -180,6 +180,30 @@ int create_info_file(pull_request *pr, const char *pr_root) { return 1; } +int get_comment_len(comment *comment) { + struct tm tm; + int len = format_len("title: %s\n", pr->title); + + localtime_r(&comment->date, &tm); + + len = format_len("id: %i\n", comment->id); + len += format_len("author: %s\n", comment->author); + len += format_len("date: ") + strftime(NULL, -1, "%c %z\n", &tm); + + /* Is this comment a reply? */ + if (comment->reply != NULL) { + localtime_r(&comment->reply->date, &tm); + len += format_len("reply-to: %i\n", comment->reply->id); + len += format_len("reply-author: %s\n", comment->reply->author); + len += format_len("reply-date: ") + strftime(NULL, -1, "%c %z\n", &tm); + } + + len += format_len("description: %s\n\n", comment->desc); + + return len; + +} + int add_comment(comment *comment, const char *pr_root) { int len; int buf_len; -- cgit v1.2.3-13-gbd6f