~herrhotzenplotz/gcli-devel

gcli: gitlab: reverse list of comments v1 APPLIED

Nico Sonack: 1
 gitlab: reverse list of comments

 1 files changed, 29 insertions(+), 6 deletions(-)
build pending: alpine.yml
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~herrhotzenplotz/gcli-devel/patches/53276/mbox | git am -3
Learn more about email & git

[PATCH gcli] gitlab: reverse list of comments Export this patch

Gitlab returns comment lists in reverse (with most recent first).
We display comments in chronological order because we don't like
top posting ...

Fixes: https://gitlab.com/herrhotzenplotz/gcli/issues/228
Signed-off-by: Nico Sonack <nsonack@herrhotzenplotz.de>
---
 src/gitlab/comments.c | 35 +++++++++++++++++++++++++++++------
 1 file changed, 29 insertions(+), 6 deletions(-)

diff --git a/src/gitlab/comments.c b/src/gitlab/comments.c
index add5c91..b132c75 100644
--- a/src/gitlab/comments.c
+++ b/src/gitlab/comments.c
@@ -80,6 +80,19 @@ gitlab_perform_submit_comment(struct gcli_ctx *ctx, struct gcli_submit_comment_o
	return rc;
}

static void
reverse_comment_list(struct gcli_comment_list *const list)
{
	struct gcli_comment *reversed =
		calloc(list->comments_size, sizeof *list->comments);

	for (size_t i = 0; i < list->comments_size; ++i)
		reversed[i] = list->comments[list->comments_size - i - 1];

	free(list->comments);
	list->comments = reversed;
}

int
gitlab_get_mr_comments(struct gcli_ctx *ctx, char const *owner, char const *repo,
                       gcli_id const mr, struct gcli_comment_list *const out)
@@ -88,10 +101,10 @@ gitlab_get_mr_comments(struct gcli_ctx *ctx, char const *owner, char const *repo
	char *e_repo = gcli_urlencode(repo);

	struct gcli_fetch_list_ctx fl = {
			.listp = &out->comments,
			.sizep = &out->comments_size,
			.parse = (parsefn)parse_gitlab_comments,
			.max = -1,
		.listp = &out->comments,
		.sizep = &out->comments_size,
		.parse = (parsefn)parse_gitlab_comments,
		.max = -1,
	};

	char *url = sn_asprintf(
@@ -102,7 +115,13 @@ gitlab_get_mr_comments(struct gcli_ctx *ctx, char const *owner, char const *repo
	free(e_owner);
	free(e_repo);

	return gcli_fetch_list(ctx, url, &fl);
	/* Comments in the resulting list are in reverse on Gitlab
	 * (most recent is first). */
	int const rc = gcli_fetch_list(ctx, url, &fl);
	if (rc == 0)
		reverse_comment_list(out);

	return rc;
}

int
@@ -127,5 +146,9 @@ gitlab_get_issue_comments(struct gcli_ctx *ctx, char const *owner,
	free(e_owner);
	free(e_repo);

	return gcli_fetch_list(ctx, url, &fl);
	int const rc = gcli_fetch_list(ctx, url, &fl);
	if (rc == 0)
		reverse_comment_list(out);

	return rc;
}
-- 
2.44.0
Applied. Thanks

-g