From f7a4bdc3dd4b9e4d2cb995881681bfac0f2c5544 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Thu, 7 Dec 2023 18:57:57 +0100 Subject: [PATCH 001/158] Development version --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index caa2c2d6..82539d70 100644 --- a/configure.ac +++ b/configure.ac @@ -3,14 +3,14 @@ AC_PREREQ([2.69]) AC_INIT([gcli], - [2.1.0-rc1], + [2.2.0-devel], [~herrhotzenplotz/gcli-discuss@lists.sr.ht], [gcli], [https://herrhotzenplotz.de/gcli]) AM_INIT_AUTOMAKE([1.0 foreign subdir-objects dist-bzip2 dist-xz -Wall]) dnl Release Date. -PACKAGE_DATE="05-Dec-2023" +PACKAGE_DATE="UNRELEASED" AC_SUBST([PACKAGE_DATE]) dnl Silent by default. From 79394a1dce631fd77e2e4cf670c8e618e1734742 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Sun, 10 Dec 2023 11:19:38 +0100 Subject: [PATCH 002/158] Make comment IDs use gcli_id type I somehow forgot to update this code while fixing builds on 32bit platforms. --- include/gcli/comments.h | 8 ++++---- src/cmd/comment.c | 4 ++-- src/comments.c | 4 ++-- src/github/comments.c | 2 +- src/gitlab/comments.c | 2 +- templates/github/comments.t | 4 ++-- templates/gitlab/comments.t | 3 ++- 7 files changed, 14 insertions(+), 13 deletions(-) diff --git a/include/gcli/comments.h b/include/gcli/comments.h index 8ec2181a..c6659fe4 100644 --- a/include/gcli/comments.h +++ b/include/gcli/comments.h @@ -48,7 +48,7 @@ typedef struct gcli_submit_comment_opts gcli_submit_comment_opts; struct gcli_comment { char *author; /* Login name of the comment author */ char *date; /* Creation date of the comment */ - int id; /* id of the comment */ + gcli_id id; /* id of the comment */ char *body; /* Raw text of the comment */ }; @@ -60,7 +60,7 @@ struct gcli_comment_list { struct gcli_submit_comment_opts { enum comment_target_type { ISSUE_COMMENT, PR_COMMENT } target_type; char const *owner, *repo; - int target_id; + gcli_id target_id; sn_sv message; }; @@ -69,10 +69,10 @@ void gcli_comments_free(gcli_comment_list *list); void gcli_comment_free(gcli_comment *const it); int gcli_get_issue_comments(gcli_ctx *ctx, char const *owner, char const *repo, - int issue, gcli_comment_list *out); + gcli_id issue, gcli_comment_list *out); int gcli_get_pull_comments(gcli_ctx *ctx, char const *owner, char const *repo, - int issue, gcli_comment_list *out); + gcli_id issue, gcli_comment_list *out); int gcli_comment_submit(gcli_ctx *ctx, gcli_submit_comment_opts opts); diff --git a/src/cmd/comment.c b/src/cmd/comment.c index 244d3c46..b726ba3a 100644 --- a/src/cmd/comment.c +++ b/src/cmd/comment.c @@ -84,7 +84,7 @@ comment_init(gcli_ctx *ctx, FILE *f, void *_data) "! Enter your comment above, save and exit.\n" "! All lines with a leading '!' are discarded and will not\n" "! appear in your comment.\n" - "! COMMENT IN : %s/%s %s #%d\n", + "! COMMENT IN : %s/%s %s #%"PRIid"\n", info->owner, info->repo, target_type, info->target_id); } @@ -103,7 +103,7 @@ comment_submit(gcli_submit_comment_opts opts, int always_yes) fprintf( stdout, - "You will be commenting the following in %s/%s #%d:\n"SV_FMT"\n", + "You will be commenting the following in %s/%s #%"PRIid":\n"SV_FMT"\n", opts.owner, opts.repo, opts.target_id, SV_ARGS(message)); if (!always_yes) { diff --git a/src/comments.c b/src/comments.c index 45cd8827..153edf15 100644 --- a/src/comments.c +++ b/src/comments.c @@ -57,14 +57,14 @@ gcli_comments_free(gcli_comment_list *const list) int gcli_get_issue_comments(gcli_ctx *ctx, char const *owner, char const *repo, - int const issue, gcli_comment_list *out) + gcli_id const issue, gcli_comment_list *out) { return gcli_forge(ctx)->get_issue_comments(ctx, owner, repo, issue, out); } int gcli_get_pull_comments(gcli_ctx *ctx, char const *owner, char const *repo, - int const pull, gcli_comment_list *out) + gcli_id const pull, gcli_comment_list *out) { return gcli_forge(ctx)->get_pull_comments(ctx, owner, repo, pull, out); } diff --git a/src/github/comments.c b/src/github/comments.c index 3c986f44..0ce9b71b 100644 --- a/src/github/comments.c +++ b/src/github/comments.c @@ -47,7 +47,7 @@ github_perform_submit_comment(gcli_ctx *ctx, gcli_submit_comment_opts opts, "{ \"body\": \""SV_FMT"\" }", SV_ARGS(opts.message)); char *url = sn_asprintf( - "%s/repos/%s/%s/issues/%d/comments", + "%s/repos/%s/%s/issues/%"PRIid"/comments", gcli_get_apibase(ctx), e_owner, e_repo, opts.target_id); diff --git a/src/gitlab/comments.c b/src/gitlab/comments.c index 85d39658..8f5eec47 100644 --- a/src/gitlab/comments.c +++ b/src/gitlab/comments.c @@ -58,7 +58,7 @@ gitlab_perform_submit_comment(gcli_ctx *ctx, gcli_submit_comment_opts opts, "{ \"body\": \""SV_FMT"\" }", SV_ARGS(opts.message)); char *url = sn_asprintf( - "%s/projects/%s%%2F%s/%s/%d/notes", + "%s/projects/%s%%2F%s/%s/%"PRIid"/notes", gcli_get_apibase(ctx), e_owner, e_repo, type, opts.target_id); diff --git a/templates/github/comments.t b/templates/github/comments.t index dcd09f15..a6e471c1 100644 --- a/templates/github/comments.t +++ b/templates/github/comments.t @@ -2,10 +2,10 @@ include "gcli/github/comments.h"; parser github_comment is object of gcli_comment with - ("id" => id as int, + ("id" => id as id, "created_at" => date as string, "body" => body as string, "user" => author as user); parser github_comments is array of gcli_comment - use parse_github_comment; \ No newline at end of file + use parse_github_comment; diff --git a/templates/gitlab/comments.t b/templates/gitlab/comments.t index 3221a4b6..3896a99a 100644 --- a/templates/gitlab/comments.t +++ b/templates/gitlab/comments.t @@ -4,7 +4,8 @@ parser gitlab_comment is object of gcli_comment with ("created_at" => date as string, "body" => body as string, - "author" => author as user); + "author" => author as user, + "id" => id as id); parser gitlab_comments is array of gcli_comment use parse_gitlab_comment; From 13cdfa64ee4ec570e0edf99505d86dbc8bc31dbd Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Sat, 16 Dec 2023 14:28:01 +0100 Subject: [PATCH 003/158] Add gcli.5 to gitignore --- docs/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/.gitignore b/docs/.gitignore index c7a552e4..01bb910c 100644 --- a/docs/.gitignore +++ b/docs/.gitignore @@ -13,3 +13,4 @@ /gcli-snippets.1 /gcli-status.1 /gcli.1 +/gcli.5 From 14ed6044810583f0f85fa14360350c38c79daa0a Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Sat, 16 Dec 2023 20:47:07 +0100 Subject: [PATCH 004/158] Remove .hgignore and update .gitignore hg-git supports gitignore files. Remove the .hgignore in order to make maintainance easier and not cause continuous difficulties for Debian packaging. --- .gitignore | 1 + .hgignore | 26 -------------------------- 2 files changed, 1 insertion(+), 26 deletions(-) delete mode 100644 .hgignore diff --git a/.gitignore b/.gitignore index f42e8c9c..992222cb 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,4 @@ /m4/ltversion.m4 /m4/lt~obsolete.m4 /libgcli.pc +/build diff --git a/.hgignore b/.hgignore deleted file mode 100644 index ba3045c3..00000000 --- a/.hgignore +++ /dev/null @@ -1,26 +0,0 @@ -syntax: glob -build/* -Makefile.in -aclocal.m4 -ar-lib -autom4te.cache/ -compile -config.guess -config.h.in -config.sub -configure -depcomp -install-sh -ltmain.sh -m4/libtool.m4 -m4/ltoptions.m4 -m4/ltsugar.m4 -m4/ltversion.m4 -m4/lt~obsolete.m4 -missing -test-driver -ylwrap -*~ -docs/tutorial/*.html -TAGS -build-*/ From 2a500b4937bd94e7d15dd8a831946072c3f2bd6f Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Tue, 19 Dec 2023 15:28:00 +0100 Subject: [PATCH 005/158] Left-align image on website --- docs/website/index.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/website/index.html b/docs/website/index.html index 40b2641a..70289881 100644 --- a/docs/website/index.html +++ b/docs/website/index.html @@ -30,14 +30,13 @@ } img#screenshot { - margin: 50px 20%; + margin: 50px 0px; width: 60%; max-width: 800px; } @media only screen and (max-width: 1024px) { img#screenshot { - margin: 50px 0px; width: 100%; } } From 88651f83167c243d308d27b92dee4cc605856824 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Tue, 19 Dec 2023 15:00:29 +0100 Subject: [PATCH 006/158] Fix segmentation fault when no authheader is available in gcli_curl This bug occured when invoking the api subcommand for bugzilla and setting a forge type with the -t flag. For some reason curl_slist_append calls strlen and segfaults when the string is a null pointer. Fix by only calling curl_slist_append when the authheader is a valid string. --- src/curl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/curl.c b/src/curl.c index 06a4e9bf..c8295019 100644 --- a/src/curl.c +++ b/src/curl.c @@ -230,7 +230,8 @@ gcli_curl(gcli_ctx *ctx, FILE *stream, char const *url, char const *content_type headers = curl_slist_append(headers, content_type); auth_header = gcli_get_authheader(ctx); - headers = curl_slist_append(headers, auth_header); + if (auth_header) + headers = curl_slist_append(headers, auth_header); curl_easy_setopt(ctx->curl, CURLOPT_URL, url); curl_easy_setopt(ctx->curl, CURLOPT_BUFFERSIZE, 102400L); From ae030a8b3e006ba2b389d05cd27ce643ef577767 Mon Sep 17 00:00:00 2001 From: Gavin-John Noonan Date: Thu, 21 Dec 2023 16:23:28 +0100 Subject: [PATCH 007/158] feat(ci): add builds.sr.ht support for freebsd Signed-off-by: Gavin-John Noonan --- .builds/freebsd.yml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .builds/freebsd.yml diff --git a/.builds/freebsd.yml b/.builds/freebsd.yml new file mode 100644 index 00000000..e85d65cf --- /dev/null +++ b/.builds/freebsd.yml @@ -0,0 +1,33 @@ +image: freebsd/14.x +packages: + - atf + - autoconf + - automake + - ca_root_nss + - curl + - kyua + - libedit + - libssh2 + - libtool + - libunistring + - m4 + - pkg + - pkgconf + - readline +sources: + - https://git.sr.ht/~herrhotzenplotz/gcli +tasks: + - build: | + cd gcli + ./autogen.sh + { + CFLAGS='-std=c99 -pedantic -Wall -Wextra -Wno-misleading-indentation -Werror' \ + CPPFLAGS='-D_XOPEN_SOURCE=600' \ + LEX=flex YACC=byacc \ + ./configure --disable-silent-rules || (cat config.log && exit 42) + } + make -j 4 + + - check: | + cd gcli + make -j 4 distcheck From 8e241c8934202a15382f248891961537fc5ba5f1 Mon Sep 17 00:00:00 2001 From: Gavin-John Noonan Date: Thu, 21 Dec 2023 16:23:47 +0100 Subject: [PATCH 008/158] feat(ci): add builds.sr.ht support for alpine Signed-off-by: Gavin-John Noonan --- .builds/alpine.yml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .builds/alpine.yml diff --git a/.builds/alpine.yml b/.builds/alpine.yml new file mode 100644 index 00000000..d67fa09b --- /dev/null +++ b/.builds/alpine.yml @@ -0,0 +1,34 @@ +image: alpine/edge +packages: + - libcurl + - gcc + - autoconf + - automake + - libtool + - make + - pkgconf + - musl-dev + - curl-dev + - flex + - bison + - xz + - gzip + - bzip2 + - libbsd-dev + - kyua + - atf-dev +sources: + - https://git.sr.ht/~herrhotzenplotz/gcli +tasks: + - build: | + cd gcli + ./autogen.sh + { + CFLAGS='-std=c99 -pedantic -Wall -Wextra -Werror' \ + CPPFLAGS='-D_XOPEN_SOURCE=600' \ + ./configure --disable-silent-rules || (cat config.log && exit 42) + } + make -j + - check: | + cd gcli + make -j distcheck From 685a6a188a641bed54da58bb016d3595abd03193 Mon Sep 17 00:00:00 2001 From: Gavin-John Noonan Date: Thu, 21 Dec 2023 16:23:55 +0100 Subject: [PATCH 009/158] feat(ci): add builds.sr.ht support for debian/stable Signed-off-by: Gavin-John Noonan --- .builds/debian-stable.yml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .builds/debian-stable.yml diff --git a/.builds/debian-stable.yml b/.builds/debian-stable.yml new file mode 100644 index 00000000..e3baf612 --- /dev/null +++ b/.builds/debian-stable.yml @@ -0,0 +1,29 @@ +image: debian/stable +packages: + - build-essential + - libcurl4-openssl-dev + - pkgconf + - autotools-dev + - bison + - flex + - make + - autoconf + - automake + - libtool + - libbsd-dev + - libatf-dev kyua +sources: + - https://git.sr.ht/~herrhotzenplotz/gcli +tasks: + - build: | + cd gcli + ./autogen.sh + { + CFLAGS='-std=c99 -pedantic -Wall -Wextra -Werror' \ + CPPFLAGS='-D_XOPEN_SOURCE=600' \ + ./configure --disable-silent-rules || (cat config.log && exit 42) + } + make + - check: | + cd gcli + make distcheck From cea2b621abd28fa7d7c98146c786b155b219d5ad Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Thu, 21 Dec 2023 14:42:46 +0100 Subject: [PATCH 010/158] Make issues use strings instead of string views The strings in the issue struct were owned by the struct itself and not some outside struct. For that reason using SVs just made things more complicated than they needed to be. --- include/gcli/issues.h | 16 ++++++++-------- include/gcli/json_util.h | 4 ++-- include/gcli/pulls.h | 2 +- src/cmd/issues.c | 27 ++++++++++++++++----------- src/cmd/pulls.c | 4 +++- src/github/pulls.c | 2 +- src/issues.c | 16 ++++++++-------- src/pulls.c | 2 +- templates/github/issues.t | 14 +++++++------- templates/github/labels.t | 2 +- templates/gitlab/issues.t | 16 ++++++++-------- templates/gitlab/merge_requests.t | 2 +- tests/github-parse-tests.c | 20 ++++++++++---------- tests/gitlab-parse-tests.c | 14 +++++++------- 14 files changed, 74 insertions(+), 67 deletions(-) diff --git a/include/gcli/issues.h b/include/gcli/issues.h index 44d0bb84..968bd9c4 100644 --- a/include/gcli/issues.h +++ b/include/gcli/issues.h @@ -46,20 +46,20 @@ typedef struct gcli_issue_fetch_details gcli_issue_fetch_details; struct gcli_issue { gcli_id number; - sn_sv title; - sn_sv created_at; - sn_sv author; - sn_sv state; + char *title; + char *created_at; + char *author; + char *state; int comments; bool locked; - sn_sv body; - sn_sv *labels; + char *body; + char **labels; size_t labels_size; - sn_sv *assignees; + char **assignees; size_t assignees_size; /* workaround for GitHub where PRs are also issues */ int is_pr; - sn_sv milestone; + char *milestone; }; struct gcli_submit_issue_options { diff --git a/include/gcli/json_util.h b/include/gcli/json_util.h index 632d8d62..284197d8 100644 --- a/include/gcli/json_util.h +++ b/include/gcli/json_util.h @@ -93,9 +93,9 @@ get_user_sv(gcli_ctx *ctx, json_stream *input, sn_sv *out) } static inline int -parse_user(gcli_ctx *ctx, json_stream *input, sn_sv *out) +parse_user(gcli_ctx *ctx, json_stream *input, char **out) { - return get_user_sv(ctx, input, out); + return get_user(ctx, input, out); } static inline char const * diff --git a/include/gcli/pulls.h b/include/gcli/pulls.h index b0b1d7eb..ec99f742 100644 --- a/include/gcli/pulls.h +++ b/include/gcli/pulls.h @@ -75,7 +75,7 @@ struct gcli_pull { int head_pipeline_id; /* GitLab specific */ char *coverage; /* Gitlab Specific */ - sn_sv *labels; + char **labels; size_t labels_size; char **reviewers; /**< User names */ diff --git a/src/cmd/issues.c b/src/cmd/issues.c index b4d4c0f2..cb739e81 100644 --- a/src/cmd/issues.c +++ b/src/cmd/issues.c @@ -153,27 +153,32 @@ gcli_issue_print_summary(gcli_issue const *const it) dict = gcli_dict_begin(); gcli_dict_add(dict, "NUMBER", 0, 0, "%"PRIid, it->number); - gcli_dict_add(dict, "TITLE", 0, 0, SV_FMT, SV_ARGS(it->title)); - gcli_dict_add(dict, "CREATED", 0, 0, SV_FMT, SV_ARGS(it->created_at)); + gcli_dict_add(dict, "TITLE", 0, 0, "%s", it->title); + + gcli_dict_add(dict, "CREATED", 0, 0, "%s", it->created_at); gcli_dict_add(dict, "AUTHOR", GCLI_TBLCOL_BOLD, 0, - SV_FMT, SV_ARGS(it->author)); + "%s", it->author); gcli_dict_add(dict, "STATE", GCLI_TBLCOL_STATECOLOURED, 0, - SV_FMT, SV_ARGS(it->state)); + "%s", it->state); + gcli_dict_add(dict, "COMMENTS", 0, 0, "%d", it->comments); gcli_dict_add(dict, "LOCKED", 0, 0, "%s", sn_bool_yesno(it->locked)); - if (it->milestone.length) - gcli_dict_add(dict, "MILESTONE", 0, 0, SV_FMT, SV_ARGS(it->milestone)); + if (it->milestone) + gcli_dict_add(dict, "MILESTONE", 0, 0, "%s", it->milestone); if (it->labels_size) { - gcli_dict_add_sv_list(dict, "LABELS", it->labels, it->labels_size); + gcli_dict_add_string_list(dict, "LABELS", + (char const *const *)it->labels, + it->labels_size); } else { gcli_dict_add(dict, "LABELS", 0, 0, "none"); } if (it->assignees_size) { - gcli_dict_add_sv_list(dict, "ASSIGNEES", - it->assignees, it->assignees_size); + gcli_dict_add_string_list(dict, "ASSIGNEES", + (char const *const *)it->assignees, + it->assignees_size); } else { gcli_dict_add(dict, "ASSIGNEES", 0, 0, "none"); } @@ -186,8 +191,8 @@ gcli_issue_print_summary(gcli_issue const *const it) void gcli_issue_print_op(gcli_issue const *const it) { - if (it->body.length && it->body.data) - pretty_print(it->body.data, 4, 80, stdout); + if (it->body) + pretty_print(it->body, 4, 80, stdout); } static void diff --git a/src/cmd/pulls.c b/src/cmd/pulls.c index bb1022f9..20c81a87 100644 --- a/src/cmd/pulls.c +++ b/src/cmd/pulls.c @@ -219,7 +219,9 @@ gcli_pull_print(gcli_pull const *const it) gcli_dict_add_string(dict, "COVERAGE", 0, 0, it->coverage); if (it->labels_size) { - gcli_dict_add_sv_list(dict, "LABELS", it->labels, it->labels_size); + gcli_dict_add_string_list(dict, "LABELS", + (char const *const *)it->labels, + it->labels_size); } else { gcli_dict_add_string(dict, "LABELS", 0, 0, "none"); } diff --git a/src/github/pulls.c b/src/github/pulls.c index f2e8b0a8..3e4c95f4 100644 --- a/src/github/pulls.c +++ b/src/github/pulls.c @@ -56,7 +56,7 @@ static bool pull_has_label(gcli_pull const *p, char const *const label) { for (size_t i = 0; i < p->labels_size; ++i) { - if (sn_sv_eq_to(p->labels[i], label)) + if (strcmp(p->labels[i], label) == 0) return true; } return false; diff --git a/src/issues.c b/src/issues.c index 08114ed5..50e18a7a 100644 --- a/src/issues.c +++ b/src/issues.c @@ -36,25 +36,25 @@ void gcli_issue_free(gcli_issue *const it) { - free(it->title.data); - free(it->created_at.data); - free(it->author.data); - free(it->state.data); - free(it->body.data); + free(it->title); + free(it->created_at); + free(it->author); + free(it->state); + free(it->body); for (size_t i = 0; i < it->labels_size; ++i) - free(it->labels[i].data); + free(it->labels[i]); free(it->labels); it->labels = NULL; for (size_t i = 0; i < it->assignees_size; ++i) - free(it->assignees[i].data); + free(it->assignees[i]); free(it->assignees); it->assignees = NULL; - free(it->milestone.data); + free(it->milestone); } void diff --git a/src/pulls.c b/src/pulls.c index a77f1b6e..4cc93b18 100644 --- a/src/pulls.c +++ b/src/pulls.c @@ -106,7 +106,7 @@ gcli_pull_free(gcli_pull *const it) free(it->coverage); for (size_t i = 0; i < it->labels_size; ++i) - free(it->labels[i].data); + free(it->labels[i]); free(it->labels); } diff --git a/templates/github/issues.t b/templates/github/issues.t index faee7f79..90b9df7d 100644 --- a/templates/github/issues.t +++ b/templates/github/issues.t @@ -5,21 +5,21 @@ include "templates/github/labels.h"; parser github_issue_milestone is object of gcli_issue with - ("title" => milestone as sv); + ("title" => milestone as string); parser github_issue is object of gcli_issue with - ("title" => title as sv, - "state" => state as sv, - "body" => body as sv, - "created_at" => created_at as sv, + ("title" => title as string, + "state" => state as string, + "body" => body as string, + "created_at" => created_at as string, "number" => number as id, "comments" => comments as int, - "user" => author as user_sv, + "user" => author as user, "locked" => locked as bool, "labels" => labels as array of github_label use parse_github_label_text, - "assignees" => assignees as array of sn_sv use parse_user, + "assignees" => assignees as array of char* use get_user, "pull_request" => is_pr as github_is_pr, "milestone" => use parse_github_issue_milestone); diff --git a/templates/github/labels.t b/templates/github/labels.t index 9aaf5d51..3de580e0 100644 --- a/templates/github/labels.t +++ b/templates/github/labels.t @@ -1,6 +1,6 @@ include "gcli/github/labels.h"; -parser github_label_text is object of sn_sv select "name" as sv; +parser github_label_text is object of char* select "name" as string; parser github_label is object of gcli_label with diff --git a/templates/gitlab/issues.t b/templates/gitlab/issues.t index 3c089348..9247c885 100644 --- a/templates/gitlab/issues.t +++ b/templates/gitlab/issues.t @@ -1,22 +1,22 @@ include "gcli/gitlab/issues.h"; -parser gitlab_user is object of sn_sv select "username" as sv; +parser gitlab_user is object of char* select "username" as string; parser gitlab_issue_milestone is object of gcli_issue with - ("title" => milestone as sv); + ("title" => milestone as string); parser gitlab_issue is object of gcli_issue with - ("title" => title as sv, - "state" => state as sv, - "description" => body as sv, - "created_at" => created_at as sv, + ("title" => title as string, + "state" => state as string, + "description" => body as string, + "created_at" => created_at as string, "iid" => number as id, "user_notes_count" => comments as int, - "author" => author as user_sv, + "author" => author as user, "discussion_locked" => locked as bool, - "labels" => labels as array of sn_sv use parse_sv, + "labels" => labels as array of char* use get_string, "assignees" => assignees as array of gitlab_user use parse_gitlab_user, "milestone" => use parse_gitlab_issue_milestone); diff --git a/templates/gitlab/merge_requests.t b/templates/gitlab/merge_requests.t index a8c4b09e..9d77c517 100644 --- a/templates/gitlab/merge_requests.t +++ b/templates/gitlab/merge_requests.t @@ -24,7 +24,7 @@ object of gcli_pull with "created_at" => created_at as string, "iid" => number as id, "id" => id as id, - "labels" => labels as array of sn_sv use parse_sv, + "labels" => labels as array of char* use get_string, "user_notes_count" => comments as int, "merge_status" => mergeable as gitlab_can_be_merged, "draft" => draft as bool, diff --git a/tests/github-parse-tests.c b/tests/github-parse-tests.c index ff3ba52a..2db73c0d 100644 --- a/tests/github-parse-tests.c +++ b/tests/github-parse-tests.c @@ -85,18 +85,18 @@ ATF_TC_BODY(simple_github_issue, tc) ATF_REQUIRE(parse_github_issue(ctx, &stream, &issue) == 0); ATF_CHECK(issue.number = 115); - ATF_CHECK_SV_EQTO(issue.title, "consider removing FILE *out from printing functions"); - ATF_CHECK_SV_EQTO(issue.created_at, "2022-03-22T16:06:10Z"); - ATF_CHECK_SV_EQTO(issue.author, "herrhotzenplotz"); - ATF_CHECK_SV_EQTO(issue.state, "closed"); + ATF_CHECK_STREQ(issue.title, "consider removing FILE *out from printing functions"); + ATF_CHECK_STREQ(issue.created_at, "2022-03-22T16:06:10Z"); + ATF_CHECK_STREQ(issue.author, "herrhotzenplotz"); + ATF_CHECK_STREQ(issue.state, "closed"); ATF_CHECK(issue.comments == 0); ATF_CHECK(issue.locked == false); - ATF_CHECK_SV_EQTO(issue.body, - "We use these functions with ghcli only anyways. In " - "the GUI stuff we use the datastructures returned by " - "the api directly. And If we output, it is stdout " - "everywhere.\n"); + ATF_CHECK_STREQ(issue.body, + "We use these functions with ghcli only anyways. In " + "the GUI stuff we use the datastructures returned by " + "the api directly. And If we output, it is stdout " + "everywhere.\n"); ATF_CHECK(issue.labels_size == 0); ATF_CHECK(issue.labels == NULL); @@ -105,7 +105,7 @@ ATF_TC_BODY(simple_github_issue, tc) ATF_CHECK(issue.assignees == NULL); ATF_CHECK(issue.is_pr == 0); - ATF_CHECK(sn_sv_null(issue.milestone)); + ATF_CHECK(!issue.milestone); json_close(&stream); gcli_issue_free(&issue); diff --git a/tests/gitlab-parse-tests.c b/tests/gitlab-parse-tests.c index be9cf383..06bfa91b 100644 --- a/tests/gitlab-parse-tests.c +++ b/tests/gitlab-parse-tests.c @@ -95,19 +95,19 @@ ATF_TC_BODY(gitlab_simple_issue, tc) ATF_REQUIRE(parse_gitlab_issue(ctx, &stream, &issue) == 0); ATF_CHECK(issue.number == 193); - ATF_CHECK_SV_EQTO(issue.title, "Make notifications API use a list struct containing both the ptr and size"); - ATF_CHECK_SV_EQTO(issue.created_at, "2023-08-13T18:43:05.766Z"); - ATF_CHECK_SV_EQTO(issue.author, "herrhotzenplotz"); - ATF_CHECK_SV_EQTO(issue.state, "closed"); + ATF_CHECK_STREQ(issue.title, "Make notifications API use a list struct containing both the ptr and size"); + ATF_CHECK_STREQ(issue.created_at, "2023-08-13T18:43:05.766Z"); + ATF_CHECK_STREQ(issue.author, "herrhotzenplotz"); + ATF_CHECK_STREQ(issue.state, "closed"); ATF_CHECK(issue.comments == 2); ATF_CHECK(issue.locked == false); - ATF_CHECK_SV_EQTO(issue.body, "That would make some of the code much cleaner"); + ATF_CHECK_STREQ(issue.body, "That would make some of the code much cleaner"); ATF_CHECK(issue.labels_size == 1); - ATF_CHECK_SV_EQTO(issue.labels[0], "good-first-issue"); + ATF_CHECK_STREQ(issue.labels[0], "good-first-issue"); ATF_CHECK(issue.assignees == NULL); ATF_CHECK(issue.assignees_size == 0); ATF_CHECK(issue.is_pr == 0); - ATF_CHECK(sn_sv_null(issue.milestone)); + ATF_CHECK(issue.milestone == NULL); json_close(&stream); gcli_issue_free(&issue); From 2077c87b7b179b7b9e6ae9f618507423f791b722 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Tue, 19 Dec 2023 16:29:26 +0100 Subject: [PATCH 011/158] Add a helper macro for calling forge specific routines from the dispatch This macro checks a given function pointer for whether it is null or not. If it is null it'll return an error message, otherwise it'll call the function with the provided arguments. --- include/gcli/forges.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/include/gcli/forges.h b/include/gcli/forges.h index 41538567..8161eea4 100644 --- a/include/gcli/forges.h +++ b/include/gcli/forges.h @@ -530,4 +530,21 @@ struct gcli_forge_descriptor { gcli_forge_descriptor const *gcli_forge(gcli_ctx *ctx); +/** A macro used for calling one of the dispatch points above. + * + * It check whether the given function pointer is null. If it is it will return + * an error message otherwise the function is called with the specified + * arguments. */ +#define gcli_null_check_call(routine, ctx, ...) \ + do { \ + gcli_forge_descriptor const *const forge = gcli_forge(ctx); \ + \ + if (forge->routine) { \ + return forge->routine(ctx, __VA_ARGS__); \ + } else { \ + return gcli_error(ctx, #routine " is not available on this forge"); \ + } \ + } while (0) + + #endif /* FORGES_H */ From 4867f728ffb3e40b899919029d686641cff4ffce Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Tue, 19 Dec 2023 16:29:52 +0100 Subject: [PATCH 012/158] issues: Use gcli_null_check_call macro --- src/issues.c | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/src/issues.c b/src/issues.c index 50e18a7a..7e2f6cee 100644 --- a/src/issues.c +++ b/src/issues.c @@ -74,48 +74,43 @@ gcli_get_issues(gcli_ctx *ctx, char const *owner, char const *repo, gcli_issue_fetch_details const *details, int const max, gcli_issue_list *const out) { - return gcli_forge(ctx)->get_issues(ctx, owner, repo, details, max, out); + gcli_null_check_call(get_issues, ctx, owner, repo, details, max, out); } int gcli_get_issue(gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const issue_number, gcli_issue *const out) { - return gcli_forge(ctx)->get_issue_summary( - ctx, owner, repo, issue_number, out); + gcli_null_check_call(get_issue_summary, ctx, owner, repo, issue_number, + out); } int gcli_issue_close(gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const issue_number) { - return gcli_forge(ctx)->issue_close(ctx, owner, repo, issue_number); + gcli_null_check_call(issue_close, ctx, owner, repo, issue_number); } int gcli_issue_reopen(gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const issue_number) { - return gcli_forge(ctx)->issue_reopen(ctx, owner, repo, issue_number); + gcli_null_check_call(issue_reopen, ctx, owner, repo, issue_number); } int gcli_issue_submit(gcli_ctx *ctx, gcli_submit_issue_options opts) { - gcli_fetch_buffer json_buffer = {0}; - int rc = 0; - - rc = gcli_forge(ctx)->perform_submit_issue(ctx, opts, &json_buffer); - free(json_buffer.data); - - return rc; + gcli_null_check_call(perform_submit_issue, ctx, opts, NULL); } int gcli_issue_assign(gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const issue_number, char const *assignee) { - return gcli_forge(ctx)->issue_assign(ctx, owner, repo, issue_number, assignee); + gcli_null_check_call(issue_assign, ctx, owner, repo, issue_number, + assignee); } int @@ -123,8 +118,8 @@ gcli_issue_add_labels(gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const issue, char const *const labels[], size_t const labels_size) { - return gcli_forge(ctx)->issue_add_labels(ctx,owner, repo, issue, labels, - labels_size); + gcli_null_check_call(issue_add_labels, ctx, owner, repo, issue, labels, + labels_size); } int @@ -132,8 +127,8 @@ gcli_issue_remove_labels(gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const issue, char const *const labels[], size_t const labels_size) { - return gcli_forge(ctx)->issue_remove_labels( - ctx, owner, repo, issue, labels, labels_size); + gcli_null_check_call(issue_remove_labels, ctx, owner, repo, issue, + labels, labels_size); } int @@ -141,20 +136,22 @@ gcli_issue_set_milestone(gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const issue, int const milestone) { - return gcli_forge(ctx)->issue_set_milestone( - ctx, owner, repo, issue, milestone); + gcli_null_check_call(issue_set_milestone, ctx, owner, repo, issue, + milestone); } int gcli_issue_clear_milestone(gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const issue) { - return gcli_forge(ctx)->issue_clear_milestone(ctx, owner, repo, issue); + gcli_null_check_call(issue_clear_milestone, ctx, owner, repo, issue); } int gcli_issue_set_title(gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue, char const *new_title) { - return gcli_forge(ctx)->issue_set_title(ctx, owner, repo, issue, new_title); + gcli_null_check_call(issue_set_title, ctx, owner, repo, issue, + new_title); } + From 7905d4a067332baff4c5f8115858d8de58924ab7 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Tue, 19 Dec 2023 16:34:44 +0100 Subject: [PATCH 013/158] pulls: use null-check macro --- src/pulls.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/pulls.c b/src/pulls.c index 4cc93b18..60231b21 100644 --- a/src/pulls.c +++ b/src/pulls.c @@ -54,21 +54,22 @@ gcli_get_pulls(gcli_ctx *ctx, char const *owner, char const *repo, gcli_pull_fetch_details const *const details, int const max, gcli_pull_list *const out) { - return gcli_forge(ctx)->get_pulls(ctx, owner, repo, details, max, out); + gcli_null_check_call(get_pulls, ctx, owner, repo, details, max, out); } int gcli_pull_get_diff(gcli_ctx *ctx, FILE *stream, char const *owner, char const *reponame, gcli_id const pr_number) { - return gcli_forge(ctx)->pull_get_diff(ctx, stream, owner, reponame, pr_number); + gcli_null_check_call(pull_get_diff, ctx, stream, owner, reponame, + pr_number); } int gcli_pull_get_commits(gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const pr_number, gcli_commit_list *const out) { - return gcli_forge(ctx)->get_pull_commits(ctx, owner, repo, pr_number, out); + gcli_null_check_call(get_pull_commits, ctx, owner, repo, pr_number, out); } void @@ -115,14 +116,14 @@ int gcli_get_pull(gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const pr_number, gcli_pull *const out) { - return gcli_forge(ctx)->get_pull(ctx, owner, repo, pr_number, out); + gcli_null_check_call(get_pull, ctx, owner, repo, pr_number, out); } int gcli_pull_get_checks(gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const pr_number, gcli_pull_checks_list *out) { - return gcli_forge(ctx)->get_pull_checks(ctx, owner, repo, pr_number, out); + gcli_null_check_call(get_pull_checks, ctx, owner, repo, pr_number, out); } void @@ -143,28 +144,29 @@ gcli_pull_checks_free(gcli_pull_checks_list *list) int gcli_pull_submit(gcli_ctx *ctx, gcli_submit_pull_options opts) { - return gcli_forge(ctx)->perform_submit_pull(ctx, opts); + gcli_null_check_call(perform_submit_pull, ctx, opts); } int gcli_pull_merge(gcli_ctx *ctx, char const *owner, char const *reponame, gcli_id const pr_number, enum gcli_merge_flags flags) { - return gcli_forge(ctx)->pull_merge(ctx, owner, reponame, pr_number, flags); + gcli_null_check_call(pull_merge, ctx, owner, reponame, pr_number, + flags); } int gcli_pull_close(gcli_ctx *ctx, char const *owner, char const *reponame, gcli_id const pr_number) { - return gcli_forge(ctx)->pull_close(ctx, owner, reponame, pr_number); + gcli_null_check_call(pull_close, ctx, owner, reponame, pr_number); } int gcli_pull_reopen(gcli_ctx *ctx, char const *owner, char const *reponame, gcli_id const pr_number) { - return gcli_forge(ctx)->pull_reopen(ctx, owner, reponame, pr_number); + gcli_null_check_call(pull_reopen, ctx, owner, reponame, pr_number); } int @@ -172,8 +174,8 @@ gcli_pull_add_labels(gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const pr_number, char const *const labels[], size_t const labels_size) { - return gcli_forge(ctx)->pull_add_labels( - ctx, owner, repo, pr_number, labels, labels_size); + gcli_null_check_call(pull_add_labels, ctx, owner, repo, pr_number, + labels, labels_size); } int @@ -181,38 +183,38 @@ gcli_pull_remove_labels(gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const pr_number, char const *const labels[], size_t const labels_size) { - return gcli_forge(ctx)->pull_remove_labels( - ctx, owner, repo, pr_number, labels, labels_size); + gcli_null_check_call(pull_remove_labels, ctx, owner, repo, pr_number, + labels, labels_size); } int gcli_pull_set_milestone(gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const pr_number, int milestone_id) { - return gcli_forge(ctx)->pull_set_milestone( - ctx, owner, repo, pr_number, milestone_id); + gcli_null_check_call(pull_set_milestone, ctx, owner, repo, pr_number, + milestone_id); } int gcli_pull_clear_milestone(gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const pr_number) { - return gcli_forge(ctx)->pull_clear_milestone(ctx, owner, repo, pr_number); + gcli_null_check_call(pull_clear_milestone, ctx, owner, repo, pr_number); } int gcli_pull_add_reviewer(gcli_ctx *ctx, char const *owner, char const *repo, gcli_id pr_number, char const *username) { - return gcli_forge(ctx)->pull_add_reviewer( - ctx, owner, repo, pr_number, username); + gcli_null_check_call(pull_add_reviewer, ctx, owner, repo, pr_number, + username); } int gcli_pull_get_patch(gcli_ctx *ctx, FILE *out, char const *owner, char const *repo, gcli_id pull_id) { - return gcli_forge(ctx)->pull_get_patch(ctx, out, owner, repo, pull_id); + gcli_null_check_call(pull_get_patch, ctx, out, owner, repo, pull_id); } int @@ -220,5 +222,5 @@ gcli_pull_set_title(gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const pull, char const *new_title) { - return gcli_forge(ctx)->pull_set_title(ctx, owner, repo, pull, new_title); + gcli_null_check_call(pull_set_title, ctx, owner, repo, pull, new_title); } From 395cc7637ac12bf748b62cfdec966c5dc698d653 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Tue, 19 Dec 2023 16:42:06 +0100 Subject: [PATCH 014/158] comments: use null-check macro --- src/comments.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/comments.c b/src/comments.c index 153edf15..de06eca2 100644 --- a/src/comments.c +++ b/src/comments.c @@ -59,18 +59,18 @@ int gcli_get_issue_comments(gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const issue, gcli_comment_list *out) { - return gcli_forge(ctx)->get_issue_comments(ctx, owner, repo, issue, out); + gcli_null_check_call(get_issue_comments, ctx, owner, repo, issue, out); } int gcli_get_pull_comments(gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const pull, gcli_comment_list *out) { - return gcli_forge(ctx)->get_pull_comments(ctx, owner, repo, pull, out); + gcli_null_check_call(get_pull_comments, ctx, owner, repo, pull, out); } int gcli_comment_submit(gcli_ctx *ctx, gcli_submit_comment_opts opts) { - return gcli_forge(ctx)->perform_submit_comment(ctx, opts, NULL); + gcli_null_check_call(perform_submit_comment, ctx, opts, NULL); } From ca468348477f8db9dfa3108049f0d50e17396fbd Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Tue, 19 Dec 2023 16:43:15 +0100 Subject: [PATCH 015/158] forks: use null-check macro --- src/forks.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/forks.c b/src/forks.c index 3508b2d9..5cdadeb1 100644 --- a/src/forks.c +++ b/src/forks.c @@ -37,14 +37,14 @@ int gcli_get_forks(gcli_ctx *ctx, char const *owner, char const *repo, int const max, gcli_fork_list *const out) { - return gcli_forge(ctx)->get_forks(ctx, owner, repo, max, out); + gcli_null_check_call(get_forks, ctx, owner, repo, max, out); } int gcli_fork_create(gcli_ctx *ctx, char const *owner, char const *repo, char const *_in) { - return gcli_forge(ctx)->fork_create(ctx, owner, repo, _in); + gcli_null_check_call(fork_create, ctx, owner, repo, _in); } void From 851941b5b5fd5c5a39f9c5cd5d89524dff3f85d1 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Tue, 19 Dec 2023 16:43:22 +0100 Subject: [PATCH 016/158] labels: use null-check macro --- src/labels.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/labels.c b/src/labels.c index 18375c7a..0478907e 100644 --- a/src/labels.c +++ b/src/labels.c @@ -34,7 +34,7 @@ int gcli_get_labels(gcli_ctx *ctx, char const *owner, char const *reponame, int const max, gcli_label_list *const out) { - return gcli_forge(ctx)->get_labels(ctx, owner, reponame, max, out); + gcli_null_check_call(get_labels, ctx, owner, reponame, max, out); } void @@ -59,12 +59,12 @@ int gcli_create_label(gcli_ctx *ctx, char const *owner, char const *repo, gcli_label *const label) { - return gcli_forge(ctx)->create_label(ctx, owner, repo, label); + gcli_null_check_call(create_label, ctx, owner, repo, label); } int gcli_delete_label(gcli_ctx *ctx, char const *owner, char const *repo, char const *const label) { - return gcli_forge(ctx)->delete_label(ctx, owner, repo, label); + gcli_null_check_call(delete_label, ctx, owner, repo, label); } From 06d3f42fd8ac63e0d475a133f1dc53cc2e409ae2 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Tue, 19 Dec 2023 16:44:24 +0100 Subject: [PATCH 017/158] milestones: use null-check macro --- src/milestones.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/milestones.c b/src/milestones.c index 4af2bf2f..89465bca 100644 --- a/src/milestones.c +++ b/src/milestones.c @@ -35,28 +35,28 @@ gcli_get_milestones(gcli_ctx *ctx, char const *const owner, char const *const repo, int const max, gcli_milestone_list *const out) { - return gcli_forge(ctx)->get_milestones(ctx, owner, repo, max, out); + gcli_null_check_call(get_milestones, ctx, owner, repo, max, out); } int gcli_get_milestone(gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const milestone, gcli_milestone *const out) { - return gcli_forge(ctx)->get_milestone(ctx, owner, repo, milestone, out); + gcli_null_check_call(get_milestone, ctx, owner, repo, milestone, out); } int gcli_create_milestone(gcli_ctx *ctx, struct gcli_milestone_create_args const *args) { - return gcli_forge(ctx)->create_milestone(ctx, args); + gcli_null_check_call(create_milestone, ctx, args); } int gcli_delete_milestone(gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const milestone) { - return gcli_forge(ctx)->delete_milestone(ctx, owner, repo, milestone); + gcli_null_check_call(delete_milestone, ctx, owner, repo, milestone); } void @@ -93,8 +93,8 @@ gcli_milestone_get_issues(gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const milestone, gcli_issue_list *const out) { - return gcli_forge(ctx)->get_milestone_issues( - ctx, owner, repo, milestone, out); + gcli_null_check_call(get_milestone_issues, ctx, owner, repo, milestone, + out); } int @@ -102,6 +102,6 @@ gcli_milestone_set_duedate(gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const milestone, char const *const date) { - return gcli_forge(ctx)->milestone_set_duedate( - ctx, owner, repo, milestone, date); + gcli_null_check_call(milestone_set_duedate, ctx, owner, repo, + milestone, date); } From 9f8dc3761e58af3a6fe74b93cd27110393a133e2 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Tue, 19 Dec 2023 16:45:14 +0100 Subject: [PATCH 018/158] releases: use null-check macro --- src/releases.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/releases.c b/src/releases.c index 5beddfa6..d075f11a 100644 --- a/src/releases.c +++ b/src/releases.c @@ -38,7 +38,7 @@ int gcli_get_releases(gcli_ctx *ctx, char const *owner, char const *repo, int const max, gcli_release_list *const list) { - return gcli_forge(ctx)->get_releases(ctx, owner, repo, max, list); + gcli_null_check_call(get_releases, ctx, owner, repo, max, list); } void @@ -75,7 +75,7 @@ gcli_free_releases(gcli_release_list *const list) int gcli_create_release(gcli_ctx *ctx, gcli_new_release const *release) { - return gcli_forge(ctx)->create_release(ctx, release); + gcli_null_check_call(create_release, ctx, release); } int @@ -94,5 +94,5 @@ int gcli_delete_release(gcli_ctx *ctx, char const *const owner, char const *const repo, char const *const id) { - return gcli_forge(ctx)->delete_release(ctx, owner, repo, id); + gcli_null_check_call(delete_release, ctx, owner, repo, id); } From 403aad9cd2d263aa843b0885f7090f6351499741 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Tue, 19 Dec 2023 16:45:49 +0100 Subject: [PATCH 019/158] repos: use null-check macro --- src/repos.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/repos.c b/src/repos.c index f90179bc..7ec475be 100644 --- a/src/repos.c +++ b/src/repos.c @@ -38,7 +38,7 @@ int gcli_get_repos(gcli_ctx *ctx, char const *owner, int const max, gcli_repo_list *const out) { - return gcli_forge(ctx)->get_repos(ctx, owner, max, out); + gcli_null_check_call(get_repos, ctx, owner, max, out); } void @@ -68,19 +68,19 @@ gcli_repos_free(gcli_repo_list *const list) int gcli_repo_delete(gcli_ctx *ctx, char const *owner, char const *repo) { - return gcli_forge(ctx)->repo_delete(ctx, owner, repo); + gcli_null_check_call(repo_delete, ctx, owner, repo); } int gcli_repo_create(gcli_ctx *ctx, gcli_repo_create_options const *options, gcli_repo *out) { - return gcli_forge(ctx)->repo_create(ctx, options, out); + gcli_null_check_call(repo_create, ctx, options, out); } int gcli_repo_set_visibility(gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_repo_visibility vis) { - return gcli_forge(ctx)->repo_set_visibility(ctx, owner, repo, vis); + gcli_null_check_call(repo_set_visibility, ctx, owner, repo, vis); } From 9b0ad13bc39a7888c722b304f96bcbcd959be70a Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Tue, 19 Dec 2023 16:48:28 +0100 Subject: [PATCH 020/158] sshkeys: use null-check macro and fix segfault if no implementation is available --- src/sshkeys.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/sshkeys.c b/src/sshkeys.c index 5ff34707..2f50ae84 100644 --- a/src/sshkeys.c +++ b/src/sshkeys.c @@ -38,7 +38,7 @@ int gcli_sshkeys_get_keys(gcli_ctx *ctx, gcli_sshkey_list *out) { - return gcli_forge(ctx)->get_sshkeys(ctx, out); + gcli_null_check_call(get_sshkeys, ctx, out); } void @@ -62,12 +62,17 @@ gcli_sshkeys_add_key(gcli_ctx *ctx, char const *title, { int rc; char *buffer; + gcli_forge_descriptor const *const forge = gcli_forge(ctx); + + if (forge->add_sshkey == NULL) { + return gcli_error(ctx, "ssh_add_key is not supported by this forge"); + } rc = sn_read_file(public_key_path, &buffer); if (rc < 0) return rc; - rc = gcli_forge(ctx)->add_sshkey(ctx, title, buffer, out); + rc = forge->add_sshkey(ctx, title, buffer, out); free(buffer); return rc; @@ -76,5 +81,5 @@ gcli_sshkeys_add_key(gcli_ctx *ctx, char const *title, int gcli_sshkeys_delete_key(gcli_ctx *ctx, gcli_id const id) { - return gcli_forge(ctx)->delete_sshkey(ctx, id); + gcli_null_check_call(delete_sshkey, ctx, id); } From 93624846f6eda70a8b2bd5614f2c77517ad4fc7e Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Tue, 19 Dec 2023 16:48:55 +0100 Subject: [PATCH 021/158] status: use null-check macro --- src/status.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/status.c b/src/status.c index aaf441c4..69a16e1e 100644 --- a/src/status.c +++ b/src/status.c @@ -34,7 +34,7 @@ int gcli_get_notifications(gcli_ctx *ctx, int const max, gcli_notification_list *const out) { - return gcli_forge(ctx)->get_notifications(ctx, max, out); + gcli_null_check_call(get_notifications, ctx, max, out); } void @@ -63,5 +63,5 @@ gcli_free_notifications(gcli_notification_list *list) int gcli_notification_mark_as_read(gcli_ctx *ctx, char const *id) { - return gcli_forge(ctx)->notification_mark_as_read(ctx, id); + gcli_null_check_call(notification_mark_as_read, ctx, id); } From 971c0225e18a335aa2f5c4a18a6c8b5f26297509 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Thu, 21 Dec 2023 20:36:02 +0100 Subject: [PATCH 022/158] Reformatting --- thirdparty/sn/sn.c | 418 ++++++++++++++++++++++----------------------- thirdparty/sn/sn.h | 44 ++--- 2 files changed, 231 insertions(+), 231 deletions(-) diff --git a/thirdparty/sn/sn.c b/thirdparty/sn/sn.c index d504bc69..8eb9785f 100644 --- a/thirdparty/sn/sn.c +++ b/thirdparty/sn/sn.c @@ -49,191 +49,191 @@ static int verbosity = VERBOSITY_NORMAL; void sn_setverbosity(int level) { - verbosity = level; + verbosity = level; } int sn_getverbosity(void) { - return verbosity; + return verbosity; } void errx(int code, const char *fmt, ...) { - va_list ap; + va_list ap; - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); - fputc('\n', stderr); - exit(code); + fputc('\n', stderr); + exit(code); } void err(int code, const char *fmt, ...) { - va_list ap; + va_list ap; - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); - fprintf(stderr, ": %s\n", strerror(errno)); - exit(code); + fprintf(stderr, ": %s\n", strerror(errno)); + exit(code); } void warnx(const char *fmt, ...) { - if (!sn_verbose()) - return; + if (!sn_verbose()) + return; - fputs("warning: ", stderr); - va_list ap; + fputs("warning: ", stderr); + va_list ap; - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); - fputc('\n', stderr); + fputc('\n', stderr); } void warn(const char *fmt, ...) { - if (!sn_verbose()) - return; + if (!sn_verbose()) + return; - fputs("warning: ", stderr); - va_list ap; + fputs("warning: ", stderr); + va_list ap; - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); - fprintf(stderr, ": %s\n", strerror(errno)); + fprintf(stderr, ": %s\n", strerror(errno)); } char * sn_strndup(const char *it, size_t len) { - size_t actual = 0; - const char *tmp = NULL; - char *result = NULL; + char *result = NULL; + char const *tmp = NULL; + size_t actual = 0; - if (!len) - return NULL; + if (!len) + return NULL; - tmp = it; + tmp = it; - while (tmp[actual++] && actual < len); + while (tmp[actual++] && actual < len); - result = calloc(1, actual + 1); - memcpy(result, it, actual); - return result; + result = calloc(1, actual + 1); + memcpy(result, it, actual); + return result; } char * sn_asprintf(const char *fmt, ...) { - char tmp = 0, *result = NULL; - size_t actual = 0; - va_list vp; + char tmp = 0, *result = NULL; + size_t actual = 0; + va_list vp; - va_start(vp, fmt); - actual = vsnprintf(&tmp, 1, fmt, vp); - va_end(vp); + va_start(vp, fmt); + actual = vsnprintf(&tmp, 1, fmt, vp); + va_end(vp); - result = calloc(1, actual + 1); - if (!result) - err(1, "calloc"); + result = calloc(1, actual + 1); + if (!result) + err(1, "calloc"); - va_start(vp, fmt); - vsnprintf(result, actual + 1, fmt, vp); - va_end(vp); + va_start(vp, fmt); + vsnprintf(result, actual + 1, fmt, vp); + va_end(vp); - return result; + return result; } static int word_length(const char *x) { - int l = 0; + int l = 0; - while (*x && !isspace(*x++)) - l++; - return l; + while (*x && !isspace(*x++)) + l++; + return l; } void pretty_print(const char *input, int indent, int maxlinelen, FILE *out) { - const char *it = input; + const char *it = input; - if (!it) - return; + if (!it) + return; - while (*it) { - int linelength = indent; - fprintf(out, "%*.*s", indent, indent, ""); + while (*it) { + int linelength = indent; + fprintf(out, "%*.*s", indent, indent, ""); - do { - int w = word_length(it) + 1; + do { + int w = word_length(it) + 1; - if (it[w - 1] == '\n') { - fprintf(out, "%.*s", w - 1, it); - it += w; - break; - } else if (it[w - 1] == '\0') { - w -= 1; - } + if (it[w - 1] == '\n') { + fprintf(out, "%.*s", w - 1, it); + it += w; + break; + } else if (it[w - 1] == '\0') { + w -= 1; + } - fprintf(out, "%.*s", w, it); - it += w; - linelength += w; + fprintf(out, "%.*s", w, it); + it += w; + linelength += w; + } while (*it && (linelength < maxlinelen)); - } while (*it && (linelength < maxlinelen)); - fputc('\n', out); - } + fputc('\n', out); + } } int sn_mmap_file(const char *path, void **buffer) { - struct stat stat_buf = {0}; - int fd = 0; + struct stat stat_buf = {0}; + int fd = 0; - /* Precautiously nullify the buffer, because it is better to have - * it point to null if the pointer variable passed here is - * allocated on the stack and not initialized. This will make - * debugging easier. */ - *buffer = NULL; + /* Precautiously nullify the buffer, because it is better to have + * it point to null if the pointer variable passed here is + * allocated on the stack and not initialized. This will make + * debugging easier. */ + *buffer = NULL; - if (access(path, R_OK) < 0) - err(1, "access"); + if (access(path, R_OK) < 0) + err(1, "access"); - if (stat(path, &stat_buf) < 0) - err(1, "stat"); + if (stat(path, &stat_buf) < 0) + err(1, "stat"); - /* we should not pass a size of 0 to mmap, as this will trigger an - * EINVAL. Thus we can also avoid calling open on the file and - * save a few resources. I discovered this error the hard way in a - * Haiku VM. */ - if (stat_buf.st_size == 0) - return 0; + /* we should not pass a size of 0 to mmap, as this will trigger an + * EINVAL. Thus we can also avoid calling open on the file and + * save a few resources. I discovered this error the hard way in a + * Haiku VM. */ + if (stat_buf.st_size == 0) + return 0; - if ((fd = open(path, O_RDONLY)) < 0) - err(1, "open"); + if ((fd = open(path, O_RDONLY)) < 0) + err(1, "open"); - *buffer = mmap(NULL, stat_buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0); - if (*buffer == MAP_FAILED) - err(1, "mmap"); + *buffer = mmap(NULL, stat_buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + if (*buffer == MAP_FAILED) + err(1, "mmap"); - return stat_buf.st_size; + return stat_buf.st_size; } int @@ -274,213 +274,213 @@ sn_read_file(char const *path, char **buffer) sn_sv sn_sv_trim_front(sn_sv it) { - if (it.length == 0) - return it; + if (it.length == 0) + return it; - // TODO: not utf-8 aware - while (it.length > 0) { - if (!isspace(*it.data)) - break; + // TODO: not utf-8 aware + while (it.length > 0) { + if (!isspace(*it.data)) + break; - it.data++; - it.length--; - } + it.data++; + it.length--; + } - return it; + return it; } static sn_sv sn_sv_trim_end(sn_sv it) { - while (it.length > 0 && isspace(it.data[it.length - 1])) - it.length--; + while (it.length > 0 && isspace(it.data[it.length - 1])) + it.length--; - return it; + return it; } sn_sv sn_sv_trim(sn_sv it) { - return sn_sv_trim_front(sn_sv_trim_end(it)); + return sn_sv_trim_front(sn_sv_trim_end(it)); } sn_sv sn_sv_chop_until(sn_sv *it, char c) { - sn_sv result = *it; + sn_sv result = *it; - result.length = 0; + result.length = 0; - while (it->length > 0) { + while (it->length > 0) { - if (*it->data == c) - break; + if (*it->data == c) + break; - it->data++; - it->length--; - result.length++; - } + it->data++; + it->length--; + result.length++; + } - return result; + return result; } bool sn_sv_has_prefix(sn_sv it, const char *prefix) { - size_t len = strlen(prefix); + size_t len = strlen(prefix); - if (it.length < len) - return false; + if (it.length < len) + return false; - return strncmp(it.data, prefix, len) == 0; + return strncmp(it.data, prefix, len) == 0; } bool sn_sv_eq(sn_sv this, sn_sv that) { - if (this.length != that.length) - return false; + if (this.length != that.length) + return false; - return strncmp(this.data, that.data, this.length) == 0; + return strncmp(this.data, that.data, this.length) == 0; } bool sn_sv_eq_to(const sn_sv this, const char *that) { - size_t len = strlen(that); - if (len != this.length) - return false; + size_t len = strlen(that); + if (len != this.length) + return false; - return strncmp(this.data, that, len) == 0; + return strncmp(this.data, that, len) == 0; } char * sn_strip_suffix(char *it, const char *suffix) { - int it_len = strlen(it); - int su_len = strlen(suffix); + int it_len = strlen(it); + int su_len = strlen(suffix); - if (su_len > it_len) - return it; + if (su_len > it_len) + return it; - int off = it_len - su_len; + int off = it_len - su_len; - if (strncmp(it + off, suffix, su_len) == 0) - it[off] = '\0'; + if (strncmp(it + off, suffix, su_len) == 0) + it[off] = '\0'; - return it; + return it; } sn_sv sn_sv_fmt(const char *fmt, ...) { - char tmp = 0; - va_list vp; - sn_sv result = {0}; + char tmp = 0; + va_list vp; + sn_sv result = {0}; - va_start(vp, fmt); + va_start(vp, fmt); - result.length = vsnprintf(&tmp, 1, fmt, vp); - va_end(vp); - result.data = calloc(1, result.length + 1); + result.length = vsnprintf(&tmp, 1, fmt, vp); + va_end(vp); + result.data = calloc(1, result.length + 1); - va_start(vp, fmt); - vsnprintf(result.data, result.length + 1, fmt, vp); - va_end(vp); + va_start(vp, fmt); + vsnprintf(result.data, result.length + 1, fmt, vp); + va_end(vp); - return result; + return result; } char * sn_sv_to_cstr(sn_sv it) { - return sn_strndup(it.data, it.length); + return sn_strndup(it.data, it.length); } bool sn_yesno(const char *fmt, ...) { - char tmp = 0; - va_list vp; - sn_sv message = {0}; - bool result = false; + char tmp = 0; + va_list vp; + sn_sv message = {0}; + bool result = false; - va_start(vp, fmt); + va_start(vp, fmt); - message.length = vsnprintf(&tmp, 1, fmt, vp); - va_end(vp); - message.data = calloc(1, message.length + 1); + message.length = vsnprintf(&tmp, 1, fmt, vp); + va_end(vp); + message.data = calloc(1, message.length + 1); - va_start(vp, fmt); - vsnprintf(message.data, message.length + 1, fmt, vp); - va_end(vp); + va_start(vp, fmt); + vsnprintf(message.data, message.length + 1, fmt, vp); + va_end(vp); - do { - printf(SV_FMT" [yN] ", SV_ARGS(message)); + do { + printf(SV_FMT" [yN] ", SV_ARGS(message)); - char c = getchar(); + char c = getchar(); - if (c == 'y' || c == 'Y') { - result = true; - break; - } else if (c == '\n' || c == 'n' || c == 'N') { - break; - } + if (c == 'y' || c == 'Y') { + result = true; + break; + } else if (c == '\n' || c == 'n' || c == 'N') { + break; + } - getchar(); // consume newline character + getchar(); // consume newline character - } while (!feof(stdin)); + } while (!feof(stdin)); - free(message.data); - return result; + free(message.data); + return result; } sn_sv sn_sv_strip_suffix(sn_sv input, const char *suffix) { - sn_sv expected_suffix = SV((char *)suffix); + sn_sv expected_suffix = SV((char *)suffix); - if (input.length < expected_suffix.length) - return input; + if (input.length < expected_suffix.length) + return input; - sn_sv actual_suffix = sn_sv_from_parts( - input.data + input.length - expected_suffix.length, - expected_suffix.length); + sn_sv actual_suffix = sn_sv_from_parts( + input.data + input.length - expected_suffix.length, + expected_suffix.length); - if (sn_sv_eq(expected_suffix, actual_suffix)) - input.length -= expected_suffix.length; + if (sn_sv_eq(expected_suffix, actual_suffix)) + input.length -= expected_suffix.length; - return input; + return input; } char * sn_join_with(char const *const items[], size_t const items_size, char const *sep) { - char *buffer = NULL; - size_t buffer_size = 0; - size_t bufoff = 0; - size_t sep_size = 0; + char *buffer = NULL; + size_t buffer_size = 0; + size_t bufoff = 0; + size_t sep_size = 0; - sep_size = strlen(sep); + sep_size = strlen(sep); - /* this works because of the null terminator at the end */ - for (size_t i = 0; i < items_size; ++i) { - buffer_size += strlen(items[i]) + sep_size; - } + /* this works because of the null terminator at the end */ + for (size_t i = 0; i < items_size; ++i) { + buffer_size += strlen(items[i]) + sep_size; + } - buffer = calloc(1, buffer_size); - if (!buffer) - return NULL; + buffer = calloc(1, buffer_size); + if (!buffer) + return NULL; - for (size_t i = 0; i < items_size; ++i) { - size_t len = strlen(items[i]); + for (size_t i = 0; i < items_size; ++i) { + size_t len = strlen(items[i]); - memcpy(buffer + bufoff, items[i], len); - if (i != items_size - 1) - memcpy(&buffer[bufoff + len], sep, sep_size); + memcpy(buffer + bufoff, items[i], len); + if (i != items_size - 1) + memcpy(&buffer[bufoff + len], sep, sep_size); - bufoff += len + sep_size; - } + bufoff += len + sep_size; + } - return buffer; + return buffer; } diff --git a/thirdparty/sn/sn.h b/thirdparty/sn/sn.h index d30b0ba1..fe823409 100644 --- a/thirdparty/sn/sn.h +++ b/thirdparty/sn/sn.h @@ -46,9 +46,9 @@ #endif enum { - VERBOSITY_NORMAL = 0, - VERBOSITY_QUIET = 1, - VERBOSITY_VERBOSE = 2, + VERBOSITY_NORMAL = 0, + VERBOSITY_QUIET = 1, + VERBOSITY_VERBOSE = 2, }; /* mostly concerning warn(x) */ @@ -58,19 +58,19 @@ int sn_getverbosity(void); static inline int sn_verbose(void) { - return sn_getverbosity() == VERBOSITY_VERBOSE; + return sn_getverbosity() == VERBOSITY_VERBOSE; } static inline int sn_normal(void) { - return sn_getverbosity() == VERBOSITY_NORMAL; + return sn_getverbosity() == VERBOSITY_NORMAL; } static inline int sn_quiet(void) { - return sn_getverbosity() == VERBOSITY_QUIET; + return sn_getverbosity() == VERBOSITY_QUIET; } /* error functions */ @@ -109,15 +109,15 @@ char *sn_strip_suffix(char *it, const char *suffix); void pretty_print(const char *input, int indent, int maxlinelen, FILE *out); /* io file mapping */ -int sn_mmap_file(const char *path, void **buffer); -int sn_read_file(char const *path, char **buffer); +int sn_mmap_file(const char *path, void **buffer); +int sn_read_file(char const *path, char **buffer); /* stringview */ typedef struct sn_sv sn_sv; struct sn_sv { - char *data; - size_t length; + char *data; + size_t length; }; #define SV(x) (sn_sv) { .data = x, .length = strlen(x) } @@ -128,23 +128,23 @@ struct sn_sv { static inline sn_sv sn_sv_from_parts(char *buf, size_t len) { - return (sn_sv) { .data = buf, .length = len }; + return (sn_sv) { .data = buf, .length = len }; } -sn_sv sn_sv_trim_front(sn_sv); -sn_sv sn_sv_trim(sn_sv); -sn_sv sn_sv_chop_until(sn_sv *, char); -bool sn_sv_has_prefix(sn_sv, const char *); -bool sn_sv_eq(const sn_sv, const sn_sv); -bool sn_sv_eq_to(const sn_sv, const char *); -sn_sv sn_sv_fmt(const char *fmt, ...) PRINTF_FORMAT(1, 2); -char *sn_sv_to_cstr(sn_sv); -sn_sv sn_sv_strip_suffix(sn_sv, const char *suffix); +sn_sv sn_sv_trim_front(sn_sv); +sn_sv sn_sv_trim(sn_sv); +sn_sv sn_sv_chop_until(sn_sv *, char); +bool sn_sv_has_prefix(sn_sv, const char *); +bool sn_sv_eq(const sn_sv, const sn_sv); +bool sn_sv_eq_to(const sn_sv, const char *); +sn_sv sn_sv_fmt(const char *fmt, ...) PRINTF_FORMAT(1, 2); +char *sn_sv_to_cstr(sn_sv); +sn_sv sn_sv_strip_suffix(sn_sv, const char *suffix); static inline bool sn_sv_null(sn_sv it) { - return it.data == NULL && it.length == 0; + return it.data == NULL && it.length == 0; } /* interactive user functions */ @@ -153,7 +153,7 @@ bool sn_yesno(const char *fmt, ...) PRINTF_FORMAT(1, 2); static inline const char * sn_bool_yesno(bool x) { - return x ? "yes" : "no"; + return x ? "yes" : "no"; } char *sn_join_with(char const *const items[], size_t const items_size, char const *sep); From ab00888d4fa6b14038c98a42fe634850909e9862 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Thu, 21 Dec 2023 21:05:37 +0100 Subject: [PATCH 023/158] Better error messages Whenever we print an error message to stdout we need to print the program name too. This is because in pipes one can only distinguish from which process an error message comes by looking at the error messages. If it isn't clear by saying "hey I'm this program, here's the error" one can only guess. This is also kind of a standard on unix-y systems. --- src/cmd/api.c | 8 +-- src/cmd/ci.c | 10 ++-- src/cmd/cmd.c | 6 +-- src/cmd/comment.c | 6 +-- src/cmd/config.c | 18 +++---- src/cmd/forks.c | 14 ++--- src/cmd/gcli.c | 12 ++--- src/cmd/gists.c | 22 ++++---- src/cmd/issues.c | 50 ++++++++--------- src/cmd/labels.c | 24 +++++---- src/cmd/milestones.c | 47 ++++++++-------- src/cmd/pipelines.c | 39 +++++++------- src/cmd/pulls.c | 124 ++++++++++++++++++++++++------------------- src/cmd/releases.c | 40 ++++++++------ src/cmd/repos.c | 35 ++++++------ src/cmd/snippets.c | 20 +++---- src/cmd/status.c | 10 ++-- 17 files changed, 263 insertions(+), 222 deletions(-) diff --git a/src/cmd/api.c b/src/cmd/api.c index 1f995bf3..dc58a343 100644 --- a/src/cmd/api.c +++ b/src/cmd/api.c @@ -67,7 +67,7 @@ fetch_all(char *_url) gcli_fetch_buffer buffer = {0}; if (gcli_fetch(g_clictx, url, &next_url, &buffer) < 0) - errx(1, "error: failed to fetch data: %s", + errx(1, "gcli: error: failed to fetch data: %s", gcli_get_error(g_clictx)); fwrite(buffer.data, buffer.length, 1, stdout); @@ -109,9 +109,9 @@ subcommand_api(int argc, char *argv[]) path = shift(&argc, &argv); } else { if (!argc) - errx(1, "error: missing path"); + errx(1, "gcli: error: missing path"); else - errx(1, "error: too many arguments"); + errx(1, "gcli: error: too many arguments"); } if (path[0] == '/') @@ -122,7 +122,7 @@ subcommand_api(int argc, char *argv[]) if (do_all) fetch_all(url); else if (gcli_curl(g_clictx, stdout, url, "application/json") < 0) - errx(1, "error: failed to fetch data: %s", + errx(1, "gcli: error: failed to fetch data: %s", gcli_get_error(g_clictx)); free(url); diff --git a/src/cmd/ci.c b/src/cmd/ci.c index 6e681874..78d4bbc6 100644 --- a/src/cmd/ci.c +++ b/src/cmd/ci.c @@ -78,7 +78,7 @@ github_print_checks(github_check_list const *const list) table = gcli_tbl_begin(cols, ARRAY_SIZE(cols)); if (!table) - errx(1, "error: could not init table"); + errx(1, "gcli: error: could not init table"); for (size_t i = 0; i < list->checks_size; ++i) { gcli_tbl_add_row(table, list->checks[i].id, list->checks[i].status, @@ -149,13 +149,13 @@ subcommand_ci(int argc, char *argv[]) /* Check that we have exactly one left argument and print proper * error messages */ if (argc < 1) { - fprintf(stderr, "error: missing ref\n"); + fprintf(stderr, "gcli: error: missing ref\n"); usage(); return EXIT_FAILURE; } if (argc > 1) { - fprintf(stderr, "error: stray arguments\n"); + fprintf(stderr, "gcli: error: stray arguments\n"); usage(); return EXIT_FAILURE; } @@ -168,11 +168,11 @@ subcommand_ci(int argc, char *argv[]) /* Make sure we are actually talking about a github remote because * we might be incorrectly inferring it */ if (gcli_config_get_forge_type(g_clictx) != GCLI_FORGE_GITHUB) - errx(1, "error: The ci subcommand only works for GitHub. " + errx(1, "gcli: error: The ci subcommand only works for GitHub. " "Use gcli -t github ... to force a GitHub remote."); if (github_checks(owner, repo, ref, count) < 0) - errx(1, "error: failed to get github checks: %s", + errx(1, "gcli: error: failed to get github checks: %s", gcli_get_error(g_clictx)); diff --git a/src/cmd/cmd.c b/src/cmd/cmd.c index dd491c66..43f44c0b 100644 --- a/src/cmd/cmd.c +++ b/src/cmd/cmd.c @@ -66,7 +66,7 @@ check_owner_and_repo(const char **owner, const char **repo) { /* If no remote was specified, try to autodetect */ if ((*owner == NULL) != (*repo == NULL)) - errx(1, "error: missing either explicit owner or repo"); + errx(1, "gcli: error: missing either explicit owner or repo"); if (*owner == NULL) gcli_config_get_repo(g_clictx, owner, repo); @@ -132,8 +132,8 @@ delete_repo(bool always_yes, const char *owner, const char *repo) } if (!delete) - errx(1, "Operation aborted"); + errx(1, "gcli: Operation aborted"); if (gcli_repo_delete(g_clictx, owner, repo) < 0) - errx(1, "error: failed to delete repo"); + errx(1, "gcli: error: failed to delete repo"); } diff --git a/src/cmd/comment.c b/src/cmd/comment.c index b726ba3a..3a28ba9c 100644 --- a/src/cmd/comment.c +++ b/src/cmd/comment.c @@ -213,7 +213,7 @@ subcommand_comment(int argc, char *argv[]) char *endptr; target_id = strtoul(optarg, &endptr, 10); if (endptr != optarg + strlen(optarg)) - err(1, "error: Cannot parse issue/PR number"); + err(1, "gcli: error: Cannot parse issue/PR number"); } break; case 'y': always_yes = true; @@ -230,7 +230,7 @@ subcommand_comment(int argc, char *argv[]) check_owner_and_repo(&owner, &repo); if (target_id < 0) { - fprintf(stderr, "error: missing issue/PR number (use -i/-p)\n"); + fprintf(stderr, "gcli: error: missing issue/PR number (use -i/-p)\n"); usage(); return EXIT_FAILURE; } @@ -243,7 +243,7 @@ subcommand_comment(int argc, char *argv[]) always_yes); if (rc < 0) - errx(1, "error: failed to submit comment: %s", gcli_get_error(g_clictx)); + errx(1, "gcli: error: failed to submit comment: %s", gcli_get_error(g_clictx)); return EXIT_SUCCESS; } diff --git a/src/cmd/config.c b/src/cmd/config.c index f4bcd852..852cebd9 100644 --- a/src/cmd/config.c +++ b/src/cmd/config.c @@ -89,7 +89,7 @@ list_sshkeys(void) gcli_sshkey_list list = {0}; if (gcli_sshkeys_get_keys(g_clictx, &list) < 0) { - fprintf(stderr, "error: could not get list of SSH keys\n"); + fprintf(stderr, "gcli: error: could not get list of SSH keys\n"); return EXIT_FAILURE; } @@ -120,7 +120,7 @@ add_sshkey(int argc, char *argv[]) keypath = optarg; if (access(keypath, R_OK) < 0) { - fprintf(stderr, "error: cannot access %s: %s\n", + fprintf(stderr, "gcli: error: cannot access %s: %s\n", keypath, strerror(errno)); return EXIT_FAILURE; } @@ -133,13 +133,13 @@ add_sshkey(int argc, char *argv[]) } if (title == NULL) { - fprintf(stderr, "error: missing title\n"); + fprintf(stderr, "gcli: error: missing title\n"); usage(); return EXIT_FAILURE; } if (keypath == NULL) { - fprintf(stderr, "error: missing public key path\n"); + fprintf(stderr, "gcli: error: missing public key path\n"); usage(); return EXIT_FAILURE; } @@ -160,7 +160,7 @@ delete_sshkey(int argc, char *argv[]) --argc; ++argv; if (argc != 1) { - fprintf(stderr, "error: incorrect number of arguments\n"); + fprintf(stderr, "gcli: error: incorrect number of arguments\n"); usage(); return EXIT_FAILURE; } @@ -169,7 +169,7 @@ delete_sshkey(int argc, char *argv[]) id = strtol(argv[0], &endptr, 10); if (endptr != argv[0] + strlen(argv[0])) { - fprintf(stderr, "error: could not parse ID of SSH key to delete\n"); + fprintf(stderr, "gcli: error: could not parse ID of SSH key to delete\n"); return EXIT_FAILURE; } @@ -194,7 +194,7 @@ subcommand_ssh(int argc, char *argv[]) else if (strcmp(cmdname, "delete") == 0) return delete_sshkey(argc, argv); - fprintf(stderr, "error: unrecognised subcommand »%s«.\n", cmdname); + fprintf(stderr, "gcli: error: unrecognised subcommand »%s«.\n", cmdname); usage(); return EXIT_FAILURE; } @@ -229,7 +229,7 @@ subcommand_config(int argc, char *argv[]) /* Check if the user gave us at least one option for this * subcommand */ if (argc == 0) { - fprintf(stderr, "error: missing subcommand for config\n"); + fprintf(stderr, "gcli: error: missing subcommand for config\n"); usage(); return EXIT_FAILURE; } @@ -239,7 +239,7 @@ subcommand_config(int argc, char *argv[]) return subcommands[i].fn(argc, argv); } - fprintf(stderr, "error: unrecognised config subcommand »%s«\n", + fprintf(stderr, "gcli: error: unrecognised config subcommand »%s«\n", argv[0]); usage(); diff --git a/src/cmd/forks.c b/src/cmd/forks.c index 64d5d596..01fb9542 100644 --- a/src/cmd/forks.c +++ b/src/cmd/forks.c @@ -87,7 +87,7 @@ gcli_print_forks(enum gcli_output_flags const flags, table = gcli_tbl_begin(cols, ARRAY_SIZE(cols)); if (!table) - errx(1, "error: could not initialize table"); + errx(1, "gcli: error: could not initialize table"); if (flags & OUTPUT_SORTED) { for (size_t i = 0; i < n; ++i) { @@ -164,7 +164,7 @@ subcommand_forks_create(int argc, char *argv[]) check_owner_and_repo(&owner, &repo); if (gcli_fork_create(g_clictx, owner, repo, in) < 0) - errx(1, "error: failed to fork repository: %s", gcli_get_error(g_clictx)); + errx(1, "gcli: error: failed to fork repository: %s", gcli_get_error(g_clictx)); if (!always_yes) { if (!sn_yesno("Do you want to add a remote for the fork?")) @@ -173,7 +173,7 @@ subcommand_forks_create(int argc, char *argv[]) if (!in) { if ((in = gcli_config_get_account_name(g_clictx)) == NULL) { - errx(1, "error: could not fetch account: %s", + errx(1, "gcli: error: could not fetch account: %s", gcli_get_error(g_clictx)); } } @@ -239,10 +239,10 @@ subcommand_forks(int argc, char *argv[]) count = strtol(optarg, &endptr, 10); if (endptr != (optarg + strlen(optarg))) - err(1, "forks: unable to parse forks count argument"); + err(1, "gcli: error: unable to parse forks count argument"); if (count == 0) - errx(1, "error: forks count must not be zero"); + errx(1, "gcli: error: forks count must not be zero"); } break; case 's': flags |= OUTPUT_SORTED; @@ -261,7 +261,7 @@ subcommand_forks(int argc, char *argv[]) if (argc == 0) { if (gcli_get_forks(g_clictx, owner, repo, count, &forks) < 0) - errx(1, "error: could not get forks: %s", gcli_get_error(g_clictx)); + errx(1, "gcli: error: could not get forks: %s", gcli_get_error(g_clictx)); gcli_print_forks(flags, &forks, count); gcli_forks_free(&forks); @@ -275,7 +275,7 @@ subcommand_forks(int argc, char *argv[]) if (strcmp(action, "delete") == 0) { delete_repo(always_yes, owner, repo); } else { - fprintf(stderr, "error: forks: unknown action '%s'\n", action); + fprintf(stderr, "gcli: error: forks: unknown action '%s'\n", action); } } diff --git a/src/cmd/gcli.c b/src/cmd/gcli.c index e542df28..de05c8d2 100644 --- a/src/cmd/gcli.c +++ b/src/cmd/gcli.c @@ -216,7 +216,7 @@ is_unique_match(size_t const idx, char const *const name, size_t const name_len) break; /* we found a duplicate prefix. */ } - fprintf(stderr, "error: %s: subcommand is ambiguous. could be one of:\n", name); + fprintf(stderr, "gcli: error: %s: subcommand is ambiguous. could be one of:\n", name); /* List until either the end or until we don't match any more prefixes */ for (size_t i = idx; i < subcommands_size; ++i) { if (strncmp(name, subcommands[i].cmd_name, name_len)) @@ -256,7 +256,7 @@ find_subcommand(char const *const name, int *error) } /* no match */ - fprintf(stderr, "error: %s: no such subcommand\n", name); + fprintf(stderr, "gcli: error: %s: no such subcommand\n", name); if (error) *error = LOOKUP_NOSUCHCMD; @@ -273,7 +273,7 @@ add_subcommand_alias(char const *alias_name, char const *alias_for) old_sc = find_subcommand(alias_for, NULL); if (old_sc == NULL) { - fprintf(stderr, "note: this error occured while defining the alias »%s«\n", + fprintf(stderr, "gcli: note: this error occured while defining the alias »%s«\n", alias_name); exit(EXIT_FAILURE); } @@ -333,10 +333,10 @@ main(int argc, char *argv[]) errmsg = gcli_init(&g_clictx, gcli_config_get_forge_type, gcli_config_get_token, gcli_config_get_apibase); if (errmsg) - errx(1, "error: %s", errmsg); + errx(1, "gcli: error: %s", errmsg); if (gcli_config_init_ctx(g_clictx) < 0) - errx(1, "error: failed to init context: %s", gcli_get_error(g_clictx)); + errx(1, "gcli: error: failed to init context: %s", gcli_get_error(g_clictx)); gcli_set_progress_func(g_clictx, gcli_progress_func); @@ -357,7 +357,7 @@ main(int argc, char *argv[]) /* Make sure we have a subcommand */ if (argc == 0) { - fprintf(stderr, "error: missing subcommand\n"); + fprintf(stderr, "gcli: error: missing subcommand\n"); usage(); return EXIT_FAILURE; } diff --git a/src/cmd/gists.c b/src/cmd/gists.c index ac1c5df5..dc0f0151 100644 --- a/src/cmd/gists.c +++ b/src/cmd/gists.c @@ -164,7 +164,7 @@ gcli_print_gists_short(enum gcli_output_flags const flags, table = gcli_tbl_begin(cols, ARRAY_SIZE(cols)); if (!table) - errx(1, "error: could not init table"); + errx(1, "gcli: error: could not init table"); if (flags & OUTPUT_SORTED) { for (size_t i = 0; i < n; ++i) { @@ -215,7 +215,7 @@ subcommand_gist_get(int argc, char *argv[]) gcli_gist_file *file = NULL; if (gcli_get_gist(g_clictx, gist_id, &gist) < 0) - errx(1, "error: failed to get gist: %s", gcli_get_error(g_clictx)); + errx(1, "gcli: error: failed to get gist: %s", gcli_get_error(g_clictx)); for (size_t f = 0; f < gist.files_size; ++f) { if (sn_sv_eq_to(gist.files[f].filename, file_name)) { @@ -225,14 +225,14 @@ subcommand_gist_get(int argc, char *argv[]) } if (!file) - errx(1, "error: gists get: %s: no such file in gist with id %s", + errx(1, "gcli: error: %s: no such file in gist with id %s", file_name, gist_id); if (isatty(STDOUT_FILENO) && (file->size >= 4 * 1024 * 1024)) - errx(1, "error: File is bigger than 4 MiB, refusing to print to stdout."); + errx(1, "gcli: error: File is bigger than 4 MiB, refusing to print to stdout."); if (gcli_curl(g_clictx, stdout, file->url.data, file->type.data) < 0) - errx(1, "error: failed to fetch gist: %s", gcli_get_error(g_clictx)); + errx(1, "gcli: error: failed to fetch gist: %s", gcli_get_error(g_clictx)); gcli_gist_free(&gist); @@ -277,7 +277,7 @@ subcommand_gist_create(int argc, char *argv[]) argv += optind; if (argc != 1) { - fprintf(stderr, "error: gists create: missing file name for gist\n"); + fprintf(stderr, "gcli: error: missing file name for gist\n"); usage(); return EXIT_FAILURE; } @@ -286,7 +286,7 @@ subcommand_gist_create(int argc, char *argv[]) if (file) { if ((opts.file = fopen(file, "r")) == NULL) - err(1, "error: gists create: cannot open file"); + err(1, "gcli: error: cannot open file"); } else { opts.file = stdin; } @@ -295,7 +295,7 @@ subcommand_gist_create(int argc, char *argv[]) opts.gist_description = "gcli paste"; if (gcli_create_gist(g_clictx, opts) < 0) - errx(1, "error: failed to create gist: %s", gcli_get_error(g_clictx)); + errx(1, "gcli: error: failed to create gist: %s", gcli_get_error(g_clictx)); return EXIT_SUCCESS; } @@ -333,7 +333,7 @@ subcommand_gist_delete(int argc, char *argv[]) gist_id = shift(&argc, &argv); if (!always_yes && !sn_yesno("Are you sure you want to delete this gist?")) - errx(1, "Aborted by user"); + errx(1, "gcli: Aborted by user"); gcli_delete_gist(g_clictx, gist_id); @@ -360,7 +360,7 @@ subcommand_gists(int argc, char *argv[]) /* Make sure we are looking at a GitHub forge */ if (gcli_config_get_forge_type(g_clictx) != GCLI_FORGE_GITHUB) { - errx(1, "error: The gists subcommand only works for Github " + errx(1, "gcli: error: The gists subcommand only works for Github " "forges. Please use either -a or -t to force using a " "Github account."); } @@ -421,7 +421,7 @@ subcommand_gists(int argc, char *argv[]) argv += optind; if (gcli_get_gists(g_clictx, user, count, &gists) < 0) - errx(1, "error: failed to get gists: %s", gcli_get_error(g_clictx)); + errx(1, "gcli: error: failed to get gists: %s", gcli_get_error(g_clictx)); gcli_print_gists(flags, &gists, count); gcli_gists_free(&gists); diff --git a/src/cmd/issues.c b/src/cmd/issues.c index cb739e81..04a6cdbb 100644 --- a/src/cmd/issues.c +++ b/src/cmd/issues.c @@ -292,7 +292,7 @@ subcommand_issue_create(int argc, char *argv[]) check_owner_and_repo(&opts.owner, &opts.repo); if (argc != 1) { - fprintf(stderr, "error: Expected one argument for issue title\n"); + fprintf(stderr, "gcli: error: Expected one argument for issue title\n"); usage(); return EXIT_FAILURE; } @@ -300,7 +300,8 @@ subcommand_issue_create(int argc, char *argv[]) opts.title = SV(argv[0]); if (create_issue(opts, always_yes) < 0) - errx(1, "error: failed to submit issue: %s", gcli_get_error(g_clictx)); + errx(1, "gcli: error: failed to submit issue: %s", + gcli_get_error(g_clictx)); return EXIT_SUCCESS; } @@ -381,21 +382,21 @@ subcommand_issues(int argc, char *argv[]) case 'i': { issue_id = strtol(optarg, &endptr, 10); if (endptr != (optarg + strlen(optarg))) - err(1, "error: cannot parse issue number"); + err(1, "gcli: error: cannot parse issue number"); if (issue_id < 0) - errx(1, "error: issue number is out of range"); + errx(1, "gcli: error: issue number is out of range"); } break; case 'n': { n = strtol(optarg, &endptr, 10); if (endptr != (optarg + strlen(optarg))) - err(1, "error: cannot parse issue count"); + err(1, "gcli: error: cannot parse issue count"); if (n < -1) - errx(1, "error: issue count is out of range"); + errx(1, "gcli: error: issue count is out of range"); if (n == 0) - errx(1, "error: issue count must not be zero"); + errx(1, "gcli: error: issue count must not be zero"); } break; case 'a': details.all = true; @@ -428,7 +429,7 @@ subcommand_issues(int argc, char *argv[]) /* No issue number was given, so list all open issues */ if (issue_id < 0) { if (gcli_get_issues(g_clictx, owner, repo, &details, n, &list) < 0) - errx(1, "error: could not get issues: %s", gcli_get_error(g_clictx)); + errx(1, "gcli: error: could not get issues: %s", gcli_get_error(g_clictx)); gcli_print_issues(flags, &list, n); @@ -438,7 +439,8 @@ subcommand_issues(int argc, char *argv[]) /* require -a to not be set */ if (details.all) { - fprintf(stderr, "error: -a cannot be combined with operations on an issue\n"); + fprintf(stderr, "gcli: error: -a cannot be combined with operations on " + "an issue\n"); usage(); return EXIT_FAILURE; } @@ -456,7 +458,7 @@ ensure_issue(char const *const owner, char const *const repo, return; if (gcli_get_issue(g_clictx, owner, repo, issue_id, issue) < 0) - errx(1, "error: failed to retrieve issue data: %s", + errx(1, "gcli: error: failed to retrieve issue data: %s", gcli_get_error(g_clictx)); *have_fetched_issue = 1; @@ -475,7 +477,7 @@ handle_issue_labels_action(int *argc, char ***argv, int rc = 0; if (argc == 0) { - fprintf(stderr, "error: expected label operations\n"); + fprintf(stderr, "gcli: error: expected label operations\n"); usage(); exit(EXIT_FAILURE); } @@ -489,7 +491,7 @@ handle_issue_labels_action(int *argc, char ***argv, add_labels, add_labels_size); if (rc < 0) { - errx(1, "error: failed to add labels: %s", + errx(1, "gcli: error: failed to add labels: %s", gcli_get_error(g_clictx)); } } @@ -499,7 +501,7 @@ handle_issue_labels_action(int *argc, char ***argv, remove_labels, remove_labels_size); if (rc < 0) { - errx(1, "error: failed to remove labels: %s", + errx(1, "gcli: error: failed to remove labels: %s", gcli_get_error(g_clictx)); } } @@ -522,7 +524,7 @@ handle_issue_milestone_action(int *argc, char ***argv, * * Check that the user provided a milestone id */ if (!argc) { - fprintf(stderr, "error: missing milestone id\n"); + fprintf(stderr, "gcli: error: missing milestone id\n"); usage(); exit(EXIT_FAILURE); } @@ -535,7 +537,7 @@ handle_issue_milestone_action(int *argc, char ***argv, if (strcmp(milestone_str, "-d") == 0) { rc = gcli_issue_clear_milestone(g_clictx, owner, repo, issue_id); if (rc < 0) { - errx(1, "error: could not clear milestone of issue #%d: %s", + errx(1, "gcli: error: could not clear milestone of issue #%d: %s", issue_id, gcli_get_error(g_clictx)); } return; @@ -546,14 +548,14 @@ handle_issue_milestone_action(int *argc, char ***argv, /* Check successful for parse */ if (endptr != milestone_str + strlen(milestone_str)) { - fprintf(stderr, "error: could not parse milestone id\n"); + fprintf(stderr, "gcli: error: could not parse milestone id\n"); usage(); exit(EXIT_FAILURE); } /* Pass it to the dispatch */ if (gcli_issue_set_milestone(g_clictx, owner, repo, issue_id, milestone) < 0) - errx(1, "error: could not assign milestone: %s", + errx(1, "gcli: error: could not assign milestone: %s", gcli_get_error(g_clictx)); } @@ -568,7 +570,7 @@ handle_issues_actions(int argc, char *argv[], /* Check if the user missed out on supplying actions */ if (argc == 0) { - fprintf(stderr, "error: no actions supplied\n"); + fprintf(stderr, "gcli: error: no actions supplied\n"); usage(); exit(EXIT_FAILURE); } @@ -590,7 +592,7 @@ handle_issues_actions(int argc, char *argv[], strcmp("notes", operation) == 0) { /* Doesn't require fetching the issue data */ if (gcli_issue_comments(owner, repo, issue_id) < 0) - errx(1, "error: failed to fetch issue comments: %s", + errx(1, "gcli: error: failed to fetch issue comments: %s", gcli_get_error(g_clictx)); } else if (strcmp("op", operation) == 0) { @@ -608,20 +610,20 @@ handle_issues_actions(int argc, char *argv[], } else if (strcmp("close", operation) == 0) { if (gcli_issue_close(g_clictx, owner, repo, issue_id) < 0) - errx(1, "error: failed to close issue: %s", + errx(1, "gcli: error: failed to close issue: %s", gcli_get_error(g_clictx)); } else if (strcmp("reopen", operation) == 0) { if (gcli_issue_reopen(g_clictx, owner, repo, issue_id) < 0) - errx(1, "error: failed to reopen issue: %s", + errx(1, "gcli: error: failed to reopen issue: %s", gcli_get_error(g_clictx)); } else if (strcmp("assign", operation) == 0) { char const *assignee = shift(&argc, &argv); if (gcli_issue_assign(g_clictx, owner, repo, issue_id, assignee) < 0) - errx(1, "error: failed to assign issue: %s", + errx(1, "gcli: error: failed to assign issue: %s", gcli_get_error(g_clictx)); } else if (strcmp("labels", operation) == 0) { @@ -641,12 +643,12 @@ handle_issues_actions(int argc, char *argv[], new_title); if (rc < 0) { - errx(1, "error: failed to set new issue title: %s", + errx(1, "gcli: error: failed to set new issue title: %s", gcli_get_error(g_clictx)); } } else { - fprintf(stderr, "error: unknown operation %s\n", operation); + fprintf(stderr, "gcli: error: unknown operation %s\n", operation); usage(); return EXIT_FAILURE; } diff --git a/src/cmd/labels.c b/src/cmd/labels.c index 047fb3d1..339c3d58 100644 --- a/src/cmd/labels.c +++ b/src/cmd/labels.c @@ -82,7 +82,7 @@ gcli_labels_print(gcli_label_list const *const list, int const max) /* Fill table */ table = gcli_tbl_begin(cols, ARRAY_SIZE(cols)); if (!table) - errx(1, "error: could not init table"); + errx(1, "gcli: error: could not init table"); for (size_t i = 0; i < n; ++i) { gcli_tbl_add_row(table, @@ -99,7 +99,7 @@ gcli_labels_print(gcli_label_list const *const list, int const max) static int subcommand_labels_delete(int argc, char *argv[]) { - int ch, rc; + int ch, rc; char const *owner = NULL, *repo = NULL; const struct option options[] = { {.name = "repo", .has_arg = required_argument, .val = 'r'}, @@ -128,14 +128,14 @@ subcommand_labels_delete(int argc, char *argv[]) check_owner_and_repo(&owner, &repo); if (argc != 1) { - fprintf(stderr, "error: missing label to delete\n"); + fprintf(stderr, "gcli: error: missing label to delete\n"); usage(); return EXIT_FAILURE; } rc = gcli_delete_label(g_clictx, owner, repo, argv[0]); if (rc < 0) { - fprintf(stderr, "error: couldn't delete label\n"); + fprintf(stderr, "gcli: error: couldn't delete label\n"); return EXIT_FAILURE; } @@ -192,19 +192,21 @@ subcommand_labels_create(int argc, char *argv[]) check_owner_and_repo(&owner, &repo); if (!label.name) { - fprintf(stderr, "error: missing name for label\n"); + fprintf(stderr, "gcli: error: missing name for label\n"); usage(); return EXIT_FAILURE; } if (!label.description) { - fprintf(stderr, "error: missing description for label\n"); + fprintf(stderr, "gcli: error: missing description for label\n"); usage(); return EXIT_FAILURE; } - if (gcli_create_label(g_clictx, owner, repo, &label) < 0) - errx(1, "error: failed to create label: %s", gcli_get_error(g_clictx)); + if (gcli_create_label(g_clictx, owner, repo, &label) < 0) { + errx(1, "gcli: error: failed to create label: %s", + gcli_get_error(g_clictx)); + } /* only if we are not quieted */ if (!sn_quiet()) @@ -262,7 +264,7 @@ subcommand_labels(int argc, char *argv[]) errx(1, "labels: cannot parse label count"); if (count == 0) - errx(1, "error: number of labels must not be zero"); + errx(1, "gcli: error: number of labels must not be zero"); } break; case '?': default: @@ -276,7 +278,7 @@ subcommand_labels(int argc, char *argv[]) /* sanity check: we must have parsed everything by now */ if (argc > 0) { - fprintf(stderr, "error: stray arguments\n"); + fprintf(stderr, "gcli: error: stray arguments\n"); usage(); return EXIT_FAILURE; } @@ -284,7 +286,7 @@ subcommand_labels(int argc, char *argv[]) check_owner_and_repo(&owner, &repo); if (gcli_get_labels(g_clictx, owner, repo, count, &labels) < 0) - errx(1, "error: could not fetch list of labels: %s", + errx(1, "gcli: error: could not fetch list of labels: %s", gcli_get_error(g_clictx)); gcli_labels_print(&labels, count); diff --git a/src/cmd/milestones.c b/src/cmd/milestones.c index ce2832b8..dc0a9731 100644 --- a/src/cmd/milestones.c +++ b/src/cmd/milestones.c @@ -82,7 +82,7 @@ gcli_print_milestones(gcli_milestone_list const *const list, int max) tbl = gcli_tbl_begin(cols, ARRAY_SIZE(cols)); if (!tbl) - errx(1, "error: could not init table printer"); + errx(1, "gcli: error: could not init table printer"); if (max < 0 || (size_t)(max) > list->milestones_size) n = list->milestones_size; @@ -188,18 +188,18 @@ subcommand_milestone_create(int argc, char *argv[]) /* sanity check argumets */ if (argc) - errx(1, "error: stray arguments"); + errx(1, "gcli: error: stray arguments"); /* make sure both are set or deduce them */ check_owner_and_repo(&args.owner, &args.repo); /* enforce the user to at least provide a title */ if (!args.title) - errx(1, "error: missing milestone title"); + errx(1, "gcli: error: missing milestone title"); /* actually create the milestone */ if (gcli_create_milestone(g_clictx, &args) < 0) - errx(1, "error: could not create milestone: %s", + errx(1, "gcli: error: could not create milestone: %s", gcli_get_error(g_clictx)); return 0; @@ -251,16 +251,16 @@ subcommand_milestones(int argc, char *argv[]) char *endptr; max = strtol(optarg, &endptr, 10); if (endptr != optarg + strlen(optarg)) - errx(1, "error: cannot parse milestone count"); + errx(1, "gcli: error: cannot parse milestone count"); } break; case 'i': { char *endptr; milestone_id = strtol(optarg, &endptr, 10); if (endptr != optarg + strlen(optarg)) - errx(1, "error: cannot parse milestone id"); + errx(1, "gcli: error: cannot parse milestone id"); if (milestone_id < 0) - errx(1, "error: milestone id must not be negative"); + errx(1, "gcli: error: milestone id must not be negative"); } break; default: { usage(); @@ -278,9 +278,10 @@ subcommand_milestones(int argc, char *argv[]) gcli_milestone_list list = {0}; rc = gcli_get_milestones(g_clictx, owner, repo, max, &list); - if (rc < 0) - errx(1, "error: cannot get list of milestones: %s", + if (rc < 0) { + errx(1, "gcli: error: cannot get list of milestones: %s", gcli_get_error(g_clictx)); + } gcli_print_milestones(&list, max); @@ -306,7 +307,7 @@ ensure_milestone(char const *const owner, rc = gcli_get_milestone(g_clictx, owner, repo, milestone_id, milestone); if (rc < 0) - errx(1, "error: could not get milestone %d: %s", milestone_id, + errx(1, "gcli: error: could not get milestone %d: %s", milestone_id, gcli_get_error(g_clictx)); *fetched_milestone = 1; @@ -323,7 +324,7 @@ handle_milestone_actions(int argc, char *argv[], /* Check if the user missed out on supplying actions */ if (argc == 0) { - fprintf(stderr, "error: no actions supplied\n"); + fprintf(stderr, "gcli: error: no actions supplied\n"); usage(); exit(EXIT_FAILURE); } @@ -347,9 +348,10 @@ handle_milestone_actions(int argc, char *argv[], rc = gcli_milestone_get_issues(g_clictx, owner, repo, milestone_id, &issues); - if (rc < 0) - errx(1, "error: failed to fetch issues: %s", + if (rc < 0) { + errx(1, "gcli: error: failed to fetch issues: %s", gcli_get_error(g_clictx)); + } printf("\nISSUES:\n"); gcli_print_issues(0, &issues, -1); @@ -362,9 +364,10 @@ handle_milestone_actions(int argc, char *argv[], /* Fetch list of issues associated with milestone */ rc = gcli_milestone_get_issues(g_clictx, owner, repo, milestone_id, &issues); - if (rc < 0) - errx(1, "error: failed to fetch issues: %s", + if (rc < 0) { + errx(1, "gcli: error: failed to fetch issues: %s", gcli_get_error(g_clictx)); + } /* Print them as a table */ gcli_print_issues(0, &issues, -1); @@ -383,9 +386,10 @@ handle_milestone_actions(int argc, char *argv[], } else if (strcmp(action, "delete") == 0) { /* Delete the milestone */ - if (gcli_delete_milestone(g_clictx, owner, repo, milestone_id) < 0) - errx(1, "error: could not delete milestone: %s", + if (gcli_delete_milestone(g_clictx, owner, repo, milestone_id) < 0) { + errx(1, "gcli: error: could not delete milestone: %s", gcli_get_error(g_clictx)); + } } else if (strcmp(action, "set-duedate") == 0) { @@ -394,22 +398,23 @@ handle_milestone_actions(int argc, char *argv[], /* grab the the date that the user provided */ if (!argc) - errx(1, "error: missing date for set-duedate"); + errx(1, "gcli: error: missing date for set-duedate"); new_date = shift(&argc, &argv); /* Do it! */ rc = gcli_milestone_set_duedate(g_clictx, owner, repo, milestone_id, new_date); - if (rc < 0) - errx(1, "error: could not update milestone due date: %s", + if (rc < 0) { + errx(1, "gcli: error: could not update milestone due date: %s", gcli_get_error(g_clictx));; + } } else { /* We don't know of the action - maybe a syntax error or * trailing garbage. Error out in this case. */ - fprintf(stderr, "error: unknown action %s\n", action); + fprintf(stderr, "gcli: error: unknown action %s\n", action); usage(); return EXIT_FAILURE; } diff --git a/src/cmd/pipelines.c b/src/cmd/pipelines.c index 92e2188a..500e8a96 100644 --- a/src/cmd/pipelines.c +++ b/src/cmd/pipelines.c @@ -103,7 +103,7 @@ gitlab_print_pipelines(gitlab_pipeline_list const *const list) table = gcli_tbl_begin(cols, ARRAY_SIZE(cols)); if (!table) - errx(1, "error: could not init table"); + errx(1, "gcli: error: could not init table"); for (size_t i = 0; i < list->pipelines_size; ++i) { gcli_tbl_add_row(table, @@ -154,7 +154,7 @@ gitlab_print_jobs(gitlab_job_list const *const list) table = gcli_tbl_begin(cols, ARRAY_SIZE(cols)); if (!table) - errx(1, "error: could not initialize table"); + errx(1, "gcli: error: could not initialize table"); for (size_t i = 0; i < list->jobs_size; ++i) { gcli_tbl_add_row(table, @@ -284,7 +284,7 @@ subcommand_pipelines(int argc, char *argv[]) if (endptr != (optarg + strlen(optarg))) err(1, "ci: cannot parse argument to -p"); if (pid < 0) { - errx(1, "error: pipeline id must be a positive number"); + errx(1, "gcli: error: pipeline id must be a positive number"); } } break; case 'j': { @@ -293,7 +293,7 @@ subcommand_pipelines(int argc, char *argv[]) if (endptr != (optarg + strlen(optarg))) err(1, "ci: cannot parse argument to -j"); if (jid < 0) { - errx(1, "error: job id must be a positive number"); + errx(1, "gcli: error: job id must be a positive number"); } } break; case '?': @@ -307,7 +307,7 @@ subcommand_pipelines(int argc, char *argv[]) argv += optind; if (pid > 0 && jid > 0) { - fprintf(stderr, "error: -p and -j are mutually exclusive\n"); + fprintf(stderr, "gcli: error: -p and -j are mutually exclusive\n"); usage(); return EXIT_FAILURE; } @@ -317,7 +317,7 @@ subcommand_pipelines(int argc, char *argv[]) /* Make sure we are actually talking about a gitlab remote because * we might be incorrectly inferring it */ if (gcli_config_get_forge_type(g_clictx) != GCLI_FORGE_GITLAB) - errx(1, "error: The pipelines subcommand only works for GitLab. " + errx(1, "gcli: error: The pipelines subcommand only works for GitLab. " "Use gcli -t gitlab ... to force a GitLab remote."); /* If the user specified a pipeline id, print the jobs of that @@ -325,14 +325,15 @@ subcommand_pipelines(int argc, char *argv[]) if (pid >= 0) { /* Make sure we are interpreting things correctly */ if (argc != 0) { - fprintf(stderr, "error: stray arguments\n"); + fprintf(stderr, "gcli: error: stray arguments\n"); usage(); return EXIT_FAILURE; } - if (gitlab_pipeline_jobs(owner, repo, pid, count) < 0) - errx(1, "error: failed to get pipeline jobs: %s", + if (gitlab_pipeline_jobs(owner, repo, pid, count) < 0) { + errx(1, "gcli: error: failed to get pipeline jobs: %s", gcli_get_error(g_clictx)); + } return EXIT_SUCCESS; } @@ -341,14 +342,15 @@ subcommand_pipelines(int argc, char *argv[]) if (jid < 0) { /* Make sure we are interpreting things correctly */ if (argc != 0) { - fprintf(stderr, "error: stray arguments\n"); + fprintf(stderr, "gcli: error: stray arguments\n"); usage(); return EXIT_FAILURE; } - if (gitlab_pipelines(owner, repo, count) < 0) - errx(1, "error: failed to get pipelines: %s", + if (gitlab_pipelines(owner, repo, count) < 0) { + errx(1, "gcli: error: failed to get pipelines: %s", gcli_get_error(g_clictx)); + } return EXIT_SUCCESS; } @@ -368,7 +370,7 @@ subcommand_pipelines(int argc, char *argv[]) /* Check if the user missed out on supplying actions */ if (argc == 0) { - fprintf(stderr, "error: no actions supplied\n"); + fprintf(stderr, "gcli: error: no actions supplied\n"); usage(); exit(EXIT_FAILURE); } @@ -383,14 +385,15 @@ subcommand_pipelines(int argc, char *argv[]) char const *outfile = "artifacts.zip"; if (argc && strcmp(argv[0], "-o") == 0) { if (argc < 2) - errx(1, "error: -o is missing the output filename"); + errx(1, "gcli: error: -o is missing the output filename"); outfile = argv[1]; argc -= 2; argv += 2; } - if (gitlab_job_download_artifacts(g_clictx, owner, repo, jid, outfile) < 0) - errx(1, "error: failed to download file: %s", + if (gitlab_job_download_artifacts(g_clictx, owner, repo, jid, outfile) < 0) { + errx(1, "gcli: error: failed to download file: %s", gcli_get_error(g_clictx)); + } goto next_action; } @@ -398,12 +401,12 @@ subcommand_pipelines(int argc, char *argv[]) for (size_t i = 0; i < ARRAY_SIZE(job_actions); ++i) { if (strcmp(action, job_actions[i].name) == 0) { if (job_actions[i].fn(owner, repo, jid) < 0) - errx(1, "error: failed to perform action '%s'", action); + errx(1, "gcli: error: failed to perform action '%s'", action); goto next_action; } } - fprintf(stderr, "error: unknown action '%s'\n", action); + fprintf(stderr, "gcli: error: unknown action '%s'\n", action); usage(); return EXIT_FAILURE; } diff --git a/src/cmd/pulls.c b/src/cmd/pulls.c index 20c81a87..75ae9079 100644 --- a/src/cmd/pulls.c +++ b/src/cmd/pulls.c @@ -130,7 +130,7 @@ gcli_print_pulls(enum gcli_output_flags const flags, /* Fill the table */ table = gcli_tbl_begin(cols, ARRAY_SIZE(cols)); if (!table) - errx(1, "error: cannot init table"); + errx(1, "gcli: error: cannot init table"); if (flags & OUTPUT_SORTED) { for (int i = 0; i < n; ++i) { @@ -324,7 +324,7 @@ gcli_print_commits(gcli_commit_list const *const list) table = gcli_tbl_begin(cols, ARRAY_SIZE(cols)); if (!table) - errx(1, "error: could not initialize table"); + errx(1, "gcli: error: could not initialize table"); for (size_t i = 0; i < list->commits_size; ++i) { char *message = cut_newline(list->commits[i].message); @@ -398,7 +398,7 @@ create_pull(gcli_submit_pull_options opts, int always_yes) if (!always_yes) if (!sn_yesno("Do you want to continue?")) - errx(1, "PR aborted."); + errx(1, "gcli: PR aborted."); return gcli_pull_submit(g_clictx, opts); } @@ -411,17 +411,18 @@ pr_try_derive_head(void) if ((account = gcli_config_get_account_name(g_clictx)) == NULL) { errx(1, - "error: Cannot derive PR head. Please specify --from or set the\n" - " account in the users gcli config file.\n" - "note: %s", + "gcli: error: Cannot derive PR head. Please specify --from or set the" + " account in the users gcli config file.\n" + "gcli: note: %s", gcli_get_error(g_clictx)); } - if (!(branch = gcli_gitconfig_get_current_branch()).length) + if (!(branch = gcli_gitconfig_get_current_branch()).length) { errx(1, - "error: Cannot derive PR head. Please specify --from or, if you\n" - " are in »detached HEAD« state, checkout the branch you \n" - " want to pull request.\n"); + "gcli: error: Cannot derive PR head. Please specify --from or, if you" + " are in »detached HEAD« state, checkout the branch you" + " want to pull request."); + } return sn_sv_fmt("%s:"SV_FMT, account, SV_ARGS(branch)); } @@ -503,14 +504,14 @@ subcommand_pull_create(int argc, char *argv[]) opts.to = gcli_config_get_base(g_clictx); if (opts.to.length == 0) errx(1, - "error: PR base is missing. Please either specify " + "gcli: error: PR base is missing. Please either specify " "--to branch-name or set pr.base in .gcli."); } check_owner_and_repo(&opts.owner, &opts.repo); if (argc != 1) { - fprintf(stderr, "error: Missing title to PR\n"); + fprintf(stderr, "gcli: error: Missing title to PR\n"); usage(); return EXIT_FAILURE; } @@ -518,7 +519,7 @@ subcommand_pull_create(int argc, char *argv[]) opts.title = SV(argv[0]); if (create_pull(opts, always_yes) < 0) - errx(1, "error: failed to submit pull request: %s", + errx(1, "gcli: error: failed to submit pull request: %s", gcli_get_error(g_clictx)); free(opts.labels); @@ -603,21 +604,21 @@ subcommand_pulls(int argc, char *argv[]) case 'i': { pr = strtoul(optarg, &endptr, 10); if (endptr != (optarg + strlen(optarg))) - err(1, "error: cannot parse pr number »%s«", optarg); + err(1, "gcli: error: cannot parse pr number »%s«", optarg); if (pr <= 0) - errx(1, "error: pr number is out of range"); + errx(1, "gcli: error: pr number is out of range"); } break; case 'n': { n = strtoul(optarg, &endptr, 10); if (endptr != (optarg + strlen(optarg))) - err(1, "error: cannot parse pr count »%s«", optarg); + err(1, "gcli: error: cannot parse pr count »%s«", optarg); if (n < -1) - errx(1, "error: pr count is out of range"); + errx(1, "gcli: error: pr count is out of range"); if (n == 0) - errx(1, "error: pr count must not be zero"); + errx(1, "gcli: error: pr count must not be zero"); } break; case 'a': { details.all = true; @@ -650,7 +651,7 @@ subcommand_pulls(int argc, char *argv[]) * open PRs and exit */ if (pr < 0) { if (gcli_get_pulls(g_clictx, owner, repo, &details, n, &pulls) < 0) - errx(1, "error: could not fetch pull requests: %s", + errx(1, "gcli: error: could not fetch pull requests: %s", gcli_get_error(g_clictx)); gcli_print_pulls(flags, &pulls, n); @@ -661,7 +662,7 @@ subcommand_pulls(int argc, char *argv[]) /* If a PR number was given, require -a to be unset */ if (details.all || details.author) { - fprintf(stderr, "error: -a and -A cannot be combined with operations on a PR\n"); + fprintf(stderr, "gcli: error: -a and -A cannot be combined with operations on a PR\n"); usage(); return EXIT_FAILURE; } @@ -691,7 +692,7 @@ action_ctx_ensure_pull(struct action_ctx *ctx) return; if (gcli_get_pull(g_clictx, ctx->owner, ctx->repo, ctx->pr, &ctx->pull) < 0) - errx(1, "error: failed to fetch pull request data: %s", + errx(1, "gcli: error: failed to fetch pull request data: %s", gcli_get_error(g_clictx)); ctx->fetched_pull = 1; @@ -713,13 +714,13 @@ action_all(struct action_ctx *ctx) /* Commits */ puts("\nCOMMITS"); if (gcli_pull_commits(ctx->owner, ctx->repo, ctx->pr) < 0) - errx(1, "error: failed to fetch pull request checks: %s", + errx(1, "gcli: error: failed to fetch pull request checks: %s", gcli_get_error(g_clictx)); /* Checks */ puts("\nCHECKS"); if (gcli_pull_checks(ctx->owner, ctx->repo, ctx->pr) < 0) - errx(1, "error: failed to fetch pull request checks: %s", + errx(1, "gcli: error: failed to fetch pull request checks: %s", gcli_get_error(g_clictx)); } @@ -753,34 +754,38 @@ action_commits(struct action_ctx *const ctx) static void action_diff(struct action_ctx *const ctx) { - if (gcli_pull_print_diff(stdout, ctx->owner, ctx->repo, ctx->pr) < 0) - errx(1, "error: failed to fetch diff: %s", + if (gcli_pull_print_diff(stdout, ctx->owner, ctx->repo, ctx->pr) < 0) { + errx(1, "gcli: error: failed to fetch diff: %s", gcli_get_error(g_clictx)); + } } static void action_patch(struct action_ctx *const ctx) { - if (gcli_pull_print_patch(stdout, ctx->owner, ctx->repo, ctx->pr) < 0) - errx(1, "error: failed to fetch patch: %s", + if (gcli_pull_print_patch(stdout, ctx->owner, ctx->repo, ctx->pr) < 0) { + errx(1, "gcli: error: failed to fetch patch: %s", gcli_get_error(g_clictx)); + } } /* aliased to notes */ static void action_comments(struct action_ctx *const ctx) { - if (gcli_pull_comments(ctx->owner, ctx->repo, ctx->pr) < 0) - errx(1, "error: failed to fetch pull comments: %s", + if (gcli_pull_comments(ctx->owner, ctx->repo, ctx->pr) < 0) { + errx(1, "gcli: error: failed to fetch pull comments: %s", gcli_get_error(g_clictx)); + } } static void action_ci(struct action_ctx *const ctx) { - if (gcli_pull_checks(ctx->owner, ctx->repo, ctx->pr) < 0) - errx(1, "error: failed to fetch pull request checks: %s", + if (gcli_pull_checks(ctx->owner, ctx->repo, ctx->pr) < 0) { + errx(1, "gcli: error: failed to fetch pull request checks: %s", gcli_get_error(g_clictx)); + } } static void @@ -810,25 +815,28 @@ action_merge(struct action_ctx *const ctx) } } - if (gcli_pull_merge(g_clictx, ctx->owner, ctx->repo, ctx->pr, flags) < 0) - errx(1, "error: failed to merge pull request: %s", + if (gcli_pull_merge(g_clictx, ctx->owner, ctx->repo, ctx->pr, flags) < 0) { + errx(1, "gcli: error: failed to merge pull request: %s", gcli_get_error(g_clictx)); + } } static void action_close(struct action_ctx *const ctx) { - if (gcli_pull_close(g_clictx, ctx->owner, ctx->repo, ctx->pr) < 0) - errx(1, "error: failed to close pull request: %s", + if (gcli_pull_close(g_clictx, ctx->owner, ctx->repo, ctx->pr) < 0) { + errx(1, "gcli: error: failed to close pull request: %s", gcli_get_error(g_clictx)); + } } static void action_reopen(struct action_ctx *const ctx) { - if (gcli_pull_reopen(g_clictx, ctx->owner, ctx->repo, ctx->pr) < 0) - errx(1, "error: failed to reopen pull request: %s", + if (gcli_pull_reopen(g_clictx, ctx->owner, ctx->repo, ctx->pr) < 0) { + errx(1, "gcli: error: failed to reopen pull request: %s", gcli_get_error(g_clictx)); + } } static void @@ -841,7 +849,7 @@ action_labels(struct action_ctx *const ctx) int rc = 0; if (ctx->argc == 0) { - fprintf(stderr, "error: expected label action\n"); + fprintf(stderr, "gcli: error: expected label action\n"); usage(); exit(EXIT_FAILURE); } @@ -863,16 +871,20 @@ action_labels(struct action_ctx *const ctx) if (add_labels_size) { rc = gcli_pull_add_labels(g_clictx, ctx->owner, ctx->repo, ctx->pr, add_labels, add_labels_size); - if (rc < 0) - errx(1, "error: failed to add labels: %s", gcli_get_error(g_clictx)); + if (rc < 0) { + errx(1, "gcli: error: failed to add labels: %s", + gcli_get_error(g_clictx)); + } } if (remove_labels_size) { rc = gcli_pull_remove_labels(g_clictx, ctx->owner, ctx->repo, ctx->pr, remove_labels, remove_labels_size); - if (rc < 0) - errx(1, "error: failed to remove labels: %s", gcli_get_error(g_clictx)); + if (rc < 0) { + errx(1, "gcli: error: failed to remove labels: %s", + gcli_get_error(g_clictx)); + } } free(add_labels); @@ -895,9 +907,10 @@ action_milestone(struct action_ctx *const ctx) ctx->argv += 1; if (strcmp(arg, "-d") == 0) { - if (gcli_pull_clear_milestone(g_clictx, ctx->owner, ctx->repo, ctx->pr) < 0) - errx(1, "error: failed to clear milestone: %s", + if (gcli_pull_clear_milestone(g_clictx, ctx->owner, ctx->repo, ctx->pr) < 0) { + errx(1, "gcli: error: failed to clear milestone: %s", gcli_get_error(g_clictx)); + } } else { int milestone_id = 0; @@ -906,15 +919,16 @@ action_milestone(struct action_ctx *const ctx) milestone_id = strtoul(arg, &endptr, 10); if (endptr != arg + strlen(arg)) { - fprintf(stderr, "error: cannot parse milestone id »%s«\n", arg); + fprintf(stderr, "gcli: error: cannot parse milestone id »%s«\n", arg); exit(EXIT_FAILURE); } rc = gcli_pull_set_milestone(g_clictx, ctx->owner, ctx->repo, ctx->pr, milestone_id); - if (rc < 0) - errx(1, "error: failed to set milestone: %s", + if (rc < 0) { + errx(1, "gcli: error: failed to set milestone: %s", gcli_get_error(g_clictx)); + } } } @@ -924,15 +938,17 @@ action_request_review(struct action_ctx *const ctx) int rc; if (ctx->argc < 2) { - fprintf(stderr, "error: missing user name for reviewer\n"); + fprintf(stderr, "gcli: error: missing user name for reviewer\n"); usage(); exit(EXIT_FAILURE); } rc = gcli_pull_add_reviewer(g_clictx, ctx->owner, ctx->repo, ctx->pr, ctx->argv[1]); - if (rc < 0) - errx(1, "error: failed to request review: %s", gcli_get_error(g_clictx)); + if (rc < 0) { + errx(1, "gcli: error: failed to request review: %s", + gcli_get_error(g_clictx)); + } ctx->argc -= 1; ctx->argv += 1; @@ -944,7 +960,7 @@ action_title(struct action_ctx *const ctx) int rc = 0; if (ctx->argc < 2) { - fprintf(stderr, "error: missing title\n"); + fprintf(stderr, "gcli: error: missing title\n"); usage(); exit(EXIT_FAILURE); } @@ -952,7 +968,7 @@ action_title(struct action_ctx *const ctx) rc = gcli_pull_set_title(g_clictx, ctx->owner, ctx->repo, ctx->pr, ctx->argv[1]); if (rc < 0) { - errx(1, "error: failed to update review title: %s", + errx(1, "gcli: error: failed to update review title: %s", gcli_get_error(g_clictx)); } @@ -1012,7 +1028,7 @@ handle_pull_actions(int argc, char *argv[], char const *owner, char const *repo, /* Check if the user missed out on supplying actions */ if (argc == 0) { - fprintf(stderr, "error: no actions supplied\n"); + fprintf(stderr, "gcli: error: no actions supplied\n"); usage(); exit(EXIT_FAILURE); } @@ -1031,7 +1047,7 @@ handle_pull_actions(int argc, char *argv[], char const *owner, char const *repo, /* At this point we found an unknown action / stray * options on the command line. Error out in this case. */ - fprintf(stderr, "error: unknown action %s\n", action); + fprintf(stderr, "gcli: error: unknown action %s\n", action); usage(); return EXIT_FAILURE; diff --git a/src/cmd/releases.c b/src/cmd/releases.c index 10f067eb..5f3d8f85 100644 --- a/src/cmd/releases.c +++ b/src/cmd/releases.c @@ -144,7 +144,7 @@ gcli_releases_print_short(enum gcli_output_flags const flags, table = gcli_tbl_begin(cols, ARRAY_SIZE(cols)); if (!table) - errx(1, "error: could not init table"); + errx(1, "gcli: error: could not init table"); if (flags & OUTPUT_SORTED) { for (size_t i = 0; i < n; ++i) { @@ -286,8 +286,10 @@ subcommand_releases_create(int argc, char *argv[]) .name = optarg, .label = "unused", }; - if (gcli_release_push_asset(g_clictx, &release, asset) < 0) - errx(1, "failed to add asset: %s", gcli_get_error(g_clictx)); + if (gcli_release_push_asset(g_clictx, &release, asset) < 0) { + errx(1, "gcli: error: failed to add asset: %s", + gcli_get_error(g_clictx)); + } } break; case 'y': { always_yes = true; @@ -305,7 +307,7 @@ subcommand_releases_create(int argc, char *argv[]) /* make sure we have a tag for the release */ if (!release.tag) { - fprintf(stderr, "error: releases create: missing tag name\n"); + fprintf(stderr, "gcli: error: releases create: missing tag name\n"); usage(); return EXIT_FAILURE; } @@ -314,10 +316,12 @@ subcommand_releases_create(int argc, char *argv[]) if (!always_yes) if (!sn_yesno("Do you want to create this release?")) - errx(1, "Aborted by user"); + errx(1, "gcli: Aborted by user"); - if (gcli_create_release(g_clictx, &release) < 0) - errx(1, "failed to create release: %s", gcli_get_error(g_clictx)); + if (gcli_create_release(g_clictx, &release) < 0) { + errx(1, "gcli: error: failed to create release: %s", + gcli_get_error(g_clictx)); + } return EXIT_SUCCESS; } @@ -370,17 +374,19 @@ subcommand_releases_delete(int argc, char *argv[]) /* make sure the user supplied the release id */ if (argc != 1) { - fprintf(stderr, "error: releases delete: missing release id\n"); + fprintf(stderr, "gcli: error: releases delete: missing release id\n"); usage(); return EXIT_FAILURE; } if (!always_yes) if (!sn_yesno("Are you sure you want to delete this release?")) - errx(1, "Aborted by user"); + errx(1, "gcli: Aborted by user"); - if (gcli_delete_release(g_clictx, owner, repo, argv[0]) < 0) - errx(1, "failed to delete the release: %s", gcli_get_error(g_clictx)); + if (gcli_delete_release(g_clictx, owner, repo, argv[0]) < 0) { + errx(1, "gcli: error: failed to delete the release: %s", + gcli_get_error(g_clictx)); + } return EXIT_SUCCESS; } @@ -448,10 +454,10 @@ subcommand_releases(int argc, char *argv[]) char *endptr = NULL; count = strtol(optarg, &endptr, 10); if (endptr != (optarg + strlen(optarg))) - err(1, "releases: cannot parse release count"); + err(1, "gcli: error: cannot parse release count"); if (count == 0) - errx(1, "error: number of releases must not be zero"); + errx(1, "gcli: error: number of releases must not be zero"); } break; case 's': @@ -472,15 +478,17 @@ subcommand_releases(int argc, char *argv[]) /* sanity check */ if (argc > 0) { - fprintf(stderr, "error: stray arguments\n"); + fprintf(stderr, "gcli: error: stray arguments\n"); usage(); return EXIT_FAILURE; } check_owner_and_repo(&owner, &repo); - if (gcli_get_releases(g_clictx, owner, repo, count, &releases) < 0) - errx(1, "error: could not get releases: %s", gcli_get_error(g_clictx)); + if (gcli_get_releases(g_clictx, owner, repo, count, &releases) < 0) { + errx(1, "gcli: error: could not get releases: %s", + gcli_get_error(g_clictx)); + } gcli_releases_print(flags, &releases, count); diff --git a/src/cmd/repos.c b/src/cmd/repos.c index 4ff42858..810b4331 100644 --- a/src/cmd/repos.c +++ b/src/cmd/repos.c @@ -92,7 +92,7 @@ gcli_print_repos(enum gcli_output_flags const flags, /* init table */ table = gcli_tbl_begin(cols, ARRAY_SIZE(cols)); if (!table) - errx(1, "error: could not init table"); + errx(1, "gcli: error: could not init table"); /* put data into table */ if (flags & OUTPUT_SORTED) { @@ -178,14 +178,16 @@ subcommand_repos_create(int argc, char *argv[]) if (sn_sv_null(create_options.name)) { fprintf(stderr, - "name cannot be empty. please set a repository " + "gcli: name cannot be empty. please set a repository " "name with -r/--name\n"); usage(); return EXIT_FAILURE; } - if (gcli_repo_create(g_clictx, &create_options, &repo) < 0) - errx(1, "error: failed to create repository: %s", gcli_get_error(g_clictx)); + if (gcli_repo_create(g_clictx, &create_options, &repo) < 0) { + errx(1, "gcli: error: failed to create repository: %s", + gcli_get_error(g_clictx)); + } gcli_repo_print(&repo); gcli_repo_free(&repo); @@ -248,7 +250,7 @@ action_set_visibility(char const *const owner, char const *const repo, int rc; if (*argc < 2) { - fprintf(stderr, "error: missing visibility level\n"); + fprintf(stderr, "gcli: error: missing visibility level\n"); return 1; } @@ -258,12 +260,12 @@ action_set_visibility(char const *const owner, char const *const repo, visblty = parse_visibility(visblty_str); if (visblty < 0) { - fprintf(stderr, "error: bad visibility level »%s«\n", visblty_str); + fprintf(stderr, "gcli: error: bad visibility level »%s«\n", visblty_str); return 1; } if ((rc = gcli_repo_set_visibility(g_clictx, owner, repo, visblty)) < 0) { - fprintf(stderr, "error: failed to set visibility: %s\n", + fprintf(stderr, "gcli: error: failed to set visibility: %s\n", gcli_get_error(g_clictx)); return 1; } @@ -343,10 +345,10 @@ subcommand_repos(int argc, char *argv[]) char *endptr = NULL; n = strtol(optarg, &endptr, 10); if (endptr != (optarg + strlen(optarg))) - err(1, "repos: cannot parse repo count"); + err(1, "gcli: error: cannot parse repo count"); if (n == 0) - errx(1, "error: number of repos must not be zero"); + errx(1, "gcli: error: number of repos must not be zero"); } break; case '?': default: @@ -364,7 +366,7 @@ subcommand_repos(int argc, char *argv[]) int rc = 0; if (repo) { - fprintf(stderr, "error: repos: no actions specified\n"); + fprintf(stderr, "gcli: error: no actions specified\n"); usage(); return EXIT_FAILURE; } @@ -376,14 +378,17 @@ subcommand_repos(int argc, char *argv[]) * gcli_get_repos. This is bad since that causes segfaults down the * line. (https://github.com/herrhotzenplotz/gcli/issues/118) */ if (!owner) { - fprintf(stderr, "error: no account specified or no default account" - " configured. use -o to provide an explicit account name.\n"); + fprintf(stderr, "gcli: error: no account specified or no default" + " account configured. use -o to provide an explicit" + " account name.\n"); return EXIT_FAILURE; } rc = gcli_get_repos(g_clictx, owner, n, &repos); - if (rc < 0) - errx(1, "error: failed to fetch repos: %s", gcli_get_error(g_clictx)); + if (rc < 0) { + errx(1, "gcli: error: failed to fetch repos: %s", + gcli_get_error(g_clictx)); + } gcli_print_repos(flags, &repos, n); gcli_repos_free(&repos); @@ -395,7 +400,7 @@ subcommand_repos(int argc, char *argv[]) int rc = 0; if (!action) { - fprintf(stderr, "error: unrecognised action »%s«\n", argv[0]); + fprintf(stderr, "gcli: error: unrecognised action »%s«\n", argv[0]); return EXIT_FAILURE; } diff --git a/src/cmd/snippets.c b/src/cmd/snippets.c index b0ff0cce..2a91ff15 100644 --- a/src/cmd/snippets.c +++ b/src/cmd/snippets.c @@ -122,7 +122,7 @@ gcli_print_snippets_short(enum gcli_output_flags const flags, /* Fill table */ table = gcli_tbl_begin(cols, ARRAY_SIZE(cols)); if (!table) - errx(1, "error: could not init table"); + errx(1, "gcli: error: could not init table"); if (flags & OUTPUT_SORTED) { for (int i = 0; i < n; ++i) @@ -167,7 +167,7 @@ subcommand_snippet_get(int argc, char *argv[]) argv += 1; if (!argc) { - fprintf(stderr, "error: get snippets: expected ID of snippet to fetch\n"); + fprintf(stderr, "gcli: error: expected ID of snippet to fetch\n"); usage(); return EXIT_FAILURE; } @@ -175,13 +175,13 @@ subcommand_snippet_get(int argc, char *argv[]) char *snippet_id = shift(&argc, &argv); if (argc) { - fprintf(stderr, "error: stray arguments\n"); + fprintf(stderr, "gcli: error: stray arguments\n"); usage(); return EXIT_FAILURE; } if (gcli_snippet_get(g_clictx, snippet_id, stdout) < 0) - errx(1, "error: failed to fetch snippet contents: %s", + errx(1, "gcli: error: failed to fetch snippet contents: %s", gcli_get_error(g_clictx)); return EXIT_SUCCESS; @@ -194,7 +194,7 @@ subcommand_snippet_delete(int argc, char *argv[]) argv += 1; if (!argc) { - fprintf(stderr, "error: delete snippets: expected ID of snippet to delete\n"); + fprintf(stderr, "gcli: error: expected ID of snippet to delete\n"); usage(); return EXIT_FAILURE; } @@ -202,13 +202,13 @@ subcommand_snippet_delete(int argc, char *argv[]) char *snippet_id = shift(&argc, &argv); if (argc) { - fprintf(stderr, "error: delete snippet: trailing options\n"); + fprintf(stderr, "gcli: error: trailing options\n"); usage(); return EXIT_FAILURE; } if (gcli_snippet_delete(g_clictx, snippet_id) < 0) - errx(1, "error: failed to delete snippet: %s", + errx(1, "gcli: error: failed to delete snippet: %s", gcli_get_error(g_clictx)); return EXIT_SUCCESS; @@ -261,10 +261,10 @@ subcommand_snippets(int argc, char *argv[]) count = strtol(optarg, &endptr, 10); if (endptr != (optarg + strlen(optarg))) - err(1, "snippets: cannot parse snippets count"); + err(1, "gcli: error: cannot parse snippets count"); if (count == 0) - errx(1, "error: snippets count must not be zero"); + errx(1, "gcli: error: snippets count must not be zero"); } break; case 's': flags |= OUTPUT_SORTED; @@ -283,7 +283,7 @@ subcommand_snippets(int argc, char *argv[]) argv += optind; if (gcli_snippets_get(g_clictx, count, &list) < 0) - errx(1, "error: failed to fetch snippets: %s", + errx(1, "gcli: error: failed to fetch snippets: %s", gcli_get_error(g_clictx)); gcli_snippets_print(flags, &list, count); diff --git a/src/cmd/status.c b/src/cmd/status.c index 268965ce..343dd378 100644 --- a/src/cmd/status.c +++ b/src/cmd/status.c @@ -112,7 +112,7 @@ subcommand_status(int argc, char *argv[]) case 'n': { count = strtol(optarg, &endptr, 10); if (endptr != optarg + strlen(optarg)) - err(1, "status: cannot parse parameter to -n"); + err(1, "gcli: error: cannot parse parameter to -n"); } break; case 'm': { mark = 1; @@ -130,22 +130,22 @@ subcommand_status(int argc, char *argv[]) gcli_status(count); } else { if (count != 30) - warnx("ignoring -n/--count argument"); + warnx("gcli: ignoring -n/--count argument"); if (argc > 1) { - fprintf(stderr, "error: too many arguments for marking notifications\n"); + fprintf(stderr, "gcli: error: too many arguments for marking notifications\n"); usage(); return EXIT_FAILURE; } if (argc < 1) { - fprintf(stderr, "error: missing notification id to mark as read\n"); + fprintf(stderr, "gcli: error: missing notification id to mark as read\n"); usage(); return EXIT_FAILURE; } if (gcli_notification_mark_as_read(g_clictx, argv[0]) < 0) - errx(1, "error: failed to mark the notification as read: %s", + errx(1, "gcli: error: failed to mark the notification as read: %s", gcli_get_error(g_clictx)); } From 102b6aed22b3073220be5805b54fd682e4710360 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 22 Dec 2023 12:47:10 +0100 Subject: [PATCH 024/158] Make version announcement less noisy Whenever an error on the command line occured and one would call usage() it would print a ton of version and copyright noise. Make it less noisy by adding a longversion() that prints all this noise in this version subcommand and use a normal version() that prints a shorter version in usage. --- include/gcli/cmd/cmd.h | 1 + src/cmd/cmd.c | 8 +++++++- src/cmd/gcli.c | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/include/gcli/cmd/cmd.h b/include/gcli/cmd/cmd.h index 367fc544..fe0ea150 100644 --- a/include/gcli/cmd/cmd.h +++ b/include/gcli/cmd/cmd.h @@ -51,6 +51,7 @@ shift(int *argc, char ***argv) } void version(void); +void longversion(void); void copyright(void); void check_owner_and_repo(const char **owner, const char **repo); diff --git a/src/cmd/cmd.c b/src/cmd/cmd.c index 43f44c0b..2a3088b4 100644 --- a/src/cmd/cmd.c +++ b/src/cmd/cmd.c @@ -51,8 +51,14 @@ copyright(void) void version(void) { + fprintf(stderr, PACKAGE_STRING" ("HOSTOS")\n"); +} + +void +longversion(void) +{ + version(); fprintf(stderr, - PACKAGE_STRING" ("HOSTOS")\n" "Using %s\n" "Using vendored pdjson library\n" "\n" diff --git a/src/cmd/gcli.c b/src/cmd/gcli.c index de05c8d2..d774f90a 100644 --- a/src/cmd/gcli.c +++ b/src/cmd/gcli.c @@ -63,7 +63,7 @@ subcommand_version(int argc, char *argv[]) (void) argc; (void) argv; - version(); + longversion(); copyright(); return EXIT_SUCCESS; From ea99049b5acf73721b1a0bc99c1acdb5ab42bb60 Mon Sep 17 00:00:00 2001 From: Gavin-John Noonan Date: Fri, 22 Dec 2023 17:11:36 +0100 Subject: [PATCH 025/158] refactor(docs): rename screenshot image Whilst it could be seen as needless churn to rename the file, this refactor is a clean-up for incoming changes. --- README.md | 2 +- docs/{screenshot-04.png => screenshot.png} | Bin docs/website/deploy.sh | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename docs/{screenshot-04.png => screenshot.png} (100%) diff --git a/README.md b/README.md index 59d555df..4c010eaa 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Simple and portable CLI tool for interacting with GitHub, GitLab and Gitea from the command line. -![](docs/screenshot-04.png) +![](docs/screenshot.png) ## Why? diff --git a/docs/screenshot-04.png b/docs/screenshot.png similarity index 100% rename from docs/screenshot-04.png rename to docs/screenshot.png diff --git a/docs/website/deploy.sh b/docs/website/deploy.sh index ae754bad..1e104b80 100755 --- a/docs/website/deploy.sh +++ b/docs/website/deploy.sh @@ -24,7 +24,7 @@ cp -vp \ ${DISTDIR}/tutorial cp -vp \ - ../screenshot-04.png \ + ../screenshot.png \ ${DISTDIR}/assets/screenshot.png tar -c -f - -C ${DISTDIR} \. | xz > website_dist.tar.xz From f08a97ac26274662cf1932cb15cf4df237f13b67 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Sat, 23 Dec 2023 23:04:01 +0100 Subject: [PATCH 026/158] Update changelog for development version --- Changelog.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Changelog.md b/Changelog.md index cb6fd647..7b063aec 100644 --- a/Changelog.md +++ b/Changelog.md @@ -7,6 +7,16 @@ This changelog does not follow semantic versioning. ### Added +### Fixed + +### Changed + +### Removed + +## 2.1.0 (2023-Dec-08) + +### Added + - Added a little spinner to indicate network activity - Added Windows 10 MSYS2 to list of confirmed-to-work platforms - Added a new action `set-visibility` to the repos subcommand that From 96c5e449bae3607d385d0b28df474b076cc92d8e Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Sat, 23 Dec 2023 23:28:04 +0100 Subject: [PATCH 027/158] fix(cmd/issues): Update bad table column types When making all fields of issues strings instead of string views I missed updating the type field causing strange things to happen when printing the list of issues. Correct the types to be strings. --- src/cmd/issues.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cmd/issues.c b/src/cmd/issues.c index 04a6cdbb..d79914d8 100644 --- a/src/cmd/issues.c +++ b/src/cmd/issues.c @@ -89,10 +89,10 @@ gcli_print_issues(enum gcli_output_flags const flags, int n, pruned = 0; gcli_tbl table; gcli_tblcoldef cols[] = { - { .name = "NUMBER", .type = GCLI_TBLCOLTYPE_ID, .flags = GCLI_TBLCOL_JUSTIFYR }, - { .name = "NOTES", .type = GCLI_TBLCOLTYPE_INT, .flags = GCLI_TBLCOL_JUSTIFYR }, - { .name = "STATE", .type = GCLI_TBLCOLTYPE_SV, .flags = GCLI_TBLCOL_STATECOLOURED }, - { .name = "TITLE", .type = GCLI_TBLCOLTYPE_SV, .flags = 0 }, + { .name = "NUMBER", .type = GCLI_TBLCOLTYPE_ID, .flags = GCLI_TBLCOL_JUSTIFYR }, + { .name = "NOTES", .type = GCLI_TBLCOLTYPE_INT, .flags = GCLI_TBLCOL_JUSTIFYR }, + { .name = "STATE", .type = GCLI_TBLCOLTYPE_STRING, .flags = GCLI_TBLCOL_STATECOLOURED }, + { .name = "TITLE", .type = GCLI_TBLCOLTYPE_STRING, .flags = 0 }, }; if (list->issues_size == 0) { From b729ac0800b8b0b1ec61b9ac3cc37e78f320c14d Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Sat, 23 Dec 2023 19:27:21 +0100 Subject: [PATCH 028/158] Prevent segmentation fault in 404 cases on Gitlab Discovered by sjr on Debian. Thanks for debugging and dissecting. Reported-by: Simon Richter Signed-off-by: Gavin-John Noonan --- Changelog.md | 6 ++++++ src/gitlab/api.c | 16 ++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Changelog.md b/Changelog.md index 7b063aec..cfda0c1f 100644 --- a/Changelog.md +++ b/Changelog.md @@ -9,6 +9,12 @@ This changelog does not follow semantic versioning. ### Fixed +- Fixed a segmentation fault when getting a 404 on Gitlab. This bug + occured on Debian Linux when querying pipelines at the KiCad project. + The returned 404 contained unparsable data which then lead to the + error message to be improperly initialised. + Reported by: Simon Richter + ### Changed ### Removed diff --git a/src/gitlab/api.c b/src/gitlab/api.c index 95aebe7f..f4c0c1e2 100644 --- a/src/gitlab/api.c +++ b/src/gitlab/api.c @@ -37,7 +37,7 @@ char const * gitlab_api_error_string(gcli_ctx *ctx, gcli_fetch_buffer *const buf) { - char *msg; + char *msg = NULL; int rc; json_stream stream = {0}; @@ -45,10 +45,18 @@ gitlab_api_error_string(gcli_ctx *ctx, gcli_fetch_buffer *const buf) rc = parse_gitlab_get_error(ctx, &stream, &msg); json_close(&stream); - if (rc < 0) - return strdup("no error message: failed to parse error response"); - else + if (rc < 0 || msg == NULL) { + if (sn_verbose()) { + return sn_asprintf("Could not parse Gitlab error response. " + "The response was:\n\n%.*s\n", + (int)buf->length, buf->data); + } else { + return strdup("no error message: failed to parse error response. " + "Please run the gcli query with verbose mode again."); + } + } else { return msg; + } } int From d00c0a1e775edb54587ea30fda8c7ae724bf47d6 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Sat, 23 Dec 2023 22:54:51 +0100 Subject: [PATCH 029/158] gitlab pipelines: Add missing urlencode calls everywhere These routines were missing urlencode calls. In particular this bug arose when testing gcli with kicad subprojects on Gitlab. These have slashes in the URLs and when cloning out a repository these were causing 404s which then caused segmentation faults because the errors were handled incorrectly. Reported-by: Simon Richter Signed-off-by: Gavin-John Noonan --- Changelog.md | 5 +++ src/gitlab/pipelines.c | 70 +++++++++++++++++++++++++++++++++--------- 2 files changed, 61 insertions(+), 14 deletions(-) diff --git a/Changelog.md b/Changelog.md index cfda0c1f..69bd5ee9 100644 --- a/Changelog.md +++ b/Changelog.md @@ -15,6 +15,11 @@ This changelog does not follow semantic versioning. error message to be improperly initialised. Reported by: Simon Richter +- Fixed missing URL-encode calls in Gitlab Pipelines causing 404 errors + when using subprojects on Gitlab. You're now not forced anymore + to manually urlencode slashes as %2F in the repos. + Reported by: Simon Richter + ### Changed ### Removed diff --git a/src/gitlab/pipelines.c b/src/gitlab/pipelines.c index a29df0ac..55dbd171 100644 --- a/src/gitlab/pipelines.c +++ b/src/gitlab/pipelines.c @@ -62,9 +62,13 @@ gitlab_get_pipelines(gcli_ctx *ctx, char const *owner, char const *repo, int const max, gitlab_pipeline_list *const list) { char *url = NULL; + char *e_owner = gcli_urlencode(owner); + char *e_repo = gcli_urlencode(repo); url = sn_asprintf("%s/projects/%s%%2F%s/pipelines", gcli_get_apibase(ctx), - owner, repo); + e_owner, e_repo); + free(e_owner); + free(e_repo); return fetch_pipelines(ctx, url, max, list); } @@ -74,9 +78,14 @@ gitlab_get_mr_pipelines(gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const mr_id, gitlab_pipeline_list *const list) { char *url = NULL; + char *e_owner = gcli_urlencode(owner); + char *e_repo = gcli_urlencode(repo); url = sn_asprintf("%s/projects/%s%%2F%s/merge_requests/%"PRIid"/pipelines", - gcli_get_apibase(ctx), owner, repo, mr_id); + gcli_get_apibase(ctx), e_owner, e_repo, mr_id); + + free(e_owner); + free(e_repo); /* fetch everything */ return fetch_pipelines(ctx, url, -1, list); @@ -110,7 +119,7 @@ gitlab_get_pipeline_jobs(gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const pipeline, int const max, gitlab_job_list *const out) { - char *url = NULL; + char *url = NULL, *e_owner = NULL, *e_repo = NULL; gcli_fetch_list_ctx fl = { .listp = &out->jobs, .sizep = &out->jobs_size, @@ -118,8 +127,14 @@ gitlab_get_pipeline_jobs(gcli_ctx *ctx, char const *owner, char const *repo, .parse = (parsefn)(parse_gitlab_jobs), }; + e_owner = gcli_urlencode(owner); + e_repo = gcli_urlencode(repo); + url = sn_asprintf("%s/projects/%s%%2F%s/pipelines/%"PRIid"/jobs", - gcli_get_apibase(ctx), owner, repo, pipeline); + gcli_get_apibase(ctx), e_owner, e_repo, pipeline); + + free(e_owner); + free(e_repo); return gcli_fetch_list(ctx, url, &fl); } @@ -154,11 +169,17 @@ int gitlab_job_get_log(gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const job_id, FILE *stream) { - char *url = NULL; + char *url = NULL, *e_owner = NULL, *e_repo = NULL; int rc = 0; + e_owner = gcli_urlencode(owner); + e_repo = gcli_urlencode(repo); + url = sn_asprintf("%s/projects/%s%%2F%s/jobs/%"PRIid"/trace", - gcli_get_apibase(ctx), owner, repo, job_id); + gcli_get_apibase(ctx), e_owner, e_repo, job_id); + + free(e_owner); + free(e_repo); rc = gcli_curl(ctx, stream, url, NULL); @@ -172,11 +193,17 @@ gitlab_get_job(gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const jid, gitlab_job *const out) { gcli_fetch_buffer buffer = {0}; - char *url = NULL; + char *url = NULL, *e_owner = NULL, *e_repo = NULL; int rc = 0; + e_owner = gcli_urlencode(owner); + e_repo = gcli_urlencode(repo); + url = sn_asprintf("%s/projects/%s%%2F%s/jobs/%"PRIid, gcli_get_apibase(ctx), - owner, repo, jid); + e_owner, e_repo, jid); + + free(e_owner); + free(e_repo); rc = gcli_fetch(ctx, url, NULL, &buffer); if (rc == 0) { @@ -198,11 +225,18 @@ int gitlab_job_cancel(gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const jid) { - char *url = NULL; + char *url = NULL, *e_owner = NULL, *e_repo = NULL; int rc = 0; + e_owner = gcli_urlencode(owner); + e_repo = gcli_urlencode(repo); + url = sn_asprintf("%s/projects/%s%%2F%s/jobs/%"PRIid"/cancel", - gcli_get_apibase(ctx), owner, repo, jid); + gcli_get_apibase(ctx), e_owner, e_repo, jid); + + free(e_owner); + free(e_repo); + rc = gcli_fetch_with_method(ctx, "POST", url, NULL, NULL, NULL); free(url); @@ -215,10 +249,17 @@ gitlab_job_retry(gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const jid) { int rc = 0; - char *url = NULL; + char *url = NULL, *e_owner = NULL, *e_repo = NULL; + + e_owner = gcli_urlencode(owner); + e_repo = gcli_urlencode(repo); url = sn_asprintf("%s/projects/%s%%2F%s/jobs/%"PRIid"/retry", gcli_get_apibase(ctx), - owner, repo, jid); + e_owner, e_repo, jid); + + free(e_owner); + free(e_repo); + rc = gcli_fetch_with_method(ctx, "POST", url, NULL, NULL, NULL); free(url); @@ -246,12 +287,13 @@ gitlab_job_download_artifacts(gcli_ctx *ctx, char const *owner, url = sn_asprintf("%s/projects/%s%%2F%s/jobs/%"PRIid"/artifacts", gcli_get_apibase(ctx), e_owner, e_repo, jid); + free(e_owner); + free(e_repo); + rc = gcli_curl(ctx, f, url, "application/zip"); fclose(f); free(url); - free(e_owner); - free(e_repo); return rc; } From 4e0b9ea91f96406ac3cab4bb14990d1f36b50179 Mon Sep 17 00:00:00 2001 From: Gavin-John Noonan Date: Tue, 26 Dec 2023 11:33:54 +0100 Subject: [PATCH 030/158] feat(dev): teach git to ignore build arifacts. After applying patches, as a local "CI" check I often run `make distcheck` to ensure there's no errors. However this command also produces devel archives ready to be distributed in the project root. Teach git to ignore these files, such that they can not be commited to the repository by mistake. --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 992222cb..f1a8221e 100644 --- a/.gitignore +++ b/.gitignore @@ -17,7 +17,10 @@ /configure /configure~ /depcomp -/gcli-0.9.9.tar.gz +# build artifacts +/gcli-*.tar.bz2 +/gcli-*.tar.gz +/gcli-*.tar.xz /install-sh /libtool /ltmain.sh From 5f15e7d35728ddcee8523c6a41c4d8034c0e2be0 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 22 Dec 2023 18:35:15 +0100 Subject: [PATCH 031/158] jsongen: Add a new gcli_jsongen_bool routine This routine is going to be used in future refactoring. It was missing in any case. --- include/gcli/json_gen.h | 1 + src/json_gen.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/include/gcli/json_gen.h b/include/gcli/json_gen.h index c5286116..bb1aeb79 100644 --- a/include/gcli/json_gen.h +++ b/include/gcli/json_gen.h @@ -67,6 +67,7 @@ int gcli_jsongen_end_array(gcli_jsongen *gen); int gcli_jsongen_objmember(gcli_jsongen *gen, char const *key); int gcli_jsongen_number(gcli_jsongen *gen, long long num); int gcli_jsongen_string(gcli_jsongen *gen, char const *value); +int gcli_jsongen_bool(gcli_jsongen *gen, bool value); int gcli_jsongen_null(gcli_jsongen *gen); #endif /* GCLI_JSON_GEN_H */ diff --git a/src/json_gen.c b/src/json_gen.c index 9c3b260f..c3bf8f94 100644 --- a/src/json_gen.c +++ b/src/json_gen.c @@ -263,6 +263,19 @@ gcli_jsongen_number(gcli_jsongen *gen, long long const number) return 0; } +int +gcli_jsongen_bool(gcli_jsongen *gen, bool const value) +{ + put_comma_if_needed(gen); + + append_strf(gen, "%s", value ? "true" : "false"); + + gen->await_object_value = false; + gen->first_elem = false; + + return 0; +} + int gcli_jsongen_string(gcli_jsongen *gen, char const *value) { From 815c1b650824f113ca944e6ce77dbe74f145bb15 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Tue, 26 Dec 2023 13:37:44 +0100 Subject: [PATCH 032/158] Remove uses of sn_sv in issues, pulls, repos, gists, forks, releases and comments The use of these types was cumbersome and technically also incorrect. Removing this code will allow some simplification such as a good common set of string handling routines, a consistent API as well as the removal of dead or rarely used code. A common pattern we can e.g. remove is: escape(SV(some_c_string)) Instead we just use the jsongen set of routines. --- include/gcli/cmd/editor.h | 4 +- include/gcli/comments.h | 2 +- include/gcli/forks.h | 7 +-- include/gcli/github/gists.h | 20 +++---- include/gcli/issues.h | 4 +- include/gcli/json_util.h | 30 +---------- include/gcli/pulls.h | 10 ++-- include/gcli/releases.h | 14 ++--- include/gcli/repos.h | 14 ++--- src/cmd/comment.c | 16 +++--- src/cmd/editor.c | 14 +++-- src/cmd/gists.c | 32 +++++------ src/cmd/issues.c | 20 ++++--- src/cmd/pulls.c | 40 +++++++------- src/cmd/releases.c | 30 +++++------ src/cmd/repos.c | 24 ++++----- src/forks.c | 6 +-- src/gitea/releases.c | 93 ++++++++++++++++---------------- src/github/comments.c | 29 ++++++---- src/github/gists.c | 20 +++---- src/github/issues.c | 38 ++++++++----- src/github/pulls.c | 64 ++++++++++++---------- src/github/releases.c | 97 ++++++++++++++++----------------- src/github/repos.c | 36 +++++++------ src/gitlab/comments.c | 32 ++++++----- src/gitlab/issues.c | 37 ++++++++----- src/gitlab/merge_requests.c | 103 +++++++++++++++++------------------- src/gitlab/releases.c | 87 ++++++++++++++---------------- src/gitlab/repos.c | 44 ++++++++------- src/json_util.c | 6 +-- src/releases.c | 12 ++--- src/repos.c | 10 ++-- templates/github/forks.t | 8 +-- templates/github/gists.t | 22 ++++---- templates/github/releases.t | 12 ++--- templates/github/repos.t | 10 ++-- templates/gitlab/forks.t | 6 +-- templates/gitlab/releases.t | 12 ++--- templates/gitlab/repos.t | 10 ++-- tests/github-parse-tests.c | 28 +++++----- tests/gitlab-parse-tests.c | 28 +++++----- 41 files changed, 573 insertions(+), 558 deletions(-) diff --git a/include/gcli/cmd/editor.h b/include/gcli/cmd/editor.h index 27062856..aff2d90c 100644 --- a/include/gcli/cmd/editor.h +++ b/include/gcli/cmd/editor.h @@ -36,9 +36,7 @@ #include -#include - -sn_sv gcli_editor_get_user_message( +char *gcli_editor_get_user_message( gcli_ctx *ctx, void (*initializer)(gcli_ctx *, FILE *, void *), void *user_data); diff --git a/include/gcli/comments.h b/include/gcli/comments.h index c6659fe4..2383087b 100644 --- a/include/gcli/comments.h +++ b/include/gcli/comments.h @@ -61,7 +61,7 @@ struct gcli_submit_comment_opts { enum comment_target_type { ISSUE_COMMENT, PR_COMMENT } target_type; char const *owner, *repo; gcli_id target_id; - sn_sv message; + char const *message; }; void gcli_comments_free(gcli_comment_list *list); diff --git a/include/gcli/forks.h b/include/gcli/forks.h index 902a137b..06b6572d 100644 --- a/include/gcli/forks.h +++ b/include/gcli/forks.h @@ -41,9 +41,9 @@ typedef struct gcli_fork gcli_fork; typedef struct gcli_fork_list gcli_fork_list; struct gcli_fork { - sn_sv full_name; - sn_sv owner; - sn_sv date; + char *full_name; + char *owner; + char *date; int forks; }; @@ -64,4 +64,5 @@ void gcli_fork_delete(char const *owner, void gcli_forks_free(gcli_fork_list *list); void gcli_fork_free(gcli_fork *fork); + #endif /* FORK_H */ diff --git a/include/gcli/github/gists.h b/include/gcli/github/gists.h index ddcc99c5..355684af 100644 --- a/include/gcli/github/gists.h +++ b/include/gcli/github/gists.h @@ -45,10 +45,10 @@ typedef struct gcli_gist_file gcli_gist_file; typedef struct gcli_new_gist gcli_new_gist; struct gcli_gist_file { - sn_sv filename; - sn_sv language; - sn_sv url; - sn_sv type; + char *filename; + char *language; + char *url; + char *type; size_t size; }; @@ -58,12 +58,12 @@ struct gcli_gist_list { }; struct gcli_gist { - sn_sv id; - sn_sv owner; - sn_sv url; - sn_sv date; - sn_sv git_pull_url; - sn_sv description; + char *id; + char *owner; + char *url; + char *date; + char *git_pull_url; + char *description; gcli_gist_file *files; size_t files_size; }; diff --git a/include/gcli/issues.h b/include/gcli/issues.h index 968bd9c4..89f8d29b 100644 --- a/include/gcli/issues.h +++ b/include/gcli/issues.h @@ -65,8 +65,8 @@ struct gcli_issue { struct gcli_submit_issue_options { char const *owner; char const *repo; - sn_sv title; - sn_sv body; + char *title; + char *body; }; struct gcli_issue_list { diff --git a/include/gcli/json_util.h b/include/gcli/json_util.h index 284197d8..573e9c7d 100644 --- a/include/gcli/json_util.h +++ b/include/gcli/json_util.h @@ -54,7 +54,6 @@ #define get_user(ctx, input, out) get_user_(ctx, input, out, __func__) #define get_label(ctx, input, out) get_label_(ctx, input, out, __func__) #define get_is_string(ctx, input, out) ((void)ctx, (*out = json_next(input) == JSON_STRING), 1) -#define get_int_to_sv(ctx, input, out) get_int_to_sv_(ctx, input, out, __func__) #define get_int_to_string(ctx, input, out) get_int_to_string_(ctx, input, out, __func__) int get_int_(gcli_ctx *ctx, json_stream *input, int *out, char const *function); @@ -72,32 +71,11 @@ int get_github_style_colour(gcli_ctx *ctx, json_stream *input, uint32_t *out); int get_gitlab_style_colour(gcli_ctx *ctx, json_stream *input, uint32_t *out); int get_github_is_pr(gcli_ctx *ctx, json_stream *input, int *out); int get_gitlab_can_be_merged(gcli_ctx *ctx, json_stream *input, bool *out); -int get_gitea_visibility(gcli_ctx *ctx, json_stream *input, sn_sv *out); -int get_int_to_sv_(gcli_ctx *ctx, json_stream *input, sn_sv *out, - char const *function); +int get_gitea_visibility(gcli_ctx *ctx, json_stream *input, char **out); sn_sv gcli_json_escape(sn_sv); #define gcli_json_escape_cstr(x) (gcli_json_escape(SV((char *)(x))).data) int gcli_json_advance(gcli_ctx *ctx, json_stream *input, char const *fmt, ...); -static inline int -get_user_sv(gcli_ctx *ctx, json_stream *input, sn_sv *out) -{ - char *user_str; - int rc = get_user(ctx, input, &user_str); - if (rc < 0) - return rc; - - *out = SV(user_str); - - return 0; -} - -static inline int -parse_user(gcli_ctx *ctx, json_stream *input, char **out) -{ - return get_user(ctx, input, out); -} - static inline char const * gcli_json_bool(bool it) { @@ -136,10 +114,4 @@ get_int_to_string_(gcli_ctx *ctx, json_stream *input, char **out, } \ } while (0) -static inline int -parse_sv(gcli_ctx *ctx, json_stream *stream, sn_sv *out) -{ - return get_sv(ctx, stream, out); -} - #endif /* JSON_UTIL_H */ diff --git a/include/gcli/pulls.h b/include/gcli/pulls.h index ec99f742..e87ad917 100644 --- a/include/gcli/pulls.h +++ b/include/gcli/pulls.h @@ -99,11 +99,11 @@ struct gcli_commit_list { struct gcli_submit_pull_options { char const *owner; char const *repo; - sn_sv from; - sn_sv to; - sn_sv title; - sn_sv body; - char const **labels; + char const *from; + char const *to; + char const *title; + char *body; + char **labels; size_t labels_size; int draft; }; diff --git a/include/gcli/releases.h b/include/gcli/releases.h index d9b13624..9bae7b95 100644 --- a/include/gcli/releases.h +++ b/include/gcli/releases.h @@ -49,14 +49,14 @@ struct gcli_release_asset { }; struct gcli_release { - sn_sv id; /* Probably shouldn't be called id */ + char *id; /* Probably shouldn't be called id */ gcli_release_asset *assets; size_t assets_size; - sn_sv name; - sn_sv body; - sn_sv author; - sn_sv date; - sn_sv upload_url; + char *name; + char *body; + char *author; + char *date; + char *upload_url; bool draft; bool prerelease; }; @@ -78,7 +78,7 @@ struct gcli_new_release { char const *repo; char const *tag; char const *name; - sn_sv body; + char *body; char const *commitish; bool draft; bool prerelease; diff --git a/include/gcli/repos.h b/include/gcli/repos.h index c196d0b6..7d6e1640 100644 --- a/include/gcli/repos.h +++ b/include/gcli/repos.h @@ -43,11 +43,11 @@ typedef struct gcli_repo_create_options gcli_repo_create_options; struct gcli_repo { gcli_id id; - sn_sv full_name; - sn_sv name; - sn_sv owner; - sn_sv date; - sn_sv visibility; + char *full_name; + char *name; + char *owner; + char *date; + char *visibility; bool is_fork; }; @@ -57,8 +57,8 @@ struct gcli_repo_list { }; struct gcli_repo_create_options { - sn_sv name; - sn_sv description; + char *name; + char *description; bool private; }; diff --git a/src/cmd/comment.c b/src/cmd/comment.c index 3a28ba9c..e1ef6331 100644 --- a/src/cmd/comment.c +++ b/src/cmd/comment.c @@ -88,7 +88,7 @@ comment_init(gcli_ctx *ctx, FILE *f, void *_data) info->owner, info->repo, target_type, info->target_id); } -static sn_sv +static char * gcli_comment_get_message(gcli_submit_comment_opts *info) { return gcli_editor_get_user_message(g_clictx, comment_init, info); @@ -97,14 +97,16 @@ gcli_comment_get_message(gcli_submit_comment_opts *info) static int comment_submit(gcli_submit_comment_opts opts, int always_yes) { - sn_sv const message = gcli_comment_get_message(&opts); - opts.message = gcli_json_escape(message); int rc = 0; + char *message; + + message = gcli_comment_get_message(&opts); + opts.message = message; fprintf( stdout, - "You will be commenting the following in %s/%s #%"PRIid":\n"SV_FMT"\n", - opts.owner, opts.repo, opts.target_id, SV_ARGS(message)); + "You will be commenting the following in %s/%s #%"PRIid":\n%s\n", + opts.owner, opts.repo, opts.target_id, opts.message); if (!always_yes) { if (!sn_yesno("Is this okay?")) @@ -113,8 +115,8 @@ comment_submit(gcli_submit_comment_opts opts, int always_yes) rc = gcli_comment_submit(g_clictx, opts); - free(message.data); - free(opts.message.data); + free(message); + opts.message = NULL; return rc; } diff --git a/src/cmd/editor.c b/src/cmd/editor.c index 244359e7..8a82c328 100644 --- a/src/cmd/editor.c +++ b/src/cmd/editor.c @@ -41,14 +41,16 @@ static sn_sv sv_append(sn_sv this, sn_sv const that) { - this.data = realloc(this.data, this.length + that.length); + /* Allocate one byte more as we're going to manually zero-terminate the result + * down in get_message */ + this.data = realloc(this.data, this.length + that.length + 1); memcpy(this.data + this.length, that.data, that.length); this.length += that.length; return this; } -sn_sv +char * gcli_editor_get_user_message( gcli_ctx *ctx, void (*file_initializer)(gcli_ctx *, FILE *, void *), @@ -64,8 +66,8 @@ gcli_editor_get_user_message( "file or set the EDITOR environment variable."); } - char filename[31] = "/tmp/gcli_message.XXXXXXX\0"; - int fd = mkstemp(filename); + char filename[31] = "/tmp/gcli_message.XXXXXXX\0"; + int fd = mkstemp(filename); FILE *file = fdopen(fd, "w"); file_initializer(ctx, file, user_data); @@ -119,5 +121,7 @@ gcli_editor_get_user_message( munmap(file_content, len); unlink(filename); - return result; + result.data[result.length] = '\0'; + + return result.data; } diff --git a/src/cmd/gists.c b/src/cmd/gists.c index dc0f0151..a6d91e0a 100644 --- a/src/cmd/gists.c +++ b/src/cmd/gists.c @@ -92,9 +92,9 @@ static void print_gist_file(gcli_gist_file const *const file) { printf(" • %-15.15s %-8.8s %-s\n", - language_fmt(file->language.data), + language_fmt(file->language), human_readable_size(file->size), - file->filename.data); + file->filename); } static void @@ -102,18 +102,18 @@ print_gist(enum gcli_output_flags const flags, gcli_gist const *const gist) { (void) flags; - printf(" ID : %s"SV_FMT"%s\n" - "OWNER : %s"SV_FMT"%s\n" - "DESCR : "SV_FMT"\n" - " DATE : "SV_FMT"\n" - " URL : "SV_FMT"\n" - " PULL : "SV_FMT"\n", - gcli_setcolour(GCLI_COLOR_YELLOW), SV_ARGS(gist->id), gcli_resetcolour(), - gcli_setbold(), SV_ARGS(gist->owner), gcli_resetbold(), - SV_ARGS(gist->description), - SV_ARGS(gist->date), - SV_ARGS(gist->url), - SV_ARGS(gist->git_pull_url)); + printf(" ID : %s%s%s\n" + "OWNER : %s%s%s\n" + "DESCR : %s\n" + " DATE : %s\n" + " URL : %s\n" + " PULL : %s\n", + gcli_setcolour(GCLI_COLOR_YELLOW), gist->id, gcli_resetcolour(), + gcli_setbold(), gist->owner, gcli_resetbold(), + gist->description, + gist->date, + gist->url, + gist->git_pull_url); printf("FILES : %-15.15s %-8.8s %-s\n", "LANGUAGE", "SIZE", "FILENAME"); @@ -218,7 +218,7 @@ subcommand_gist_get(int argc, char *argv[]) errx(1, "gcli: error: failed to get gist: %s", gcli_get_error(g_clictx)); for (size_t f = 0; f < gist.files_size; ++f) { - if (sn_sv_eq_to(gist.files[f].filename, file_name)) { + if (strcmp(gist.files[f].filename, file_name) == 0) { file = &gist.files[f]; break; } @@ -231,7 +231,7 @@ subcommand_gist_get(int argc, char *argv[]) if (isatty(STDOUT_FILENO) && (file->size >= 4 * 1024 * 1024)) errx(1, "gcli: error: File is bigger than 4 MiB, refusing to print to stdout."); - if (gcli_curl(g_clictx, stdout, file->url.data, file->type.data) < 0) + if (gcli_curl(g_clictx, stdout, file->url, file->type) < 0) errx(1, "gcli: error: failed to fetch gist: %s", gcli_get_error(g_clictx)); gcli_gist_free(&gist); diff --git a/src/cmd/issues.c b/src/cmd/issues.c index d79914d8..994caf4a 100644 --- a/src/cmd/issues.c +++ b/src/cmd/issues.c @@ -202,13 +202,13 @@ issue_init_user_file(gcli_ctx *ctx, FILE *stream, void *_opts) gcli_submit_issue_options *opts = _opts; fprintf( stream, - "! ISSUE TITLE : "SV_FMT"\n" + "! ISSUE TITLE : %s\n" "! Enter issue description above.\n" "! All lines starting with '!' will be discarded.\n", - SV_ARGS(opts->title)); + opts->title); } -static sn_sv +static char * gcli_issue_get_user_message(gcli_submit_issue_options *opts) { return gcli_editor_get_user_message(g_clictx, issue_init_user_file, opts); @@ -223,13 +223,11 @@ create_issue(gcli_submit_issue_options opts, int always_yes) printf("The following issue will be created:\n" "\n" - "TITLE : "SV_FMT"\n" + "TITLE : %s\n" "OWNER : %s\n" "REPO : %s\n" - "MESSAGE :\n"SV_FMT"\n", - SV_ARGS(opts.title), - opts.owner, opts.repo, - SV_ARGS(opts.body)); + "MESSAGE :\n%s\n", + opts.title, opts.owner, opts.repo, opts.body); putchar('\n'); @@ -240,8 +238,8 @@ create_issue(gcli_submit_issue_options opts, int always_yes) rc = gcli_issue_submit(g_clictx, opts); - free(opts.body.data); - free(opts.body.data); + free(opts.body); + free(opts.body); return rc; } @@ -297,7 +295,7 @@ subcommand_issue_create(int argc, char *argv[]) return EXIT_FAILURE; } - opts.title = SV(argv[0]); + opts.title = argv[0]; if (create_issue(opts, always_yes) < 0) errx(1, "gcli: error: failed to submit issue: %s", diff --git a/src/cmd/pulls.c b/src/cmd/pulls.c index 75ae9079..7a5c10e7 100644 --- a/src/cmd/pulls.c +++ b/src/cmd/pulls.c @@ -364,13 +364,13 @@ pull_init_user_file(gcli_ctx *ctx, FILE *stream, void *_opts) (void) ctx; fprintf( stream, - "! PR TITLE : "SV_FMT"\n" + "! PR TITLE : %s\n" "! Enter PR comments above.\n" "! All lines starting with '!' will be discarded.\n", - SV_ARGS(opts->title)); + opts->title); } -static sn_sv +static char * gcli_pull_get_user_message(gcli_submit_pull_options *opts) { return gcli_editor_get_user_message(g_clictx, pull_init_user_file, opts); @@ -384,15 +384,13 @@ create_pull(gcli_submit_pull_options opts, int always_yes) fprintf(stdout, "The following PR will be created:\n" "\n" - "TITLE : "SV_FMT"\n" - "BASE : "SV_FMT"\n" - "HEAD : "SV_FMT"\n" + "TITLE : %s\n" + "BASE : %s\n" + "HEAD : %s\n" "IN : %s/%s\n" - "MESSAGE :\n"SV_FMT"\n", - SV_ARGS(opts.title),SV_ARGS(opts.to), - SV_ARGS(opts.from), - opts.owner, opts.repo, - SV_ARGS(opts.body)); + "MESSAGE :\n%s\n", + opts.title, opts.to, opts.from, + opts.owner, opts.repo, opts.body); fputc('\n', stdout); @@ -403,7 +401,7 @@ create_pull(gcli_submit_pull_options opts, int always_yes) return gcli_pull_submit(g_clictx, opts); } -static sn_sv +static char const * pr_try_derive_head(void) { char const *account; @@ -424,7 +422,7 @@ pr_try_derive_head(void) " want to pull request."); } - return sn_sv_fmt("%s:"SV_FMT, account, SV_ARGS(branch)); + return sn_asprintf("%s:"SV_FMT, account, SV_ARGS(branch)); } static int @@ -466,10 +464,10 @@ subcommand_pull_create(int argc, char *argv[]) while ((ch = getopt_long(argc, argv, "yf:t:do:r:l:", options, NULL)) != -1) { switch (ch) { case 'f': - opts.from = SV(optarg); + opts.from = optarg; break; case 't': - opts.to = SV(optarg); + opts.to = optarg; break; case 'd': opts.draft = 1; @@ -497,15 +495,17 @@ subcommand_pull_create(int argc, char *argv[]) argc -= optind; argv += optind; - if (!opts.from.length) + if (!opts.from) opts.from = pr_try_derive_head(); - if (!opts.to.length) { - opts.to = gcli_config_get_base(g_clictx); - if (opts.to.length == 0) + if (!opts.to) { + sn_sv base = gcli_config_get_base(g_clictx); + if (base.length == 0) errx(1, "gcli: error: PR base is missing. Please either specify " "--to branch-name or set pr.base in .gcli."); + + opts.to = sn_sv_to_cstr(base); } check_owner_and_repo(&opts.owner, &opts.repo); @@ -516,7 +516,7 @@ subcommand_pull_create(int argc, char *argv[]) return EXIT_FAILURE; } - opts.title = SV(argv[0]); + opts.title = argv[0]; if (create_pull(opts, always_yes) < 0) errx(1, "gcli: error: failed to submit pull request: %s", diff --git a/src/cmd/releases.c b/src/cmd/releases.c index 5f3d8f85..c481d011 100644 --- a/src/cmd/releases.c +++ b/src/cmd/releases.c @@ -77,10 +77,10 @@ gcli_print_release(enum gcli_output_flags const flags, dict = gcli_dict_begin(); - gcli_dict_add(dict, "ID", 0, 0, SV_FMT, SV_ARGS(it->id)); - gcli_dict_add(dict, "NAME", 0, 0, SV_FMT, SV_ARGS(it->name)); - gcli_dict_add(dict, "AUTHOR", 0, 0, SV_FMT, SV_ARGS(it->author)); - gcli_dict_add(dict, "DATE", 0, 0, SV_FMT, SV_ARGS(it->date)); + gcli_dict_add(dict, "ID", 0, 0, "%s", it->id); + gcli_dict_add(dict, "NAME", 0, 0, "%s", it->name); + gcli_dict_add(dict, "AUTHOR", 0, 0, "%s", it->author); + gcli_dict_add(dict, "DATE", 0, 0, "%s", it->date); gcli_dict_add_string(dict, "DRAFT", 0, 0, sn_bool_yesno(it->draft)); gcli_dict_add_string(dict, "PRERELEASE", 0, 0, sn_bool_yesno(it->prerelease)); gcli_dict_add_string(dict, "ASSETS", 0, 0, ""); @@ -94,9 +94,9 @@ gcli_print_release(enum gcli_output_flags const flags, gcli_dict_end(dict); /* body */ - if (it->body.length) { + if (it->body) { putchar('\n'); - pretty_print(it->body.data, 13, 80, stdout); + pretty_print(it->body, 13, 80, stdout); } putchar('\n'); @@ -130,11 +130,11 @@ gcli_releases_print_short(enum gcli_output_flags const flags, size_t n; gcli_tbl table; gcli_tblcoldef cols[] = { - { .name = "ID", .type = GCLI_TBLCOLTYPE_SV, .flags = 0 }, - { .name = "DATE", .type = GCLI_TBLCOLTYPE_SV, .flags = 0 }, - { .name = "DRAFT", .type = GCLI_TBLCOLTYPE_BOOL, .flags = 0 }, - { .name = "PRERELEASE", .type = GCLI_TBLCOLTYPE_BOOL, .flags = 0 }, - { .name = "NAME", .type = GCLI_TBLCOLTYPE_SV, .flags = 0 }, + { .name = "ID", .type = GCLI_TBLCOLTYPE_STRING, .flags = 0 }, + { .name = "DATE", .type = GCLI_TBLCOLTYPE_STRING, .flags = 0 }, + { .name = "DRAFT", .type = GCLI_TBLCOLTYPE_BOOL, .flags = 0 }, + { .name = "PRERELEASE", .type = GCLI_TBLCOLTYPE_BOOL, .flags = 0 }, + { .name = "NAME", .type = GCLI_TBLCOLTYPE_STRING, .flags = 0 }, }; if (max < 0 || (size_t)(max) > list->releases_size) @@ -202,7 +202,7 @@ releasemsg_init(gcli_ctx *ctx, FILE *f, void *_data) info->owner, info->repo, info->tag, info->name); } -static sn_sv +static char * get_release_message(gcli_new_release const *info) { return gcli_editor_get_user_message(g_clictx, releasemsg_init, @@ -212,9 +212,9 @@ get_release_message(gcli_new_release const *info) static int subcommand_releases_create(int argc, char *argv[]) { - gcli_new_release release = {0}; - int ch; - bool always_yes = false; + gcli_new_release release = {0}; + int ch; + bool always_yes = false; struct option const options[] = { { .name = "yes", diff --git a/src/cmd/repos.c b/src/cmd/repos.c index 810b4331..748a883a 100644 --- a/src/cmd/repos.c +++ b/src/cmd/repos.c @@ -72,10 +72,10 @@ gcli_print_repos(enum gcli_output_flags const flags, size_t n; gcli_tbl table; gcli_tblcoldef cols[] = { - { .name = "FORK", .type = GCLI_TBLCOLTYPE_BOOL, .flags = 0 }, - { .name = "VISBLTY", .type = GCLI_TBLCOLTYPE_SV, .flags = 0 }, - { .name = "DATE", .type = GCLI_TBLCOLTYPE_SV, .flags = 0 }, - { .name = "FULLNAME", .type = GCLI_TBLCOLTYPE_SV, .flags = 0 }, + { .name = "FORK", .type = GCLI_TBLCOLTYPE_BOOL, .flags = 0 }, + { .name = "VISBLTY", .type = GCLI_TBLCOLTYPE_STRING, .flags = 0 }, + { .name = "DATE", .type = GCLI_TBLCOLTYPE_STRING, .flags = 0 }, + { .name = "FULLNAME", .type = GCLI_TBLCOLTYPE_STRING, .flags = 0 }, }; if (list->repos_size == 0) { @@ -122,11 +122,11 @@ gcli_repo_print(gcli_repo const *it) dict = gcli_dict_begin(); gcli_dict_add(dict, "ID", 0, 0, "%"PRIid, it->id); - gcli_dict_add(dict, "FULL NAME", 0, 0, SV_FMT, SV_ARGS(it->full_name)); - gcli_dict_add(dict, "NAME", 0, 0, SV_FMT, SV_ARGS(it->name)); - gcli_dict_add(dict, "OWNER", 0, 0, SV_FMT, SV_ARGS(it->owner)); - gcli_dict_add(dict, "DATE", 0, 0, SV_FMT, SV_ARGS(it->date)); - gcli_dict_add(dict, "VISIBILITY", 0, 0, SV_FMT, SV_ARGS(it->visibility)); + gcli_dict_add(dict, "FULL NAME", 0, 0, "%s", it->full_name); + gcli_dict_add(dict, "NAME", 0, 0, "%s", it->name); + gcli_dict_add(dict, "OWNER", 0, 0, "%s", it->owner); + gcli_dict_add(dict, "DATE", 0, 0, "%s", it->date); + gcli_dict_add(dict, "VISIBILITY", 0, 0, "%s", it->visibility); gcli_dict_add(dict, "IS FORK", 0, 0, "%s", sn_bool_yesno(it->is_fork)); gcli_dict_end(dict); @@ -158,10 +158,10 @@ subcommand_repos_create(int argc, char *argv[]) while ((ch = getopt_long(argc, argv, "r:d:p", options, NULL)) != -1) { switch (ch) { case 'r': - create_options.name = SV(optarg); + create_options.name = optarg; break; case 'd': - create_options.description = SV(optarg); + create_options.description = optarg; break; case 'p': create_options.private = true; @@ -176,7 +176,7 @@ subcommand_repos_create(int argc, char *argv[]) argc -= optind; argv += optind; - if (sn_sv_null(create_options.name)) { + if (!create_options.name) { fprintf(stderr, "gcli: name cannot be empty. please set a repository " "name with -r/--name\n"); diff --git a/src/forks.c b/src/forks.c index 5cdadeb1..2afc4810 100644 --- a/src/forks.c +++ b/src/forks.c @@ -50,9 +50,9 @@ gcli_fork_create(gcli_ctx *ctx, char const *owner, char const *repo, void gcli_fork_free(gcli_fork *fork) { - free(fork->full_name.data); - free(fork->owner.data); - free(fork->date.data); + free(fork->full_name); + free(fork->owner); + free(fork->date); } void diff --git a/src/gitea/releases.c b/src/gitea/releases.c index 6d78f79a..51c0006a 100644 --- a/src/gitea/releases.c +++ b/src/gitea/releases.c @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -76,61 +77,59 @@ gitea_upload_release_asset(gcli_ctx *ctx, char *const url, int gitea_create_release(gcli_ctx *ctx, gcli_new_release const *release) { - char *commitish_json = NULL; - char *e_owner = NULL; - char *e_repo = NULL; - char *name_json = NULL; - char *post_data = NULL; - char *upload_url = NULL; - char *url = NULL; + char *e_owner = NULL, *e_repo = NULL, *payload = NULL, *upload_url = NULL, *url = NULL; gcli_fetch_buffer buffer = {0}; + gcli_jsongen gen = {0}; gcli_release response = {0}; - sn_sv escaped_body = {0}; int rc = 0; + /* Payload */ + gcli_jsongen_init(&gen); + gcli_jsongen_begin_object(&gen); + { + gcli_jsongen_objmember(&gen, "tag_name"); + gcli_jsongen_string(&gen, release->tag); + + gcli_jsongen_objmember(&gen, "draft"); + gcli_jsongen_bool(&gen, release->draft); + + gcli_jsongen_objmember(&gen, "prerelease"); + gcli_jsongen_bool(&gen, release->prerelease); + + gcli_jsongen_objmember(&gen, "body"); + gcli_jsongen_string(&gen, release->body); + + if (release->commitish) { + gcli_jsongen_objmember(&gen, "target_commitish"); + gcli_jsongen_string(&gen, release->commitish); + } + + if (release->name) { + gcli_jsongen_objmember(&gen, "name"); + gcli_jsongen_string(&gen, release->name); + } + } + gcli_jsongen_end_object(&gen); + payload = gcli_jsongen_to_string(&gen); + gcli_jsongen_free(&gen); + + /* Generate URL */ e_owner = gcli_urlencode(release->owner); - e_repo = gcli_urlencode(release->repo); + e_repo = gcli_urlencode(release->repo); /* https://docs.github.com/en/rest/reference/repos#create-a-release */ - url = sn_asprintf( - "%s/repos/%s/%s/releases", - gcli_get_apibase(ctx), e_owner, e_repo); - - escaped_body = gcli_json_escape(release->body); - - if (release->commitish) - commitish_json = sn_asprintf( - ",\"target_commitish\": \"%s\"", - release->commitish); - - if (release->name) - name_json = sn_asprintf(",\"name\": \"%s\"", release->name); - - post_data = sn_asprintf( - "{" - " \"tag_name\": \"%s\"," - " \"draft\": %s," - " \"prerelease\": %s," - " \"body\": \""SV_FMT"\"" - " %s" - " %s" - "}", - release->tag, - gcli_json_bool(release->draft), - gcli_json_bool(release->prerelease), - SV_ARGS(escaped_body), - commitish_json ? commitish_json : "", - name_json ? name_json : ""); - - rc = gcli_fetch_with_method(ctx, "POST", url, post_data, NULL, &buffer); + url = sn_asprintf("%s/repos/%s/%s/releases", gcli_get_apibase(ctx), + e_owner, e_repo); + + rc = gcli_fetch_with_method(ctx, "POST", url, payload, NULL, &buffer); if (rc < 0) goto out; gitea_parse_release(ctx, &buffer, &response); - upload_url = sn_asprintf("%s/repos/%s/%s/releases/"SV_FMT"/assets", + upload_url = sn_asprintf("%s/repos/%s/%s/releases/%s/assets", gcli_get_apibase(ctx), e_owner, e_repo, - SV_ARGS(response.id)); + response.id); for (size_t i = 0; i < release->assets_size; ++i) { printf("INFO : Uploading asset %s...\n", release->assets[i].path); @@ -140,16 +139,14 @@ gitea_create_release(gcli_ctx *ctx, gcli_new_release const *release) break; } + gcli_release_free(&response); out: + free(e_owner); + free(e_repo); free(upload_url); free(buffer.data); free(url); - free(post_data); - free(escaped_body.data); - free(e_owner); - free(e_repo); - free(name_json); - free(commitish_json); + free(payload); return rc; } diff --git a/src/github/comments.c b/src/github/comments.c index 0ce9b71b..07109545 100644 --- a/src/github/comments.c +++ b/src/github/comments.c @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -40,23 +41,31 @@ github_perform_submit_comment(gcli_ctx *ctx, gcli_submit_comment_opts opts, gcli_fetch_buffer *out) { int rc = 0; + gcli_jsongen gen = {0}; char *e_owner = gcli_urlencode(opts.owner); char *e_repo = gcli_urlencode(opts.repo); + char *payload = NULL, *url = NULL; - char *post_fields = sn_asprintf( - "{ \"body\": \""SV_FMT"\" }", - SV_ARGS(opts.message)); - char *url = sn_asprintf( - "%s/repos/%s/%s/issues/%"PRIid"/comments", - gcli_get_apibase(ctx), - e_owner, e_repo, opts.target_id); + gcli_jsongen_init(&gen); + gcli_jsongen_begin_object(&gen); + { + gcli_jsongen_objmember(&gen, "body"); + gcli_jsongen_string(&gen, opts.message); + } + gcli_jsongen_end_object(&gen); - rc = gcli_fetch_with_method(ctx, "POST", url, post_fields, NULL, out); + payload = gcli_jsongen_to_string(&gen); + gcli_jsongen_free(&gen); - free(post_fields); + url = sn_asprintf("%s/repos/%s/%s/issues/%"PRIid"/comments", + gcli_get_apibase(ctx), e_owner, e_repo, opts.target_id); + + rc = gcli_fetch_with_method(ctx, "POST", url, payload, NULL, out); + + free(payload); + free(url); free(e_owner); free(e_repo); - free(url); return rc; } diff --git a/src/github/gists.c b/src/github/gists.c index 177a8673..d7abfd5d 100644 --- a/src/github/gists.c +++ b/src/github/gists.c @@ -203,18 +203,18 @@ gcli_delete_gist(gcli_ctx *ctx, char const *gist_id) void gcli_gist_free(gcli_gist *g) { - free(g->id.data); - free(g->owner.data); - free(g->url.data); - free(g->date.data); - free(g->git_pull_url.data); - free(g->description.data); + free(g->id); + free(g->owner); + free(g->url); + free(g->date); + free(g->git_pull_url); + free(g->description); for (size_t j = 0; j < g->files_size; ++j) { - free(g->files[j].filename.data); - free(g->files[j].language.data); - free(g->files[j].url.data); - free(g->files[j].type.data); + free(g->files[j].filename); + free(g->files[j].language); + free(g->files[j].url); + free(g->files[j].type); } free(g->files); diff --git a/src/github/issues.c b/src/github/issues.c index f122001b..2fa2b8d3 100644 --- a/src/github/issues.c +++ b/src/github/issues.c @@ -278,26 +278,38 @@ int github_perform_submit_issue(gcli_ctx *ctx, gcli_submit_issue_options opts, gcli_fetch_buffer *out) { - char *e_owner = gcli_urlencode(opts.owner); - char *e_repo = gcli_urlencode(opts.repo); - sn_sv e_title = gcli_json_escape(opts.title); - sn_sv e_body = gcli_json_escape(opts.body); + char *e_owner = NULL, *e_repo = NULL, *payload = NULL, *url = NULL; + gcli_jsongen gen = {0}; int rc = 0; - char *post_fields = sn_asprintf( - "{ \"title\": \""SV_FMT"\", \"body\": \""SV_FMT"\" }", - SV_ARGS(e_title), SV_ARGS(e_body)); + /* Generate Payload */ + gcli_jsongen_init(&gen); + gcli_jsongen_begin_object(&gen); + { + gcli_jsongen_objmember(&gen, "title"); + gcli_jsongen_string(&gen, opts.title); - char *url = sn_asprintf("%s/repos/%s/%s/issues", - gcli_get_apibase(ctx), e_owner, e_repo); + gcli_jsongen_objmember(&gen, "body"); + gcli_jsongen_string(&gen, opts.body); + } + gcli_jsongen_begin_object(&gen); - rc = gcli_fetch_with_method(ctx, "POST", url, post_fields, NULL, out); + payload = gcli_jsongen_to_string(&gen); + gcli_jsongen_free(&gen); + + /* Generate URL */ + e_owner = gcli_urlencode(opts.owner); + e_repo = gcli_urlencode(opts.repo); + + url = sn_asprintf("%s/repos/%s/%s/issues", gcli_get_apibase(ctx), e_owner, + e_repo); free(e_owner); free(e_repo); - free(e_title.data); - free(e_body.data); - free(post_fields); + + rc = gcli_fetch_with_method(ctx, "POST", url, payload, NULL, out); + + free(payload); free(url); return rc; diff --git a/src/github/pulls.c b/src/github/pulls.c index 3e4c95f4..63ee722a 100644 --- a/src/github/pulls.c +++ b/src/github/pulls.c @@ -306,51 +306,61 @@ github_pull_reopen(gcli_ctx *ctx, char const *owner, char const *repo, int github_perform_submit_pull(gcli_ctx *ctx, gcli_submit_pull_options opts) { - sn_sv e_head, e_base, e_title, e_body; + char *url = NULL, *payload = NULL, *e_owner = NULL, *e_repo = NULL; gcli_fetch_buffer fetch_buffer = {0}; - struct json_stream json = {0}; - gcli_pull pull = {0}; + gcli_jsongen gen = {0}; int rc = 0; - e_head = gcli_json_escape(opts.from); - e_base = gcli_json_escape(opts.to); - e_title = gcli_json_escape(opts.title); - e_body = gcli_json_escape(opts.body); - - char *post_fields = sn_asprintf( - "{\"head\":\""SV_FMT"\",\"base\":\""SV_FMT"\", " - "\"title\": \""SV_FMT"\", \"body\": \""SV_FMT"\" }", - SV_ARGS(e_head), - SV_ARGS(e_base), - SV_ARGS(e_title), - SV_ARGS(e_body)); - char *url = sn_asprintf( - "%s/repos/%s/%s/pulls", - gcli_get_apibase(ctx), - opts.owner, opts.repo); + gcli_jsongen_init(&gen); + gcli_jsongen_begin_object(&gen); + { + gcli_jsongen_objmember(&gen, "head"); + gcli_jsongen_string(&gen, opts.from); + + gcli_jsongen_objmember(&gen, "base"); + gcli_jsongen_string(&gen, opts.to); + + gcli_jsongen_objmember(&gen, "title"); + gcli_jsongen_string(&gen, opts.title); + + gcli_jsongen_objmember(&gen, "body"); + gcli_jsongen_string(&gen, opts.body); + } + gcli_jsongen_end_object(&gen); + payload = gcli_jsongen_to_string(&gen); + gcli_jsongen_free(&gen); - rc = gcli_fetch_with_method(ctx, "POST", url, post_fields, NULL, - &fetch_buffer); + e_owner = gcli_urlencode(opts.owner); + e_repo = gcli_urlencode(opts.repo); + + url = sn_asprintf("%s/repos/%s/%s/pulls", gcli_get_apibase(ctx), e_owner, + e_repo); + + free(e_owner); + free(e_repo); + + rc = gcli_fetch_with_method(ctx, "POST", url, payload, NULL, &fetch_buffer); /* Add labels if requested. GitHub doesn't allow us to do this all * with one request. */ if (rc == 0 && opts.labels_size) { + json_stream json = {0}; + gcli_pull pull = {0}; + json_open_buffer(&json, fetch_buffer.data, fetch_buffer.length); parse_github_pull(ctx, &json, &pull); github_issue_add_labels(ctx, opts.owner, opts.repo, pull.id, - opts.labels, opts.labels_size); + (char const *const *)opts.labels, + opts.labels_size); gcli_pull_free(&pull); json_close(&json); } + free(fetch_buffer.data); - free(e_head.data); - free(e_base.data); - free(e_title.data); - free(e_body.data); - free(post_fields); + free(payload); free(url); return rc; diff --git a/src/github/releases.c b/src/github/releases.c index 46df9cd2..f13d5292 100644 --- a/src/github/releases.c +++ b/src/github/releases.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -83,12 +84,12 @@ github_parse_single_release(gcli_ctx *ctx, gcli_fetch_buffer buffer, static int github_get_upload_url(gcli_ctx *ctx, gcli_release *const it, char **out) { - char *delim = strchr(it->upload_url.data, '{'); + char *delim = strchr(it->upload_url, '{'); if (delim == NULL) return gcli_error(ctx, "GitHub API returned an invalid upload url"); - size_t len = delim - it->upload_url.data; - *out = sn_strndup(it->upload_url.data, len); + size_t len = delim - it->upload_url; + *out = sn_strndup(it->upload_url, len); return 0; } @@ -126,57 +127,55 @@ github_upload_release_asset(gcli_ctx *ctx, char const *url, int github_create_release(gcli_ctx *ctx, gcli_new_release const *release) { - char *url = NULL; - char *e_owner = NULL; - char *e_repo = NULL; - char *upload_url = NULL; - char *post_data = NULL; - char *name_json = NULL; - char *commitish_json = NULL; - sn_sv escaped_body = {0}; + char *url = NULL, *e_owner = NULL, *e_repo = NULL, *upload_url = NULL, + *payload = NULL; gcli_fetch_buffer buffer = {0}; + gcli_jsongen gen = {0}; gcli_release response = {0}; int rc = 0; - assert(release); + /* Payload */ + gcli_jsongen_init(&gen); + gcli_jsongen_begin_object(&gen); + { + gcli_jsongen_objmember(&gen, "tag_name"); + gcli_jsongen_string(&gen, release->tag); + + gcli_jsongen_objmember(&gen, "draft"); + gcli_jsongen_bool(&gen, release->draft); + + gcli_jsongen_objmember(&gen, "prerelease"); + gcli_jsongen_bool(&gen, release->prerelease); + + gcli_jsongen_objmember(&gen, "body"); + gcli_jsongen_string(&gen, release->body); + + + if (release->commitish) { + gcli_jsongen_objmember(&gen, "target_commitish"); + gcli_jsongen_string(&gen, release->commitish); + } + + if (release->name) { + gcli_jsongen_objmember(&gen, "name"); + gcli_jsongen_string(&gen, release->name); + } + } + gcli_jsongen_end_object(&gen); + payload = gcli_jsongen_to_string(&gen); + gcli_jsongen_free(&gen); e_owner = gcli_urlencode(release->owner); e_repo = gcli_urlencode(release->repo); /* https://docs.github.com/en/rest/reference/repos#create-a-release */ - url = sn_asprintf( - "%s/repos/%s/%s/releases", - gcli_get_apibase(ctx), e_owner, e_repo); - - escaped_body = gcli_json_escape(release->body); - - if (release->commitish) - commitish_json = sn_asprintf( - ",\"target_commitish\": \"%s\"", - release->commitish); - - if (release->name) - name_json = sn_asprintf( - ",\"name\": \"%s\"", - release->name); - - post_data = sn_asprintf( - "{" - " \"tag_name\": \"%s\"," - " \"draft\": %s," - " \"prerelease\": %s," - " \"body\": \""SV_FMT"\"" - " %s" - " %s" - "}", - release->tag, - gcli_json_bool(release->draft), - gcli_json_bool(release->prerelease), - SV_ARGS(escaped_body), - commitish_json ? commitish_json : "", - name_json ? name_json : ""); - - rc = gcli_fetch_with_method(ctx, "POST", url, post_data, NULL, &buffer); + url = sn_asprintf("%s/repos/%s/%s/releases", gcli_get_apibase(ctx), + e_owner, e_repo); + + free(e_owner); + free(e_repo); + + rc = gcli_fetch_with_method(ctx, "POST", url, payload, NULL, &buffer); if (rc < 0) goto out; @@ -195,15 +194,11 @@ github_create_release(gcli_ctx *ctx, gcli_new_release const *release) } out: + gcli_release_free(&response); free(upload_url); free(buffer.data); free(url); - free(post_data); - free(escaped_body.data); - free(e_owner); - free(e_repo); - free(name_json); - free(commitish_json); + free(payload); return rc; } diff --git a/src/github/repos.c b/src/github/repos.c index 83a848a5..05bc8004 100644 --- a/src/github/repos.c +++ b/src/github/repos.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -131,28 +132,35 @@ int github_repo_create(gcli_ctx *ctx, gcli_repo_create_options const *options, gcli_repo *const out) { - char *url, *data; + char *url, *payload; gcli_fetch_buffer buffer = {0}; + gcli_jsongen gen = {0}; struct json_stream stream = {0}; - sn_sv e_name, e_description; int rc = 0; /* Request preparation */ url = sn_asprintf("%s/user/repos", gcli_get_apibase(ctx)); - /* JSON-escape repo name and description */ - e_name = gcli_json_escape(options->name); - e_description = gcli_json_escape(options->description); - /* Construct payload */ - data = sn_asprintf("{\"name\": \""SV_FMT"\"," - " \"description\": \""SV_FMT"\"," - " \"private\": %s }", - SV_ARGS(e_name), SV_ARGS(e_description), - gcli_json_bool(options->private)); + gcli_jsongen_init(&gen); + gcli_jsongen_begin_object(&gen); + { + gcli_jsongen_objmember(&gen, "name"); + gcli_jsongen_string(&gen, options->name); + + gcli_jsongen_objmember(&gen, "description"); + gcli_jsongen_string(&gen, options->description); + + gcli_jsongen_objmember(&gen, "private"); + gcli_jsongen_bool(&gen, options->private); + } + gcli_jsongen_end_object(&gen); + + payload = gcli_jsongen_to_string(&gen); + gcli_jsongen_free(&gen); /* Fetch and parse result */ - rc = gcli_fetch_with_method(ctx, "POST", url, data, NULL, + rc = gcli_fetch_with_method(ctx, "POST", url, payload, NULL, out ? &buffer : NULL); if (rc == 0 && out) { @@ -163,9 +171,7 @@ github_repo_create(gcli_ctx *ctx, gcli_repo_create_options const *options, /* Cleanup */ free(buffer.data); - free(e_name.data); - free(e_description.data); - free(data); + free(payload); free(url); return rc; diff --git a/src/gitlab/comments.c b/src/gitlab/comments.c index 8f5eec47..86f852a5 100644 --- a/src/gitlab/comments.c +++ b/src/gitlab/comments.c @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -37,9 +38,9 @@ int gitlab_perform_submit_comment(gcli_ctx *ctx, gcli_submit_comment_opts opts, gcli_fetch_buffer *const out) { + char *url = NULL, *payload = NULL, *e_owner = NULL, *e_repo = NULL; char const *type = NULL; - char *e_owner = NULL; - char *e_repo = NULL; + gcli_jsongen gen = {0}; int rc = 0; e_owner = gcli_urlencode(opts.owner); @@ -54,20 +55,27 @@ gitlab_perform_submit_comment(gcli_ctx *ctx, gcli_submit_comment_opts opts, break; } - char *post_fields = sn_asprintf( - "{ \"body\": \""SV_FMT"\" }", - SV_ARGS(opts.message)); - char *url = sn_asprintf( - "%s/projects/%s%%2F%s/%s/%"PRIid"/notes", - gcli_get_apibase(ctx), - e_owner, e_repo, type, opts.target_id); + gcli_jsongen_init(&gen); + gcli_jsongen_begin_object(&gen); + { + gcli_jsongen_objmember(&gen, "body"); + gcli_jsongen_string(&gen, opts.message); + } + gcli_jsongen_end_object(&gen); + + payload = gcli_jsongen_to_string(&gen); + gcli_jsongen_free(&gen); - rc = gcli_fetch_with_method(ctx, "POST", url, post_fields, NULL, out); + url = sn_asprintf("%s/project/%s%%2F%s/%s/%"PRIid"/notes", + gcli_get_apibase(ctx), e_owner, e_repo, type, + opts.target_id); - free(post_fields); + rc = gcli_fetch_with_method(ctx, "POST", url, payload, NULL, out); + + free(payload); + free(url); free(e_owner); free(e_repo); - free(url); return rc; } diff --git a/src/gitlab/issues.c b/src/gitlab/issues.c index 386cfed0..5bd4edff 100644 --- a/src/gitlab/issues.c +++ b/src/gitlab/issues.c @@ -200,25 +200,36 @@ int gitlab_perform_submit_issue(gcli_ctx *ctx, gcli_submit_issue_options opts, gcli_fetch_buffer *const out) { - char *e_owner = gcli_urlencode(opts.owner); - char *e_repo = gcli_urlencode(opts.repo); - sn_sv e_title = gcli_json_escape(opts.title); - sn_sv e_body = gcli_json_escape(opts.body); + char *e_owner = NULL, *e_repo = NULL, *url = NULL, *payload = NULL; + gcli_jsongen gen = {0}; int rc = 0; - char *post_fields = sn_asprintf( - "{ \"title\": \""SV_FMT"\", \"description\": \""SV_FMT"\" }", - SV_ARGS(e_title), SV_ARGS(e_body)); - char *url = sn_asprintf("%s/projects/%s%%2F%s/issues", gcli_get_apibase(ctx), - e_owner, e_repo); + e_owner = gcli_urlencode(opts.owner); + e_repo = gcli_urlencode(opts.repo); + + gcli_jsongen_init(&gen); + gcli_jsongen_begin_object(&gen); + { + gcli_jsongen_objmember(&gen, "title"); + gcli_jsongen_string(&gen, opts.title); - rc = gcli_fetch_with_method(ctx, "POST", url, post_fields, NULL, out); + gcli_jsongen_objmember(&gen, "description"); + gcli_jsongen_string(&gen, opts.body); + } + gcli_jsongen_end_object(&gen); + + payload = gcli_jsongen_to_string(&gen); + gcli_jsongen_free(&gen); + + url = sn_asprintf("%s/projects/%s%%2F%s/issues", gcli_get_apibase(ctx), + e_owner, e_repo); free(e_owner); free(e_repo); - free(e_title.data); - free(e_body.data); - free(post_fields); + + rc = gcli_fetch_with_method(ctx, "POST", url, payload, NULL, out); + + free(payload); free(url); return rc; diff --git a/src/gitlab/merge_requests.c b/src/gitlab/merge_requests.c index 65bfe744..9c70d91f 100644 --- a/src/gitlab/merge_requests.c +++ b/src/gitlab/merge_requests.c @@ -416,82 +416,75 @@ gitlab_perform_submit_mr(gcli_ctx *ctx, gcli_submit_pull_options opts) /* Note: this doesn't really allow merging into repos with * different names. We need to figure out a way to make this * better for both github and gitlab. */ + char *source_branch = NULL, *source_owner = NULL, *payload = NULL, + *e_owner = NULL, *e_repo = NULL, *url = NULL; + char const *target_branch = NULL; + gcli_jsongen gen = {0}; gcli_repo target = {0}; - sn_sv target_branch = {0}; - sn_sv source_owner = {0}; - sn_sv source_branch = {0}; - char *labels = NULL; int rc = 0; - /* json escaped variants */ - sn_sv e_source_branch, e_target_branch, e_title, e_body; - target_branch = opts.to; - source_branch = opts.from; - source_owner = sn_sv_chop_until(&source_branch, ':'); - if (source_branch.length == 0) + source_owner = strdup(opts.from); + source_branch = strchr(source_owner, ':'); + if (source_branch == NULL) return gcli_error(ctx, "bad merge request source: expected 'owner:branch'"); - source_branch.length -= 1; - source_branch.data += 1; + *source_branch++ = '\0'; /* Figure out the project id */ rc = gitlab_get_repo(ctx, opts.owner, opts.repo, &target); if (rc < 0) return rc; - /* escape things in the post payload */ - e_source_branch = gcli_json_escape(source_branch); - e_target_branch = gcli_json_escape(target_branch); - e_title = gcli_json_escape(opts.title); - e_body = gcli_json_escape(opts.body); + /* generate payload */ + gcli_jsongen_init(&gen); + gcli_jsongen_begin_object(&gen); + { + gcli_jsongen_objmember(&gen, "source_branch"); + gcli_jsongen_string(&gen, source_branch); + + gcli_jsongen_objmember(&gen, "target_branch"); + gcli_jsongen_string(&gen, target_branch); + + gcli_jsongen_objmember(&gen, "title"); + gcli_jsongen_string(&gen, opts.title); - /* Prepare the label list if needed */ - if (opts.labels_size) { - char *joined_items = NULL; + gcli_jsongen_objmember(&gen, "description"); + gcli_jsongen_string(&gen, opts.body); - /* Join by "," */ - joined_items = sn_join_with( - opts.labels, opts.labels_size, "\",\""); + gcli_jsongen_objmember(&gen, "target_project_id"); + gcli_jsongen_number(&gen, target.id); - /* Construct something we can shove into the payload below */ - labels = sn_asprintf(", \"labels\": [\"%s\"]", joined_items); - free(joined_items); + if (opts.labels_size) { + gcli_jsongen_objmember(&gen, "labels"); + + gcli_jsongen_begin_array(&gen); + for (size_t i = 0; i < opts.labels_size; ++i) + gcli_jsongen_string(&gen, opts.labels[i]); + gcli_jsongen_end_array(&gen); + } } + gcli_jsongen_end_object(&gen); + payload = gcli_jsongen_to_string(&gen); + gcli_jsongen_free(&gen); + gcli_repo_free(&target); - /* prepare payload */ - char *post_fields = sn_asprintf( - "{\"source_branch\":\""SV_FMT"\",\"target_branch\":\""SV_FMT"\", " - "\"title\": \""SV_FMT"\", \"description\": \""SV_FMT"\", " - "\"target_project_id\": %"PRIid" %s }", - SV_ARGS(e_source_branch), - SV_ARGS(e_target_branch), - SV_ARGS(e_title), - SV_ARGS(e_body), - target.id, - labels ? labels : ""); - - /* construct url. The thing below works as the string view is - * malloced and also NUL-terminated */ - char *e_owner = gcli_urlencode_sv(source_owner).data; - char *e_repo = gcli_urlencode(opts.repo); - - char *url = sn_asprintf("%s/projects/%s%%2F%s/merge_requests", - gcli_get_apibase(ctx), - e_owner, e_repo); + /* generate url */ + e_owner = gcli_urlencode(source_owner); + e_repo = gcli_urlencode(opts.repo); - /* perform request */ - rc = gcli_fetch_with_method(ctx, "POST", url, post_fields, NULL, NULL); + url = sn_asprintf("%s/projects/%s%%2F%s/merge_requests", gcli_get_apibase(ctx), + e_owner, e_repo); - /* cleanup */ - free(e_source_branch.data); - free(e_target_branch.data); - free(e_title.data); - free(e_body.data); free(e_owner); free(e_repo); - free(labels); - free(post_fields); + + /* perform request */ + rc = gcli_fetch_with_method(ctx, "POST", url, payload, NULL, NULL); + + /* cleanup */ + free(source_owner); + free(payload); free(url); return rc; diff --git a/src/gitlab/releases.c b/src/gitlab/releases.c index 5f251e32..626415ac 100644 --- a/src/gitlab/releases.c +++ b/src/gitlab/releases.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -98,35 +99,10 @@ gitlab_get_releases(gcli_ctx *ctx, char const *owner, char const *repo, int gitlab_create_release(gcli_ctx *ctx, gcli_new_release const *release) { - char *url = NULL; - char *upload_url = NULL; - char *post_data = NULL; - char *name_json = NULL; - char *e_owner = NULL; - char *e_repo = NULL; - char *commitish_json = NULL; - sn_sv escaped_body = {0}; + char *e_owner = NULL, *e_repo = NULL, *url = NULL, *payload = NULL; + gcli_jsongen gen = {0}; int rc = 0; - e_owner = gcli_urlencode(release->owner); - e_repo = gcli_urlencode(release->repo); - - /* https://docs.github.com/en/rest/reference/repos#create-a-release */ - url = sn_asprintf("%s/projects/%s%%2F%s/releases", gcli_get_apibase(ctx), - e_owner, e_repo); - - escaped_body = gcli_json_escape(release->body); - - if (release->commitish) - commitish_json = sn_asprintf( - ",\"ref\": \"%s\"", - release->commitish); - - if (release->name) - name_json = sn_asprintf( - ",\"name\": \"%s\"", - release->name); - /* Warnings because unsupported on gitlab */ if (release->prerelease) warnx("prereleases are not supported on GitLab, option ignored"); @@ -134,32 +110,49 @@ gitlab_create_release(gcli_ctx *ctx, gcli_new_release const *release) if (release->draft) warnx("draft releases are not supported on GitLab, option ignored"); - post_data = sn_asprintf( - "{" - " \"tag_name\": \"%s\"," - " \"description\": \""SV_FMT"\"" - " %s" - " %s" - "}", - release->tag, - SV_ARGS(escaped_body), - commitish_json ? commitish_json : "", - name_json ? name_json : ""); - - rc = gcli_fetch_with_method(ctx, "POST", url, post_data, NULL, NULL); - if (release->assets_size) warnx("GitLab release asset uploads are not yet supported"); - free(upload_url); - free(url); - free(post_data); - free(escaped_body.data); - free(name_json); - free(commitish_json); + /* Payload generation */ + gcli_jsongen_init(&gen); + gcli_jsongen_begin_object(&gen); + { + gcli_jsongen_objmember(&gen, "tag_name"); + gcli_jsongen_string(&gen, release->tag); + + gcli_jsongen_objmember(&gen, "description"); + gcli_jsongen_string(&gen, release->body); + + if (release->commitish) { + gcli_jsongen_objmember(&gen, "ref"); + gcli_jsongen_string(&gen, release->commitish); + } + + if (release->name) { + gcli_jsongen_objmember(&gen, "name"); + gcli_jsongen_string(&gen, release->name); + } + } + gcli_jsongen_end_object(&gen); + payload = gcli_jsongen_to_string(&gen); + gcli_jsongen_free(&gen); + + /* Generate URL */ + e_owner = gcli_urlencode(release->owner); + e_repo = gcli_urlencode(release->repo); + + /* https://docs.github.com/en/rest/reference/repos#create-a-release */ + url = sn_asprintf("%s/projects/%s%%2F%s/releases", gcli_get_apibase(ctx), + e_owner, e_repo); + free(e_owner); free(e_repo); + rc = gcli_fetch_with_method(ctx, "POST", url, payload, NULL, NULL); + + free(url); + free(payload); + return rc; } diff --git a/src/gitlab/repos.c b/src/gitlab/repos.c index 9f012da6..d8578509 100644 --- a/src/gitlab/repos.c +++ b/src/gitlab/repos.c @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -75,18 +76,14 @@ gitlab_get_repo(gcli_ctx *ctx, char const *owner, char const *repo, static void gitlab_repos_fixup_missing_visibility(gcli_repo_list *const list) { - static char const public[] = "public"; - static size_t const public_len = sizeof(public) - 1; + static char const *const public = "public"; /* Gitlab does not return a visibility field in the repo object on * unauthenticated API requests. We fix up the missing field here * assuming that the repository must be public. */ for (size_t i = 0; i < list->repos_size; ++i) { - if (sn_sv_null(list->repos[i].visibility)) - list->repos[i].visibility = (sn_sv) { - .data = strdup(public), - .length = public_len, - }; + if (!list->repos[i].visibility) + list->repos[i].visibility = strdup(public); } } @@ -143,23 +140,34 @@ int gitlab_repo_create(gcli_ctx *ctx, gcli_repo_create_options const *options, gcli_repo *out) { - char *url, *data; + char *url, *payload; gcli_fetch_buffer buffer = {0}; - json_stream stream = {0}; + gcli_jsongen gen = {0}; int rc; + json_stream stream = {0}; /* Request preparation */ url = sn_asprintf("%s/projects", gcli_get_apibase(ctx)); - /* TODO: escape the repo name and the description */ - data = sn_asprintf("{\"name\": \""SV_FMT"\"," - " \"description\": \""SV_FMT"\"," - " \"visibility\": \"%s\" }", - SV_ARGS(options->name), - SV_ARGS(options->description), - options->private ? "private" : "public"); + + gcli_jsongen_init(&gen); + gcli_jsongen_begin_object(&gen); + { + gcli_jsongen_objmember(&gen, "name"); + gcli_jsongen_string(&gen, options->name); + + gcli_jsongen_objmember(&gen, "description"); + gcli_jsongen_string(&gen, options->description); + + gcli_jsongen_objmember(&gen, "visibility"); + gcli_jsongen_string(&gen, options->private ? "private" : "public"); + } + gcli_jsongen_end_object(&gen); + + payload = gcli_jsongen_to_string(&gen); + gcli_jsongen_free(&gen); /* Fetch and parse result */ - rc = gcli_fetch_with_method(ctx, "POST", url, data, NULL, out ? &buffer : NULL); + rc = gcli_fetch_with_method(ctx, "POST", url, payload, NULL, out ? &buffer : NULL); if (rc == 0 && out) { json_open_buffer(&stream, buffer.data, buffer.length); parse_gitlab_repo(ctx, &stream, out); @@ -168,7 +176,7 @@ gitlab_repo_create(gcli_ctx *ctx, gcli_repo_create_options const *options, } free(buffer.data); - free(data); + free(payload); free(url); return rc; diff --git a/src/json_util.c b/src/json_util.c index 8c3581ac..62801757 100644 --- a/src/json_util.c +++ b/src/json_util.c @@ -363,16 +363,14 @@ get_gitlab_style_colour(gcli_ctx *ctx, json_stream *const input, uint32_t *out) } int -get_gitea_visibility(gcli_ctx *ctx, json_stream *const input, sn_sv *out) +get_gitea_visibility(gcli_ctx *ctx, json_stream *const input, char **out) { - char *v = NULL; bool is_private; int rc = get_bool(ctx, input, &is_private); if (rc < 0) return rc; - v = strdup(is_private ? "private" : "public"); - *out = SV(v); + *out = strdup(is_private ? "private" : "public"); return 0; } diff --git a/src/releases.c b/src/releases.c index d075f11a..0df5f0a7 100644 --- a/src/releases.c +++ b/src/releases.c @@ -44,12 +44,12 @@ gcli_get_releases(gcli_ctx *ctx, char const *owner, char const *repo, void gcli_release_free(gcli_release *release) { - free(release->id.data); - free(release->name.data); - free(release->body.data); - free(release->author.data); - free(release->date.data); - free(release->upload_url.data); + free(release->id); + free(release->name); + free(release->body); + free(release->author); + free(release->date); + free(release->upload_url); for (size_t i = 0; i < release->assets_size; ++i) { free(release->assets[i].name); diff --git a/src/repos.c b/src/repos.c index 7ec475be..1546fdff 100644 --- a/src/repos.c +++ b/src/repos.c @@ -44,11 +44,11 @@ gcli_get_repos(gcli_ctx *ctx, char const *owner, int const max, void gcli_repo_free(gcli_repo *it) { - free(it->full_name.data); - free(it->name.data); - free(it->owner.data); - free(it->date.data); - free(it->visibility.data); + free(it->full_name); + free(it->name); + free(it->owner); + free(it->date); + free(it->visibility); memset(it, 0, sizeof(*it)); } diff --git a/templates/github/forks.t b/templates/github/forks.t index acf96c0e..ef5fdf95 100644 --- a/templates/github/forks.t +++ b/templates/github/forks.t @@ -2,10 +2,10 @@ include "gcli/forks.h"; parser github_fork is object of gcli_fork with - ("full_name" => full_name as sv, - "owner" => owner as user_sv, - "created_at" => date as sv, + ("full_name" => full_name as string, + "owner" => owner as user, + "created_at" => date as string, "forks_count" => forks as int); parser github_forks is array of gcli_fork - use parse_github_fork; \ No newline at end of file + use parse_github_fork; diff --git a/templates/github/gists.t b/templates/github/gists.t index be625efe..970563db 100644 --- a/templates/github/gists.t +++ b/templates/github/gists.t @@ -3,21 +3,21 @@ include "gcli/github/gists.h"; parser github_gist_file is object of gcli_gist_file with - ("filename" => filename as sv, - "language" => language as sv, - "raw_url" => url as sv, + ("filename" => filename as string, + "language" => language as string, + "raw_url" => url as string, "size" => size as size_t, - "type" => type as sv); + "type" => type as string); parser github_gist is object of gcli_gist with - ("owner" => owner as user_sv, - "html_url" => url as sv, - "id" => id as sv, - "created_at" => date as sv, - "git_pull_url" => git_pull_url as sv, - "description" => description as sv, + ("owner" => owner as user, + "html_url" => url as string, + "id" => id as string, + "created_at" => date as string, + "git_pull_url" => git_pull_url as string, + "description" => description as string, "files" => use parse_github_gist_files_idiot_hack); parser github_gists is array of gcli_gist - use parse_github_gist; \ No newline at end of file + use parse_github_gist; diff --git a/templates/github/releases.t b/templates/github/releases.t index d2748590..0565a9f4 100644 --- a/templates/github/releases.t +++ b/templates/github/releases.t @@ -7,16 +7,16 @@ object of gcli_release_asset with parser github_release is object of gcli_release with - ("name" => name as sv, - "body" => body as sv, - "id" => id as int_to_sv, - "author" => author as user_sv, - "created_at" => date as sv, + ("name" => name as string, + "body" => body as string, + "id" => id as int_to_string, + "author" => author as user, + "created_at" => date as string, "draft" => draft as bool, "prerelease" => prerelease as bool, "assets" => assets as array of gcli_release_asset use parse_github_release_asset, - "upload_url" => upload_url as sv); + "upload_url" => upload_url as string); parser github_releases is array of gcli_release use parse_github_release; diff --git a/templates/github/repos.t b/templates/github/repos.t index cd08aba4..90a77c04 100644 --- a/templates/github/repos.t +++ b/templates/github/repos.t @@ -4,11 +4,11 @@ include "gcli/gitea/repos.h"; parser github_repo is object of gcli_repo with ("id" => id as id, - "full_name" => full_name as sv, - "name" => name as sv, - "owner" => owner as user_sv, - "created_at" => date as sv, - "visibility" => visibility as sv, + "full_name" => full_name as string, + "name" => name as string, + "owner" => owner as user, + "created_at" => date as string, + "visibility" => visibility as string, "private" => visibility as gitea_visibility, "fork" => is_fork as bool); diff --git a/templates/gitlab/forks.t b/templates/gitlab/forks.t index 7e673546..d4c1cff3 100644 --- a/templates/gitlab/forks.t +++ b/templates/gitlab/forks.t @@ -2,13 +2,13 @@ include "gcli/gitlab/forks.h"; parser gitlab_fork_namespace is object of gcli_fork with - ("full_path" => owner as sv); + ("full_path" => owner as string); parser gitlab_fork is object of gcli_fork with - ("path_with_namespace" => full_name as sv, + ("path_with_namespace" => full_name as string, "namespace" => use parse_gitlab_fork_namespace, - "created_at" => date as sv, + "created_at" => date as string, "forks_count" => forks as int); parser gitlab_forks is diff --git a/templates/gitlab/releases.t b/templates/gitlab/releases.t index 1c4b83d9..f533ec42 100644 --- a/templates/gitlab/releases.t +++ b/templates/gitlab/releases.t @@ -11,13 +11,13 @@ object of gcli_release with parser gitlab_release is object of gcli_release with - ("name" => name as sv, - "tag_name" => id as sv, - "description" => body as sv, + ("name" => name as string, + "tag_name" => id as string, + "description" => body as string, "assets" => use parse_gitlab_release_assets, - "author" => author as user_sv, - "created_at" => date as sv, + "author" => author as user, + "created_at" => date as string, "upcoming_release" => prerelease as bool); parser gitlab_releases is -array of gcli_release use parse_gitlab_release; \ No newline at end of file +array of gcli_release use parse_gitlab_release; diff --git a/templates/gitlab/repos.t b/templates/gitlab/repos.t index 5c2c9913..8ee7b75e 100644 --- a/templates/gitlab/repos.t +++ b/templates/gitlab/repos.t @@ -2,11 +2,11 @@ include "gcli/gitlab/repos.h"; parser gitlab_repo is object of gcli_repo with - ("path_with_namespace" => full_name as sv, - "name" => name as sv, - "owner" => owner as user_sv, - "created_at" => date as sv, - "visibility" => visibility as sv, + ("path_with_namespace" => full_name as string, + "name" => name as string, + "owner" => owner as user, + "created_at" => date as string, + "visibility" => visibility as string, "fork" => is_fork as bool, "id" => id as id); diff --git a/tests/github-parse-tests.c b/tests/github-parse-tests.c index 2db73c0d..77ee184d 100644 --- a/tests/github-parse-tests.c +++ b/tests/github-parse-tests.c @@ -217,14 +217,14 @@ ATF_TC_BODY(simple_github_release, tc) ATF_REQUIRE(parse_github_release(ctx, &stream, &release) == 0); - ATF_CHECK_SV_EQTO(release.id, "116031718"); + ATF_CHECK_STREQ(release.id, "116031718"); ATF_CHECK(release.assets_size == 0); ATF_CHECK(release.assets == NULL); - ATF_CHECK_SV_EQTO(release.name, "1.2.0"); - ATF_CHECK_SV_EQTO(release.body, "# Version 1.2.0\n\nThis is version 1.2.0 of gcli.\n\n## Notes\n\nPlease test and report bugs.\n\nYou can download autotoolized tarballs at: https://herrhotzenplotz.de/gcli/releases/gcli-1.2.0/\n\n## Bug Fixes\n\n- Fix compile error when providing --with-libcurl without any arguments\n- Fix memory leaks in string processing functions\n- Fix missing nul termination in read-file function\n- Fix segmentation fault when clearing the milestone of a PR on Gitea\n- Fix missing documentation for milestone action in issues and pulls\n- Set the 'merged' flag properly when showing Gitlab merge requests\n\n## New features\n\n- Add a config subcommand for managing ssh keys (see gcli-config(1))\n- Show number of comments/notes in list of issues and PRs\n- Add support for milestone management in pull requests\n"); - ATF_CHECK_SV_EQTO(release.author, "herrhotzenplotz"); - ATF_CHECK_SV_EQTO(release.date, "2023-08-11T07:42:37Z"); - ATF_CHECK_SV_EQTO(release.upload_url, "https://uploads.github.com/repos/herrhotzenplotz/gcli/releases/116031718/assets{?name,label}"); + ATF_CHECK_STREQ(release.name, "1.2.0"); + ATF_CHECK_STREQ(release.body, "# Version 1.2.0\n\nThis is version 1.2.0 of gcli.\n\n## Notes\n\nPlease test and report bugs.\n\nYou can download autotoolized tarballs at: https://herrhotzenplotz.de/gcli/releases/gcli-1.2.0/\n\n## Bug Fixes\n\n- Fix compile error when providing --with-libcurl without any arguments\n- Fix memory leaks in string processing functions\n- Fix missing nul termination in read-file function\n- Fix segmentation fault when clearing the milestone of a PR on Gitea\n- Fix missing documentation for milestone action in issues and pulls\n- Set the 'merged' flag properly when showing Gitlab merge requests\n\n## New features\n\n- Add a config subcommand for managing ssh keys (see gcli-config(1))\n- Show number of comments/notes in list of issues and PRs\n- Add support for milestone management in pull requests\n"); + ATF_CHECK_STREQ(release.author, "herrhotzenplotz"); + ATF_CHECK_STREQ(release.date, "2023-08-11T07:42:37Z"); + ATF_CHECK_STREQ(release.upload_url, "https://uploads.github.com/repos/herrhotzenplotz/gcli/releases/116031718/assets{?name,label}"); ATF_CHECK(release.draft == false); ATF_CHECK(release.prerelease == false); @@ -247,11 +247,11 @@ ATF_TC_BODY(simple_github_repo, tc) ATF_REQUIRE(parse_github_repo(ctx, &stream, &repo) == 0); ATF_CHECK(repo.id == 415015197); - ATF_CHECK_SV_EQTO(repo.full_name, "herrhotzenplotz/gcli"); - ATF_CHECK_SV_EQTO(repo.name, "gcli"); - ATF_CHECK_SV_EQTO(repo.owner, "herrhotzenplotz"); - ATF_CHECK_SV_EQTO(repo.date, "2021-10-08T14:20:15Z"); - ATF_CHECK_SV_EQTO(repo.visibility, "public"); + ATF_CHECK_STREQ(repo.full_name, "herrhotzenplotz/gcli"); + ATF_CHECK_STREQ(repo.name, "gcli"); + ATF_CHECK_STREQ(repo.owner, "herrhotzenplotz"); + ATF_CHECK_STREQ(repo.date, "2021-10-08T14:20:15Z"); + ATF_CHECK_STREQ(repo.visibility, "public"); ATF_CHECK(repo.is_fork == false); json_close(&stream); @@ -272,9 +272,9 @@ ATF_TC_BODY(simple_github_fork, tc) ATF_REQUIRE(parse_github_fork(ctx, &stream, &fork) == 0); - ATF_CHECK_SV_EQTO(fork.full_name, "gjnoonan/quick-lint-js"); - ATF_CHECK_SV_EQTO(fork.owner, "gjnoonan"); - ATF_CHECK_SV_EQTO(fork.date, "2023-05-11T05:37:41Z"); + ATF_CHECK_STREQ(fork.full_name, "gjnoonan/quick-lint-js"); + ATF_CHECK_STREQ(fork.owner, "gjnoonan"); + ATF_CHECK_STREQ(fork.date, "2023-05-11T05:37:41Z"); ATF_CHECK(fork.forks == 0); json_close(&stream); diff --git a/tests/gitlab-parse-tests.c b/tests/gitlab-parse-tests.c index 06bfa91b..6e7d3bfa 100644 --- a/tests/gitlab-parse-tests.c +++ b/tests/gitlab-parse-tests.c @@ -152,7 +152,7 @@ ATF_TC_BODY(gitlab_simple_release, tc) gitlab_fixup_release_assets(ctx, &release); /* NOTE(Nico): on gitlab this is the tag name */ - ATF_CHECK_SV_EQTO(release.id, "1.2.0"); + ATF_CHECK_STREQ(release.id, "1.2.0"); ATF_CHECK(release.assets_size == 4); { ATF_CHECK_STREQ(release.assets[0].name, "gcli-1.2.0.zip"); @@ -175,11 +175,11 @@ ATF_TC_BODY(gitlab_simple_release, tc) "https://gitlab.com/herrhotzenplotz/gcli/-/archive/1.2.0/gcli-1.2.0.tar"); } - ATF_CHECK_SV_EQTO(release.name, "1.2.0"); - ATF_CHECK_SV_EQTO(release.body, "# Version 1.2.0\n\nThis is version 1.2.0 of gcli.\n\n## Notes\n\nPlease test and report bugs.\n\nYou can download autotoolized tarballs at: https://herrhotzenplotz.de/gcli/releases/gcli-1.2.0/\n\n## Bug Fixes\n\n- Fix compile error when providing --with-libcurl without any arguments\n- Fix memory leaks in string processing functions\n- Fix missing nul termination in read-file function\n- Fix segmentation fault when clearing the milestone of a PR on Gitea\n- Fix missing documentation for milestone action in issues and pulls\n- Set the 'merged' flag properly when showing Gitlab merge requests\n\n## New features\n\n- Add a config subcommand for managing ssh keys (see gcli-config(1))\n- Show number of comments/notes in list of issues and PRs\n- Add support for milestone management in pull requests\n"); - ATF_CHECK_SV_EQTO(release.author, "herrhotzenplotz"); - ATF_CHECK_SV_EQTO(release.date, "2023-08-11T07:56:06.371Z"); - ATF_CHECK(sn_sv_null(release.upload_url)); + ATF_CHECK_STREQ(release.name, "1.2.0"); + ATF_CHECK_STREQ(release.body, "# Version 1.2.0\n\nThis is version 1.2.0 of gcli.\n\n## Notes\n\nPlease test and report bugs.\n\nYou can download autotoolized tarballs at: https://herrhotzenplotz.de/gcli/releases/gcli-1.2.0/\n\n## Bug Fixes\n\n- Fix compile error when providing --with-libcurl without any arguments\n- Fix memory leaks in string processing functions\n- Fix missing nul termination in read-file function\n- Fix segmentation fault when clearing the milestone of a PR on Gitea\n- Fix missing documentation for milestone action in issues and pulls\n- Set the 'merged' flag properly when showing Gitlab merge requests\n\n## New features\n\n- Add a config subcommand for managing ssh keys (see gcli-config(1))\n- Show number of comments/notes in list of issues and PRs\n- Add support for milestone management in pull requests\n"); + ATF_CHECK_STREQ(release.author, "herrhotzenplotz"); + ATF_CHECK_STREQ(release.date, "2023-08-11T07:56:06.371Z"); + ATF_CHECK(release.upload_url == NULL); ATF_CHECK(release.draft == false); ATF_CHECK(release.prerelease == false); @@ -199,9 +199,9 @@ ATF_TC_BODY(gitlab_simple_fork, tc) json_open_stream(&stream, f); ATF_REQUIRE(parse_gitlab_fork(ctx, &stream, &fork) == 0); - ATF_CHECK_SV_EQTO(fork.full_name, "gjnoonan/gcli"); - ATF_CHECK_SV_EQTO(fork.owner, "gjnoonan"); - ATF_CHECK_SV_EQTO(fork.date, "2022-10-02T13:54:20.517Z"); + ATF_CHECK_STREQ(fork.full_name, "gjnoonan/gcli"); + ATF_CHECK_STREQ(fork.owner, "gjnoonan"); + ATF_CHECK_STREQ(fork.date, "2022-10-02T13:54:20.517Z"); ATF_CHECK(fork.forks == 0); json_close(&stream); @@ -274,11 +274,11 @@ ATF_TC_BODY(gitlab_simple_repo, tc) ATF_REQUIRE(parse_gitlab_repo(ctx, &stream, &repo) == 0); ATF_CHECK(repo.id == 34707535); - ATF_CHECK_SV_EQTO(repo.full_name, "herrhotzenplotz/gcli"); - ATF_CHECK_SV_EQTO(repo.name, "gcli"); - ATF_CHECK_SV_EQTO(repo.owner, "herrhotzenplotz"); - ATF_CHECK_SV_EQTO(repo.date, "2022-03-22T16:57:59.891Z"); - ATF_CHECK_SV_EQTO(repo.visibility, "public"); + ATF_CHECK_STREQ(repo.full_name, "herrhotzenplotz/gcli"); + ATF_CHECK_STREQ(repo.name, "gcli"); + ATF_CHECK_STREQ(repo.owner, "herrhotzenplotz"); + ATF_CHECK_STREQ(repo.date, "2022-03-22T16:57:59.891Z"); + ATF_CHECK_STREQ(repo.visibility, "public"); ATF_CHECK(repo.is_fork == false); json_close(&stream); From 0b0bb3740196d29f53525afc2ecd35ee7ca3b162 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Sat, 30 Dec 2023 17:59:31 +0100 Subject: [PATCH 033/158] Fix diff header generation Previously the patch generator was producing incorrect diff headers in cases of new or deleted files. Fix the header generator to produce the correct output. --- Changelog.md | 5 +++++ src/gitlab/merge_requests.c | 44 ++++++++++++++++++++++++------------- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/Changelog.md b/Changelog.md index 69bd5ee9..3a07b792 100644 --- a/Changelog.md +++ b/Changelog.md @@ -20,6 +20,11 @@ This changelog does not follow semantic versioning. to manually urlencode slashes as %2F in the repos. Reported by: Simon Richter +- Fixed the patch generator for Gitlab Merge Requests to produce + patches that can be applied with `git am`. + Previously the patches were invalid when new files were created + or deleted. + ### Changed ### Removed diff --git a/src/gitlab/merge_requests.c b/src/gitlab/merge_requests.c index 9c70d91f..4221fba6 100644 --- a/src/gitlab/merge_requests.c +++ b/src/gitlab/merge_requests.c @@ -148,6 +148,29 @@ gitlab_free_diffs(gitlab_diff_list *list) list->diffs_size = 0; } +static void +gitlab_make_commit_diff(gcli_commit const *const commit, + gitlab_diff const *const diff, + char const *const prev_commit_sha, FILE *const out) +{ + fprintf(out, "diff --git a/%s b/%s\n", diff->old_path, diff->new_path); + if (diff->new_file) { + fprintf(out, "new file mode %s\n", diff->b_mode); + fprintf(out, "index 0000000..%s\n", commit->sha); + } else { + fprintf(out, "index %s..%s %s\n", prev_commit_sha, commit->sha, + diff->b_mode); + } + + fprintf(out, "--- %s%s\n", + diff->new_file ? "" : "a/", + diff->new_file ? "/dev/null" : diff->old_path); + fprintf(out, "+++ %s%s\n", + diff->deleted_file ? "" : "b/", + diff->deleted_file ? "/dev/null" : diff->new_path); + fputs(diff->diff, out); +} + static int gitlab_make_commit_patch(gcli_ctx *ctx, FILE *stream, char const *const e_owner, char const *const e_repo, @@ -179,20 +202,11 @@ gitlab_make_commit_patch(gcli_ctx *ctx, FILE *stream, fprintf(stream, "Subject: %s\n\n", commit->message); for (size_t i = 0; i < list.diffs_size; ++i) { - gitlab_diff const *d = &list.diffs[i]; - fprintf(stream, - "diff --git a/%s b/%s\n" - "index %s..%s %s\n" - "--- a/%s\n" - "+++ b/%s\n" - "%s", - d->old_path, d->new_path, - prev_commit_sha, commit->sha, d->b_mode, - d->old_path, d->new_path, - d->diff); + gitlab_make_commit_diff(commit, &list.diffs[i], + prev_commit_sha, stream); } - fprintf(stream, "--\n2.42.2\n\n"); + fprintf(stream, "--\n2.42.2\n\n\n"); gitlab_free_diffs(&list); @@ -225,14 +239,14 @@ gitlab_mr_get_patch(gcli_ctx *ctx, FILE *stream, char const *owner, base_sha_short = sn_strndup(pull.base_sha, 8); prev_commit_sha = base_sha_short; - for (size_t i = 0; i < commits.commits_size; ++i) { + for (size_t i = commits.commits_size; i > 0; --i) { rc = gitlab_make_commit_patch(ctx, stream, e_owner, e_repo, prev_commit_sha, - &commits.commits[i]); + &commits.commits[i - 1]); if (rc < 0) goto err_make_commit_patch; - prev_commit_sha = commits.commits[i].sha; + prev_commit_sha = commits.commits[i - 1].sha; } err_make_commit_patch: From 6bfa90eab306987de8b8b7cd5cd862430261ea90 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Wed, 27 Dec 2023 18:46:09 +0100 Subject: [PATCH 034/158] Add a sn_strempty function This is a version of strlen(x) == 0 except it doesn't segfault when x is NULL. --- thirdparty/sn/sn.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/thirdparty/sn/sn.h b/thirdparty/sn/sn.h index fe823409..1b501c5c 100644 --- a/thirdparty/sn/sn.h +++ b/thirdparty/sn/sn.h @@ -147,6 +147,15 @@ sn_sv_null(sn_sv it) return it.data == NULL && it.length == 0; } +static inline bool +sn_strempty(char const *const str) +{ + if (str == NULL) + return true; + + return *str == '\0'; +} + /* interactive user functions */ bool sn_yesno(const char *fmt, ...) PRINTF_FORMAT(1, 2); From b4777a29d484256ef85c3f4f95457c4094500287 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Wed, 27 Dec 2023 18:55:15 +0100 Subject: [PATCH 035/158] github issues: generalise issue state patching code This removes the duplicate implementation and now also has a reason for using sn_asprintf. Previously we used sn_asprintf where we could have just used a plain rodata-allocated string. --- src/github/issues.c | 59 +++++++++++++++------------------------------ 1 file changed, 19 insertions(+), 40 deletions(-) diff --git a/src/github/issues.c b/src/github/issues.c index 2fa2b8d3..ae8ba2b9 100644 --- a/src/github/issues.c +++ b/src/github/issues.c @@ -214,29 +214,24 @@ github_get_issue_summary(gcli_ctx *ctx, char const *owner, char const *repo, return rc; } -int -github_issue_close(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const issue_number) +static int +github_issue_patch_state(gcli_ctx *ctx, char const *const owner, + char const *const repo, gcli_id const issue, + char const *const state) { - char *url = NULL; - char *data = NULL; - char *e_owner = NULL; - char *e_repo = NULL; + char *url = NULL, *payload = NULL, *e_owner = NULL, *e_repo = NULL; int rc = 0; e_owner = gcli_urlencode(owner); e_repo = gcli_urlencode(repo); - url = sn_asprintf( - "%s/repos/%s/%s/issues/%"PRIid, - gcli_get_apibase(ctx), - e_owner, e_repo, - issue_number); - data = sn_asprintf("{ \"state\": \"close\"}"); + url = sn_asprintf("%s/repos/%s/%s/issues/%"PRIid, gcli_get_apibase(ctx), + e_owner, e_repo, issue); + payload = sn_asprintf("{ \"state\": \"%s\"}", state); - rc = gcli_fetch_with_method(ctx, "PATCH", url, data, NULL, NULL); + rc = gcli_fetch_with_method(ctx, "PATCH", url, payload, NULL, NULL); - free(data); + free(payload); free(url); free(e_owner); free(e_repo); @@ -245,33 +240,17 @@ github_issue_close(gcli_ctx *ctx, char const *owner, char const *repo, } int -github_issue_reopen(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const issue_number) +github_issue_close(gcli_ctx *ctx, char const *owner, char const *repo, + gcli_id const issue) { - char *url = NULL; - char *data = NULL; - char *e_owner = NULL; - char *e_repo = NULL; - int rc = 0; - - e_owner = gcli_urlencode(owner); - e_repo = gcli_urlencode(repo); - - url = sn_asprintf( - "%s/repos/%s/%s/issues/%"PRIid, - gcli_get_apibase(ctx), - e_owner, e_repo, - issue_number); - data = sn_asprintf("{ \"state\": \"open\"}"); - - rc = gcli_fetch_with_method(ctx, "PATCH", url, data, NULL, NULL); - - free(data); - free(url); - free(e_owner); - free(e_repo); + return github_issue_patch_state(ctx, owner, repo, issue, "closed"); +} - return rc; +int +github_issue_reopen(gcli_ctx *ctx, char const *owner, char const *repo, + gcli_id const issue) +{ + return github_issue_patch_state(ctx, owner, repo, issue, "open"); } int From 5b627592d890bad8f2bf64d6a234ee4107091c41 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Wed, 27 Dec 2023 18:55:44 +0100 Subject: [PATCH 036/158] github issues: remove redundant allocation of JSON payload --- src/github/issues.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/github/issues.c b/src/github/issues.c index ae8ba2b9..3d3cbb8f 100644 --- a/src/github/issues.c +++ b/src/github/issues.c @@ -412,7 +412,8 @@ int github_issue_clear_milestone(gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const issue) { - char *url, *e_owner, *e_repo, *body; + char *url, *e_owner, *e_repo; + char const *payload; int rc; e_owner = gcli_urlencode(owner); @@ -422,11 +423,10 @@ github_issue_clear_milestone(gcli_ctx *ctx, char const *const owner, gcli_get_apibase(ctx), e_owner, e_repo, issue); - body = sn_asprintf("{ \"milestone\": null }"); + payload = "{ \"milestone\": null }"; - rc = gcli_fetch_with_method(ctx, "PATCH", url, body, NULL, NULL); + rc = gcli_fetch_with_method(ctx, "PATCH", url, payload, NULL, NULL); - free(body); free(url); free(e_repo); free(e_owner); From 5e2baff43d673a6105b555ffd5093da45e8b537c Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Wed, 27 Dec 2023 19:06:45 +0100 Subject: [PATCH 037/158] github_issue_assign: Use gcli_jsongen instead of fiddly escaping We used to manually escape all the strings - requiring us to manually free the escaped versions. The gcli_jsongen set of routines takes care of this for us. --- src/github/issues.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/github/issues.c b/src/github/issues.c index 3d3cbb8f..f0a14b49 100644 --- a/src/github/issues.c +++ b/src/github/issues.c @@ -298,31 +298,38 @@ int github_issue_assign(gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const issue_number, char const *assignee) { - sn_sv escaped_assignee = SV_NULL; - char *post_fields = NULL; - char *url = NULL; - char *e_owner = NULL; - char *e_repo = NULL; + gcli_jsongen gen = {0}; + char *url = NULL, *payload = NULL, *e_owner = NULL, *e_repo = NULL; int rc = 0; - escaped_assignee = gcli_json_escape(SV((char *)assignee)); - post_fields = sn_asprintf("{ \"assignees\": [\""SV_FMT"\"] }", - SV_ARGS(escaped_assignee)); + /* Generate Payload */ + gcli_jsongen_init(&gen); + gcli_jsongen_begin_object(&gen); + { + gcli_jsongen_objmember(&gen, "assignees"); + gcli_jsongen_begin_array(&gen); + gcli_jsongen_string(&gen, assignee); + gcli_jsongen_end_object(&gen); + } + gcli_jsongen_end_object(&gen); + + payload = gcli_jsongen_to_string(&gen); + gcli_jsongen_free(&gen); + /* Generate URL */ e_owner = gcli_urlencode(owner); e_repo = gcli_urlencode(repo); - url = sn_asprintf( - "%s/repos/%s/%s/issues/%"PRIid"/assignees", - gcli_get_apibase(ctx), e_owner, e_repo, issue_number); - - rc = gcli_fetch_with_method(ctx, "POST", url, post_fields, NULL, NULL); + url = sn_asprintf("%s/repos/%s/%s/issues/%"PRIid"/assignees", + gcli_get_apibase(ctx), e_owner, e_repo, issue_number); - free(escaped_assignee.data); - free(post_fields); free(e_owner); free(e_repo); + + rc = gcli_fetch_with_method(ctx, "POST", url, payload, NULL, NULL); + free(url); + free(payload); return rc; } From cf8344400f751b3963be93c64f68932483436c75 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Thu, 28 Dec 2023 11:56:18 +0100 Subject: [PATCH 038/158] gitlab issues: Update issue state patch code to use gcli_jsongen This both generalises the state patching code and also uses the less error-prone gcli_jsongen routines that don't need special handling of json escaping. --- src/gitlab/issues.c | 71 ++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/src/gitlab/issues.c b/src/gitlab/issues.c index 5bd4edff..7a22577b 100644 --- a/src/gitlab/issues.c +++ b/src/gitlab/issues.c @@ -142,58 +142,57 @@ gitlab_get_issue_summary(gcli_ctx *ctx, char const *owner, char const *repo, return rc; } -int -gitlab_issue_close(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const issue_number) +static int +gitlab_issue_patch_state(gcli_ctx *const ctx, char const *const owner, + char const *const repo, gcli_id const issue, + char const *const new_state) { - char *url = NULL; - char *data = NULL; - char *e_owner = NULL; - char *e_repo = NULL; + char *url = NULL, *payload = NULL, *e_owner = NULL, *e_repo = NULL; + gcli_jsongen gen = {0}; int rc = 0; + /* Generate payload */ + gcli_jsongen_init(&gen); + gcli_jsongen_begin_object(&gen); + { + gcli_jsongen_objmember(&gen, "state_event"); + gcli_jsongen_string(&gen, new_state); + } + gcli_jsongen_end_object(&gen); + + payload = gcli_jsongen_to_string(&gen); + gcli_jsongen_free(&gen); + + /* Generate URL */ e_owner = gcli_urlencode(owner); e_repo = gcli_urlencode(repo); - url = sn_asprintf("%s/projects/%s%%2F%s/issues/%"PRIid, gcli_get_apibase(ctx), - e_owner, e_repo, issue_number); - data = sn_asprintf("{ \"state_event\": \"close\"}"); + url = sn_asprintf("%s/projects/%s%%2F%s/issues/%"PRIid, + gcli_get_apibase(ctx), e_owner, e_repo, issue); - rc = gcli_fetch_with_method(ctx, "PUT", url, data, NULL, NULL); - - free(data); - free(url); free(e_owner); free(e_repo); + rc = gcli_fetch_with_method(ctx, "PUT", url, payload, NULL, NULL); + + free(payload); + free(url); + return rc; } int -gitlab_issue_reopen(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const issue_number) +gitlab_issue_close(gcli_ctx *ctx, char const *owner, char const *repo, + gcli_id const issue) { - char *url = NULL; - char *data = NULL; - char *e_owner = NULL; - char *e_repo = NULL; - int rc = 0; - - e_owner = gcli_urlencode(owner); - e_repo = gcli_urlencode(repo); - - url = sn_asprintf("%s/projects/%s%%2F%s/issues/%"PRIid, gcli_get_apibase(ctx), - e_owner, e_repo, issue_number); - data = sn_asprintf("{ \"state_event\": \"reopen\"}"); - - rc = gcli_fetch_with_method(ctx, "PUT", url, data, NULL, NULL); - - free(data); - free(url); - free(e_owner); - free(e_repo); + return gitlab_issue_patch_state(ctx, owner, repo, issue, "close"); +} - return rc; +int +gitlab_issue_reopen(gcli_ctx *ctx, char const *owner, char const *repo, + gcli_id const issue) +{ + return gitlab_issue_patch_state(ctx, owner, repo, issue, "reopen"); } int From c77e98710baae99654c3bd001453619d550f22ff Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Thu, 28 Dec 2023 12:13:57 +0100 Subject: [PATCH 039/158] gitlab issues: make assign code use gcli_jsongen --- src/gitlab/issues.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/gitlab/issues.c b/src/gitlab/issues.c index 7a22577b..36d98f42 100644 --- a/src/gitlab/issues.c +++ b/src/gitlab/issues.c @@ -238,29 +238,42 @@ int gitlab_issue_assign(gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const issue_number, char const *assignee) { + char *url = NULL, *payload = NULL, *e_owner = NULL, *e_repo = NULL; + gcli_jsongen gen = {0}; int assignee_uid = -1; - char *url = NULL; - char *post_data = NULL; - char *e_owner = NULL; - char *e_repo = NULL; int rc = 0; assignee_uid = gitlab_user_id(ctx, assignee); if (assignee_uid < 0) return assignee_uid; + /* Generate payload */ + gcli_jsongen_init(&gen); + gcli_jsongen_begin_object(&gen); + { + gcli_jsongen_objmember(&gen, "assignee_ids"); + gcli_jsongen_begin_array(&gen); + gcli_jsongen_number(&gen, assignee_uid); + gcli_jsongen_end_array(&gen); + } + gcli_jsongen_end_object(&gen); + + payload = gcli_jsongen_to_string(&gen); + gcli_jsongen_free(&gen); + + /* Generate URL */ e_owner = gcli_urlencode(owner); e_repo = gcli_urlencode(repo); url = sn_asprintf("%s/projects/%s%%2F%s/issues/%"PRIid, gcli_get_apibase(ctx), e_owner, e_repo, issue_number); - post_data = sn_asprintf("{ \"assignee_ids\": [ %d ] }", assignee_uid); - rc = gcli_fetch_with_method(ctx, "PUT", url, post_data, NULL, NULL); - free(e_owner); free(e_repo); + + rc = gcli_fetch_with_method(ctx, "PUT", url, payload, NULL, NULL); + free(url); - free(post_data); + free(payload); return rc; } From 5ca9e39323ea83d17529adc6332b3e162d88f8b3 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Thu, 28 Dec 2023 12:40:00 +0100 Subject: [PATCH 040/158] gitlab issues: update label update code to use gcli_jsongen instead of manual escaping --- src/gitlab/issues.c | 76 +++++++++++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 31 deletions(-) diff --git a/src/gitlab/issues.c b/src/gitlab/issues.c index 36d98f42..d2ef1dcb 100644 --- a/src/gitlab/issues.c +++ b/src/gitlab/issues.c @@ -278,54 +278,68 @@ gitlab_issue_assign(gcli_ctx *ctx, char const *owner, char const *repo, return rc; } -int -gitlab_issue_add_labels(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const issue, char const *const labels[], - size_t const labels_size) +static int +gitlab_issues_update_labels(gcli_ctx *const ctx, char const *const owner, + char const *const repo, gcli_id const issue, + char const *const labels[], size_t const labels_size, + char const *const what) { - char *url = NULL; - char *data = NULL; - char *list = NULL; + char *url = NULL, *payload = NULL, *label_list = NULL, *e_owner = NULL, + *e_repo = NULL; + gcli_jsongen gen = {0}; int rc = 0; + /* Generate payload. For some reason Gitlab expects us to put a + * comma-separated list of issues into a JSON string. Figures...*/ + label_list = sn_join_with(labels, labels_size, ","); + + gcli_jsongen_init(&gen); + gcli_jsongen_begin_object(&gen); + { + gcli_jsongen_objmember(&gen, what); + gcli_jsongen_string(&gen, label_list); + } + gcli_jsongen_end_object(&gen); + + free(label_list); + + payload = gcli_jsongen_to_string(&gen); + gcli_jsongen_free(&gen); + + /* Generate URL */ + e_owner = gcli_urlencode(owner); + e_repo = gcli_urlencode(repo); + url = sn_asprintf("%s/projects/%s%%2F%s/issues/%"PRIid, gcli_get_apibase(ctx), - owner, repo, issue); + e_owner, e_repo, issue); - list = sn_join_with(labels, labels_size, ","); - data = sn_asprintf("{ \"add_labels\": \"%s\"}", list); + free(e_owner); + free(e_repo); - rc = gcli_fetch_with_method(ctx, "PUT", url, data, NULL, NULL); + rc = gcli_fetch_with_method(ctx, "PUT", url, payload, NULL, NULL); free(url); - free(data); - free(list); + free(payload); return rc; } +int +gitlab_issue_add_labels(gcli_ctx *ctx, char const *owner, char const *repo, + gcli_id const issue, char const *const labels[], + size_t const labels_size) +{ + return gitlab_issues_update_labels(ctx, owner, repo, issue, labels, + labels_size, "add_labels"); +} + int gitlab_issue_remove_labels(gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const issue, char const *const labels[], size_t const labels_size) { - char *url = NULL; - char *data = NULL; - char *list = NULL; - int rc = 0; - - url = sn_asprintf("%s/projects/%s%%2F%s/issues/%"PRIid, gcli_get_apibase(ctx), - owner, repo, issue); - - list = sn_join_with(labels, labels_size, ","); - data = sn_asprintf("{ \"remove_labels\": \"%s\"}", list); - - rc = gcli_fetch_with_method(ctx, "PUT", url, data, NULL, NULL); - - free(url); - free(data); - free(list); - - return rc; + return gitlab_issues_update_labels(ctx, owner, repo, issue, labels, + labels_size, "remove_labels"); } int From 13860f85486bc2ecc40e65cb201c42d6529adc7d Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Thu, 28 Dec 2023 12:42:33 +0100 Subject: [PATCH 041/158] gitlab_issue_clear_milestone: avoid redundant allocation The asprintf only forces us to free the allocated string again. --- src/gitlab/issues.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gitlab/issues.c b/src/gitlab/issues.c index d2ef1dcb..c84fba65 100644 --- a/src/gitlab/issues.c +++ b/src/gitlab/issues.c @@ -368,7 +368,8 @@ int gitlab_issue_clear_milestone(gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const issue) { - char *url, *e_owner, *e_repo, *payload; + char *url, *e_owner, *e_repo; + char const *payload; int rc; /* The Gitlab API says: @@ -387,11 +388,10 @@ gitlab_issue_clear_milestone(gcli_ctx *ctx, char const *const owner, e_repo = gcli_urlencode(repo); url = sn_asprintf("%s/projects/%s%%2F%s/issues/%"PRIid, gcli_get_apibase(ctx), e_owner, e_repo, issue); - payload = sn_asprintf("{ \"milestone_id\": null }"); + payload = "{ \"milestone_id\": null }"; rc = gcli_fetch_with_method(ctx, "PUT", url, payload, NULL, NULL); - free(payload); free(url); free(e_repo); free(e_owner); From e4eab1d3b000db3d5bfcac8816ab044243e1432a Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Thu, 28 Dec 2023 12:57:13 +0100 Subject: [PATCH 042/158] gitea_issue_patch_state: Use gcli_jsongen --- src/gitea/issues.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/gitea/issues.c b/src/gitea/issues.c index 010418df..d9cafd05 100644 --- a/src/gitea/issues.c +++ b/src/gitea/issues.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -64,26 +65,35 @@ static int gitea_issue_patch_state(gcli_ctx *ctx, char const *owner, char const *repo, int const issue_number, char const *const state) { - char *url = NULL; - char *data = NULL; - char *e_owner = NULL; - char *e_repo = NULL; + char *url = NULL, *payload = NULL, *e_owner = NULL, *e_repo = NULL; + gcli_jsongen gen = {0}; int rc = 0; + gcli_jsongen_init(&gen); + gcli_jsongen_begin_object(&gen); + { + gcli_jsongen_objmember(&gen, "state"); + gcli_jsongen_string(&gen, state); + } + gcli_jsongen_end_object(&gen); + + payload = gcli_jsongen_to_string(&gen); + gcli_jsongen_free(&gen); + e_owner = gcli_urlencode(owner); e_repo = gcli_urlencode(repo); url = sn_asprintf("%s/repos/%s/%s/issues/%d", gcli_get_apibase(ctx), e_owner, e_repo, issue_number); - data = sn_asprintf("{ \"state\": \"%s\"}", state); - rc = gcli_fetch_with_method(ctx, "PATCH", url, data, NULL, NULL); - - free(data); - free(url); free(e_owner); free(e_repo); + rc = gcli_fetch_with_method(ctx, "PATCH", url, payload, NULL, NULL); + + free(payload); + free(url); + return rc; } From 5ddf5e9919e7c2ada550e19bc6dccf6b8a924cf2 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Thu, 28 Dec 2023 12:57:26 +0100 Subject: [PATCH 043/158] gitea_issue_assign: Use gcli_jsongen --- src/gitea/issues.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/gitea/issues.c b/src/gitea/issues.c index d9cafd05..8aa3b1a0 100644 --- a/src/gitea/issues.c +++ b/src/gitea/issues.c @@ -115,29 +115,37 @@ int gitea_issue_assign(gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const issue_number, char const *const assignee) { - sn_sv escaped_assignee = SV_NULL; - char *post_fields = NULL; - char *url = NULL; - char *e_owner = NULL; - char *e_repo = NULL; + char *url = NULL, *e_owner = NULL, *e_repo = NULL, *payload = NULL; + gcli_jsongen gen = {0}; int rc = 0; - escaped_assignee = gcli_json_escape(SV((char *)assignee)); - post_fields = sn_asprintf("{ \"assignees\": [\""SV_FMT"\"] }", - SV_ARGS(escaped_assignee)); + /* Generate payload */ + gcli_jsongen_init(&gen); + gcli_jsongen_begin_object(&gen); + { + gcli_jsongen_objmember(&gen, "assignees"); + gcli_jsongen_begin_array(&gen); + gcli_jsongen_string(&gen, assignee); + gcli_jsongen_end_array(&gen); + } + gcli_jsongen_end_object(&gen); + payload = gcli_jsongen_to_string(&gen); + gcli_jsongen_free(&gen); + + /* Generate URL */ e_owner = gcli_urlencode(owner); e_repo = gcli_urlencode(repo); url = sn_asprintf("%s/repos/%s/%s/issues/%"PRIid, gcli_get_apibase(ctx), e_owner, e_repo, issue_number); - rc = gcli_fetch_with_method(ctx, "PATCH", url, post_fields, NULL, NULL); - - free(escaped_assignee.data); - free(post_fields); free(e_owner); free(e_repo); + + rc = gcli_fetch_with_method(ctx, "PATCH", url, payload, NULL, NULL); + + free(payload); free(url); return rc; From 090821ef131da42b739bc4f1aa95a1df8fd08416 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Thu, 28 Dec 2023 13:28:58 +0100 Subject: [PATCH 044/158] gitea_issue_add_labels: Use gcli_jsongen --- src/gitea/issues.c | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/src/gitea/issues.c b/src/gitea/issues.c index 8aa3b1a0..6d479de2 100644 --- a/src/gitea/issues.c +++ b/src/gitea/issues.c @@ -206,9 +206,8 @@ gitea_issue_add_labels(gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const issue, char const *const labels[], size_t const labels_size) { - char *list = NULL; - char *data = NULL; - char *url = NULL; + char *payload = NULL, *url = NULL, *e_owner = NULL, *e_repo = NULL; + gcli_jsongen gen = {0}; int rc = 0; /* First, convert to ids */ @@ -217,20 +216,35 @@ gitea_issue_add_labels(gcli_ctx *ctx, char const *owner, char const *repo, return -1; /* Construct json payload */ + gcli_jsongen_init(&gen); + gcli_jsongen_begin_object(&gen); + { + gcli_jsongen_objmember(&gen, "labels"); + gcli_jsongen_begin_array(&gen); + for (size_t i = 0; i < labels_size; ++i) { + gcli_jsongen_string(&gen, ids[i]); + } + gcli_jsongen_end_array(&gen); + } + gcli_jsongen_end_object(&gen); + + payload = gcli_jsongen_to_string(&gen); + gcli_jsongen_free(&gen); + free_id_list(ids, labels_size); + + e_owner = gcli_urlencode(owner); + e_repo = gcli_urlencode(repo); - /* Note: http://www.c-faq.com/ansi/constmismatch.html */ - list = sn_join_with((char const **)ids, labels_size, ","); - data = sn_asprintf("{ \"labels\": [%s] }", list); + url = sn_asprintf("%s/repos/%s/%s/issues/%"PRIid"/labels", + gcli_get_apibase(ctx), e_owner, e_repo, issue); - url = sn_asprintf("%s/repos/%s/%s/issues/%"PRIid"/labels", gcli_get_apibase(ctx), - owner, repo, issue); + free(e_owner); + free(e_repo); - rc = gcli_fetch_with_method(ctx, "POST", url, data, NULL, NULL); + rc = gcli_fetch_with_method(ctx, "POST", url, payload, NULL, NULL); - free(list); - free(data); + free(payload); free(url); - free_id_list(ids, labels_size); return rc; } From edffe04880e285fd0f1da1f946f0d7c02faca8a4 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Thu, 28 Dec 2023 13:31:42 +0100 Subject: [PATCH 045/158] gitea_issue_remove_labels: Escape owner and repo properly --- src/gitea/issues.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/gitea/issues.c b/src/gitea/issues.c index 6d479de2..2df99bb7 100644 --- a/src/gitea/issues.c +++ b/src/gitea/issues.c @@ -255,6 +255,7 @@ gitea_issue_remove_labels(gcli_ctx *ctx, char const *owner, char const *repo, size_t const labels_size) { int rc = 0; + char *e_owner, *e_repo; /* Unfortunately the gitea api does not give us an endpoint to * delete labels from an issue in bulk. So, just iterate over the * given labels and delete them one after another. */ @@ -262,11 +263,15 @@ gitea_issue_remove_labels(gcli_ctx *ctx, char const *owner, char const *repo, if (!ids) return -1; + e_owner = gcli_urlencode(owner); + e_repo = gcli_urlencode(repo); + for (size_t i = 0; i < labels_size; ++i) { char *url = NULL; url = sn_asprintf("%s/repos/%s/%s/issues/%"PRIid"/labels/%s", - gcli_get_apibase(ctx), owner, repo, issue, ids[i]); + gcli_get_apibase(ctx), e_owner, e_repo, issue, + ids[i]); rc = gcli_fetch_with_method(ctx, "DELETE", url, NULL, NULL, NULL); free(url); @@ -275,6 +280,9 @@ gitea_issue_remove_labels(gcli_ctx *ctx, char const *owner, char const *repo, break; } + free(e_owner); + free(e_repo); + free_id_list(ids, labels_size); return rc; From 6e29d04a979577663948a0c522056466135474a1 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 29 Dec 2023 13:55:22 +0100 Subject: [PATCH 046/158] github_pull_close, github_pull_reopen: Generalise state patching code This now uses the less error-prone gcli_jsongen routines. --- src/github/pulls.c | 75 ++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 40 deletions(-) diff --git a/src/github/pulls.c b/src/github/pulls.c index 63ee722a..b5841db0 100644 --- a/src/github/pulls.c +++ b/src/github/pulls.c @@ -245,62 +245,57 @@ github_pull_merge(gcli_ctx *ctx, char const *owner, char const *repo, return rc; } -int -github_pull_close(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const pr_number) +static int +github_pull_patch_state(gcli_ctx *const ctx, char const *const owner, + char const *const repo, gcli_id const pr, + char const *const new_state) { - char *url = NULL; - char *e_owner = NULL; - char *e_repo = NULL; - char *data = NULL; + char *url = NULL, *e_owner = NULL, *e_repo = NULL, *payload = NULL; + gcli_jsongen gen = {0}; int rc = 0; + /* Generate payload */ + gcli_jsongen_init(&gen); + gcli_jsongen_begin_object(&gen); + { + gcli_jsongen_objmember(&gen, "state"); + gcli_jsongen_string(&gen, new_state); + } + gcli_jsongen_end_object(&gen); + + payload = gcli_jsongen_to_string(&gen); + gcli_jsongen_free(&gen); + + /* Generate URL */ e_owner = gcli_urlencode(owner); e_repo = gcli_urlencode(repo); - url = sn_asprintf( - "%s/repos/%s/%s/pulls/%"PRIid, - gcli_get_apibase(ctx), - e_owner, e_repo, pr_number); - data = sn_asprintf("{ \"state\": \"closed\"}"); - - rc = gcli_fetch_with_method(ctx, "PATCH", url, data, NULL, NULL); + url = sn_asprintf("%s/repos/%s/%s/pulls/%"PRIid, gcli_get_apibase(ctx), + e_owner, e_repo, pr); - free(url); free(e_repo); free(e_owner); - free(data); + + rc = gcli_fetch_with_method(ctx, "PATCH", url, payload, NULL, NULL); + + free(url); + free(payload); return rc; } int -github_pull_reopen(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const pr_number) +github_pull_close(gcli_ctx *ctx, char const *owner, char const *repo, + gcli_id const pr) { - char *url = NULL; - char *data = NULL; - char *e_owner = NULL; - char *e_repo = NULL; - int rc = 0; - - e_owner = gcli_urlencode(owner); - e_repo = gcli_urlencode(repo); - - url = sn_asprintf( - "%s/repos/%s/%s/pulls/%"PRIid, - gcli_get_apibase(ctx), - e_owner, e_repo, pr_number); - data = sn_asprintf("{ \"state\": \"open\"}"); - - rc = gcli_fetch_with_method(ctx, "PATCH", url, data, NULL, NULL); - - free(url); - free(data); - free(e_owner); - free(e_repo); + return github_pull_patch_state(ctx, owner, repo, pr, "closed"); +} - return rc; +int +github_pull_reopen(gcli_ctx *ctx, char const *owner, char const *repo, + gcli_id const pr) +{ + return github_pull_patch_state(ctx, owner, repo, pr, "open"); } int From 8a73a3354f882df2b52fc1d15637d2692bab364d Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 29 Dec 2023 13:59:46 +0100 Subject: [PATCH 047/158] Formatting --- src/github/pulls.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/github/pulls.c b/src/github/pulls.c index b5841db0..19582cf9 100644 --- a/src/github/pulls.c +++ b/src/github/pulls.c @@ -372,7 +372,7 @@ filter_commit_short_sha(gcli_commit **listp, size_t *sizep, void *_data) int github_get_pull_commits(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const pr_number, gcli_commit_list *const out) + gcli_id const pr, gcli_commit_list *const out) { char *url = NULL; char *e_owner = NULL; @@ -389,10 +389,8 @@ github_get_pull_commits(gcli_ctx *ctx, char const *owner, char const *repo, e_owner = gcli_urlencode(owner); e_repo = gcli_urlencode(repo); - url = sn_asprintf( - "%s/repos/%s/%s/pulls/%"PRIid"/commits", - gcli_get_apibase(ctx), - e_owner, e_repo, pr_number); + url = sn_asprintf("%s/repos/%s/%s/pulls/%"PRIid"/commits", + gcli_get_apibase(ctx), e_owner, e_repo, pr); free(e_owner); free(e_repo); @@ -402,21 +400,18 @@ github_get_pull_commits(gcli_ctx *ctx, char const *owner, char const *repo, int github_get_pull(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const pr_number, gcli_pull *const out) + gcli_id const pr, gcli_pull *const out) { int rc = 0; gcli_fetch_buffer json_buffer = {0}; - char *url = NULL; - char *e_owner = NULL; - char *e_repo = NULL; + char *url = NULL, *e_owner = NULL, *e_repo = NULL; e_owner = gcli_urlencode(owner); e_repo = gcli_urlencode(repo); - url = sn_asprintf( - "%s/repos/%s/%s/pulls/%"PRIid, - gcli_get_apibase(ctx), - e_owner, e_repo, pr_number); + url = sn_asprintf("%s/repos/%s/%s/pulls/%"PRIid, gcli_get_apibase(ctx), + e_owner, e_repo, pr); + free(e_owner); free(e_repo); From f971f929df764081d6f63fc9824a58a1b020e083 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 29 Dec 2023 14:14:31 +0100 Subject: [PATCH 048/158] gitlab mr: generalise state patching code This again uses the gcli_jsongen set of routines to generalise the state patching code and also to make it less error-prone compared to if we were using manual escaping and free-ing. --- src/gitlab/merge_requests.c | 71 ++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/src/gitlab/merge_requests.c b/src/gitlab/merge_requests.c index 4221fba6..d3b8cecd 100644 --- a/src/gitlab/merge_requests.c +++ b/src/gitlab/merge_requests.c @@ -370,58 +370,57 @@ gitlab_get_pull_commits(gcli_ctx *ctx, char const *owner, char const *repo, return gcli_fetch_list(ctx, url, &fl); } -int -gitlab_mr_close(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const pr_number) +static int +gitlab_mr_patch_state(gcli_ctx *const ctx, char const *const owner, + char const *const repo, gcli_id const mr, + char const *const new_state) { - char *url = NULL; - char *data = NULL; - char *e_owner = NULL; - char *e_repo = NULL; + char *url = NULL, *payload = NULL, *e_owner = NULL, *e_repo = NULL; + gcli_jsongen gen = {0}; int rc = 0; + /* Generate payload */ + gcli_jsongen_init(&gen); + gcli_jsongen_begin_object(&gen); + { + gcli_jsongen_objmember(&gen, "state_event"); + gcli_jsongen_string(&gen, new_state); + } + gcli_jsongen_end_object(&gen); + + payload = gcli_jsongen_to_string(&gen); + gcli_jsongen_free(&gen); + + /* Generate URL */ e_owner = gcli_urlencode(owner); - e_repo = gcli_urlencode(repo); + e_repo = gcli_urlencode(repo); url = sn_asprintf("%s/projects/%s%%2F%s/merge_requests/%"PRIid, - gcli_get_apibase(ctx), e_owner, e_repo, pr_number); - data = sn_asprintf("{ \"state_event\": \"close\"}"); - - rc = gcli_fetch_with_method(ctx, "PUT", url, data, NULL, NULL); + gcli_get_apibase(ctx), e_owner, e_repo, mr); - free(url); free(e_owner); free(e_repo); - free(data); + + rc = gcli_fetch_with_method(ctx, "PUT", url, payload, NULL, NULL); + + free(url); + free(payload); return rc; } int -gitlab_mr_reopen(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const pr_number) +gitlab_mr_close(gcli_ctx *ctx, char const *owner, char const *repo, + gcli_id const mr) { - char *url = NULL; - char *data = NULL; - char *e_owner = NULL; - char *e_repo = NULL; - int rc = 0; - - e_owner = gcli_urlencode(owner); - e_repo = gcli_urlencode(repo); - - url = sn_asprintf("%s/projects/%s%%2F%s/merge_requests/%"PRIid, - gcli_get_apibase(ctx), e_owner, e_repo, pr_number); - data = sn_asprintf("{ \"state_event\": \"reopen\"}"); - - rc = gcli_fetch_with_method(ctx, "PUT", url, data, NULL, NULL); - - free(e_owner); - free(e_repo); - free(url); - free(data); + return gitlab_mr_patch_state(ctx, owner, repo, mr, "close"); +} - return rc; +int +gitlab_mr_reopen(gcli_ctx *ctx, char const *owner, char const *repo, + gcli_id const mr) +{ + return gitlab_mr_patch_state(ctx, owner, repo, mr, "reopen"); } int From 68bb3d6f903b89e5ee4234a88bf15b249483977f Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 29 Dec 2023 14:43:42 +0100 Subject: [PATCH 049/158] Add a gcli_jsongen_id routine This is a type-clean version for generating ID fields with the jsongen routines. The gcli_jsongen_number routine is not ideal because it accepts a long-long whereas gcli_id is a uint64_t (as of the time of writing). --- include/gcli/json_gen.h | 3 +++ src/json_gen.c | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/gcli/json_gen.h b/include/gcli/json_gen.h index bb1aeb79..55de9a35 100644 --- a/include/gcli/json_gen.h +++ b/include/gcli/json_gen.h @@ -34,6 +34,8 @@ #include #endif +#include + #include #include @@ -66,6 +68,7 @@ int gcli_jsongen_begin_array(gcli_jsongen *gen); int gcli_jsongen_end_array(gcli_jsongen *gen); int gcli_jsongen_objmember(gcli_jsongen *gen, char const *key); int gcli_jsongen_number(gcli_jsongen *gen, long long num); +int gcli_jsongen_id(gcli_jsongen *gen, gcli_id const id); int gcli_jsongen_string(gcli_jsongen *gen, char const *value); int gcli_jsongen_bool(gcli_jsongen *gen, bool value); int gcli_jsongen_null(gcli_jsongen *gen); diff --git a/src/json_gen.c b/src/json_gen.c index c3bf8f94..091d13bd 100644 --- a/src/json_gen.c +++ b/src/json_gen.c @@ -263,6 +263,18 @@ gcli_jsongen_number(gcli_jsongen *gen, long long const number) return 0; } +int +gcli_jsongen_id(gcli_jsongen *gen, gcli_id const id) +{ + put_comma_if_needed(gen); + append_strf(gen, "%"PRIid, id); + + gen->await_object_value = false; + gen->first_elem = false; + + return 0; +} + int gcli_jsongen_bool(gcli_jsongen *gen, bool const value) { From e77692bead8947df191ec3a843766601d1cdc1b3 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 29 Dec 2023 14:47:01 +0100 Subject: [PATCH 050/158] gitlab mr: generalise label update code and use gcli_jsongen instead of manual escaping --- src/gitlab/merge_requests.c | 75 +++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 32 deletions(-) diff --git a/src/gitlab/merge_requests.c b/src/gitlab/merge_requests.c index d3b8cecd..34173a4b 100644 --- a/src/gitlab/merge_requests.c +++ b/src/gitlab/merge_requests.c @@ -503,54 +503,65 @@ gitlab_perform_submit_mr(gcli_ctx *ctx, gcli_submit_pull_options opts) return rc; } -int -gitlab_mr_add_labels(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const mr, char const *const labels[], - size_t const labels_size) +static int +gitlab_mr_update_labels(gcli_ctx *ctx, char const *owner, char const *repo, + gcli_id const mr, char const *const labels[], + size_t const labels_size, + char const *const update_action) { - char *url = NULL; - char *data = NULL; - char *list = NULL; - int rc = 0; + char *url = NULL, *payload = NULL, *list = NULL, *e_owner = NULL, + *e_repo = NULL; + gcli_jsongen gen = {0}; + int rc = 0; + + /* Generate payload */ + list = sn_join_with(labels, labels_size, ","); + gcli_jsongen_init(&gen); + gcli_jsongen_begin_object(&gen); + { + gcli_jsongen_objmember(&gen, update_action); + gcli_jsongen_string(&gen, list); + } + gcli_jsongen_end_object(&gen); + payload = gcli_jsongen_to_string(&gen); + + gcli_jsongen_free(&gen); + free(list); + + /* Generate URL */ + e_owner = gcli_urlencode(owner); + e_repo = gcli_urlencode(repo); url = sn_asprintf("%s/projects/%s%%2F%s/merge_requests/%"PRIid, - gcli_get_apibase(ctx), owner, repo, mr); + gcli_get_apibase(ctx), e_owner, e_repo, mr); - list = sn_join_with(labels, labels_size, ","); - data = sn_asprintf("{ \"add_labels\": \"%s\"}", list); + free(e_owner); + free(e_repo); - rc = gcli_fetch_with_method(ctx, "PUT", url, data, NULL, NULL); + rc = gcli_fetch_with_method(ctx, "PUT", url, payload, NULL, NULL); free(url); - free(data); - free(list); + free(payload); return rc; } +int +gitlab_mr_add_labels(gcli_ctx *ctx, char const *owner, char const *repo, + gcli_id const mr, char const *const labels[], + size_t const labels_size) +{ + return gitlab_mr_update_labels(ctx, owner, repo, mr, labels, labels_size, + "add_labels"); +} + int gitlab_mr_remove_labels(gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const mr, char const *const labels[], size_t const labels_size) { - char *url = NULL; - char *data = NULL; - char *list = NULL; - int rc = 0; - - url = sn_asprintf("%s/projects/%s%%2F%s/merge_requests/%"PRIid, - gcli_get_apibase(ctx), owner, repo, mr); - - list = sn_join_with(labels, labels_size, ","); - data = sn_asprintf("{ \"remove_labels\": \"%s\"}", list); - - rc = gcli_fetch_with_method(ctx, "PUT", url, data, NULL, NULL); - - free(url); - free(data); - free(list); - - return rc; + return gitlab_mr_update_labels(ctx, owner, repo, mr, labels, labels_size, + "remove_labels"); } int From 959bdebb3ce3321f06bad580a7dab6e0664f3c8e Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 29 Dec 2023 14:47:50 +0100 Subject: [PATCH 051/158] gitlab_mr_set_milestone: Add missing urlencodes and use gcli_jsongen --- src/gitlab/merge_requests.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/gitlab/merge_requests.c b/src/gitlab/merge_requests.c index 34173a4b..8e5e325b 100644 --- a/src/gitlab/merge_requests.c +++ b/src/gitlab/merge_requests.c @@ -568,19 +568,36 @@ int gitlab_mr_set_milestone(gcli_ctx *ctx, char const *owner, char const *repo, gcli_id mr, gcli_id milestone_id) { - char *url = NULL; - char *data = NULL; + char *url = NULL, *payload = NULL, *e_owner = NULL, *e_repo = NULL; + gcli_jsongen gen = {0}; int rc = 0; + /* Generate Payload */ + gcli_jsongen_init(&gen); + gcli_jsongen_begin_object(&gen); + { + gcli_jsongen_objmember(&gen, "milestone_id"); + gcli_jsongen_id(&gen, milestone_id); + } + gcli_jsongen_end_object(&gen); + + payload = gcli_jsongen_to_string(&gen); + gcli_jsongen_free(&gen); + + /* Generate URL */ + e_owner = gcli_urlencode(owner); + e_repo = gcli_urlencode(repo); + url = sn_asprintf("%s/projects/%s%%2F%s/merge_requests/%"PRIid, - gcli_get_apibase(ctx), owner, repo, mr); + gcli_get_apibase(ctx), e_owner, e_repo, mr); - data = sn_asprintf("{ \"milestone_id\": \"%"PRIid"\"}", milestone_id); + free(e_owner); + free(e_repo); - rc = gcli_fetch_with_method(ctx, "PUT", url, data, NULL, NULL); + rc = gcli_fetch_with_method(ctx, "PUT", url, payload, NULL, NULL); free(url); - free(data); + free(payload); return rc; } From f4be5189cf6747c3b5a8d39bdf62692284345b99 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 29 Dec 2023 14:57:16 +0100 Subject: [PATCH 052/158] gitea_pull_merge: Use gcli_jsongen and add proper escaping --- src/gitea/pulls.c | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/src/gitea/pulls.c b/src/gitea/pulls.c index c4233d41..155ffd24 100644 --- a/src/gitea/pulls.c +++ b/src/gitea/pulls.c @@ -31,6 +31,8 @@ #include #include +#include + int gitea_get_pulls(gcli_ctx *ctx, char const *owner, char const *repo, gcli_pull_fetch_details const *const details, int const max, @@ -63,30 +65,43 @@ gitea_pull_submit(gcli_ctx *ctx, gcli_submit_pull_options opts) int gitea_pull_merge(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const pr_number, enum gcli_merge_flags const flags) + gcli_id const pr, enum gcli_merge_flags const flags) { - int rc = 0; - char *url = NULL; - char *e_owner = NULL; - char *e_repo = NULL; - char *data = NULL; - bool const squash = flags & GCLI_PULL_MERGE_SQUASH; bool const delete_branch = flags & GCLI_PULL_MERGE_DELETEHEAD; + bool const squash = flags & GCLI_PULL_MERGE_SQUASH; + char *url = NULL, *e_owner = NULL, *e_repo = NULL, *payload = NULL; + gcli_jsongen gen = {0}; + int rc = 0; + + /* Generate payload */ + gcli_jsongen_init(&gen); + gcli_jsongen_begin_object(&gen); + { + gcli_jsongen_objmember(&gen, "Do"); + gcli_jsongen_string(&gen, squash ? "squash" : "merge"); + gcli_jsongen_objmember(&gen, "delete_branch_after_merge"); + gcli_jsongen_bool(&gen, delete_branch); + } + gcli_jsongen_end_object(&gen); + + payload = gcli_jsongen_to_string(&gen); + gcli_jsongen_free(&gen); + + /* Generate URL */ e_owner = gcli_urlencode(owner); e_repo = gcli_urlencode(repo); - url = sn_asprintf("%s/repos/%s/%s/pulls/%"PRIid"/merge", - gcli_get_apibase(ctx), e_owner, e_repo, pr_number); - data = sn_asprintf("{ \"Do\": \"%s\", \"delete_branch_after_merge\": %s }", - squash ? "squash" : "merge", - delete_branch ? "true" : "false"); - rc = gcli_fetch_with_method(ctx, "POST", url, data, NULL, NULL); + url = sn_asprintf("%s/repos/%s/%s/pulls/%"PRIid"/merge", + gcli_get_apibase(ctx), e_owner, e_repo, pr); - free(url); free(e_owner); free(e_repo); - free(data); + + rc = gcli_fetch_with_method(ctx, "POST", url, payload, NULL, NULL); + + free(url); + free(payload); return rc; } From 6ebc437020ea5e4214bb0dd7081e1c17bee1cd3a Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 29 Dec 2023 15:10:55 +0100 Subject: [PATCH 053/158] gitlab_create_label: Use gcli_jsongen routines and handle urlencoding properly --- src/gitlab/labels.c | 58 ++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/src/gitlab/labels.c b/src/gitlab/labels.c index 67421e6e..4f22345f 100644 --- a/src/gitlab/labels.c +++ b/src/gitlab/labels.c @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -59,30 +60,46 @@ int gitlab_create_label(gcli_ctx *ctx, char const *owner, char const *repo, gcli_label *const label) { - char *url = NULL; - char *data = NULL; - char *colour_string = NULL; - sn_sv lname_escaped = SV_NULL; - sn_sv ldesc_escaped = SV_NULL; + char *url = NULL, *payload = NULL, *colour_string = NULL, *e_owner = NULL, + *e_repo = NULL; gcli_fetch_buffer buffer = {0}; - struct json_stream stream = {0}; + gcli_jsongen gen = {0}; int rc = 0; + json_stream stream = {0}; + + /* Generate payload */ + colour_string = sn_asprintf("#%06X", (label->colour>>8)&0xFFFFFF); + + gcli_jsongen_init(&gen); + gcli_jsongen_begin_object(&gen); + { + gcli_jsongen_objmember(&gen, "name"); + gcli_jsongen_string(&gen, label->name); + + gcli_jsongen_objmember(&gen, "color"); + gcli_jsongen_string(&gen, colour_string); + + gcli_jsongen_objmember(&gen, "description"); + gcli_jsongen_string(&gen, label->description); + } + gcli_jsongen_end_object(&gen); + + payload = gcli_jsongen_to_string(&gen); + + gcli_jsongen_free(&gen); + free(colour_string); + + /* Generate URL */ + e_owner = gcli_urlencode(owner); + e_repo = gcli_urlencode(repo); url = sn_asprintf("%s/projects/%s%%2F%s/labels", gcli_get_apibase(ctx), - owner, repo); + e_owner, e_repo); - lname_escaped = gcli_json_escape(SV(label->name)); - ldesc_escaped = gcli_json_escape(SV(label->description)); - colour_string = sn_asprintf("%06X", (label->colour>>8)&0xFFFFFF); - data = sn_asprintf( - "{\"name\": \""SV_FMT"\"," - "\"color\":\"#%s\"," - "\"description\":\""SV_FMT"\"}", - SV_ARGS(lname_escaped), - colour_string, - SV_ARGS(ldesc_escaped)); + free(e_owner); + free(e_repo); - rc = gcli_fetch_with_method(ctx, "POST", url, data, NULL, &buffer); + rc = gcli_fetch_with_method(ctx, "POST", url, payload, NULL, &buffer); if (rc == 0) { json_open_buffer(&stream, buffer.data, buffer.length); @@ -91,10 +108,7 @@ gitlab_create_label(gcli_ctx *ctx, char const *owner, char const *repo, json_close(&stream); } - free(lname_escaped.data); - free(ldesc_escaped.data); - free(colour_string); - free(data); + free(payload); free(url); free(buffer.data); From fa9e77584575602e2df61529dcfd2063adc283ca Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 29 Dec 2023 15:26:10 +0100 Subject: [PATCH 054/158] github_create_label: Use gcli_jsongen instead --- src/github/labels.c | 68 ++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/src/github/labels.c b/src/github/labels.c index 46a344a3..6d6dbe36 100644 --- a/src/github/labels.c +++ b/src/github/labels.c @@ -28,6 +28,7 @@ */ #include +#include #include #include @@ -59,42 +60,47 @@ int github_create_label(gcli_ctx *ctx, char const *owner, char const *repo, gcli_label *const label) { - char *url = NULL; - char *data = NULL; - char *e_owner = NULL; - char *e_repo = NULL; - char *colour = NULL; - sn_sv label_name = SV_NULL; - sn_sv label_descr = SV_NULL; - sn_sv label_colour = SV_NULL; + char *url = NULL, *payload = NULL, *e_owner = NULL, *e_repo = NULL, + *colour = NULL; gcli_fetch_buffer buffer = {0}; - struct json_stream stream = {0}; + gcli_jsongen gen = {0}; int rc = 0; + json_stream stream = {0}; - e_owner = gcli_urlencode(owner); - e_repo = gcli_urlencode(repo); - + /* Generate payload */ colour = sn_asprintf("%06X", label->colour >> 8); - label_name = gcli_json_escape(SV(label->name)); - label_descr = gcli_json_escape(SV(label->description)); - label_colour = gcli_json_escape(SV(colour)); + gcli_jsongen_init(&gen); + gcli_jsongen_begin_object(&gen); + { + gcli_jsongen_objmember(&gen, "name"); + gcli_jsongen_string(&gen, label->name); - /* /repos/{owner}/{repo}/labels */ - url = sn_asprintf("%s/repos/%s/%s/labels", - gcli_get_apibase(ctx), e_owner, e_repo); + gcli_jsongen_objmember(&gen, "description"); + gcli_jsongen_string(&gen, label->description); + gcli_jsongen_objmember(&gen, "color"); + gcli_jsongen_string(&gen, colour); + } + gcli_jsongen_end_object(&gen); - data = sn_asprintf("{ " - " \"name\": \""SV_FMT"\", " - " \"description\": \""SV_FMT"\", " - " \"color\": \""SV_FMT"\"" - "}", - SV_ARGS(label_name), - SV_ARGS(label_descr), - SV_ARGS(label_colour)); + payload = gcli_jsongen_to_string(&gen); - rc = gcli_fetch_with_method(ctx, "POST", url, data, NULL, &buffer); + gcli_jsongen_free(&gen); + free(colour); + + /* Generate URL */ + e_owner = gcli_urlencode(owner); + e_repo = gcli_urlencode(repo); + + /* /repos/{owner}/{repo}/labels */ + url = sn_asprintf("%s/repos/%s/%s/labels", gcli_get_apibase(ctx), e_owner, + e_repo); + + free(e_owner); + free(e_repo); + + rc = gcli_fetch_with_method(ctx, "POST", url, payload, NULL, &buffer); if (rc == 0) { json_open_buffer(&stream, buffer.data, buffer.length); @@ -103,13 +109,7 @@ github_create_label(gcli_ctx *ctx, char const *owner, char const *repo, } free(url); - free(data); - free(e_owner); - free(e_repo); - free(colour); - free(label_name.data); - free(label_descr.data); - free(label_colour.data); + free(payload); free(buffer.data); return rc; From ef4fc5674cac08051c8a8198551ebbcf9f8863a3 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Sun, 31 Dec 2023 13:17:35 +0100 Subject: [PATCH 055/158] Update Changelog for stringview refactor --- Changelog.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Changelog.md b/Changelog.md index 3a07b792..65c78740 100644 --- a/Changelog.md +++ b/Changelog.md @@ -27,6 +27,16 @@ This changelog does not follow semantic versioning. ### Changed +- Internally a lot of code was using string views. Maintaining this + was a bit cumbersome and required frequent reallocations. + A lot of these uses have been refactored to use plain C-Strings + now. This also involved changing some code to use the new + `gcli_jsongen` set of routines. + Due to these changes there may be regressions that are only visible + during use. If you encounter such regressions where previously + working commands suddenly fail due to malformed requests please + report immediately. + ### Removed ## 2.1.0 (2023-Dec-08) From 107e7ca27448dab8ec9c59f74e89dde613c42d96 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 8 Dec 2023 17:26:03 +0100 Subject: [PATCH 056/158] Add definitions for Bugzilla --- Makefile.am | 11 +++- include/gcli/bugzilla/bugs.h | 41 ++++++++++++ include/gcli/gcli.h | 1 + src/bugzilla/bugs.c | 46 ++++++++++++++ src/cmd/cmd.c | 4 ++ src/cmd/cmdconfig.c | 4 ++ src/cmd/colour.c | 30 +++++---- src/cmd/comment.c | 5 ++ src/cmd/gcli.c | 1 + src/ctx.c | 5 +- src/forges.c | 13 ++++ tests/Kyuafile.in | 5 ++ tests/bugzilla-parse-tests.c | 88 ++++++++++++++++++++++++++ tests/samples/bugzilla_simple_bug.json | 53 ++++++++++++++++ 14 files changed, 291 insertions(+), 16 deletions(-) create mode 100644 include/gcli/bugzilla/bugs.h create mode 100644 src/bugzilla/bugs.c create mode 100644 tests/bugzilla-parse-tests.c create mode 100644 tests/samples/bugzilla_simple_bug.json diff --git a/Makefile.am b/Makefile.am index 41b488bc..bcdb5e69 100644 --- a/Makefile.am +++ b/Makefile.am @@ -119,7 +119,8 @@ TEMPLATES = \ templates/gitlab/status.t \ templates/gitlab/snippets.t \ templates/gitea/milestones.t \ - templates/gitea/status.t + templates/gitea/status.t \ + templates/bugzilla/bugs.t headerdir = $(prefix) nobase_header_HEADERS = include/gcli/gcli.h include/gcli/comments.h \ @@ -189,6 +190,7 @@ libgcli_la_SOURCES = \ src/gitea/sshkeys.c include/gcli/gitea/sshkeys.h \ src/gitea/status.c include/gcli/gitea/status.h \ src/gitea/milestones.c include/gcli/gitea/milestones.h \ + src/bugzilla/bugs.c include/gcli/bugzilla/bugs.h \ $(TEMPLATES) libgcli_la_CPPFLAGS = \ @@ -218,6 +220,7 @@ check_PROGRAMS = \ tests/github-parse-tests$(EXEEXT) \ tests/gitlab-parse-tests$(EXEEXT) \ tests/gitea-parse-tests$(EXEEXT) \ + tests/bugzilla-parse-tests$(EXEEXT) \ tests/url-encode$(EXEEXT) \ tests/pretty_print_test$(EXEEXT) \ tests/test-jsongen$(EXEEXT) @@ -254,6 +257,12 @@ tests_gitea_parse_tests_LDADD = \ libgcli.la libpdjson.la libsn.la \ $(LIBATFC_LDFLAGS) +tests_bugzilla_parse_tests_SOURCES = \ + tests/bugzilla-parse-tests.c +tests_bugzilla_parse_tests_LDADD = \ + libgcli.la libpdjson.la libsn.la \ + $(LIBATFC_LDFLAGS) + tests_url_encode_SOURCES = \ tests/url-encode.c tests_url_encode_LDADD = \ diff --git a/include/gcli/bugzilla/bugs.h b/include/gcli/bugzilla/bugs.h new file mode 100644 index 00000000..e8b75f73 --- /dev/null +++ b/include/gcli/bugzilla/bugs.h @@ -0,0 +1,41 @@ +/* + * Copyright 2023 Nico Sonack + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef GCLI_BUGZILLA_BUGS_H +#define GCLI_BUGZILLA_BUGS_H + +#include + +#include + +int bugzilla_get_bugs(gcli_ctx *ctx, char const *product, char const *component, + gcli_issue_fetch_details const *details, int const max, + gcli_issue_list *out); + +#endif /* GCLI_BUGZILLA_BUGS_H */ diff --git a/include/gcli/gcli.h b/include/gcli/gcli.h index 3d682fd4..0a0941c6 100644 --- a/include/gcli/gcli.h +++ b/include/gcli/gcli.h @@ -47,6 +47,7 @@ typedef enum gcli_forge_type { GCLI_FORGE_GITHUB, GCLI_FORGE_GITLAB, GCLI_FORGE_GITEA, + GCLI_FORGE_BUGZILLA, } gcli_forge_type; typedef uint64_t gcli_id; diff --git a/src/bugzilla/bugs.c b/src/bugzilla/bugs.c new file mode 100644 index 00000000..2daec48f --- /dev/null +++ b/src/bugzilla/bugs.c @@ -0,0 +1,46 @@ +/* + * Copyright 2023 Nico Sonack + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +#include + +int +bugzilla_get_bugs(gcli_ctx *ctx, char const *product, char const *component, + gcli_issue_fetch_details const *details, int const max, + gcli_issue_list *out) +{ + (void) product; + (void) component; + (void) details; + (void) max; + (void) out; + + return gcli_error(ctx, "%s: not yet implemented", __func__); +} diff --git a/src/cmd/cmd.c b/src/cmd/cmd.c index 2a3088b4..56e7ed90 100644 --- a/src/cmd/cmd.c +++ b/src/cmd/cmd.c @@ -70,6 +70,10 @@ longversion(void) void check_owner_and_repo(const char **owner, const char **repo) { + /* HACK */ + if (gcli_config_get_forge_type(g_clictx) == GCLI_FORGE_BUGZILLA) + return; + /* If no remote was specified, try to autodetect */ if ((*owner == NULL) != (*repo == NULL)) errx(1, "gcli: error: missing either explicit owner or repo"); diff --git a/src/cmd/cmdconfig.c b/src/cmd/cmdconfig.c index 159c1463..62bedc02 100644 --- a/src/cmd/cmdconfig.c +++ b/src/cmd/cmdconfig.c @@ -562,6 +562,8 @@ gcli_config_parse_args(gcli_ctx *ctx, int *argc, char ***argv) cfg->override_forgetype = GCLI_FORGE_GITLAB; } else if (strcmp(optarg, "gitea") == 0) { cfg->override_forgetype = GCLI_FORGE_GITEA; + } else if (strcmp(optarg, "bugzilla") == 0) { + cfg->override_forgetype = GCLI_FORGE_BUGZILLA; } else { fprintf(stderr, "error: unknown forge type '%s'. " "Have either github, gitlab or gitea.\n", optarg); @@ -852,6 +854,8 @@ gcli_config_get_forge_type_internal(gcli_ctx *ctx) return GCLI_FORGE_GITLAB; else if (sn_sv_eq_to(entry, "gitea")) return GCLI_FORGE_GITEA; + else if (sn_sv_eq_to(entry, "bugzilla")) + return GCLI_FORGE_BUGZILLA; else errx(1, "Unknown forge type "SV_FMT, SV_ARGS(entry)); } diff --git a/src/cmd/colour.c b/src/cmd/colour.c index ca84d628..71f00e93 100644 --- a/src/cmd/colour.c +++ b/src/cmd/colour.c @@ -152,19 +152,23 @@ gcli_state_colour_str(char const *it) static const struct { char const *name; int code; } state_colour_table[] = { - { .name = "open", .code = GCLI_COLOR_GREEN }, - { .name = "active", .code = GCLI_COLOR_GREEN }, - { .name = "success", .code = GCLI_COLOR_GREEN }, - { .name = "APPROVED", .code = GCLI_COLOR_GREEN }, - { .name = "merged", .code = GCLI_COLOR_MAGENTA }, - { .name = "closed", .code = GCLI_COLOR_RED }, - { .name = "failed", .code = GCLI_COLOR_RED }, - { .name = "canceled", .code = GCLI_COLOR_RED }, /* orthography has left the channel */ - { .name = "failure", .code = GCLI_COLOR_RED }, - { .name = "running", .code = GCLI_COLOR_BLUE }, - { .name = "created", .code = GCLI_COLOR_BLUE }, - { .name = "COMMENTED", .code = GCLI_COLOR_BLUE }, - { .name = "pending", .code = GCLI_COLOR_CYAN }, + { .name = "open", .code = GCLI_COLOR_GREEN }, + { .name = "Open", .code = GCLI_COLOR_GREEN }, + { .name = "active", .code = GCLI_COLOR_GREEN }, + { .name = "success", .code = GCLI_COLOR_GREEN }, + { .name = "APPROVED", .code = GCLI_COLOR_GREEN }, + { .name = "merged", .code = GCLI_COLOR_MAGENTA }, + { .name = "closed", .code = GCLI_COLOR_RED }, + { .name = "Closed", .code = GCLI_COLOR_RED }, + { .name = "failed", .code = GCLI_COLOR_RED }, + { .name = "canceled", .code = GCLI_COLOR_RED }, /* orthography has left the channel */ + { .name = "failure", .code = GCLI_COLOR_RED }, + { .name = "running", .code = GCLI_COLOR_BLUE }, + { .name = "created", .code = GCLI_COLOR_BLUE }, + { .name = "New", .code = GCLI_COLOR_BLUE }, + { .name = "COMMENTED", .code = GCLI_COLOR_BLUE }, + { .name = "pending", .code = GCLI_COLOR_CYAN }, + { .name = "In Progress", .code = GCLI_COLOR_CYAN }, }; char const * diff --git a/src/cmd/comment.c b/src/cmd/comment.c index e1ef6331..b4c1e71f 100644 --- a/src/cmd/comment.c +++ b/src/cmd/comment.c @@ -38,6 +38,7 @@ #include #include +#include #ifdef HAVE_GETOPT_H #include #endif @@ -75,6 +76,10 @@ comment_init(gcli_ctx *ctx, FILE *f, void *_data) case GCLI_FORGE_GITLAB: target_type = "Merge Request"; break; + case GCLI_FORGE_BUGZILLA: + /* FIXME think about this one */ + assert(0 && "unreachable"); + break; } } break; } diff --git a/src/cmd/gcli.c b/src/cmd/gcli.c index d774f90a..56408291 100644 --- a/src/cmd/gcli.c +++ b/src/cmd/gcli.c @@ -138,6 +138,7 @@ usage(void) fprintf(stderr, " - github (default: github.com)\n"); fprintf(stderr, " - gitlab (default: gitlab.com)\n"); fprintf(stderr, " - gitea (default: codeberg.org)\n"); + fprintf(stderr, " - bugzilla (default: bugs.freebsd.org)\n"); fprintf(stderr, " -c Force colour and text formatting.\n"); fprintf(stderr, " -q Be quiet. (Not implemented yet)\n\n"); fprintf(stderr, " -v Be verbose.\n\n"); diff --git a/src/ctx.c b/src/ctx.c index 0ff61590..8713689a 100644 --- a/src/ctx.c +++ b/src/ctx.c @@ -93,10 +93,11 @@ gcli_get_authheader(struct gcli_ctx *ctx) char *hdr = NULL; char *token = ctx->get_token(ctx); - if (token) { + if (token && gcli_forge(ctx)->make_authheader) { hdr = gcli_forge(ctx)->make_authheader(ctx, token); - free(token); } + free(token); + return hdr; } diff --git a/src/forges.c b/src/forges.c index 7461740a..be8d5666 100644 --- a/src/forges.c +++ b/src/forges.c @@ -70,6 +70,8 @@ #include #include +#include + static gcli_forge_descriptor const github_forge_descriptor = { @@ -342,6 +344,15 @@ gitea_forge_descriptor = | GCLI_PRS_QUIRK_COVERAGE, }; +static gcli_forge_descriptor const +bugzilla_forge_descriptor = +{ + /* Issues */ + .get_issues = bugzilla_get_bugs, + + .user_object_key = "---dummy---", +}; + gcli_forge_descriptor const * gcli_forge(gcli_ctx *ctx) { @@ -352,6 +363,8 @@ gcli_forge(gcli_ctx *ctx) return &gitlab_forge_descriptor; case GCLI_FORGE_GITEA: return &gitea_forge_descriptor; + case GCLI_FORGE_BUGZILLA: + return &bugzilla_forge_descriptor; default: errx(1, "error: cannot determine forge type. try forcing an account " diff --git a/tests/Kyuafile.in b/tests/Kyuafile.in index 483eab8b..c7f9485b 100644 --- a/tests/Kyuafile.in +++ b/tests/Kyuafile.in @@ -21,6 +21,11 @@ atf_test_program{ required_files = '@TESTSRCDIR@/samples/gitea_simple_notification.json' } +atf_test_program{ + name = 'bugzilla-parse-tests', + required_files = '@TESTSRCDIR@/samples/bugzilla_simple_bug.json' +} + atf_test_program{ name = 'url-encode' } diff --git a/tests/bugzilla-parse-tests.c b/tests/bugzilla-parse-tests.c new file mode 100644 index 00000000..a05ff721 --- /dev/null +++ b/tests/bugzilla-parse-tests.c @@ -0,0 +1,88 @@ +/* + * Copyright 2023 Nico Sonack + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +#include +#include +#include + +#include + +#include "gcli_tests.h" + +static gcli_forge_type +get_bugzilla_forge_type(gcli_ctx *ctx) +{ + (void) ctx; + return GCLI_FORGE_BUGZILLA; +} + +static gcli_ctx * +test_context(void) +{ + gcli_ctx *ctx; + ATF_REQUIRE(gcli_init(&ctx, get_bugzilla_forge_type, NULL, NULL) == NULL); + return ctx; +} + +static FILE * +open_sample(char const *const name) +{ + FILE *r; + char p[4096] = {0}; + + snprintf(p, sizeof p, "%s/samples/%s", TESTSRCDIR, name); + + r = fopen(p, "r"); + return r; +} + +ATF_TC_WITHOUT_HEAD(simple_bugzilla_issue); +ATF_TC_BODY(simple_bugzilla_issue, tc) +{ + gcli_issue_list list = {0}; + FILE *f; + json_stream stream; + gcli_ctx *ctx = test_context(); + + ATF_REQUIRE(f = open_sample("bugzilla_simple_bug.json")); + json_open_stream(&stream, f); + + json_close(&stream); + gcli_destroy(&ctx); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, simple_bugzilla_issue); + + return atf_no_error(); +} diff --git a/tests/samples/bugzilla_simple_bug.json b/tests/samples/bugzilla_simple_bug.json new file mode 100644 index 00000000..f451d762 --- /dev/null +++ b/tests/samples/bugzilla_simple_bug.json @@ -0,0 +1,53 @@ +{ + "bugs": [ + { + "platform": "Any", + "target_milestone": "---", + "op_sys": "Any", + "summary": "[aha] [scsi] Toshiba MK156FB scsi drive does not work with 2.0 kernel", + "blocks": [], + "last_change_time": "2016-08-11T10:54:59Z", + "priority": "Normal", + "resolution": "FIXED", + "is_cc_accessible": true, + "deadline": null, + "classification": "Unclassified", + "is_creator_accessible": true, + "dupe_of": null, + "id": 1, + "see_also": [], + "status": "Closed", + "groups": [], + "is_open": false, + "whiteboard": "", + "assigned_to": "core@FreeBSD.org", + "assigned_to_detail": { + "name": "core@FreeBSD.org", + "real_name": "FreeBSD Core Team", + "id": 3, + "email": "core@FreeBSD.org" + }, + "keywords": [], + "alias": [], + "cc_detail": [], + "url": "", + "cc": [], + "version": "Unspecified", + "is_confirmed": true, + "component": "kern", + "creator_detail": { + "name": "root@hclb.demon.co.uk", + "real_name": "Dave Evans", + "email": "root@hclb.demon.co.uk", + "id": 22 + }, + "depends_on": [], + "creation_time": "1994-09-14T09:10:01Z", + "severity": "Affects Only Me", + "flags": [], + "qa_contact": "", + "creator": "root@hclb.demon.co.uk", + "product": "Base System" + } + ] +} From 1851c04c2cb6998e89f2cabdc3eda60b18b750ca Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 8 Dec 2023 15:20:28 +0100 Subject: [PATCH 057/158] Start parsing bugzilla bug tickets --- templates/bugzilla/bugs.t | 11 +++++++++++ tests/bugzilla-parse-tests.c | 12 ++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 templates/bugzilla/bugs.t diff --git a/templates/bugzilla/bugs.t b/templates/bugzilla/bugs.t new file mode 100644 index 00000000..2db6554a --- /dev/null +++ b/templates/bugzilla/bugs.t @@ -0,0 +1,11 @@ +include "gcli/issues.h"; + +parser bugzilla_bug_item is +object of gcli_issue with + ("id" => number as id, + "summary" => title as sv); + +parser bugzilla_bugs is +object of gcli_issue_list with + ("bugs" => issues as array of gcli_issue use parse_bugzilla_bug_item); + diff --git a/tests/bugzilla-parse-tests.c b/tests/bugzilla-parse-tests.c index a05ff721..b1e7d6f1 100644 --- a/tests/bugzilla-parse-tests.c +++ b/tests/bugzilla-parse-tests.c @@ -34,6 +34,8 @@ #include #include +#include + #include #include "gcli_tests.h" @@ -69,6 +71,7 @@ ATF_TC_WITHOUT_HEAD(simple_bugzilla_issue); ATF_TC_BODY(simple_bugzilla_issue, tc) { gcli_issue_list list = {0}; + gcli_issue const *issue; FILE *f; json_stream stream; gcli_ctx *ctx = test_context(); @@ -76,6 +79,15 @@ ATF_TC_BODY(simple_bugzilla_issue, tc) ATF_REQUIRE(f = open_sample("bugzilla_simple_bug.json")); json_open_stream(&stream, f); + ATF_REQUIRE(parse_bugzilla_bugs(ctx, &stream, &list) == 0); + + ATF_REQUIRE_EQ(list.issues_size, 1); + + issue = &list.issues[0]; + + ATF_CHECK_EQ(issue->number, 1); + ATF_CHECK(sn_sv_eq_to(issue->title, "[aha] [scsi] Toshiba MK156FB scsi drive does not work with 2.0 kernel")); + json_close(&stream); gcli_destroy(&ctx); } From 649aa7000210819b11001d6614ea379582b90a57 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 8 Dec 2023 16:33:20 +0100 Subject: [PATCH 058/158] More flags for Bugzilla bug lists --- src/bugzilla/bugs.c | 29 ++++++++++++++++++++++++++--- templates/bugzilla/bugs.t | 9 ++++++++- tests/bugzilla-parse-tests.c | 5 ++++- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/bugzilla/bugs.c b/src/bugzilla/bugs.c index 2daec48f..ee6a699d 100644 --- a/src/bugzilla/bugs.c +++ b/src/bugzilla/bugs.c @@ -31,16 +31,39 @@ #include +#include + +#include + int bugzilla_get_bugs(gcli_ctx *ctx, char const *product, char const *component, gcli_issue_fetch_details const *details, int const max, gcli_issue_list *out) { + char *url; + gcli_fetch_buffer buffer = {0}; + int rc = 0; + (void) product; (void) component; (void) details; - (void) max; - (void) out; - return gcli_error(ctx, "%s: not yet implemented", __func__); + /* TODO: handle the max = -1 case */ + url = sn_asprintf("%s/rest/bug?limit=%d&%s&order=id%%20DESC", + gcli_get_apibase(ctx), max, + details->all ? "status=All" : "status=Open"); + rc = gcli_fetch(ctx, url, NULL, &buffer); + if (rc == 0) { + json_stream stream = {0}; + + json_open_buffer(&stream, buffer.data, buffer.length); + rc = parse_bugzilla_bugs(ctx, &stream, out); + + json_close(&stream); + } + + free(buffer.data); + free(url); + + return rc; } diff --git a/templates/bugzilla/bugs.t b/templates/bugzilla/bugs.t index 2db6554a..1778e2af 100644 --- a/templates/bugzilla/bugs.t +++ b/templates/bugzilla/bugs.t @@ -1,9 +1,16 @@ include "gcli/issues.h"; +parser bugzilla_bug_creator is +object of gcli_issue with + ("real_name" => author as string); + parser bugzilla_bug_item is object of gcli_issue with ("id" => number as id, - "summary" => title as sv); + "summary" => title as string, + "creation_time" => created_at as string, + "creator_detail" => use parse_bugzilla_bug_creator, + "status" => state as string); parser bugzilla_bugs is object of gcli_issue_list with diff --git a/tests/bugzilla-parse-tests.c b/tests/bugzilla-parse-tests.c index b1e7d6f1..c1769a7d 100644 --- a/tests/bugzilla-parse-tests.c +++ b/tests/bugzilla-parse-tests.c @@ -86,7 +86,10 @@ ATF_TC_BODY(simple_bugzilla_issue, tc) issue = &list.issues[0]; ATF_CHECK_EQ(issue->number, 1); - ATF_CHECK(sn_sv_eq_to(issue->title, "[aha] [scsi] Toshiba MK156FB scsi drive does not work with 2.0 kernel")); + ATF_CHECK_STREQ(issue->title, "[aha] [scsi] Toshiba MK156FB scsi drive does not work with 2.0 kernel"); + ATF_CHECK_STREQ(issue->created_at, "1994-09-14T09:10:01Z"); + ATF_CHECK_STREQ(issue->author, "Dave Evans"); + ATF_CHECK_STREQ(issue->state, "Closed"); json_close(&stream); gcli_destroy(&ctx); From 9c1faec1a739fba0b999005af1c09159f228b468 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 8 Dec 2023 17:26:03 +0100 Subject: [PATCH 059/158] Improve bugzilla bug list sorting and querying --- src/bugzilla/bugs.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/bugzilla/bugs.c b/src/bugzilla/bugs.c index ee6a699d..34bae0d0 100644 --- a/src/bugzilla/bugs.c +++ b/src/bugzilla/bugs.c @@ -40,18 +40,35 @@ bugzilla_get_bugs(gcli_ctx *ctx, char const *product, char const *component, gcli_issue_fetch_details const *details, int const max, gcli_issue_list *out) { - char *url; + char *url, *e_product = NULL, *e_component = NULL; gcli_fetch_buffer buffer = {0}; int rc = 0; - (void) product; - (void) component; - (void) details; + if (product) { + char *tmp = gcli_urlencode(product); + e_product = sn_asprintf("&product=%s", tmp); + free(tmp); + } + + if (component) { + char *tmp = gcli_urlencode(component); + e_component = sn_asprintf("&component=%s", tmp); + free(tmp); + } /* TODO: handle the max = -1 case */ - url = sn_asprintf("%s/rest/bug?limit=%d&%s&order=id%%20DESC", + /* Note(Nico): Most of the options here are not very well + * documented. Specifically the order= parameter I have figured out by + * reading the code and trying things until it worked. */ + url = sn_asprintf("%s/rest/bug?order=bug_id%%20DESC%%2C&limit=%d%s%s%s", gcli_get_apibase(ctx), max, - details->all ? "status=All" : "status=Open"); + details->all ? "&status=All" : "&status=Open&status=New", + e_product ? e_product : "", + e_component ? e_component : ""); + + free(e_product); + free(e_component); + rc = gcli_fetch(ctx, url, NULL, &buffer); if (rc == 0) { json_stream stream = {0}; From 5ee323c0abea1ef32ab43902727a81e95bc7ba78 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 8 Dec 2023 17:38:22 +0100 Subject: [PATCH 060/158] Implement fetching issue summary for Bugzilla --- include/gcli/bugzilla/bugs.h | 3 +++ src/bugzilla/bugs.c | 12 ++++++++++++ src/forges.c | 1 + 3 files changed, 16 insertions(+) diff --git a/include/gcli/bugzilla/bugs.h b/include/gcli/bugzilla/bugs.h index e8b75f73..73cbbaf7 100644 --- a/include/gcli/bugzilla/bugs.h +++ b/include/gcli/bugzilla/bugs.h @@ -38,4 +38,7 @@ int bugzilla_get_bugs(gcli_ctx *ctx, char const *product, char const *component, gcli_issue_fetch_details const *details, int const max, gcli_issue_list *out); +int bugzilla_get_bug(gcli_ctx *ctx, char const *product, char const *component, + gcli_id bug_id, gcli_issue *out); + #endif /* GCLI_BUGZILLA_BUGS_H */ diff --git a/src/bugzilla/bugs.c b/src/bugzilla/bugs.c index 34bae0d0..77298a27 100644 --- a/src/bugzilla/bugs.c +++ b/src/bugzilla/bugs.c @@ -84,3 +84,15 @@ bugzilla_get_bugs(gcli_ctx *ctx, char const *product, char const *component, return rc; } + +int +bugzilla_get_bug(gcli_ctx *ctx, char const *product, char const *component, + gcli_id bug_id, gcli_issue *out) +{ + (void) product; + (void) component; + (void) bug_id; + (void) out; + + return gcli_error(ctx, "%s: not yet implemented", __func__); +} diff --git a/src/forges.c b/src/forges.c index be8d5666..e667273a 100644 --- a/src/forges.c +++ b/src/forges.c @@ -349,6 +349,7 @@ bugzilla_forge_descriptor = { /* Issues */ .get_issues = bugzilla_get_bugs, + .get_issue_summary = bugzilla_get_bug, .user_object_key = "---dummy---", }; From 239dd780e598306584898c8df3ed080c37655a22 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Sat, 9 Dec 2023 11:26:59 +0100 Subject: [PATCH 061/158] Bugzilla: Fetch a single bug This is missing the OP - however it should be pretty straightforward to implement. Famous last words. --- src/bugzilla/bugs.c | 47 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/src/bugzilla/bugs.c b/src/bugzilla/bugs.c index 77298a27..1187b7b4 100644 --- a/src/bugzilla/bugs.c +++ b/src/bugzilla/bugs.c @@ -35,6 +35,8 @@ #include +#include + int bugzilla_get_bugs(gcli_ctx *ctx, char const *product, char const *component, gcli_issue_fetch_details const *details, int const max, @@ -89,10 +91,49 @@ int bugzilla_get_bug(gcli_ctx *ctx, char const *product, char const *component, gcli_id bug_id, gcli_issue *out) { + int rc = 0; + char *url; + gcli_fetch_buffer buffer = {0}; + gcli_issue_list list = {0}; + json_stream stream = {0}; + + /* XXX should we warn if product or component is set? */ (void) product; (void) component; - (void) bug_id; - (void) out; - return gcli_error(ctx, "%s: not yet implemented", __func__); + url = sn_asprintf("%s/rest/bug?limit=1&id=%"PRIid, gcli_get_apibase(ctx), bug_id); + rc = gcli_fetch(ctx, url, NULL, &buffer); + + if (rc < 0) + goto error_fetch; + + json_open_buffer(&stream, buffer.data, buffer.length); + rc = parse_bugzilla_bugs(ctx, &stream, &list); + + if (rc < 0) + goto error_parse; + + if (list.issues_size == 0) { + rc = gcli_error(ctx, "no bug with id %"PRIid, bug_id); + goto error_no_such_bug; + } + + if (list.issues_size > 0) { + assert(list.issues_size == 1); + memcpy(out, &list.issues[0], sizeof(*out)); + } + + /* don't use gcli_issues_free because it frees data behind pointers we + * just copied */ + free(list.issues); + +error_no_such_bug: +error_parse: + json_close(&stream); + free(buffer.data); + +error_fetch: + free(url); + + return rc; } From 770012d8c5c2dccd4a7368720929b1aac42d4945 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Sat, 9 Dec 2023 11:57:31 +0100 Subject: [PATCH 062/158] Make the api subcommand work with Bugzilla --- Makefile.am | 3 ++ include/gcli/bugzilla/api.h | 41 +++++++++++++++++++++++++++ include/gcli/bugzilla/config.h | 37 ++++++++++++++++++++++++ src/bugzilla/api.c | 52 ++++++++++++++++++++++++++++++++++ src/bugzilla/config.c | 38 +++++++++++++++++++++++++ src/forges.c | 7 ++++- templates/bugzilla/api.t | 1 + 7 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 include/gcli/bugzilla/api.h create mode 100644 include/gcli/bugzilla/config.h create mode 100644 src/bugzilla/api.c create mode 100644 src/bugzilla/config.c create mode 100644 templates/bugzilla/api.t diff --git a/Makefile.am b/Makefile.am index bcdb5e69..ca39747b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -120,6 +120,7 @@ TEMPLATES = \ templates/gitlab/snippets.t \ templates/gitea/milestones.t \ templates/gitea/status.t \ + templates/bugzilla/api.t \ templates/bugzilla/bugs.t headerdir = $(prefix) @@ -190,7 +191,9 @@ libgcli_la_SOURCES = \ src/gitea/sshkeys.c include/gcli/gitea/sshkeys.h \ src/gitea/status.c include/gcli/gitea/status.h \ src/gitea/milestones.c include/gcli/gitea/milestones.h \ + src/bugzilla/api.c include/gcli/bugzilla/api.h \ src/bugzilla/bugs.c include/gcli/bugzilla/bugs.h \ + src/bugzilla/config.c include/gcli/bugzilla/config.h \ $(TEMPLATES) libgcli_la_CPPFLAGS = \ diff --git a/include/gcli/bugzilla/api.h b/include/gcli/bugzilla/api.h new file mode 100644 index 00000000..36fdac5c --- /dev/null +++ b/include/gcli/bugzilla/api.h @@ -0,0 +1,41 @@ +/* + * Copyright 2023 Nico Sonack + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef GCLI_BUGZILLA_API_H +#define GCLI_BUGZILLA_API_H + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +char const *bugzilla_api_error_string(gcli_ctx *ctx, gcli_fetch_buffer *it); + +#endif /* GCLI_BUGZILLA_API_H */ diff --git a/include/gcli/bugzilla/config.h b/include/gcli/bugzilla/config.h new file mode 100644 index 00000000..d0bf76af --- /dev/null +++ b/include/gcli/bugzilla/config.h @@ -0,0 +1,37 @@ +/* + * Copyright 2023 Nico Sonack + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef GCLI_BUGZILLA_CONFIG_H +#define GCLI_BUGZILLA_CONFIG_H + +#include + +char *bugzilla_make_authheader(gcli_ctx *ctx, char const *token); + +#endif /* GCLI_BUGZILLA_CONFIG_H */ diff --git a/src/bugzilla/api.c b/src/bugzilla/api.c new file mode 100644 index 00000000..b6288457 --- /dev/null +++ b/src/bugzilla/api.c @@ -0,0 +1,52 @@ +/* + * Copyright 2023 Nico Sonack + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +#include + +#include + +char const * +bugzilla_api_error_string(gcli_ctx *ctx, gcli_fetch_buffer *const buf) +{ + json_stream stream = {0}; + int rc; + char *msg; + + json_open_buffer(&stream, buf->data, buf->length); + rc = parse_bugzilla_get_error(ctx, &stream, &msg); + json_close(&stream); + + if (rc < 0) + return strdup("no message: failed to parser error response"); + else + return msg; +} diff --git a/src/bugzilla/config.c b/src/bugzilla/config.c new file mode 100644 index 00000000..ad84b053 --- /dev/null +++ b/src/bugzilla/config.c @@ -0,0 +1,38 @@ +/* + * Copyright 2023 Nico Sonack + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +char * +bugzilla_make_authheader(gcli_ctx *ctx, char const *const token) +{ + (void) ctx; + return sn_asprintf("X-BUGZILLA-API-KEY: %s", token); +} diff --git a/src/forges.c b/src/forges.c index e667273a..99cae09e 100644 --- a/src/forges.c +++ b/src/forges.c @@ -1,5 +1,5 @@ /* - * Copyright 2021, 2022 Nico Sonack + * Copyright 2021, 2022, 2023 Nico Sonack * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -70,7 +70,9 @@ #include #include +#include #include +#include static gcli_forge_descriptor const github_forge_descriptor = @@ -351,6 +353,9 @@ bugzilla_forge_descriptor = .get_issues = bugzilla_get_bugs, .get_issue_summary = bugzilla_get_bug, + /* Internal stuff */ + .make_authheader = bugzilla_make_authheader, + .get_api_error_string = bugzilla_api_error_string, .user_object_key = "---dummy---", }; diff --git a/templates/bugzilla/api.t b/templates/bugzilla/api.t new file mode 100644 index 00000000..1b862aad --- /dev/null +++ b/templates/bugzilla/api.t @@ -0,0 +1 @@ +parser bugzilla_get_error is object of char* select "message" as string; From 64f6ffedc34a4e9ae8f0f9724929082a51f492ea Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Sat, 9 Dec 2023 12:58:27 +0100 Subject: [PATCH 063/158] Implement fetching comments for Bugzilla --- include/gcli/bugzilla/bugs.h | 11 ++++++++ src/bugzilla/bugs.c | 54 ++++++++++++++++++++++++++++++++++++ src/forges.c | 1 + templates/bugzilla/bugs.t | 16 +++++++++++ 4 files changed, 82 insertions(+) diff --git a/include/gcli/bugzilla/bugs.h b/include/gcli/bugzilla/bugs.h index 73cbbaf7..8b7ee8ba 100644 --- a/include/gcli/bugzilla/bugs.h +++ b/include/gcli/bugzilla/bugs.h @@ -32,8 +32,11 @@ #include +#include #include +#include + int bugzilla_get_bugs(gcli_ctx *ctx, char const *product, char const *component, gcli_issue_fetch_details const *details, int const max, gcli_issue_list *out); @@ -41,4 +44,12 @@ int bugzilla_get_bugs(gcli_ctx *ctx, char const *product, char const *component, int bugzilla_get_bug(gcli_ctx *ctx, char const *product, char const *component, gcli_id bug_id, gcli_issue *out); +int parse_bugzilla_bug_comments_dictionary(gcli_ctx *const ctx, + json_stream *stream, + gcli_comment_list *out); + +int bugzilla_bug_get_comments(gcli_ctx *const ctx, char const *const product, + char const *const component, gcli_id const bug_id, + gcli_comment_list *out); + #endif /* GCLI_BUGZILLA_BUGS_H */ diff --git a/src/bugzilla/bugs.c b/src/bugzilla/bugs.c index 1187b7b4..28e0b42e 100644 --- a/src/bugzilla/bugs.c +++ b/src/bugzilla/bugs.c @@ -87,6 +87,60 @@ bugzilla_get_bugs(gcli_ctx *ctx, char const *product, char const *component, return rc; } +int +parse_bugzilla_bug_comments_dictionary(gcli_ctx *const ctx, json_stream *stream, + gcli_comment_list *out) +{ + enum json_type next = JSON_NULL; + int rc = 0; + + if ((next = json_next(stream)) != JSON_OBJECT) + return gcli_error(ctx, "expected bugzilla comments dictionary"); + + while ((next = json_next(stream)) == JSON_STRING) { + rc = parse_bugzilla_comments_internal(ctx, stream, out); + if (rc < 0) + return rc; + } + + if (next != JSON_OBJECT_END) + return gcli_error(ctx, "unclosed bugzilla comments dictionary"); + + return rc; +} + +int +bugzilla_bug_get_comments(gcli_ctx *const ctx, char const *const product, + char const *const component, gcli_id const bug_id, + gcli_comment_list *out) +{ + int rc = 0; + gcli_fetch_buffer buffer = {0}; + json_stream stream = {0}; + char *url = NULL; + + (void) product; + (void) component; + + url = sn_asprintf("%s/rest/bug/%"PRIid"/comment?include_fields=_all", + gcli_get_apibase(ctx), bug_id); + + rc = gcli_fetch(ctx, url, NULL, &buffer); + if (rc < 0) + goto error_fetch; + + json_open_buffer(&stream, buffer.data, buffer.length); + rc = parse_bugzilla_comments(ctx, &stream, out); + json_close(&stream); + + free(buffer.data); + +error_fetch: + free(url); + + return rc; +} + int bugzilla_get_bug(gcli_ctx *ctx, char const *product, char const *component, gcli_id bug_id, gcli_issue *out) diff --git a/src/forges.c b/src/forges.c index 99cae09e..f63927bb 100644 --- a/src/forges.c +++ b/src/forges.c @@ -352,6 +352,7 @@ bugzilla_forge_descriptor = /* Issues */ .get_issues = bugzilla_get_bugs, .get_issue_summary = bugzilla_get_bug, + .get_issue_comments = bugzilla_bug_get_comments, /* Internal stuff */ .make_authheader = bugzilla_make_authheader, diff --git a/templates/bugzilla/bugs.t b/templates/bugzilla/bugs.t index 1778e2af..d23826ad 100644 --- a/templates/bugzilla/bugs.t +++ b/templates/bugzilla/bugs.t @@ -1,4 +1,6 @@ +include "gcli/comments.h"; include "gcli/issues.h"; +include "gcli/bugzilla/bugs.h"; parser bugzilla_bug_creator is object of gcli_issue with @@ -16,3 +18,17 @@ parser bugzilla_bugs is object of gcli_issue_list with ("bugs" => issues as array of gcli_issue use parse_bugzilla_bug_item); +parser bugzilla_comment is +object of gcli_comment with + ("id" => id as id, + "text" => body as string, + "creation_time" => date as string, + "creator" => author as string); + +parser bugzilla_comments_internal is +object of gcli_comment_list with + ("comments" => comments as array of gcli_comment use parse_bugzilla_comment); + +parser bugzilla_comments is +object of gcli_comment_list with + ("bugs" => use parse_bugzilla_bug_comments_dictionary); From e6c6ddc9a719c9d92eb497cf15ff15ce5cf6c169 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Sat, 9 Dec 2023 13:20:37 +0100 Subject: [PATCH 064/158] Add default config for Bugzilla FreeBSD's bugzilla as a default is probably not nice but I'll use it for debugging. --- src/cmd/cmdconfig.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/cmd/cmdconfig.c b/src/cmd/cmdconfig.c index 62bedc02..0ee53402 100644 --- a/src/cmd/cmdconfig.c +++ b/src/cmd/cmdconfig.c @@ -666,9 +666,10 @@ gcli_config_get_editor(gcli_ctx *ctx) static char const *const default_account_entry_names[] = { - [GCLI_FORGE_GITHUB] = "github-default-account", - [GCLI_FORGE_GITLAB] = "gitlab-default-account", - [GCLI_FORGE_GITEA] = "gitea-default-account", }; + [GCLI_FORGE_GITHUB] = "github-default-account", + [GCLI_FORGE_GITLAB] = "gitlab-default-account", + [GCLI_FORGE_GITEA] = "gitea-default-account", + [GCLI_FORGE_BUGZILLA] = "bugzilla-default-account",}; static char * get_default_account(gcli_ctx *ctx, gcli_forge_type ftype) @@ -699,9 +700,10 @@ gcli_config_get_account(gcli_ctx *ctx) } static char const *const default_urls[] = { - [GCLI_FORGE_GITHUB] = "https://api.github.com", - [GCLI_FORGE_GITLAB] = "https://gitlab.com/api/v4", - [GCLI_FORGE_GITEA] = "https://codeberg.org/api/v1", + [GCLI_FORGE_GITHUB] = "https://api.github.com", + [GCLI_FORGE_GITLAB] = "https://gitlab.com/api/v4", + [GCLI_FORGE_GITEA] = "https://codeberg.org/api/v1", + [GCLI_FORGE_BUGZILLA] = "https://bugs.freebsd.org/bugzilla", }; char * From 9a6e4babff413ab56487687bdeebb2f9be169ccd Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Sat, 9 Dec 2023 19:05:08 +0100 Subject: [PATCH 065/158] Add Author filter for Bugzilla Bugs --- src/bugzilla/bugs.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/bugzilla/bugs.c b/src/bugzilla/bugs.c index 28e0b42e..0691bb7d 100644 --- a/src/bugzilla/bugs.c +++ b/src/bugzilla/bugs.c @@ -42,7 +42,7 @@ bugzilla_get_bugs(gcli_ctx *ctx, char const *product, char const *component, gcli_issue_fetch_details const *details, int const max, gcli_issue_list *out) { - char *url, *e_product = NULL, *e_component = NULL; + char *url, *e_product = NULL, *e_component = NULL, *e_author = NULL; gcli_fetch_buffer buffer = {0}; int rc = 0; @@ -58,18 +58,26 @@ bugzilla_get_bugs(gcli_ctx *ctx, char const *product, char const *component, free(tmp); } + if (details->author) { + char *tmp = gcli_urlencode(details->author); + e_author = sn_asprintf("&creator=%s", tmp); + free(tmp); + } + /* TODO: handle the max = -1 case */ /* Note(Nico): Most of the options here are not very well * documented. Specifically the order= parameter I have figured out by * reading the code and trying things until it worked. */ - url = sn_asprintf("%s/rest/bug?order=bug_id%%20DESC%%2C&limit=%d%s%s%s", + url = sn_asprintf("%s/rest/bug?order=bug_id%%20DESC%%2C&limit=%d%s%s%s%s", gcli_get_apibase(ctx), max, details->all ? "&status=All" : "&status=Open&status=New", e_product ? e_product : "", - e_component ? e_component : ""); + e_component ? e_component : "", + e_author ? e_author : ""); free(e_product); free(e_component); + free(e_author); rc = gcli_fetch(ctx, url, NULL, &buffer); if (rc == 0) { From 317328619a11debe34d6c51e2a4b0ab647d086e8 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Sun, 10 Dec 2023 11:09:20 +0100 Subject: [PATCH 066/158] Add test for parsing bugzilla comments --- tests/bugzilla-parse-tests.c | 36 ++++++++++++++++++++++++++++ tests/samples/bugzilla_comments.json | 1 + 2 files changed, 37 insertions(+) create mode 100644 tests/samples/bugzilla_comments.json diff --git a/tests/bugzilla-parse-tests.c b/tests/bugzilla-parse-tests.c index c1769a7d..4ecd052b 100644 --- a/tests/bugzilla-parse-tests.c +++ b/tests/bugzilla-parse-tests.c @@ -95,9 +95,45 @@ ATF_TC_BODY(simple_bugzilla_issue, tc) gcli_destroy(&ctx); } +ATF_TC_WITHOUT_HEAD(bugzilla_comments); +ATF_TC_BODY(bugzilla_comments, tc) +{ + FILE *f; + gcli_comment const *cmt = NULL; + gcli_comment_list list = {0}; + gcli_ctx *ctx = test_context(); + json_stream stream; + + ATF_REQUIRE(f = open_sample("bugzilla_comments.json")); + json_open_stream(&stream, f); + + ATF_REQUIRE(parse_bugzilla_comments(ctx, &stream, &list) == 0); + json_close(&stream); + fclose(f); + f = NULL; + + ATF_REQUIRE_EQ(list.comments_size, 2); + + cmt = &list.comments[0]; + ATF_CHECK_EQ(cmt->id, 1285941); + ATF_CHECK_STREQ(cmt->author, "zlei@FreeBSD.org"); + ATF_CHECK_STREQ(cmt->date, "2023-11-27T17:14:39Z"); + ATF_CHECK(cmt->body != NULL); + + cmt += 1; + ATF_CHECK_EQ(cmt->id, 1285943); + ATF_CHECK_STREQ(cmt->author, "zlei@FreeBSD.org"); + ATF_CHECK_STREQ(cmt->date, "2023-11-27T17:20:15Z"); + ATF_CHECK(cmt->body != NULL); + + gcli_comments_free(&list); + gcli_destroy(&ctx); +} + ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, simple_bugzilla_issue); + ATF_TP_ADD_TC(tp, bugzilla_comments); return atf_no_error(); } diff --git a/tests/samples/bugzilla_comments.json b/tests/samples/bugzilla_comments.json new file mode 100644 index 00000000..31abfa20 --- /dev/null +++ b/tests/samples/bugzilla_comments.json @@ -0,0 +1 @@ +{"comments":{},"bugs":{"275381":{"comments":[{"is_private":false,"time":"2023-11-27T17:14:39Z","text":"This is originally reported by khng@ on Telegram bsd dev group. Post it here to make it public.\n\nSteps to repeat:\n\nBoot with Ethernet interface disabled, then try to enable it.\n\n```\n> set hint.hn.0.disabled=\"1\"\n> boot\n...\n# devctl enable hn0\n```\n\n\nPart of core text dump:\n\nfreebsd dumped core - see /var/crash/vmcore.0\n\nMon Nov 20 04:17:24 UTC 2023\n\nFreeBSD freebsd 14.0-RELEASE FreeBSD 14.0-RELEASE #0 releng/14.0-n265380-f9716eee8ab4: Fri Nov 10 05:57:23 UTC 2023 root@releng1.nyi.freebsd.org:/usr/obj/usr/src/amd64.amd64/sys/GENERIC amd64\n\npanic: page fault\n\nGNU gdb (GDB) 13.2 [GDB v13.2 for FreeBSD]\nCopyright (C) 2023 Free Software Foundation, Inc.\nLicense GPLv3+: GNU GPL version 3 or later \nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law.\nType \"show copying\" and \"show warranty\" for details.\nThis GDB was configured as \"x86_64-portbld-freebsd14.0\".\nType \"show configuration\" for configuration details.\nFor bug reporting instructions, please see:\n.\nFind the GDB manual and other documentation resources online at:\n .\n\nFor help, type \"help\".\nType \"apropos word\" to search for commands related to \"word\"...\nReading symbols from /boot/kernel/kernel...\nReading symbols from /usr/lib/debug//boot/kernel/kernel.debug...\n\nUnread portion of the kernel message buffer:\n\n\nFatal trap 12: page fault while in kernel mode\ncpuid = 1; apic id = 01\nfault virtual address\t= 0x28\nfault code\t\t= supervisor read data, page not present\ninstruction pointer\t= 0x20:0xffffffff80c5e0c8\nstack pointer\t = 0x28:0xfffffe0053f4b900\nframe pointer\t = 0x28:0xfffffe0053f4b940\ncode segment\t\t= base 0x0, limit 0xfffff, type 0x1b\n\t\t\t= DPL 0, pres 1, long 1, def32 0, gran 1\nprocessor eflags\t= interrupt enabled, resume, IOPL = 0\ncurrent process\t\t= 650 (devctl)\nrdi: fffff80006eb6800 rsi: fffff80001027500 rdx: 0000000000000001\nrcx: 0000000000000001 r8: 0000000000000000 r9: 8080808080808080\nrax: 0000000000000000 rbx: fffffe0054963c80 rbp: fffffe0053f4b940\nr10: ffffffff811e1f39 r11: 8b9091ff93939e00 r12: fffff80007fca000\nr13: fffff80007305c20 r14: ffffffff811e1f39 r15: 0000000000000000\ntrap number\t\t= 12\npanic: page fault\ncpuid = 1\ntime = 1700453806\nKDB: stack backtrace:\n#0 0xffffffff80b9002d at kdb_backtrace+0x5d\n#1 0xffffffff80b43132 at vpanic+0x132\n#2 0xffffffff80b42ff3 at panic+0x43\n#3 0xffffffff8100c85c at trap_fatal+0x40c\n#4 0xffffffff8100c8af at trap_pfault+0x4f\n#5 0xffffffff80fe3828 at calltrap+0x8\n#6 0xffffffff80c5ceb5 at if_attach_internal+0x55\n#7 0xffffffff80c6824c at ether_ifattach+0x2c\n#8 0xffffffff80f779c6 at hn_attach+0x21d6\n#9 0xffffffff80b7fa1e at device_attach+0x3be\n#10 0xffffffff80b84dcf at devctl2_ioctl+0x56f\n#11 0xffffffff809d10dc at devfs_ioctl+0xcc\n#12 0xffffffff80c3b9b4 at vn_ioctl+0xd4\n#13 0xffffffff809d177e at devfs_ioctl_f+0x1e\n#14 0xffffffff80bb1535 at kern_ioctl+0x255\n#15 0xffffffff80bb1273 at sys_ioctl+0x123\n#16 0xffffffff8100d119 at amd64_syscall+0x109\n#17 0xffffffff80fe413b at fast_syscall_common+0xf8\nUptime: 15s\nDumping 212 out of 470 MB:..8%..16%..23%..31%..46%..53%..61%..76%..83%..91%\n\n__curthread () at /usr/src/sys/amd64/include/pcpu_aux.h:57\n57\t/usr/src/sys/amd64/include/pcpu_aux.h: No such file or directory.\n(kgdb) #0 __curthread () at /usr/src/sys/amd64/include/pcpu_aux.h:57\n#1 doadump (textdump=)\n at /usr/src/sys/kern/kern_shutdown.c:405\n#2 0xffffffff80b42cc7 in kern_reboot (howto=260)\n at /usr/src/sys/kern/kern_shutdown.c:526\n#3 0xffffffff80b4319f in vpanic (fmt=0xffffffff81136b3b \"%s\", \n ap=ap@entry=0xfffffe0053f4b750) at /usr/src/sys/kern/kern_shutdown.c:970\n#4 0xffffffff80b42ff3 in panic (fmt=)\n at /usr/src/sys/kern/kern_shutdown.c:894\n#5 0xffffffff8100c85c in trap_fatal (frame=0xfffffe0053f4b840, eva=40)\n at /usr/src/sys/amd64/amd64/trap.c:952\n#6 0xffffffff8100c8af in trap_pfault (frame=0xfffffe0053f4b840, \n usermode=false, signo=, ucode=)\n at /usr/src/sys/amd64/amd64/trap.c:760\n#7 \n#8 0xffffffff80c5e0c8 in if_addgroup (ifp=ifp@entry=0xfffff80007fca000, \n groupname=0xffffffff811e1f39 \"all\") at /usr/src/sys/net/if.c:1477\n#9 0xffffffff80c5ceb5 in if_attach_internal (\n ifp=ifp@entry=0xfffff80007fca000, vmove=false)\n at /usr/src/sys/net/if.c:842\n#10 0xffffffff80c5ce59 in if_attach (ifp=0xfffff80006eb6800, \n ifp@entry=0xfffff80007fca000) at /usr/src/sys/net/if.c:772\n#11 0xffffffff80c6824c in ether_ifattach (ifp=0xfffff80006eb6800, \n ifp@entry=0xfffff80007fca000, lla=0xfffff80001027500 \"\", \n lla@entry=0xfffffe0053f4ba80 \"\") at /usr/src/sys/net/if_ethersubr.c:1001\n#12 0xffffffff80f779c6 in hn_attach (dev=0xfffff8000291ce00)\n at /usr/src/sys/dev/hyperv/netvsc/if_hn.c:2436\n#13 0xffffffff80b7fa1e in DEVICE_ATTACH (dev=0xfffff8000291ce00)\n at ./device_if.h:195\n#14 device_attach (dev=dev@entry=0xfffff8000291ce00)\n at /usr/src/sys/kern/subr_bus.c:2535\n#15 0xffffffff80b84dcf in devctl2_ioctl (cdev=, \n cmd=2157462531, data=, fflag=, \n td=0xfffffe0054963c80) at /usr/src/sys/kern/subr_bus.c:5433\n#16 0xffffffff809d10dc in devfs_ioctl (ap=0xfffffe0053f4bc40)\n at /usr/src/sys/fs/devfs/devfs_vnops.c:933\n#17 0xffffffff80c3b9b4 in vn_ioctl (fp=0xfffff8000704ce10, \n com=18446735277633467648, data=0xfffff8000779ee00, \n active_cred=0xfffff8000702cb00, td=0x0)\n at /usr/src/sys/kern/vfs_vnops.c:1701\n#18 0xffffffff809d177e in devfs_ioctl_f (fp=0xfffff80006eb6800, \n com=18446735277633467648, data=0x1, cred=0x1, td=0x0)\n at /usr/src/sys/fs/devfs/devfs_vnops.c:864\n#19 0xffffffff80bb1535 in fo_ioctl (fp=0xfffff8000704ce10, com=2157462531, \n data=0x1, active_cred=0x1, td=0xfffffe0054963c80)\n at /usr/src/sys/sys/file.h:366\n#20 kern_ioctl (td=td@entry=0xfffffe0054963c80, fd=, \n com=com@entry=2157462531, \n data=0x1 , \n data@entry=0xfffff8000779ee00 \"hn0\")\n at /usr/src/sys/kern/sys_generic.c:805\n#21 0xffffffff80bb1273 in sys_ioctl (td=0xfffffe0054963c80, \n uap=0xfffffe0054964080) at /usr/src/sys/kern/sys_generic.c:713\n#22 0xffffffff8100d119 in syscallenter (td=0xfffffe0054963c80)\n at /usr/src/sys/amd64/amd64/../../kern/subr_syscall.c:187\n#23 amd64_syscall (td=0xfffffe0054963c80, traced=0)\n at /usr/src/sys/amd64/amd64/trap.c:1197\n#24 \n#25 0x000032e7074bce0a in ?? ()\nBacktrace stopped: Cannot access memory at address 0x32e7069aff48\n(kgdb)","creation_time":"2023-11-27T17:14:39Z","bug_id":275381,"count":0,"id":1285941,"creator":"zlei@FreeBSD.org","attachment_id":null},{"text":"Other ethernet interface drivers are also affected, tested with re(4) and cxgbe(4).\n\nProposed fix: https://reviews.freebsd.org/D42678","time":"2023-11-27T17:20:15Z","bug_id":275381,"creation_time":"2023-11-27T17:20:15Z","is_private":false,"attachment_id":null,"creator":"zlei@FreeBSD.org","id":1285943,"count":1}]}}} \ No newline at end of file From 51d651d738a357818aa366cf65cf9d0cc37862e7 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Sun, 10 Dec 2023 12:09:24 +0100 Subject: [PATCH 067/158] Make bugzilla comments only return actual comments The first "comment" in the comments array is the description. Skip it. Next I will add a function that only returns the first comment which is the original post/description of the bug report. --- include/gcli/bugzilla/bugs.h | 12 ++++++++---- src/bugzilla/bugs.c | 35 ++++++++++++++++++++++++++++++++--- templates/bugzilla/bugs.t | 6 +++--- tests/bugzilla-parse-tests.c | 8 +------- 4 files changed, 44 insertions(+), 17 deletions(-) diff --git a/include/gcli/bugzilla/bugs.h b/include/gcli/bugzilla/bugs.h index 8b7ee8ba..ca291cc6 100644 --- a/include/gcli/bugzilla/bugs.h +++ b/include/gcli/bugzilla/bugs.h @@ -44,12 +44,16 @@ int bugzilla_get_bugs(gcli_ctx *ctx, char const *product, char const *component, int bugzilla_get_bug(gcli_ctx *ctx, char const *product, char const *component, gcli_id bug_id, gcli_issue *out); -int parse_bugzilla_bug_comments_dictionary(gcli_ctx *const ctx, - json_stream *stream, - gcli_comment_list *out); - int bugzilla_bug_get_comments(gcli_ctx *const ctx, char const *const product, char const *const component, gcli_id const bug_id, gcli_comment_list *out); +int parse_bugzilla_bug_comments_dictionary_skip_first(gcli_ctx *const ctx, + json_stream *stream, + gcli_comment_list *out); + +int parse_bugzilla_comments_array_skip_first(gcli_ctx *ctx, + struct json_stream *stream, + gcli_comment_list *out); + #endif /* GCLI_BUGZILLA_BUGS_H */ diff --git a/src/bugzilla/bugs.c b/src/bugzilla/bugs.c index 0691bb7d..18e1c913 100644 --- a/src/bugzilla/bugs.c +++ b/src/bugzilla/bugs.c @@ -34,6 +34,7 @@ #include #include +#include #include @@ -96,8 +97,36 @@ bugzilla_get_bugs(gcli_ctx *ctx, char const *product, char const *component, } int -parse_bugzilla_bug_comments_dictionary(gcli_ctx *const ctx, json_stream *stream, - gcli_comment_list *out) +parse_bugzilla_comments_array_skip_first(gcli_ctx *ctx, + struct json_stream *stream, + gcli_comment_list *out) +{ + int rc = 0; + + if (json_next(stream) != JSON_ARRAY) + return gcli_error(ctx, "expected array for comments array"); + + SKIP_OBJECT_VALUE(stream); + + while (json_peek(stream) != JSON_ARRAY_END) { + out->comments = realloc(out->comments, sizeof(*out->comments) * (out->comments_size + 1)); + memset(&out->comments[out->comments_size], 0, sizeof(out->comments[out->comments_size])); + rc = parse_bugzilla_comment(ctx, stream, &out->comments[out->comments_size++]); + if (rc < 0) + return rc; + } + + if (json_next(stream) != JSON_ARRAY_END) + return gcli_error(ctx, "unexpected element in array while parsing"); + + return 0; +} + + +int +parse_bugzilla_bug_comments_dictionary_skip_first(gcli_ctx *const ctx, + json_stream *stream, + gcli_comment_list *out) { enum json_type next = JSON_NULL; int rc = 0; @@ -106,7 +135,7 @@ parse_bugzilla_bug_comments_dictionary(gcli_ctx *const ctx, json_stream *stream, return gcli_error(ctx, "expected bugzilla comments dictionary"); while ((next = json_next(stream)) == JSON_STRING) { - rc = parse_bugzilla_comments_internal(ctx, stream, out); + rc = parse_bugzilla_comments_internal_skip_first(ctx, stream, out); if (rc < 0) return rc; } diff --git a/templates/bugzilla/bugs.t b/templates/bugzilla/bugs.t index d23826ad..129ca212 100644 --- a/templates/bugzilla/bugs.t +++ b/templates/bugzilla/bugs.t @@ -25,10 +25,10 @@ object of gcli_comment with "creation_time" => date as string, "creator" => author as string); -parser bugzilla_comments_internal is +parser bugzilla_comments_internal_skip_first is object of gcli_comment_list with - ("comments" => comments as array of gcli_comment use parse_bugzilla_comment); + ("comments" => use parse_bugzilla_comments_array_skip_first); parser bugzilla_comments is object of gcli_comment_list with - ("bugs" => use parse_bugzilla_bug_comments_dictionary); + ("bugs" => use parse_bugzilla_bug_comments_dictionary_skip_first); diff --git a/tests/bugzilla-parse-tests.c b/tests/bugzilla-parse-tests.c index 4ecd052b..eb9dde15 100644 --- a/tests/bugzilla-parse-tests.c +++ b/tests/bugzilla-parse-tests.c @@ -112,15 +112,9 @@ ATF_TC_BODY(bugzilla_comments, tc) fclose(f); f = NULL; - ATF_REQUIRE_EQ(list.comments_size, 2); + ATF_REQUIRE_EQ(list.comments_size, 1); cmt = &list.comments[0]; - ATF_CHECK_EQ(cmt->id, 1285941); - ATF_CHECK_STREQ(cmt->author, "zlei@FreeBSD.org"); - ATF_CHECK_STREQ(cmt->date, "2023-11-27T17:14:39Z"); - ATF_CHECK(cmt->body != NULL); - - cmt += 1; ATF_CHECK_EQ(cmt->id, 1285943); ATF_CHECK_STREQ(cmt->author, "zlei@FreeBSD.org"); ATF_CHECK_STREQ(cmt->date, "2023-11-27T17:20:15Z"); From 114373e2530caf9a64fc506f10a046d1acab3ec6 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Sun, 10 Dec 2023 12:07:51 +0100 Subject: [PATCH 068/158] Implement Bugzilla OP/description of a bug report This is a follow up for the previous change where I split out the comments into a separate code path that skips the first comment in the returned "comments" array. This now adds a path that only returns the first comment in said array. (to be specific, only the text in the first comment) --- include/gcli/bugzilla/bugs.h | 8 ++++ src/bugzilla/bugs.c | 76 ++++++++++++++++++++++++++++++++++++ templates/bugzilla/bugs.t | 11 ++++++ 3 files changed, 95 insertions(+) diff --git a/include/gcli/bugzilla/bugs.h b/include/gcli/bugzilla/bugs.h index ca291cc6..d564cc36 100644 --- a/include/gcli/bugzilla/bugs.h +++ b/include/gcli/bugzilla/bugs.h @@ -56,4 +56,12 @@ int parse_bugzilla_comments_array_skip_first(gcli_ctx *ctx, struct json_stream *stream, gcli_comment_list *out); +int parse_bugzilla_bug_comments_dictionary_only_first(gcli_ctx *const ctx, + json_stream *stream, + sn_sv *out); + +int parse_bugzilla_comments_array_only_first(gcli_ctx *ctx, + struct json_stream *stream, + sn_sv *out); + #endif /* GCLI_BUGZILLA_BUGS_H */ diff --git a/src/bugzilla/bugs.c b/src/bugzilla/bugs.c index 18e1c913..a5687e0b 100644 --- a/src/bugzilla/bugs.c +++ b/src/bugzilla/bugs.c @@ -122,6 +122,29 @@ parse_bugzilla_comments_array_skip_first(gcli_ctx *ctx, return 0; } +int +parse_bugzilla_comments_array_only_first(gcli_ctx *ctx, + struct json_stream *stream, + sn_sv *out) +{ + int rc = 0; + + if (json_next(stream) != JSON_ARRAY) + return gcli_error(ctx, "expected array for comments array"); + + rc = parse_bugzilla_comment_text(ctx, stream, out); + if (rc < 0) + return rc; + + while (json_peek(stream) != JSON_ARRAY_END) { + SKIP_OBJECT_VALUE(stream); + } + + if (json_next(stream) != JSON_ARRAY_END) + return gcli_error(ctx, "unexpected element in array while parsing"); + + return 0; +} int parse_bugzilla_bug_comments_dictionary_skip_first(gcli_ctx *const ctx, @@ -146,6 +169,29 @@ parse_bugzilla_bug_comments_dictionary_skip_first(gcli_ctx *const ctx, return rc; } +int +parse_bugzilla_bug_comments_dictionary_only_first(gcli_ctx *const ctx, + json_stream *stream, + sn_sv *out) +{ + enum json_type next = JSON_NULL; + int rc = 0; + + if ((next = json_next(stream)) != JSON_OBJECT) + return gcli_error(ctx, "expected bugzilla comments dictionary"); + + while ((next = json_next(stream)) == JSON_STRING) { + rc = parse_bugzilla_comments_internal_only_first(ctx, stream, out); + if (rc < 0) + return rc; + } + + if (next != JSON_OBJECT_END) + return gcli_error(ctx, "unclosed bugzilla comments dictionary"); + + return rc; +} + int bugzilla_bug_get_comments(gcli_ctx *const ctx, char const *const product, char const *const component, gcli_id const bug_id, @@ -178,6 +224,33 @@ bugzilla_bug_get_comments(gcli_ctx *const ctx, char const *const product, return rc; } +static int +bugzilla_bug_get_op(gcli_ctx *ctx, gcli_id const bug_id, sn_sv *out) +{ + int rc = 0; + gcli_fetch_buffer buffer = {0}; + json_stream stream = {0}; + char *url = NULL; + + url = sn_asprintf("%s/rest/bug/%"PRIid"/comment?include_fields=_all", + gcli_get_apibase(ctx), bug_id); + + rc = gcli_fetch(ctx, url, NULL, &buffer); + if (rc < 0) + goto error_fetch; + + json_open_buffer(&stream, buffer.data, buffer.length); + rc = parse_bugzilla_bug_op(ctx, &stream, out); + json_close(&stream); + + free(buffer.data); + +error_fetch: + free(url); + + return rc; +} + int bugzilla_get_bug(gcli_ctx *ctx, char const *product, char const *component, gcli_id bug_id, gcli_issue *out) @@ -218,6 +291,9 @@ bugzilla_get_bug(gcli_ctx *ctx, char const *product, char const *component, * just copied */ free(list.issues); + /* The OP is in the comments. Fetch it separately. */ + rc = bugzilla_bug_get_op(ctx, bug_id, &out->body); + error_no_such_bug: error_parse: json_close(&stream); diff --git a/templates/bugzilla/bugs.t b/templates/bugzilla/bugs.t index 129ca212..972c3d3b 100644 --- a/templates/bugzilla/bugs.t +++ b/templates/bugzilla/bugs.t @@ -32,3 +32,14 @@ object of gcli_comment_list with parser bugzilla_comments is object of gcli_comment_list with ("bugs" => use parse_bugzilla_bug_comments_dictionary_skip_first); + +parser bugzilla_comment_text is +object of sn_sv select "text" as sv; + +parser bugzilla_comments_internal_only_first is +object of sn_sv with + ("comments" => use parse_bugzilla_comments_array_only_first); + +parser bugzilla_bug_op is +object of sn_sv with + ("bugs" => use parse_bugzilla_bug_comments_dictionary_only_first); From ed033851dc4e94a3dbc4f079a9a7aa31f5c78aa5 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Sun, 10 Dec 2023 12:12:14 +0100 Subject: [PATCH 069/158] Fix bad forge type report in verbose mode I forgot to add a case for Bugzilla so it only printed: forge type is (null) --- src/cmd/cmdconfig.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cmd/cmdconfig.c b/src/cmd/cmdconfig.c index 0ee53402..35d5cfc2 100644 --- a/src/cmd/cmdconfig.c +++ b/src/cmd/cmdconfig.c @@ -882,8 +882,9 @@ gcli_config_get_forge_type(gcli_ctx *ctx) static char const *const ftype_name[] = { [GCLI_FORGE_GITHUB] = "GitHub", [GCLI_FORGE_GITLAB] = "Gitlab", - [GCLI_FORGE_GITEA] = "Gitea", - }; + [GCLI_FORGE_GITEA] = "Gitea", + [GCLI_FORGE_BUGZILLA] = "Bugzilla", + }; if (!have_printed_forge_type) { have_printed_forge_type = 1; From c1a67bf372178d9aef30ae44403b42d3adeb5d6a Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Sun, 10 Dec 2023 12:36:27 +0100 Subject: [PATCH 070/158] Add issue summary quirks These allow us to define which fields are available and valid per-forge. --- include/gcli/bugzilla/bugs.h | 4 ++-- include/gcli/forges.h | 7 +++++++ src/bugzilla/bugs.c | 6 +++--- src/cmd/issues.c | 9 +++++++-- src/forges.c | 5 +++++ templates/bugzilla/bugs.t | 6 +++--- 6 files changed, 27 insertions(+), 10 deletions(-) diff --git a/include/gcli/bugzilla/bugs.h b/include/gcli/bugzilla/bugs.h index d564cc36..ef51bf16 100644 --- a/include/gcli/bugzilla/bugs.h +++ b/include/gcli/bugzilla/bugs.h @@ -58,10 +58,10 @@ int parse_bugzilla_comments_array_skip_first(gcli_ctx *ctx, int parse_bugzilla_bug_comments_dictionary_only_first(gcli_ctx *const ctx, json_stream *stream, - sn_sv *out); + char **out); int parse_bugzilla_comments_array_only_first(gcli_ctx *ctx, struct json_stream *stream, - sn_sv *out); + char **out); #endif /* GCLI_BUGZILLA_BUGS_H */ diff --git a/include/gcli/forges.h b/include/gcli/forges.h index 8161eea4..9dccf6a1 100644 --- a/include/gcli/forges.h +++ b/include/gcli/forges.h @@ -176,6 +176,13 @@ struct gcli_forge_descriptor { gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue, char const *new_title); + /* Issue quirk bitmask */ + enum { + GCLI_ISSUE_QUIRKS_LOCKED = 0x1, + GCLI_ISSUE_QUIRKS_COMMENTS = 0x2, + GCLI_ISSUE_QUIRKS_PROD_COMP = 0x4, + } const issue_quirks; + /** * Bitmask of exceptions/fields that the forge doesn't support */ enum { diff --git a/src/bugzilla/bugs.c b/src/bugzilla/bugs.c index a5687e0b..88ac1284 100644 --- a/src/bugzilla/bugs.c +++ b/src/bugzilla/bugs.c @@ -125,7 +125,7 @@ parse_bugzilla_comments_array_skip_first(gcli_ctx *ctx, int parse_bugzilla_comments_array_only_first(gcli_ctx *ctx, struct json_stream *stream, - sn_sv *out) + char **out) { int rc = 0; @@ -172,7 +172,7 @@ parse_bugzilla_bug_comments_dictionary_skip_first(gcli_ctx *const ctx, int parse_bugzilla_bug_comments_dictionary_only_first(gcli_ctx *const ctx, json_stream *stream, - sn_sv *out) + char **out) { enum json_type next = JSON_NULL; int rc = 0; @@ -225,7 +225,7 @@ bugzilla_bug_get_comments(gcli_ctx *const ctx, char const *const product, } static int -bugzilla_bug_get_op(gcli_ctx *ctx, gcli_id const bug_id, sn_sv *out) +bugzilla_bug_get_op(gcli_ctx *ctx, gcli_id const bug_id, char **out) { int rc = 0; gcli_fetch_buffer buffer = {0}; diff --git a/src/cmd/issues.c b/src/cmd/issues.c index 994caf4a..325cb73d 100644 --- a/src/cmd/issues.c +++ b/src/cmd/issues.c @@ -36,6 +36,7 @@ #include #include +#include #include #include @@ -149,6 +150,7 @@ void gcli_issue_print_summary(gcli_issue const *const it) { gcli_dict dict; + uint32_t const quirks = gcli_forge(g_clictx)->issue_quirks; dict = gcli_dict_begin(); @@ -161,8 +163,11 @@ gcli_issue_print_summary(gcli_issue const *const it) gcli_dict_add(dict, "STATE", GCLI_TBLCOL_STATECOLOURED, 0, "%s", it->state); - gcli_dict_add(dict, "COMMENTS", 0, 0, "%d", it->comments); - gcli_dict_add(dict, "LOCKED", 0, 0, "%s", sn_bool_yesno(it->locked)); + if ((quirks & GCLI_ISSUE_QUIRKS_COMMENTS) == 0) + gcli_dict_add(dict, "COMMENTS", 0, 0, "%d", it->comments); + + if ((quirks & GCLI_ISSUE_QUIRKS_LOCKED) == 0) + gcli_dict_add(dict, "LOCKED", 0, 0, "%s", sn_bool_yesno(it->locked)); if (it->milestone) gcli_dict_add(dict, "MILESTONE", 0, 0, "%s", it->milestone); diff --git a/src/forges.c b/src/forges.c index f63927bb..644e5bd2 100644 --- a/src/forges.c +++ b/src/forges.c @@ -98,6 +98,7 @@ github_forge_descriptor = .issue_set_milestone = github_issue_set_milestone, .issue_set_title = github_issue_set_title, .perform_submit_issue = github_perform_submit_issue, + .issue_quirks = GCLI_ISSUE_QUIRKS_PROD_COMP, /* Milestones */ .create_milestone = github_create_milestone, @@ -190,6 +191,7 @@ gitlab_forge_descriptor = .issue_set_milestone = gitlab_issue_set_milestone, .issue_set_title = gitlab_issue_set_title, .perform_submit_issue = gitlab_perform_submit_issue, + .issue_quirks = GCLI_ISSUE_QUIRKS_PROD_COMP, /* Milestones */ .create_milestone = gitlab_create_milestone, @@ -279,6 +281,7 @@ gitea_forge_descriptor = .issue_set_milestone = gitea_issue_set_milestone, .issue_set_title = gitea_issue_set_title, .perform_submit_issue = gitea_submit_issue, + .issue_quirks = GCLI_ISSUE_QUIRKS_PROD_COMP, /* Milestones */ .create_milestone = gitea_create_milestone, @@ -353,6 +356,8 @@ bugzilla_forge_descriptor = .get_issues = bugzilla_get_bugs, .get_issue_summary = bugzilla_get_bug, .get_issue_comments = bugzilla_bug_get_comments, + .issue_quirks = GCLI_ISSUE_QUIRKS_COMMENTS + | GCLI_ISSUE_QUIRKS_LOCKED, /* Internal stuff */ .make_authheader = bugzilla_make_authheader, diff --git a/templates/bugzilla/bugs.t b/templates/bugzilla/bugs.t index 972c3d3b..bab75007 100644 --- a/templates/bugzilla/bugs.t +++ b/templates/bugzilla/bugs.t @@ -34,12 +34,12 @@ object of gcli_comment_list with ("bugs" => use parse_bugzilla_bug_comments_dictionary_skip_first); parser bugzilla_comment_text is -object of sn_sv select "text" as sv; +object of char* select "text" as string; parser bugzilla_comments_internal_only_first is -object of sn_sv with +object of char* with ("comments" => use parse_bugzilla_comments_array_only_first); parser bugzilla_bug_op is -object of sn_sv with +object of char* with ("bugs" => use parse_bugzilla_bug_comments_dictionary_only_first); From 9f338c62d96b801ee7af1edf0577d11ab73983be Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Sun, 10 Dec 2023 13:13:31 +0100 Subject: [PATCH 071/158] Add product/component fields for issues on Bugzilla --- include/gcli/issues.h | 2 ++ src/cmd/issues.c | 6 ++++++ src/issues.c | 3 ++- templates/bugzilla/bugs.t | 4 +++- tests/bugzilla-parse-tests.c | 2 ++ 5 files changed, 15 insertions(+), 2 deletions(-) diff --git a/include/gcli/issues.h b/include/gcli/issues.h index 89f8d29b..a5a71acd 100644 --- a/include/gcli/issues.h +++ b/include/gcli/issues.h @@ -47,6 +47,8 @@ typedef struct gcli_issue_fetch_details gcli_issue_fetch_details; struct gcli_issue { gcli_id number; char *title; + char *product; /* only on Bugzilla */ + char *component; /* only on Bugzilla */ char *created_at; char *author; char *state; diff --git a/src/cmd/issues.c b/src/cmd/issues.c index 325cb73d..e7e45fb3 100644 --- a/src/cmd/issues.c +++ b/src/cmd/issues.c @@ -158,6 +158,12 @@ gcli_issue_print_summary(gcli_issue const *const it) gcli_dict_add(dict, "TITLE", 0, 0, "%s", it->title); gcli_dict_add(dict, "CREATED", 0, 0, "%s", it->created_at); + + if ((quirks & GCLI_ISSUE_QUIRKS_PROD_COMP) == 0) { + gcli_dict_add(dict, "PRODUCT", 0, 0, "%s", it->product); + gcli_dict_add(dict, "COMPONENT", 0, 0, "%s", it->component); + } + gcli_dict_add(dict, "AUTHOR", GCLI_TBLCOL_BOLD, 0, "%s", it->author); gcli_dict_add(dict, "STATE", GCLI_TBLCOL_STATECOLOURED, 0, diff --git a/src/issues.c b/src/issues.c index 7e2f6cee..0653c1ed 100644 --- a/src/issues.c +++ b/src/issues.c @@ -36,7 +36,8 @@ void gcli_issue_free(gcli_issue *const it) { - free(it->title); + free(it->product); + free(it->component); free(it->created_at); free(it->author); free(it->state); diff --git a/templates/bugzilla/bugs.t b/templates/bugzilla/bugs.t index bab75007..2b2f3763 100644 --- a/templates/bugzilla/bugs.t +++ b/templates/bugzilla/bugs.t @@ -12,7 +12,9 @@ object of gcli_issue with "summary" => title as string, "creation_time" => created_at as string, "creator_detail" => use parse_bugzilla_bug_creator, - "status" => state as string); + "status" => state as string, + "product" => product as string, + "component" => component as string); parser bugzilla_bugs is object of gcli_issue_list with diff --git a/tests/bugzilla-parse-tests.c b/tests/bugzilla-parse-tests.c index eb9dde15..870f031d 100644 --- a/tests/bugzilla-parse-tests.c +++ b/tests/bugzilla-parse-tests.c @@ -90,6 +90,8 @@ ATF_TC_BODY(simple_bugzilla_issue, tc) ATF_CHECK_STREQ(issue->created_at, "1994-09-14T09:10:01Z"); ATF_CHECK_STREQ(issue->author, "Dave Evans"); ATF_CHECK_STREQ(issue->state, "Closed"); + ATF_CHECK_STREQ(issue->product, "Base System"); + ATF_CHECK_STREQ(issue->component, "kern"); json_close(&stream); gcli_destroy(&ctx); From 4b030647e72e06c214bfbe461f5246282fd1b4fa Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Sun, 10 Dec 2023 13:02:14 +0100 Subject: [PATCH 072/158] Parse assignees for Bugzilla issues This one required some indirection because on Bugzilla a ticket can only have one assignee. --- include/gcli/bugzilla/bugs.h | 3 +++ src/bugzilla/bugs.c | 10 ++++++++++ templates/bugzilla/bugs.t | 10 +++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/include/gcli/bugzilla/bugs.h b/include/gcli/bugzilla/bugs.h index ef51bf16..234c52d6 100644 --- a/include/gcli/bugzilla/bugs.h +++ b/include/gcli/bugzilla/bugs.h @@ -64,4 +64,7 @@ int parse_bugzilla_comments_array_only_first(gcli_ctx *ctx, struct json_stream *stream, char **out); +int parse_bugzilla_assignee(gcli_ctx *ctx, struct json_stream *stream, + gcli_issue *out); + #endif /* GCLI_BUGZILLA_BUGS_H */ diff --git a/src/bugzilla/bugs.c b/src/bugzilla/bugs.c index 88ac1284..88edb1d3 100644 --- a/src/bugzilla/bugs.c +++ b/src/bugzilla/bugs.c @@ -304,3 +304,13 @@ bugzilla_get_bug(gcli_ctx *ctx, char const *product, char const *component, return rc; } + +int +parse_bugzilla_assignee(gcli_ctx *ctx, struct json_stream *stream, + gcli_issue *out) +{ + out->assignees = calloc(1, sizeof (*out->assignees)); + out->assignees_size = 1; + + return get_string(ctx, stream, out->assignees); +} diff --git a/templates/bugzilla/bugs.t b/templates/bugzilla/bugs.t index 2b2f3763..7f4396ea 100644 --- a/templates/bugzilla/bugs.t +++ b/templates/bugzilla/bugs.t @@ -6,6 +6,10 @@ parser bugzilla_bug_creator is object of gcli_issue with ("real_name" => author as string); +parser bugzilla_assigned_to_detail is +object of gcli_issue with + ("name" => use parse_bugzilla_assignee); + parser bugzilla_bug_item is object of gcli_issue with ("id" => number as id, @@ -14,7 +18,11 @@ object of gcli_issue with "creator_detail" => use parse_bugzilla_bug_creator, "status" => state as string, "product" => product as string, - "component" => component as string); + "component" => component as string, + "status" => state as string, + "product" => product as string, + "component" => component as string, + "assigned_to_detail" => use parse_bugzilla_assigned_to_detail); parser bugzilla_bugs is object of gcli_issue_list with From 7a45ebf9ef4319be98416058a0f4b09e8f7f2803 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Sun, 10 Dec 2023 13:03:47 +0100 Subject: [PATCH 073/158] Add a URL field to gcli_issues Also add a quirk for forges that don't supply this field. --- include/gcli/forges.h | 1 + include/gcli/issues.h | 1 + src/cmd/issues.c | 3 +++ src/forges.c | 9 ++++++--- src/issues.c | 1 + templates/bugzilla/bugs.t | 3 ++- 6 files changed, 14 insertions(+), 4 deletions(-) diff --git a/include/gcli/forges.h b/include/gcli/forges.h index 9dccf6a1..b84d5eb6 100644 --- a/include/gcli/forges.h +++ b/include/gcli/forges.h @@ -181,6 +181,7 @@ struct gcli_forge_descriptor { GCLI_ISSUE_QUIRKS_LOCKED = 0x1, GCLI_ISSUE_QUIRKS_COMMENTS = 0x2, GCLI_ISSUE_QUIRKS_PROD_COMP = 0x4, + GCLI_ISSUE_QUIRKS_URL = 0x8, } const issue_quirks; /** diff --git a/include/gcli/issues.h b/include/gcli/issues.h index a5a71acd..e2175989 100644 --- a/include/gcli/issues.h +++ b/include/gcli/issues.h @@ -49,6 +49,7 @@ struct gcli_issue { char *title; char *product; /* only on Bugzilla */ char *component; /* only on Bugzilla */ + char *url; /* only on Bugzilla */ char *created_at; char *author; char *state; diff --git a/src/cmd/issues.c b/src/cmd/issues.c index e7e45fb3..e6a26192 100644 --- a/src/cmd/issues.c +++ b/src/cmd/issues.c @@ -169,6 +169,9 @@ gcli_issue_print_summary(gcli_issue const *const it) gcli_dict_add(dict, "STATE", GCLI_TBLCOL_STATECOLOURED, 0, "%s", it->state); + if ((quirks & GCLI_ISSUE_QUIRKS_URL) == 0 && it->url) + gcli_dict_add(dict, "URL", 0, 0, "%s", it->url); + if ((quirks & GCLI_ISSUE_QUIRKS_COMMENTS) == 0) gcli_dict_add(dict, "COMMENTS", 0, 0, "%d", it->comments); diff --git a/src/forges.c b/src/forges.c index 644e5bd2..51daac14 100644 --- a/src/forges.c +++ b/src/forges.c @@ -98,7 +98,8 @@ github_forge_descriptor = .issue_set_milestone = github_issue_set_milestone, .issue_set_title = github_issue_set_title, .perform_submit_issue = github_perform_submit_issue, - .issue_quirks = GCLI_ISSUE_QUIRKS_PROD_COMP, + .issue_quirks = GCLI_ISSUE_QUIRKS_PROD_COMP + | GCLI_ISSUE_QUIRKS_URL, /* Milestones */ .create_milestone = github_create_milestone, @@ -191,7 +192,8 @@ gitlab_forge_descriptor = .issue_set_milestone = gitlab_issue_set_milestone, .issue_set_title = gitlab_issue_set_title, .perform_submit_issue = gitlab_perform_submit_issue, - .issue_quirks = GCLI_ISSUE_QUIRKS_PROD_COMP, + .issue_quirks = GCLI_ISSUE_QUIRKS_PROD_COMP + | GCLI_ISSUE_QUIRKS_URL, /* Milestones */ .create_milestone = gitlab_create_milestone, @@ -281,7 +283,8 @@ gitea_forge_descriptor = .issue_set_milestone = gitea_issue_set_milestone, .issue_set_title = gitea_issue_set_title, .perform_submit_issue = gitea_submit_issue, - .issue_quirks = GCLI_ISSUE_QUIRKS_PROD_COMP, + .issue_quirks = GCLI_ISSUE_QUIRKS_PROD_COMP + | GCLI_ISSUE_QUIRKS_URL, /* Milestones */ .create_milestone = gitea_create_milestone, diff --git a/src/issues.c b/src/issues.c index 0653c1ed..7c7d7d99 100644 --- a/src/issues.c +++ b/src/issues.c @@ -42,6 +42,7 @@ gcli_issue_free(gcli_issue *const it) free(it->author); free(it->state); free(it->body); + free(it->url); for (size_t i = 0; i < it->labels_size; ++i) free(it->labels[i]); diff --git a/templates/bugzilla/bugs.t b/templates/bugzilla/bugs.t index 7f4396ea..535758a8 100644 --- a/templates/bugzilla/bugs.t +++ b/templates/bugzilla/bugs.t @@ -22,7 +22,8 @@ object of gcli_issue with "status" => state as string, "product" => product as string, "component" => component as string, - "assigned_to_detail" => use parse_bugzilla_assigned_to_detail); + "assigned_to_detail" => use parse_bugzilla_assigned_to_detail, + "url" => url as string); parser bugzilla_bugs is object of gcli_issue_list with From 4c420eb53fdda4b7308d398d637bd60d3920648d Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Sun, 10 Dec 2023 13:43:52 +0100 Subject: [PATCH 074/158] Add attachment list and dispatch points for them --- include/gcli/bugzilla/bugs.h | 5 +++++ include/gcli/forges.h | 15 +++++++++++---- include/gcli/issues.h | 23 +++++++++++++++++++++++ src/bugzilla/bugs.c | 12 ++++++++++++ src/forges.c | 10 +++++++--- src/issues.c | 18 ++++++++++++++++++ 6 files changed, 76 insertions(+), 7 deletions(-) diff --git a/include/gcli/bugzilla/bugs.h b/include/gcli/bugzilla/bugs.h index 234c52d6..5384a1fb 100644 --- a/include/gcli/bugzilla/bugs.h +++ b/include/gcli/bugzilla/bugs.h @@ -48,6 +48,11 @@ int bugzilla_bug_get_comments(gcli_ctx *const ctx, char const *const product, char const *const component, gcli_id const bug_id, gcli_comment_list *out); +int bugzilla_bug_get_attachments(gcli_ctx *ctx, char const *const product, + char const *const component, + gcli_id const bug_id, + gcli_attachment_list *const out); + int parse_bugzilla_bug_comments_dictionary_skip_first(gcli_ctx *const ctx, json_stream *stream, gcli_comment_list *out); diff --git a/include/gcli/forges.h b/include/gcli/forges.h index b84d5eb6..8cab3c82 100644 --- a/include/gcli/forges.h +++ b/include/gcli/forges.h @@ -176,12 +176,19 @@ struct gcli_forge_descriptor { gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue, char const *new_title); + /** + * Get attachments of an issue */ + int (*get_issue_attachments)( + gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue, + gcli_attachment_list *out); + /* Issue quirk bitmask */ enum { - GCLI_ISSUE_QUIRKS_LOCKED = 0x1, - GCLI_ISSUE_QUIRKS_COMMENTS = 0x2, - GCLI_ISSUE_QUIRKS_PROD_COMP = 0x4, - GCLI_ISSUE_QUIRKS_URL = 0x8, + GCLI_ISSUE_QUIRKS_LOCKED = 0x1, + GCLI_ISSUE_QUIRKS_COMMENTS = 0x2, + GCLI_ISSUE_QUIRKS_PROD_COMP = 0x4, + GCLI_ISSUE_QUIRKS_URL = 0x8, + GCLI_ISSUE_QUIRKS_ATTACHMENTS = 0x10, } const issue_quirks; /** diff --git a/include/gcli/issues.h b/include/gcli/issues.h index e2175989..907ef1ca 100644 --- a/include/gcli/issues.h +++ b/include/gcli/issues.h @@ -43,6 +43,8 @@ typedef struct gcli_issue gcli_issue; typedef struct gcli_submit_issue_options gcli_submit_issue_options; typedef struct gcli_issue_list gcli_issue_list; typedef struct gcli_issue_fetch_details gcli_issue_fetch_details; +typedef struct gcli_attachment gcli_attachment; +typedef struct gcli_attachment_list gcli_attachment_list; struct gcli_issue { gcli_id number; @@ -65,6 +67,23 @@ struct gcli_issue { char *milestone; }; +struct gcli_attachment { + gcli_id id; + char *created_at; + char *author; + char *file_name; + char *summary; + char *content_type; + + uint8_t *data; + size_t data_size; +}; + +struct gcli_attachment_list { + gcli_attachment *attachments; + size_t attachments_size; +}; + struct gcli_submit_issue_options { char const *owner; char const *repo; @@ -123,4 +142,8 @@ int gcli_issue_clear_milestone(gcli_ctx *cxt, char const *owner, int gcli_issue_set_title(gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue, char const *new_title); +int gcli_issue_get_attachments(gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id issue, + gcli_attachment_list *attachments); + #endif /* ISSUES_H */ diff --git a/src/bugzilla/bugs.c b/src/bugzilla/bugs.c index 88edb1d3..0661c434 100644 --- a/src/bugzilla/bugs.c +++ b/src/bugzilla/bugs.c @@ -314,3 +314,15 @@ parse_bugzilla_assignee(gcli_ctx *ctx, struct json_stream *stream, return get_string(ctx, stream, out->assignees); } + +int +bugzilla_bug_get_attachments(gcli_ctx *ctx, char const *const product, + char const *const component, gcli_id const bug_id, + gcli_attachment_list *const out) +{ + (void) product; + (void) component; + (void) bug_id; + (void) out; + return gcli_error(ctx, "not yet implemented"); +} diff --git a/src/forges.c b/src/forges.c index 51daac14..7c603393 100644 --- a/src/forges.c +++ b/src/forges.c @@ -99,7 +99,8 @@ github_forge_descriptor = .issue_set_title = github_issue_set_title, .perform_submit_issue = github_perform_submit_issue, .issue_quirks = GCLI_ISSUE_QUIRKS_PROD_COMP - | GCLI_ISSUE_QUIRKS_URL, + | GCLI_ISSUE_QUIRKS_URL + | GCLI_ISSUE_QUIRKS_ATTACHMENTS, /* Milestones */ .create_milestone = github_create_milestone, @@ -193,7 +194,8 @@ gitlab_forge_descriptor = .issue_set_title = gitlab_issue_set_title, .perform_submit_issue = gitlab_perform_submit_issue, .issue_quirks = GCLI_ISSUE_QUIRKS_PROD_COMP - | GCLI_ISSUE_QUIRKS_URL, + | GCLI_ISSUE_QUIRKS_URL + | GCLI_ISSUE_QUIRKS_ATTACHMENTS, /* Milestones */ .create_milestone = gitlab_create_milestone, @@ -284,7 +286,8 @@ gitea_forge_descriptor = .issue_set_title = gitea_issue_set_title, .perform_submit_issue = gitea_submit_issue, .issue_quirks = GCLI_ISSUE_QUIRKS_PROD_COMP - | GCLI_ISSUE_QUIRKS_URL, + | GCLI_ISSUE_QUIRKS_URL + | GCLI_ISSUE_QUIRKS_ATTACHMENTS, /* Milestones */ .create_milestone = gitea_create_milestone, @@ -359,6 +362,7 @@ bugzilla_forge_descriptor = .get_issues = bugzilla_get_bugs, .get_issue_summary = bugzilla_get_bug, .get_issue_comments = bugzilla_bug_get_comments, + .get_issue_attachments = bugzilla_bug_get_attachments, .issue_quirks = GCLI_ISSUE_QUIRKS_COMMENTS | GCLI_ISSUE_QUIRKS_LOCKED, diff --git a/src/issues.c b/src/issues.c index 7c7d7d99..21a367c8 100644 --- a/src/issues.c +++ b/src/issues.c @@ -157,3 +157,21 @@ gcli_issue_set_title(gcli_ctx *ctx, char const *owner, char const *repo, new_title); } +int +gcli_issue_get_attachments(gcli_ctx *ctx, char const *owner, char const *repo, + gcli_id issue, gcli_attachment_list *out) +{ + gcli_forge_descriptor const *const forge = + gcli_forge(ctx); + + bool const avail = + (forge->issue_quirks & GCLI_ISSUE_QUIRKS_ATTACHMENTS) && + (forge->get_issue_attachments != NULL); + + if (avail) { + return gcli_error(ctx, "attachments are not available on this forge"); + } else { + return gcli_forge(ctx)->get_issue_attachments(ctx, owner, repo, + issue, out); + } +} From 91f85a02ddae05231df29893b2ddb10e81192e16 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Sun, 10 Dec 2023 13:49:47 +0100 Subject: [PATCH 075/158] Add free routines for attachments --- include/gcli/issues.h | 3 +++ src/issues.c | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/include/gcli/issues.h b/include/gcli/issues.h index 907ef1ca..29bddf95 100644 --- a/include/gcli/issues.h +++ b/include/gcli/issues.h @@ -146,4 +146,7 @@ int gcli_issue_get_attachments(gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue, gcli_attachment_list *attachments); +void gcli_attachments_free(gcli_attachment_list *list); +void gcli_attachment_free(gcli_attachment *attachment); + #endif /* ISSUES_H */ diff --git a/src/issues.c b/src/issues.c index 21a367c8..4346a900 100644 --- a/src/issues.c +++ b/src/issues.c @@ -175,3 +175,26 @@ gcli_issue_get_attachments(gcli_ctx *ctx, char const *owner, char const *repo, issue, out); } } + +void +gcli_attachments_free(gcli_attachment_list *list) +{ + for (size_t i = 0; i < list->attachments_size; ++i) { + gcli_attachment_free(&list->attachments[i]); + } + + free(list->attachments); + list->attachments = NULL; + list->attachments_size = 0; +} + +void +gcli_attachment_free(gcli_attachment *it) +{ + free(it->created_at); + free(it->author); + free(it->file_name); + free(it->summary); + free(it->content_type); + free(it->data); +} From 45b409511c740d8f2178c7d79716791da2f735ad Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Sun, 10 Dec 2023 13:50:57 +0100 Subject: [PATCH 076/158] Add attachments action to issues subcommand --- src/cmd/issues.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/cmd/issues.c b/src/cmd/issues.c index e6a26192..a55a73ea 100644 --- a/src/cmd/issues.c +++ b/src/cmd/issues.c @@ -659,6 +659,18 @@ handle_issues_actions(int argc, char *argv[], gcli_get_error(g_clictx)); } + } else if (strcmp("attachments", operation) == 0) { + + gcli_attachment_list list = {0}; + int rc = gcli_issue_get_attachments(g_clictx, owner, repo, issue_id, + &list); + if (rc < 0) { + errx(1, "error: failed to fetch attachments: %s", + gcli_get_error(g_clictx)); + } + + gcli_attachments_free(&list); + } else { fprintf(stderr, "gcli: error: unknown operation %s\n", operation); usage(); From 0d3e53313720a69ee7a6e11102a8be19c8e4762c Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Sun, 10 Dec 2023 14:01:47 +0100 Subject: [PATCH 077/158] Implement parsing bug attachments on bugzilla --- include/gcli/bugzilla/bugs.h | 3 +++ src/bugzilla/bugs.c | 50 +++++++++++++++++++++++++++++++++--- templates/bugzilla/bugs.t | 15 +++++++++++ 3 files changed, 65 insertions(+), 3 deletions(-) diff --git a/include/gcli/bugzilla/bugs.h b/include/gcli/bugzilla/bugs.h index 5384a1fb..6d0e3975 100644 --- a/include/gcli/bugzilla/bugs.h +++ b/include/gcli/bugzilla/bugs.h @@ -72,4 +72,7 @@ int parse_bugzilla_comments_array_only_first(gcli_ctx *ctx, int parse_bugzilla_assignee(gcli_ctx *ctx, struct json_stream *stream, gcli_issue *out); +int parse_bugzilla_bug_attachments_dict(gcli_ctx *ctx, json_stream *stream, + gcli_attachment_list *out); + #endif /* GCLI_BUGZILLA_BUGS_H */ diff --git a/src/bugzilla/bugs.c b/src/bugzilla/bugs.c index 0661c434..a41032c2 100644 --- a/src/bugzilla/bugs.c +++ b/src/bugzilla/bugs.c @@ -320,9 +320,53 @@ bugzilla_bug_get_attachments(gcli_ctx *ctx, char const *const product, char const *const component, gcli_id const bug_id, gcli_attachment_list *const out) { + int rc = 0; + char *url = NULL; + gcli_fetch_buffer buffer = {0}; + json_stream stream = {0}; + (void) product; (void) component; - (void) bug_id; - (void) out; - return gcli_error(ctx, "not yet implemented"); + + url = sn_asprintf("%s/rest/bug/%"PRIid"/attachment", + gcli_get_apibase(ctx), bug_id); + + rc = gcli_fetch(ctx, url, NULL, &buffer); + if (rc < 0) + goto error_fetch; + + json_open_buffer(&stream, buffer.data, buffer.length); + rc = parse_bugzilla_bug_attachments(ctx, &stream, out); + json_close(&stream); + + free(buffer.data); + +error_fetch: + free(url); + + return rc; +} + +int +parse_bugzilla_bug_attachments_dict(gcli_ctx *ctx, json_stream *stream, + gcli_attachment_list *out) +{ + enum json_type next = JSON_NULL; + int rc = 0; + + if ((next = json_next(stream)) != JSON_OBJECT) + return gcli_error(ctx, "expected bugzilla attachments dictionary"); + + while ((next = json_next(stream)) == JSON_STRING) { + rc = parse_bugzilla_bug_attachments_internal(ctx, stream, + &out->attachments, + &out->attachments_size); + if (rc < 0) + return rc; + } + + if (next != JSON_OBJECT_END) + return gcli_error(ctx, "unclosed bugzilla attachments dictionary"); + + return rc; } diff --git a/templates/bugzilla/bugs.t b/templates/bugzilla/bugs.t index 535758a8..e03ec946 100644 --- a/templates/bugzilla/bugs.t +++ b/templates/bugzilla/bugs.t @@ -54,3 +54,18 @@ object of char* with parser bugzilla_bug_op is object of char* with ("bugs" => use parse_bugzilla_bug_comments_dictionary_only_first); + +parser bugzilla_bug_attachments is +object of gcli_attachment_list with + ("bugs" => use parse_bugzilla_bug_attachments_dict); + +parser bugzilla_bug_attachment is +object of gcli_attachment with + ("id" => id as id, + "summary" => summary as string, + "file_name" => file_name as string, + "creation_time" => created_at as string, + "creator" => author as string); + +parser bugzilla_bug_attachments_internal is +array of gcli_attachment use parse_bugzilla_bug_attachment; From bd7c50dcc6403458f6fb8f551823128644b7f645 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Sun, 10 Dec 2023 16:05:58 +0100 Subject: [PATCH 078/158] Bugzilla: Move bugs parser helpers to separate compilation unit --- Makefile.am | 1 + include/gcli/bugzilla/bugs-parser.h | 63 +++++++++++ include/gcli/bugzilla/bugs.h | 22 ---- src/bugzilla/bugs-parser.c | 166 ++++++++++++++++++++++++++++ src/bugzilla/bugs.c | 131 ---------------------- templates/bugzilla/bugs.t | 1 + 6 files changed, 231 insertions(+), 153 deletions(-) create mode 100644 include/gcli/bugzilla/bugs-parser.h create mode 100644 src/bugzilla/bugs-parser.c diff --git a/Makefile.am b/Makefile.am index ca39747b..27c2760b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -193,6 +193,7 @@ libgcli_la_SOURCES = \ src/gitea/milestones.c include/gcli/gitea/milestones.h \ src/bugzilla/api.c include/gcli/bugzilla/api.h \ src/bugzilla/bugs.c include/gcli/bugzilla/bugs.h \ + src/bugzilla/bugs-parser.c include/gcli/bugzilla/bugs-parser.h \ src/bugzilla/config.c include/gcli/bugzilla/config.h \ $(TEMPLATES) diff --git a/include/gcli/bugzilla/bugs-parser.h b/include/gcli/bugzilla/bugs-parser.h new file mode 100644 index 00000000..23f4b1c8 --- /dev/null +++ b/include/gcli/bugzilla/bugs-parser.h @@ -0,0 +1,63 @@ +/* + * Copyright 2023 Nico Sonack + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef GCLI_BUGZILLA_BUGS_PARSER_H +#define GCLI_BUGZILLA_BUGS_PARSER_H + +#include + +#include +#include +#include + +#include + +int parse_bugzilla_bug_comments_dictionary_skip_first(gcli_ctx *const ctx, + json_stream *stream, + gcli_comment_list *out); + +int parse_bugzilla_comments_array_skip_first(gcli_ctx *ctx, + struct json_stream *stream, + gcli_comment_list *out); + +int parse_bugzilla_bug_comments_dictionary_only_first(gcli_ctx *const ctx, + json_stream *stream, + char **out); + +int parse_bugzilla_comments_array_only_first(gcli_ctx *ctx, + struct json_stream *stream, + char **out); + +int parse_bugzilla_assignee(gcli_ctx *ctx, struct json_stream *stream, + gcli_issue *out); + +int parse_bugzilla_bug_attachments_dict(gcli_ctx *ctx, json_stream *stream, + gcli_attachment_list *out); + +#endif /* GCLI_BUGZILLA_BUGS_PARSER_H */ diff --git a/include/gcli/bugzilla/bugs.h b/include/gcli/bugzilla/bugs.h index 6d0e3975..5e2619db 100644 --- a/include/gcli/bugzilla/bugs.h +++ b/include/gcli/bugzilla/bugs.h @@ -53,26 +53,4 @@ int bugzilla_bug_get_attachments(gcli_ctx *ctx, char const *const product, gcli_id const bug_id, gcli_attachment_list *const out); -int parse_bugzilla_bug_comments_dictionary_skip_first(gcli_ctx *const ctx, - json_stream *stream, - gcli_comment_list *out); - -int parse_bugzilla_comments_array_skip_first(gcli_ctx *ctx, - struct json_stream *stream, - gcli_comment_list *out); - -int parse_bugzilla_bug_comments_dictionary_only_first(gcli_ctx *const ctx, - json_stream *stream, - char **out); - -int parse_bugzilla_comments_array_only_first(gcli_ctx *ctx, - struct json_stream *stream, - char **out); - -int parse_bugzilla_assignee(gcli_ctx *ctx, struct json_stream *stream, - gcli_issue *out); - -int parse_bugzilla_bug_attachments_dict(gcli_ctx *ctx, json_stream *stream, - gcli_attachment_list *out); - #endif /* GCLI_BUGZILLA_BUGS_H */ diff --git a/src/bugzilla/bugs-parser.c b/src/bugzilla/bugs-parser.c new file mode 100644 index 00000000..6bbf27b5 --- /dev/null +++ b/src/bugzilla/bugs-parser.c @@ -0,0 +1,166 @@ +/* + * Copyright 2023 Nico Sonack + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + /* Parser helpers for Bugzilla */ + +#include + +#include +#include + +#include + +int +parse_bugzilla_comments_array_skip_first(gcli_ctx *ctx, + struct json_stream *stream, + gcli_comment_list *out) +{ + int rc = 0; + + if (json_next(stream) != JSON_ARRAY) + return gcli_error(ctx, "expected array for comments array"); + + SKIP_OBJECT_VALUE(stream); + + while (json_peek(stream) != JSON_ARRAY_END) { + out->comments = realloc(out->comments, sizeof(*out->comments) * (out->comments_size + 1)); + memset(&out->comments[out->comments_size], 0, sizeof(out->comments[out->comments_size])); + rc = parse_bugzilla_comment(ctx, stream, &out->comments[out->comments_size++]); + if (rc < 0) + return rc; + } + + if (json_next(stream) != JSON_ARRAY_END) + return gcli_error(ctx, "unexpected element in array while parsing"); + + return 0; +} + +int +parse_bugzilla_comments_array_only_first(gcli_ctx *ctx, + struct json_stream *stream, char **out) +{ + int rc = 0; + + if (json_next(stream) != JSON_ARRAY) + return gcli_error(ctx, "expected array for comments array"); + + rc = parse_bugzilla_comment_text(ctx, stream, out); + if (rc < 0) + return rc; + + while (json_peek(stream) != JSON_ARRAY_END) { + SKIP_OBJECT_VALUE(stream); + } + + if (json_next(stream) != JSON_ARRAY_END) + return gcli_error(ctx, "unexpected element in array while parsing"); + + return 0; +} + +int +parse_bugzilla_bug_comments_dictionary_skip_first(gcli_ctx *const ctx, + json_stream *stream, + gcli_comment_list *out) +{ + enum json_type next = JSON_NULL; + int rc = 0; + + if ((next = json_next(stream)) != JSON_OBJECT) + return gcli_error(ctx, "expected bugzilla comments dictionary"); + + while ((next = json_next(stream)) == JSON_STRING) { + rc = parse_bugzilla_comments_internal_skip_first(ctx, stream, out); + if (rc < 0) + return rc; + } + + if (next != JSON_OBJECT_END) + return gcli_error(ctx, "unclosed bugzilla comments dictionary"); + + return rc; +} + +int +parse_bugzilla_bug_comments_dictionary_only_first(gcli_ctx *const ctx, + json_stream *stream, + char **out) +{ + enum json_type next = JSON_NULL; + int rc = 0; + + if ((next = json_next(stream)) != JSON_OBJECT) + return gcli_error(ctx, "expected bugzilla comments dictionary"); + + while ((next = json_next(stream)) == JSON_STRING) { + rc = parse_bugzilla_comments_internal_only_first(ctx, stream, out); + if (rc < 0) + return rc; + } + + if (next != JSON_OBJECT_END) + return gcli_error(ctx, "unclosed bugzilla comments dictionary"); + + return rc; +} + +int +parse_bugzilla_assignee(gcli_ctx *ctx, struct json_stream *stream, + gcli_issue *out) +{ + out->assignees = calloc(1, sizeof (*out->assignees)); + out->assignees_size = 1; + + return get_string(ctx, stream, out->assignees); +} + +int +parse_bugzilla_bug_attachments_dict(gcli_ctx *ctx, json_stream *stream, + gcli_attachment_list *out) +{ + enum json_type next = JSON_NULL; + int rc = 0; + + if ((next = json_next(stream)) != JSON_OBJECT) + return gcli_error(ctx, "expected bugzilla attachments dictionary"); + + while ((next = json_next(stream)) == JSON_STRING) { + rc = parse_bugzilla_bug_attachments_internal(ctx, stream, + &out->attachments, + &out->attachments_size); + if (rc < 0) + return rc; + } + + if (next != JSON_OBJECT_END) + return gcli_error(ctx, "unclosed bugzilla attachments dictionary"); + + return rc; +} diff --git a/src/bugzilla/bugs.c b/src/bugzilla/bugs.c index a41032c2..96a5d68a 100644 --- a/src/bugzilla/bugs.c +++ b/src/bugzilla/bugs.c @@ -34,7 +34,6 @@ #include #include -#include #include @@ -96,102 +95,6 @@ bugzilla_get_bugs(gcli_ctx *ctx, char const *product, char const *component, return rc; } -int -parse_bugzilla_comments_array_skip_first(gcli_ctx *ctx, - struct json_stream *stream, - gcli_comment_list *out) -{ - int rc = 0; - - if (json_next(stream) != JSON_ARRAY) - return gcli_error(ctx, "expected array for comments array"); - - SKIP_OBJECT_VALUE(stream); - - while (json_peek(stream) != JSON_ARRAY_END) { - out->comments = realloc(out->comments, sizeof(*out->comments) * (out->comments_size + 1)); - memset(&out->comments[out->comments_size], 0, sizeof(out->comments[out->comments_size])); - rc = parse_bugzilla_comment(ctx, stream, &out->comments[out->comments_size++]); - if (rc < 0) - return rc; - } - - if (json_next(stream) != JSON_ARRAY_END) - return gcli_error(ctx, "unexpected element in array while parsing"); - - return 0; -} - -int -parse_bugzilla_comments_array_only_first(gcli_ctx *ctx, - struct json_stream *stream, - char **out) -{ - int rc = 0; - - if (json_next(stream) != JSON_ARRAY) - return gcli_error(ctx, "expected array for comments array"); - - rc = parse_bugzilla_comment_text(ctx, stream, out); - if (rc < 0) - return rc; - - while (json_peek(stream) != JSON_ARRAY_END) { - SKIP_OBJECT_VALUE(stream); - } - - if (json_next(stream) != JSON_ARRAY_END) - return gcli_error(ctx, "unexpected element in array while parsing"); - - return 0; -} - -int -parse_bugzilla_bug_comments_dictionary_skip_first(gcli_ctx *const ctx, - json_stream *stream, - gcli_comment_list *out) -{ - enum json_type next = JSON_NULL; - int rc = 0; - - if ((next = json_next(stream)) != JSON_OBJECT) - return gcli_error(ctx, "expected bugzilla comments dictionary"); - - while ((next = json_next(stream)) == JSON_STRING) { - rc = parse_bugzilla_comments_internal_skip_first(ctx, stream, out); - if (rc < 0) - return rc; - } - - if (next != JSON_OBJECT_END) - return gcli_error(ctx, "unclosed bugzilla comments dictionary"); - - return rc; -} - -int -parse_bugzilla_bug_comments_dictionary_only_first(gcli_ctx *const ctx, - json_stream *stream, - char **out) -{ - enum json_type next = JSON_NULL; - int rc = 0; - - if ((next = json_next(stream)) != JSON_OBJECT) - return gcli_error(ctx, "expected bugzilla comments dictionary"); - - while ((next = json_next(stream)) == JSON_STRING) { - rc = parse_bugzilla_comments_internal_only_first(ctx, stream, out); - if (rc < 0) - return rc; - } - - if (next != JSON_OBJECT_END) - return gcli_error(ctx, "unclosed bugzilla comments dictionary"); - - return rc; -} - int bugzilla_bug_get_comments(gcli_ctx *const ctx, char const *const product, char const *const component, gcli_id const bug_id, @@ -305,16 +208,6 @@ bugzilla_get_bug(gcli_ctx *ctx, char const *product, char const *component, return rc; } -int -parse_bugzilla_assignee(gcli_ctx *ctx, struct json_stream *stream, - gcli_issue *out) -{ - out->assignees = calloc(1, sizeof (*out->assignees)); - out->assignees_size = 1; - - return get_string(ctx, stream, out->assignees); -} - int bugzilla_bug_get_attachments(gcli_ctx *ctx, char const *const product, char const *const component, gcli_id const bug_id, @@ -346,27 +239,3 @@ bugzilla_bug_get_attachments(gcli_ctx *ctx, char const *const product, return rc; } - -int -parse_bugzilla_bug_attachments_dict(gcli_ctx *ctx, json_stream *stream, - gcli_attachment_list *out) -{ - enum json_type next = JSON_NULL; - int rc = 0; - - if ((next = json_next(stream)) != JSON_OBJECT) - return gcli_error(ctx, "expected bugzilla attachments dictionary"); - - while ((next = json_next(stream)) == JSON_STRING) { - rc = parse_bugzilla_bug_attachments_internal(ctx, stream, - &out->attachments, - &out->attachments_size); - if (rc < 0) - return rc; - } - - if (next != JSON_OBJECT_END) - return gcli_error(ctx, "unclosed bugzilla attachments dictionary"); - - return rc; -} diff --git a/templates/bugzilla/bugs.t b/templates/bugzilla/bugs.t index e03ec946..6e4ebe2f 100644 --- a/templates/bugzilla/bugs.t +++ b/templates/bugzilla/bugs.t @@ -1,6 +1,7 @@ include "gcli/comments.h"; include "gcli/issues.h"; include "gcli/bugzilla/bugs.h"; +include "gcli/bugzilla/bugs-parser.h"; parser bugzilla_bug_creator is object of gcli_issue with From 080005c0db9c5c7874a72ab14374b8f5683e023b Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Sun, 10 Dec 2023 16:18:06 +0100 Subject: [PATCH 079/158] Implement printing bug attachments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This adds a new »attachments« action that prints the list of attachments. --- src/cmd/issues.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/cmd/issues.c b/src/cmd/issues.c index a55a73ea..dad5a76c 100644 --- a/src/cmd/issues.c +++ b/src/cmd/issues.c @@ -571,6 +571,29 @@ handle_issue_milestone_action(int *argc, char ***argv, gcli_get_error(g_clictx)); } +static void +gcli_print_attachments(gcli_attachment_list const *const list) +{ + gcli_tbl tbl; + gcli_tblcoldef columns[] = { + { .name = "ID", .type = GCLI_TBLCOLTYPE_ID, .flags = GCLI_TBLCOL_JUSTIFYR }, + { .name = "AUTHOR", .type = GCLI_TBLCOLTYPE_STRING, .flags = GCLI_TBLCOL_BOLD }, + { .name = "CREATED", .type = GCLI_TBLCOLTYPE_STRING, .flags = 0 }, + { .name = "CONTENT", .type = GCLI_TBLCOLTYPE_STRING, .flags = 0 }, + { .name = "FILENAME", .type = GCLI_TBLCOLTYPE_STRING, .flags = 0 }, + }; + + tbl = gcli_tbl_begin(columns, ARRAY_SIZE(columns)); + + for (size_t i = 0; i < list->attachments_size; ++i) { + gcli_attachment const *const it = &list->attachments[i]; + gcli_tbl_add_row(tbl, it->id, it->author, it->created_at, + it->content_type, it->file_name); + } + + gcli_tbl_end(tbl); +} + static inline int handle_issues_actions(int argc, char *argv[], char const *const owner, @@ -669,6 +692,7 @@ handle_issues_actions(int argc, char *argv[], gcli_get_error(g_clictx)); } + gcli_print_attachments(&list); gcli_attachments_free(&list); } else { From 03a0cbf8bb2b47901d69c7e0f82b43bf5bf0b86e Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Sun, 10 Dec 2023 16:29:38 +0100 Subject: [PATCH 080/158] Add obsoleteness flag for attachments This tells the user whether this attachment has been superseded/obsoleted by another attachment or events. --- include/gcli/issues.h | 1 + include/gcli/json_util.h | 2 ++ src/cmd/issues.c | 3 ++- src/json_util.c | 18 ++++++++++++++++++ templates/bugzilla/bugs.t | 4 +++- 5 files changed, 26 insertions(+), 2 deletions(-) diff --git a/include/gcli/issues.h b/include/gcli/issues.h index 29bddf95..4bac8671 100644 --- a/include/gcli/issues.h +++ b/include/gcli/issues.h @@ -69,6 +69,7 @@ struct gcli_issue { struct gcli_attachment { gcli_id id; + bool is_obsolete; char *created_at; char *author; char *file_name; diff --git a/include/gcli/json_util.h b/include/gcli/json_util.h index 573e9c7d..208b39bc 100644 --- a/include/gcli/json_util.h +++ b/include/gcli/json_util.h @@ -49,6 +49,7 @@ #define get_double(ctx, input, out) get_double_(ctx, input, out, __func__) #define get_parse_int(ctx, input, out) get_parse_int_(ctx, input, out, __func__) #define get_bool(ctx, input, out) get_bool_(ctx, input, out, __func__) +#define get_bool_relaxed(ctx, input, out) get_bool_relaxed_(ctx, input, out, __func__) #define get_string(ctx, input, out) get_string_(ctx, input, out, __func__) #define get_sv(ctx, input, out) get_sv_(ctx, input, out, __func__) #define get_user(ctx, input, out) get_user_(ctx, input, out, __func__) @@ -63,6 +64,7 @@ int get_size_t_(gcli_ctx *ctx, json_stream *input, size_t *out, char const *func int get_double_(gcli_ctx *ctx, json_stream *input, double *out, char const *function); int get_parse_int_(gcli_ctx *ctx, json_stream *input, long *out, char const *function); int get_bool_(gcli_ctx *ctx, json_stream *input, bool *out, char const *function); +int get_bool_relaxed_(gcli_ctx *ctx, json_stream *input, bool *out, char const *function); int get_string_(gcli_ctx *ctx, json_stream *input, char **out, char const *function); int get_sv_(gcli_ctx *ctx, json_stream *input, sn_sv *out, char const *function); int get_user_(gcli_ctx *ctx, json_stream *input, char **out, char const *function); diff --git a/src/cmd/issues.c b/src/cmd/issues.c index dad5a76c..fbc8ef94 100644 --- a/src/cmd/issues.c +++ b/src/cmd/issues.c @@ -580,6 +580,7 @@ gcli_print_attachments(gcli_attachment_list const *const list) { .name = "AUTHOR", .type = GCLI_TBLCOLTYPE_STRING, .flags = GCLI_TBLCOL_BOLD }, { .name = "CREATED", .type = GCLI_TBLCOLTYPE_STRING, .flags = 0 }, { .name = "CONTENT", .type = GCLI_TBLCOLTYPE_STRING, .flags = 0 }, + { .name = "OBSOLETE", .type = GCLI_TBLCOLTYPE_BOOL, .flags = 0 }, { .name = "FILENAME", .type = GCLI_TBLCOLTYPE_STRING, .flags = 0 }, }; @@ -588,7 +589,7 @@ gcli_print_attachments(gcli_attachment_list const *const list) for (size_t i = 0; i < list->attachments_size; ++i) { gcli_attachment const *const it = &list->attachments[i]; gcli_tbl_add_row(tbl, it->id, it->author, it->created_at, - it->content_type, it->file_name); + it->content_type, it->is_obsolete, it->file_name); } gcli_tbl_end(tbl); diff --git a/src/json_util.c b/src/json_util.c index 62801757..c409c72a 100644 --- a/src/json_util.c +++ b/src/json_util.c @@ -138,6 +138,24 @@ get_bool_(gcli_ctx *ctx,json_stream *const input, bool *out, char const *where) return gcli_error(ctx, "unexpected non-boolean value in %s", where); } +int +get_bool_relaxed_(gcli_ctx *ctx,json_stream *const input, bool *out, char const *where) +{ + enum json_type value_type = json_next(input); + if (value_type == JSON_TRUE) { + *out = true; + return 0; + } else if (value_type == JSON_FALSE || value_type == JSON_NULL) { // HACK + *out = false; + return 0; + } else if (value_type == JSON_NUMBER) { + *out = json_get_number(input) != 0.0; + return 0; + } + + return gcli_error(ctx, "unexpected non-boolean value in %s", where); +} + int get_user_(gcli_ctx *ctx, json_stream *const input, char **out, char const *where) diff --git a/templates/bugzilla/bugs.t b/templates/bugzilla/bugs.t index 6e4ebe2f..66a23763 100644 --- a/templates/bugzilla/bugs.t +++ b/templates/bugzilla/bugs.t @@ -66,7 +66,9 @@ object of gcli_attachment with "summary" => summary as string, "file_name" => file_name as string, "creation_time" => created_at as string, - "creator" => author as string); + "creator" => author as string, + "content_type" => content_type as string, + "is_obsolete" => is_obsolete as bool_relaxed); parser bugzilla_bug_attachments_internal is array of gcli_attachment use parse_bugzilla_bug_attachment; From a3a05d58e04a81fa034b35fd2d820ecddaf603bf Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Sun, 10 Dec 2023 19:43:39 +0100 Subject: [PATCH 081/158] Add parse tests for bugzilla attachments These are missing checks for the data, however that is entirely unimplemented right now so the tests missing is fine in this case. These tests will have to be added once we have proper base64 decoding. --- tests/bugzilla-parse-tests.c | 44 ++++++++++++++++++ tests/samples/bugzilla_attachments.json | 59 +++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 tests/samples/bugzilla_attachments.json diff --git a/tests/bugzilla-parse-tests.c b/tests/bugzilla-parse-tests.c index 870f031d..c0627c5d 100644 --- a/tests/bugzilla-parse-tests.c +++ b/tests/bugzilla-parse-tests.c @@ -126,10 +126,54 @@ ATF_TC_BODY(bugzilla_comments, tc) gcli_destroy(&ctx); } +ATF_TC_WITHOUT_HEAD(bugzilla_attachments); +ATF_TC_BODY(bugzilla_attachments, tc) +{ + FILE *f = NULL; + gcli_attachment const *it; + gcli_attachment_list list = {0}; + gcli_ctx *ctx = test_context(); + json_stream stream = {0}; + + ATF_REQUIRE(f = open_sample("bugzilla_attachments.json")); + json_open_stream(&stream, f); + + ATF_REQUIRE(parse_bugzilla_bug_attachments(ctx, &stream, &list) == 0); + + ATF_CHECK(list.attachments_size == 2); + + it = list.attachments; + ATF_CHECK_EQ(it->id, 246131); + ATF_CHECK_EQ(it->is_obsolete, true); + ATF_CHECK_STREQ(it->author, "nsonack@outlook.com"); + ATF_CHECK_STREQ(it->content_type, "text/plain"); + ATF_CHECK_STREQ(it->created_at, "2023-11-04T20:19:11Z"); + ATF_CHECK_STREQ(it->file_name, "0001-devel-open62541-Update-to-version-1.3.8.patch"); + ATF_CHECK_STREQ(it->summary, "Patch for updating the port"); + + it++; + ATF_CHECK_EQ(it->id, 246910); + ATF_CHECK_EQ(it->is_obsolete, false); + ATF_CHECK_STREQ(it->author, "nsonack@outlook.com"); + ATF_CHECK_STREQ(it->content_type, "text/plain"); + ATF_CHECK_STREQ(it->created_at, "2023-12-08T17:10:06Z"); + ATF_CHECK_STREQ(it->file_name, "0001-devel-open62541-Update-to-version-1.3.8.patch"); + ATF_CHECK_STREQ(it->summary, "Patch v2 (now for version 1.3.9)"); + + gcli_attachments_free(&list); + + json_close(&stream); + fclose(f); + f = NULL; + + gcli_destroy(&ctx); +} + ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, simple_bugzilla_issue); ATF_TP_ADD_TC(tp, bugzilla_comments); + ATF_TP_ADD_TC(tp, bugzilla_attachments); return atf_no_error(); } diff --git a/tests/samples/bugzilla_attachments.json b/tests/samples/bugzilla_attachments.json new file mode 100644 index 00000000..f8981c09 --- /dev/null +++ b/tests/samples/bugzilla_attachments.json @@ -0,0 +1,59 @@ +{ + "attachments": {}, + "bugs": { + "274920": [ + { + "bug_id": 274920, + "creation_time": "2023-11-04T20:19:11Z", + "creator": "nsonack@outlook.com", + "size": 2290, + "data": "RnJvbSA0ZWFiYjEzNTU4YTY5YmQwYWJlYmExMmQ0YzBmNjA5YmY3NTFjZTMyIE1vbiBTZXAgMTcgMDA6MDA6MDAgMjAwMQpGcm9tOiBOaWNvIFNvbmFjayA8bnNvbmFja0BoZXJyaG90emVucGxvdHouZGU+CkRhdGU6IEZyaSwgMjcgT2N0IDIwMjMgMTY6MTY6MjEgKzAwMDAKU3ViamVjdDogW1BBVENIXSBkZXZlbC9vcGVuNjI1NDE6IFVwZGF0ZSB0byB2ZXJzaW9uIDEuMy44CgpSZW1vdmVzIHRoZSBwYXRjaCBhcyB0aGUgdXBzdHJlYW0gYnVnIHJlcG9ydCBoYXMgYmVlbiByZXNvbHZlZC4KU2VlIGh0dHBzOi8vZ2l0aHViLmNvbS9vcGVuNjI1NDEvb3BlbjYyNTQxL2lzc3Vlcy82MDEwCgpTaWduZWQtb2ZmLWJ5OiBOaWNvIFNvbmFjayA8bnNvbmFja0BoZXJyaG90emVucGxvdHouZGU+Ci0tLQogZGV2ZWwvb3BlbjYyNTQxL01ha2VmaWxlICAgICAgICAgICAgICAgICAgIHwgIDIgKy0KIGRldmVsL29wZW42MjU0MS9kaXN0aW5mbyAgICAgICAgICAgICAgICAgICB8ICA2ICsrKy0tLQogZGV2ZWwvb3BlbjYyNTQxL2ZpbGVzL3BhdGNoLUNNYWtlTGlzdHMudHh0IHwgMTEgLS0tLS0tLS0tLS0KIDMgZmlsZXMgY2hhbmdlZCwgNCBpbnNlcnRpb25zKCspLCAxNSBkZWxldGlvbnMoLSkKIGRlbGV0ZSBtb2RlIDEwMDY0NCBkZXZlbC9vcGVuNjI1NDEvZmlsZXMvcGF0Y2gtQ01ha2VMaXN0cy50eHQKCmRpZmYgLS1naXQgYS9kZXZlbC9vcGVuNjI1NDEvTWFrZWZpbGUgYi9kZXZlbC9vcGVuNjI1NDEvTWFrZWZpbGUKaW5kZXggYTY5MDg0ZWY5NzQzLi5mOTkzMWJhNTE3ZjUgMTAwNjQ0Ci0tLSBhL2RldmVsL29wZW42MjU0MS9NYWtlZmlsZQorKysgYi9kZXZlbC9vcGVuNjI1NDEvTWFrZWZpbGUKQEAgLTEsNiArMSw2IEBACiBQT1JUTkFNRT0Jb3BlbjYyNTQxCiBESVNUVkVSU0lPTlBSRUZJWD0JdgotRElTVFZFUlNJT049CTEuMy43CitESVNUVkVSU0lPTj0JMS4zLjgKIENBVEVHT1JJRVM9CWRldmVsCiAKIE1BSU5UQUlORVI9CW5zb25hY2tAb3V0bG9vay5jb20KZGlmZiAtLWdpdCBhL2RldmVsL29wZW42MjU0MS9kaXN0aW5mbyBiL2RldmVsL29wZW42MjU0MS9kaXN0aW5mbwppbmRleCAyMTQzNzIyMWU2YjEuLjQ5YzQ4YzVhNjE5MCAxMDA2NDQKLS0tIGEvZGV2ZWwvb3BlbjYyNTQxL2Rpc3RpbmZvCisrKyBiL2RldmVsL29wZW42MjU0MS9kaXN0aW5mbwpAQCAtMSwzICsxLDMgQEAKLVRJTUVTVEFNUCA9IDE2OTQ0MzYwNjAKLVNIQTI1NiAob3BlbjYyNTQxLW9wZW42MjU0MS12MS4zLjdfR0gwLnRhci5neikgPSBkM2Y4NGYxZTI2MzJjMTVhMzg5MmRjNmM4OWYwY2Q2YjQxMzdlOTkwYjhhZWY4ZmUyNDVjZDhlNzVmYmI1Mzg4Ci1TSVpFIChvcGVuNjI1NDEtb3BlbjYyNTQxLXYxLjMuN19HSDAudGFyLmd6KSA9IDM4NzEwNTcKK1RJTUVTVEFNUCA9IDE2OTg0MjI4MTYKK1NIQTI1NiAob3BlbjYyNTQxLW9wZW42MjU0MS12MS4zLjhfR0gwLnRhci5neikgPSBiNjk0M2I1NjQ3ODdjNDk1M2I3N2NhOGQ3Zjk4N2M0Yjg5NmIzZjNlOTFmNDVkOWYxM2U5MDU2YjYxNDhiYzFkCitTSVpFIChvcGVuNjI1NDEtb3BlbjYyNTQxLXYxLjMuOF9HSDAudGFyLmd6KSA9IDM4NzQxODUKZGlmZiAtLWdpdCBhL2RldmVsL29wZW42MjU0MS9maWxlcy9wYXRjaC1DTWFrZUxpc3RzLnR4dCBiL2RldmVsL29wZW42MjU0MS9maWxlcy9wYXRjaC1DTWFrZUxpc3RzLnR4dApkZWxldGVkIGZpbGUgbW9kZSAxMDA2NDQKaW5kZXggMzBhNmVmZmM3ZjcxLi4wMDAwMDAwMDAwMDAKLS0tIGEvZGV2ZWwvb3BlbjYyNTQxL2ZpbGVzL3BhdGNoLUNNYWtlTGlzdHMudHh0CisrKyAvZGV2L251bGwKQEAgLTEsMTEgKzAsMCBAQAotLS0tIENNYWtlTGlzdHMudHh0Lm9yaWcJMjAyMy0wOS0xMSAxMjo0NzowOCBVVEMKLSsrKyBDTWFrZUxpc3RzLnR4dAotQEAgLTQzLDcgKzQzLDcgQEAgc2V0KENNQUtFX0FSQ0hJVkVfT1VUUFVUX0RJUkVDVE9SWSAke0NNQUtFX0JJTkFSWV9ESVJ9Ci0gIyBvdmVyd3JpdHRlbiB3aXRoIG1vcmUgZGV0YWlsZWQgaW5mb3JtYXRpb24gaWYgZ2l0IGlzIGF2YWlsYWJsZS4KLSBzZXQoT1BFTjYyNTQxX1ZFUl9NQUpPUiAxKQotIHNldChPUEVONjI1NDFfVkVSX01JTk9SIDMpCi0tc2V0KE9QRU42MjU0MV9WRVJfUEFUQ0ggNikKLStzZXQoT1BFTjYyNTQxX1ZFUl9QQVRDSCA3KQotIHNldChPUEVONjI1NDFfVkVSX0xBQkVMICItdW5kZWZpbmVkIikgIyBsaWtlICItcmMxIiBvciAiLWc0NTM4YWJjZCIgb3IgIi1nNDUzOGFiY2QtZGlydHkiCi0gc2V0KE9QRU42MjU0MV9WRVJfQ09NTUlUICJ1bmtub3duLWNvbW1pdCIpCi0gCi0tIAoyLjQyLjAKCg==", + "file_name": "0001-devel-open62541-Update-to-version-1.3.8.patch", + "content_type": "text/plain", + "flags": [ + { + "status": "+", + "setter": "nsonack@outlook.com", + "id": 76972, + "name": "maintainer-approval", + "type_id": 1, + "creation_date": "2023-11-04T20:19:11Z", + "modification_date": "2023-11-04T20:19:11Z" + } + ], + "is_private": 0, + "id": 246131, + "last_change_time": "2023-12-08T17:10:06Z", + "is_patch": 1, + "summary": "Patch for updating the port", + "is_obsolete": 1 + }, + { + "id": 246910, + "is_private": 0, + "is_obsolete": 0, + "summary": "Patch v2 (now for version 1.3.9)", + "last_change_time": "2023-12-08T17:10:06Z", + "is_patch": 1, + "creation_time": "2023-12-08T17:10:06Z", + "bug_id": 274920, + "flags": [ + { + "creation_date": "2023-12-08T17:10:06Z", + "modification_date": "2023-12-08T17:10:06Z", + "type_id": 1, + "name": "maintainer-approval", + "id": 77649, + "setter": "nsonack@outlook.com", + "status": "+" + } + ], + "content_type": "text/plain", + "data": "RnJvbSA5MTE2MmYyY2Y2NGI4NjlmOTEwYzBmMjRmMzIyZWU3Y2Q1ZDZmZDdlIE1vbiBTZXAgMTcgMDA6MDA6MDAgMjAwMQpGcm9tOiBOaWNvIFNvbmFjayA8bnNvbmFja0BoZXJyaG90emVucGxvdHouZGU+CkRhdGU6IEZyaSwgMjcgT2N0IDIwMjMgMTY6MTY6MjEgKzAwMDAKU3ViamVjdDogW1BBVENIXSBkZXZlbC9vcGVuNjI1NDE6IFVwZGF0ZSB0byB2ZXJzaW9uIDEuMy44CgpSZW1vdmVzIHRoZSBwYXRjaCBhcyB0aGUgdXBzdHJlYW0gYnVnIHJlcG9ydCBoYXMgYmVlbiByZXNvbHZlZC4KU2VlIGh0dHBzOi8vZ2l0aHViLmNvbS9vcGVuNjI1NDEvb3BlbjYyNTQxL2lzc3Vlcy82MDEwCgpTaWduZWQtb2ZmLWJ5OiBOaWNvIFNvbmFjayA8bnNvbmFja0BoZXJyaG90emVucGxvdHouZGU+Ci0tLQogZGV2ZWwvb3BlbjYyNTQxL01ha2VmaWxlICAgICAgICAgICAgICAgICAgIHwgIDYgKysrLS0tCiBkZXZlbC9vcGVuNjI1NDEvZGlzdGluZm8gICAgICAgICAgICAgICAgICAgfCAgNiArKystLS0KIGRldmVsL29wZW42MjU0MS9maWxlcy9wYXRjaC1DTWFrZUxpc3RzLnR4dCB8IDExIC0tLS0tLS0tLS0tCiAzIGZpbGVzIGNoYW5nZWQsIDYgaW5zZXJ0aW9ucygrKSwgMTcgZGVsZXRpb25zKC0pCiBkZWxldGUgbW9kZSAxMDA2NDQgZGV2ZWwvb3BlbjYyNTQxL2ZpbGVzL3BhdGNoLUNNYWtlTGlzdHMudHh0CgpkaWZmIC0tZ2l0IGEvZGV2ZWwvb3BlbjYyNTQxL01ha2VmaWxlIGIvZGV2ZWwvb3BlbjYyNTQxL01ha2VmaWxlCmluZGV4IGE2OTA4NGVmOTc0My4uMWE5Y2E1ZTJlZWI4IDEwMDY0NAotLS0gYS9kZXZlbC9vcGVuNjI1NDEvTWFrZWZpbGUKKysrIGIvZGV2ZWwvb3BlbjYyNTQxL01ha2VmaWxlCkBAIC0xLDYgKzEsNiBAQAogUE9SVE5BTUU9CW9wZW42MjU0MQogRElTVFZFUlNJT05QUkVGSVg9CXYKLURJU1RWRVJTSU9OPQkxLjMuNworRElTVFZFUlNJT049CTEuMy45CiBDQVRFR09SSUVTPQlkZXZlbAogCiBNQUlOVEFJTkVSPQluc29uYWNrQG91dGxvb2suY29tCkBAIC0xNiw5ICsxNiw5IEBAIFVTRV9MRENPTkZJRz0JeWVzCiAKIFNIRUJBTkdfR0xPQj0JKi5weQogCi1DTUFLRV9PTj0JQlVJTERfU0hBUkVEX0xJQlMKK0NNQUtFX09OPQlCVUlMRF9TSEFSRURfTElCUyBcCisJCUNNQUtFX0RJU0FCTEVfRklORF9QQUNLQUdFX0dpdAogQ01BS0VfT0ZGPQlVQV9GT1JDRV9XRVJST1IKLUJJTkFSWV9BTElBUz0JcHl0aG9uMz0ke1BZVEhPTl9DTUR9CiBQTElTVF9TVUI9CURJU1RWRVJTSU9OPSR7RElTVFZFUlNJT059CiAKIE9QVElPTlNfREVGSU5FPQkJT1NTTApkaWZmIC0tZ2l0IGEvZGV2ZWwvb3BlbjYyNTQxL2Rpc3RpbmZvIGIvZGV2ZWwvb3BlbjYyNTQxL2Rpc3RpbmZvCmluZGV4IDIxNDM3MjIxZTZiMS4uNDE4Njk4MTU4MTFmIDEwMDY0NAotLS0gYS9kZXZlbC9vcGVuNjI1NDEvZGlzdGluZm8KKysrIGIvZGV2ZWwvb3BlbjYyNTQxL2Rpc3RpbmZvCkBAIC0xLDMgKzEsMyBAQAotVElNRVNUQU1QID0gMTY5NDQzNjA2MAotU0hBMjU2IChvcGVuNjI1NDEtb3BlbjYyNTQxLXYxLjMuN19HSDAudGFyLmd6KSA9IGQzZjg0ZjFlMjYzMmMxNWEzODkyZGM2Yzg5ZjBjZDZiNDEzN2U5OTBiOGFlZjhmZTI0NWNkOGU3NWZiYjUzODgKLVNJWkUgKG9wZW42MjU0MS1vcGVuNjI1NDEtdjEuMy43X0dIMC50YXIuZ3opID0gMzg3MTA1NworVElNRVNUQU1QID0gMTcwMjA1NTE4MgorU0hBMjU2IChvcGVuNjI1NDEtb3BlbjYyNTQxLXYxLjMuOV9HSDAudGFyLmd6KSA9IDcxNzY0ZDRhMDYwY2ZhMDdlYWU3YWFhYmQxNzZkYTM4YjE1NWVmMDFjNjMxMDM1MTMzMzk2OTlmZDgwMjZlMmYKK1NJWkUgKG9wZW42MjU0MS1vcGVuNjI1NDEtdjEuMy45X0dIMC50YXIuZ3opID0gMzg3NDcwMQpkaWZmIC0tZ2l0IGEvZGV2ZWwvb3BlbjYyNTQxL2ZpbGVzL3BhdGNoLUNNYWtlTGlzdHMudHh0IGIvZGV2ZWwvb3BlbjYyNTQxL2ZpbGVzL3BhdGNoLUNNYWtlTGlzdHMudHh0CmRlbGV0ZWQgZmlsZSBtb2RlIDEwMDY0NAppbmRleCAzMGE2ZWZmYzdmNzEuLjAwMDAwMDAwMDAwMAotLS0gYS9kZXZlbC9vcGVuNjI1NDEvZmlsZXMvcGF0Y2gtQ01ha2VMaXN0cy50eHQKKysrIC9kZXYvbnVsbApAQCAtMSwxMSArMCwwIEBACi0tLS0gQ01ha2VMaXN0cy50eHQub3JpZwkyMDIzLTA5LTExIDEyOjQ3OjA4IFVUQwotKysrIENNYWtlTGlzdHMudHh0Ci1AQCAtNDMsNyArNDMsNyBAQCBzZXQoQ01BS0VfQVJDSElWRV9PVVRQVVRfRElSRUNUT1JZICR7Q01BS0VfQklOQVJZX0RJUn0KLSAjIG92ZXJ3cml0dGVuIHdpdGggbW9yZSBkZXRhaWxlZCBpbmZvcm1hdGlvbiBpZiBnaXQgaXMgYXZhaWxhYmxlLgotIHNldChPUEVONjI1NDFfVkVSX01BSk9SIDEpCi0gc2V0KE9QRU42MjU0MV9WRVJfTUlOT1IgMykKLS1zZXQoT1BFTjYyNTQxX1ZFUl9QQVRDSCA2KQotK3NldChPUEVONjI1NDFfVkVSX1BBVENIIDcpCi0gc2V0KE9QRU42MjU0MV9WRVJfTEFCRUwgIi11bmRlZmluZWQiKSAjIGxpa2UgIi1yYzEiIG9yICItZzQ1MzhhYmNkIiBvciAiLWc0NTM4YWJjZC1kaXJ0eSIKLSBzZXQoT1BFTjYyNTQxX1ZFUl9DT01NSVQgInVua25vd24tY29tbWl0IikKLSAKLS0gCjIuNDIuMAoK", + "file_name": "0001-devel-open62541-Update-to-version-1.3.8.patch", + "size": 2577, + "creator": "nsonack@outlook.com" + } + ] + } +} From 0d07c37b54f12cfd85a5ea883d2d3646e919f498 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Sun, 10 Dec 2023 19:50:14 +0100 Subject: [PATCH 082/158] Update documentation for Bugzilla --- docs/gcli-issues.1.in | 2 ++ docs/gcli.1.in | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/gcli-issues.1.in b/docs/gcli-issues.1.in index a0d2f158..98119098 100644 --- a/docs/gcli-issues.1.in +++ b/docs/gcli-issues.1.in @@ -119,6 +119,8 @@ action that prints the list of comments associated with the issue. .It Cm title Ar new-title Change the title of the issue to .Ar new-title . +.It Cm attachments +List bug attachments. This action is only available on Bugzilla. .El .Sh EXAMPLES Print a list of issues in the current project: diff --git a/docs/gcli.1.in b/docs/gcli.1.in index 66acf37a..b7a2fc9b 100644 --- a/docs/gcli.1.in +++ b/docs/gcli.1.in @@ -115,8 +115,9 @@ Forcefully override the forge type. Set to .Sq github , .Sq gitlab +.Sq gitea , or -.Sq gitea +.Sq bugzilla to connect to the corresponding services. .El .Pp From 654853312a8d06d721391b6c751c5a4d77d7220b Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 15 Dec 2023 15:12:56 +0100 Subject: [PATCH 083/158] Add base64 decode module and simple test for it --- Makefile.am | 8 +++ include/gcli/base64.h | 42 ++++++++++++ src/base64.c | 152 ++++++++++++++++++++++++++++++++++++++++++ src/bugzilla/bugs.c | 2 + src/json_util.c | 1 + tests/Kyuafile.in | 4 ++ tests/base64-tests.c | 21 ++++++ 7 files changed, 230 insertions(+) create mode 100644 include/gcli/base64.h create mode 100644 src/base64.c create mode 100644 tests/base64-tests.c diff --git a/Makefile.am b/Makefile.am index 27c2760b..db14ec42 100644 --- a/Makefile.am +++ b/Makefile.am @@ -138,6 +138,7 @@ libgcli_la_SOURCES = \ include/gcli/ctx.h src/ctx.c \ include/gcli/gcli.h src/gcli.c \ include/gcli/date_time.h src/date_time.c \ + src/base64.c include/gcli/base64.h \ src/comments.c include/gcli/comments.h \ src/curl.c include/gcli/curl.h \ src/forges.c include/gcli/forges.h \ @@ -225,6 +226,7 @@ check_PROGRAMS = \ tests/gitlab-parse-tests$(EXEEXT) \ tests/gitea-parse-tests$(EXEEXT) \ tests/bugzilla-parse-tests$(EXEEXT) \ + tests/base64-tests$(EXEEXT) \ tests/url-encode$(EXEEXT) \ tests/pretty_print_test$(EXEEXT) \ tests/test-jsongen$(EXEEXT) @@ -267,6 +269,12 @@ tests_bugzilla_parse_tests_LDADD = \ libgcli.la libpdjson.la libsn.la \ $(LIBATFC_LDFLAGS) +tests_base64_tests_SOURCES = \ + tests/base64-tests.c +tests_base64_tests_LDADD = \ + libgcli.la libpdjson.la libsn.la \ + $(LIBATFC_LDFLAGS) + tests_url_encode_SOURCES = \ tests/url-encode.c tests_url_encode_LDADD = \ diff --git a/include/gcli/base64.h b/include/gcli/base64.h new file mode 100644 index 00000000..ef1b5623 --- /dev/null +++ b/include/gcli/base64.h @@ -0,0 +1,42 @@ +/* + * Copyright 2023 Nico Sonack + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef GCLI_BASE64_H +#define GCLI_BASE64_H + +#include + +#include + +int gcli_decode_base64(gcli_ctx *ctx, char const *input, char *buffer, + size_t buffer_size); + +int gcli_base64_decode_print(gcli_ctx *ctx, FILE *out, char const *const input); + +#endif /* GCLI_BASE64_H */ diff --git a/src/base64.c b/src/base64.c new file mode 100644 index 00000000..2d1103c7 --- /dev/null +++ b/src/base64.c @@ -0,0 +1,152 @@ +/* + * Copyright 2023 Nico Sonack + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +#include +#include + +/* The code below is taken from my IRC chat bot and was originally written by + * raym aka. Aritra Sarkar in 2022. */ +int +gcli_decode_base64(gcli_ctx *ctx, char const *input, char *buffer, + size_t buffer_size) +{ + char const digits[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxy" + "z0123456789+/"; + + char digit = 0; + unsigned long octets = 0; + size_t bits_rem = 0; + size_t length = 0; + + memset(buffer, 0, buffer_size); + + while ((digit = *input++)) { + + if (digit == '=') { + if (bits_rem % 8 == 0) + /* Unnecessary padding char */ + return gcli_error(ctx, "invalid base64 input"); + + do { + if (digit != '=') + return gcli_error(ctx, "invalid base64 input"); + + octets >>= 2; + bits_rem -= 2; + + digit = *input++; + + } while (bits_rem % 8 != 0); + + if (digit) + return gcli_error(ctx, "invalid base64 input"); + + size_t byte_count = 0; + while (bits_rem > 0) { + unsigned char octet = octets & 0xff; + + if (octet == '\0') + return gcli_error(ctx, "null-character encountered during base64 decode"); + + buffer[length + (bits_rem / 8) - 1] = (char) octet; + octets >>= 8; + bits_rem -= 8; + byte_count++; + } + + length += byte_count; + + return 0; + } + + size_t sextet = 0; + + /* Lookup index for a digit. We shall perform a linear search + * for the index of the digit. Since there are only 64 digits, + * this should be done in a jiffy. */ + for ( ; sextet < 64; sextet++) + if (digits[sextet] == digit) + break; + + if (sextet == 64) + /* Oops! We couldn't lookup the index of `digit` */ + return gcli_error(ctx, "invalid base64 input"); + + octets = (octets << 6) | sextet; + bits_rem += 6; + + /* 4 sextets (24 bits) of base64 input yields 3 bytes */ + + if (bits_rem == 24) { + while (bits_rem > 0) { + unsigned char octet = octets & 0xff; + + if (octet == '\0') + return gcli_error(ctx, "null-character encountered during base64 decode"); + + buffer[length + (bits_rem / 8) - 1] = (char) octet; + octets >>= 8; + bits_rem -= 8; + } + + length += 3; + } + } + + if (bits_rem > 0) + return gcli_error(ctx, "invalid base64 input"); + + return 0; +} + +int +gcli_base64_decode_print(gcli_ctx *ctx, FILE *out, char const *const input) +{ + int rc = 0; + char *buffer = NULL; + size_t buffer_size = 0, input_size = 0; + + input_size = strlen(input); + /* account for BASE64 inflation */ + buffer_size = (input_size / 4) * 3; + buffer = calloc(1, buffer_size); + + rc = gcli_decode_base64(ctx, input, buffer, buffer_size); + if (rc < 0) + return rc; + + fwrite(buffer, buffer_size, 1, out); + + free(buffer); + buffer = NULL; + + return 0; +} diff --git a/src/bugzilla/bugs.c b/src/bugzilla/bugs.c index 96a5d68a..0a6227f6 100644 --- a/src/bugzilla/bugs.c +++ b/src/bugzilla/bugs.c @@ -33,6 +33,7 @@ #include +#include #include #include @@ -239,3 +240,4 @@ bugzilla_bug_get_attachments(gcli_ctx *ctx, char const *const product, return rc; } + diff --git a/src/json_util.c b/src/json_util.c index c409c72a..6055af4b 100644 --- a/src/json_util.c +++ b/src/json_util.c @@ -440,3 +440,4 @@ get_int_to_sv_(gcli_ctx *ctx, json_stream *input, sn_sv *out, return 0; } + diff --git a/tests/Kyuafile.in b/tests/Kyuafile.in index c7f9485b..22a7b553 100644 --- a/tests/Kyuafile.in +++ b/tests/Kyuafile.in @@ -26,6 +26,10 @@ atf_test_program{ required_files = '@TESTSRCDIR@/samples/bugzilla_simple_bug.json' } +atf_test_program{ + name = 'base64-tests' +} + atf_test_program{ name = 'url-encode' } diff --git a/tests/base64-tests.c b/tests/base64-tests.c new file mode 100644 index 00000000..a7af3901 --- /dev/null +++ b/tests/base64-tests.c @@ -0,0 +1,21 @@ +#include + +#include + +ATF_TC_WITHOUT_HEAD(simple_decode); +ATF_TC_BODY(simple_decode, tc) +{ + char const input[] = "aGVsbG8gd29ybGQ="; + char output[sizeof("hello world")] = {0}; + + int rc = gcli_decode_base64(NULL, input, output, sizeof(output)); + ATF_REQUIRE(rc == 0); + ATF_CHECK_STREQ(output, "hello world"); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, simple_decode); + + return atf_no_error(); +} From f182119c579aa5bc715531c30032a7ee58d95bae Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 15 Dec 2023 16:01:57 +0100 Subject: [PATCH 084/158] Add stubs for a new attachments subcommand --- Makefile.am | 1 + include/gcli/cmd/attachments.h | 35 ++++++++++++++++++++++++++++ src/cmd/attachments.c | 42 ++++++++++++++++++++++++++++++++++ src/cmd/gcli.c | 4 ++++ 4 files changed, 82 insertions(+) create mode 100644 include/gcli/cmd/attachments.h create mode 100644 src/cmd/attachments.c diff --git a/Makefile.am b/Makefile.am index db14ec42..c3144767 100644 --- a/Makefile.am +++ b/Makefile.am @@ -61,6 +61,7 @@ dist_man_MANS = \ docs/gcli.5 gcli_SOURCES = \ + include/gcli/cmd/attachments.h src/cmd/attachments.c \ include/gcli/cmd/ci.h src/cmd/ci.c \ include/gcli/cmd/cmdconfig.h src/cmd/cmdconfig.c \ include/gcli/cmd/cmd.h src/cmd/cmd.c \ diff --git a/include/gcli/cmd/attachments.h b/include/gcli/cmd/attachments.h new file mode 100644 index 00000000..34be2850 --- /dev/null +++ b/include/gcli/cmd/attachments.h @@ -0,0 +1,35 @@ +/* + * Copyright 2023 Nico Sonack + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef GCLI_CMD_ATTACHMENTS_H +#define GCLI_CMD_ATTACHMENTS_H + +int subcommand_attachments(int argc, char *argv[]); + +#endif /* GCLI_CMD_ATTACHMENTS_H */ diff --git a/src/cmd/attachments.c b/src/cmd/attachments.c new file mode 100644 index 00000000..bf171b60 --- /dev/null +++ b/src/cmd/attachments.c @@ -0,0 +1,42 @@ +/* + * Copyright 2023 Nico Sonack + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +int +subcommand_attachments(int argc, char *argv[]) +{ + (void) argc; + (void) argv; + + fprintf(stderr, "gcli: attachments subcommand is not yet implemented\n"); + + return 1; +} diff --git a/src/cmd/gcli.c b/src/cmd/gcli.c index 56408291..0e4ad230 100644 --- a/src/cmd/gcli.c +++ b/src/cmd/gcli.c @@ -38,6 +38,7 @@ #include #include +#include #include #include #include @@ -116,6 +117,9 @@ static struct subcommand { { .cmd_name = "status", .fn = subcommand_status, .docstring = "General user status and notifications" }, + { .cmd_name = "attachments", + .fn = subcommand_attachments, + .docstring = "Bugzilla Attachments management" }, { .cmd_name = "api", .fn = subcommand_api, .docstring = "Fetch plain JSON info from an API (for debugging purposes)" }, From e125a28d8f87d6d8be7768767305a27067f55517 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 15 Dec 2023 16:27:44 +0100 Subject: [PATCH 085/158] Add attachments subcommand argument parsing logic This is very simple for now. There's only one 'get' subcommand and not a lot of options. We will gradually expand these in the future depending on what we need from this subcommand. I am unsure whether adding a new subcommand is the right way to go here but I cannot think of a better way of interfacing with attachments right now since they are living in their own ID namespace. --- src/cmd/attachments.c | 108 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 104 insertions(+), 4 deletions(-) diff --git a/src/cmd/attachments.c b/src/cmd/attachments.c index bf171b60..527b334c 100644 --- a/src/cmd/attachments.c +++ b/src/cmd/attachments.c @@ -30,13 +30,113 @@ #include #include -int -subcommand_attachments(int argc, char *argv[]) +#include +#include + +static void +usage(void) +{ + fprintf(stderr, "usage: gcli [options] attachments -i actions...\n"); + fprintf(stderr, "OPTIONS:\n"); + fprintf(stderr, " -i id Execute the given actions for the specified attachment id.\n"); + fprintf(stderr, "ACTIONS:\n"); + fprintf(stderr, " get [-o path] Fetch and dump the contents of the " + "attachments to the given path or stdout\n"); + fprintf(stderr, "\n"); + version(); +} + +static int +action_attachment_get(int *argc, char ***argv, gcli_id const id) { (void) argc; (void) argv; + (void) id; + + fprintf(stderr, "gcli: get action is not yet implemented\n"); + return EXIT_FAILURE; +} + +static struct action { + char const *const name; + int (*fn)(int *argc, char ***argv, gcli_id const id); +} const actions[] = { + { .name = "get", .fn = action_attachment_get }, +}; + +static size_t const actions_size = ARRAY_SIZE(actions); + +static struct action const * +find_action(char const *const name) +{ + for (size_t i = 0; i < actions_size; ++i) { + if (strcmp(name, actions[i].name) == 0) + return &actions[i]; + } + return NULL; +} + +int +subcommand_attachments(int argc, char *argv[]) +{ + int ch; + gcli_id iflag; + bool iflag_seen = false; + + struct option options[] = { + { .name = "id", .has_arg = required_argument, .flag = NULL, .val = 'i' }, + {0}, + }; + + while ((ch = getopt_long(argc, argv, "+i:", options, NULL)) != -1) { + switch (ch) { + case 'i': { + char *endptr; + + iflag_seen = true; + iflag = strtoull(optarg, &endptr, 10); + + if (optarg + strlen(optarg) != endptr) { + fprintf(stderr, "gcli: bad attachment id »%s«\n", optarg); + return EXIT_FAILURE; + } + } break; + default: + usage(); + return EXIT_FAILURE; + } + } + + argc -= optind; + argv += optind; + + if (!iflag_seen) { + fprintf(stderr, "gcli: missing -i flag\n"); + usage(); + return EXIT_FAILURE; + } + + if (argc == 0) { + fprintf(stderr, "gcli: missing actions\n"); + usage(); + return EXIT_FAILURE; + } + + while (argc) { + int rc; + char const *const action_name = *argv; + struct action const *const action = find_action(action_name); + + if (action == NULL) { + fprintf(stderr, "gcli: %s: no such action\n", action_name); + usage(); + return EXIT_FAILURE; + } - fprintf(stderr, "gcli: attachments subcommand is not yet implemented\n"); + rc = action->fn(&argc, &argv, iflag); + if (rc) + return rc; + } - return 1; + return 0; } From f97ac69430e5079a6ac16d60f18f727a281a9b0b Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Tue, 19 Dec 2023 13:25:19 +0100 Subject: [PATCH 086/158] attachments: Add options parser for get subcommand This only adds the argument parsers - we're entirely missing any actions. --- src/cmd/attachments.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/cmd/attachments.c b/src/cmd/attachments.c index 527b334c..d5f66011 100644 --- a/src/cmd/attachments.c +++ b/src/cmd/attachments.c @@ -30,6 +30,7 @@ #include #include +#include #include #include @@ -49,8 +50,38 @@ usage(void) static int action_attachment_get(int *argc, char ***argv, gcli_id const id) { - (void) argc; - (void) argv; + int ch; + FILE *outfile = NULL; + struct option options[] = { + { .name = "output", .has_arg = required_argument, .flag = NULL, .val = 'o' }, + {0}, + }; + + while ((ch = getopt_long(*argc, *argv, "+o:", options, NULL)) != -1) { + switch (ch) { + case 'o': { + outfile = fopen(optarg, "w"); + if (!outfile) { + fprintf(stderr, "gcli: failed to open »%s«: %s\n", + optarg, strerror(errno)); + return EXIT_FAILURE; + } + } break; + default: { + usage(); + return EXIT_FAILURE; + } break; + } + } + + *argc -= optind; + *argv += optind; + optind = 0; /* reset */ + + /* -o wasn't specified */ + if (outfile == NULL) + outfile = stdout; + (void) id; fprintf(stderr, "gcli: get action is not yet implemented\n"); @@ -110,6 +141,8 @@ subcommand_attachments(int argc, char *argv[]) argc -= optind; argv += optind; + optind = 0; /* reset */ + if (!iflag_seen) { fprintf(stderr, "gcli: missing -i flag\n"); usage(); From ce70315dbe0bad59115d59c4e636311d34d2d03d Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Tue, 19 Dec 2023 15:03:41 +0100 Subject: [PATCH 087/158] Move attachment routines and definitions to a new header and implementation file This file is going to grow a bit and we need a new place to put stuff regarding attachments. --- Makefile.am | 1 + include/gcli/attachments.h | 68 ++++++++++++++++++++++++++++++++++++++ include/gcli/issues.h | 29 +++------------- src/attachments.c | 55 ++++++++++++++++++++++++++++++ src/issues.c | 22 ------------ 5 files changed, 128 insertions(+), 47 deletions(-) create mode 100644 include/gcli/attachments.h create mode 100644 src/attachments.c diff --git a/Makefile.am b/Makefile.am index c3144767..cf58347e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -139,6 +139,7 @@ libgcli_la_SOURCES = \ include/gcli/ctx.h src/ctx.c \ include/gcli/gcli.h src/gcli.c \ include/gcli/date_time.h src/date_time.c \ + src/attachments.c include/gcli/attachments.h \ src/base64.c include/gcli/base64.h \ src/comments.c include/gcli/comments.h \ src/curl.c include/gcli/curl.h \ diff --git a/include/gcli/attachments.h b/include/gcli/attachments.h new file mode 100644 index 00000000..ad1d089b --- /dev/null +++ b/include/gcli/attachments.h @@ -0,0 +1,68 @@ +/* + * Copyright 2023 Nico Sonack + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef GCLI_ATTACHMENTS_H +#define GCLI_ATTACHMENTS_H + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include + +#include + +typedef struct gcli_attachment gcli_attachment; +typedef struct gcli_attachment_list gcli_attachment_list; + +struct gcli_attachment { + gcli_id id; + bool is_obsolete; + char *created_at; + char *author; + char *file_name; + char *summary; + char *content_type; + + uint8_t *data; + size_t data_size; +}; + +struct gcli_attachment_list { + gcli_attachment *attachments; + size_t attachments_size; +}; + +void gcli_attachments_free(gcli_attachment_list *list); +void gcli_attachment_free(gcli_attachment *attachment); + +#endif /* GCLI_ATTACHMENTS_H */ diff --git a/include/gcli/issues.h b/include/gcli/issues.h index 4bac8671..c4654cb7 100644 --- a/include/gcli/issues.h +++ b/include/gcli/issues.h @@ -34,18 +34,18 @@ #include #endif -#include #include + +#include #include #include +#include + typedef struct gcli_issue gcli_issue; typedef struct gcli_submit_issue_options gcli_submit_issue_options; typedef struct gcli_issue_list gcli_issue_list; typedef struct gcli_issue_fetch_details gcli_issue_fetch_details; -typedef struct gcli_attachment gcli_attachment; -typedef struct gcli_attachment_list gcli_attachment_list; - struct gcli_issue { gcli_id number; char *title; @@ -67,24 +67,6 @@ struct gcli_issue { char *milestone; }; -struct gcli_attachment { - gcli_id id; - bool is_obsolete; - char *created_at; - char *author; - char *file_name; - char *summary; - char *content_type; - - uint8_t *data; - size_t data_size; -}; - -struct gcli_attachment_list { - gcli_attachment *attachments; - size_t attachments_size; -}; - struct gcli_submit_issue_options { char const *owner; char const *repo; @@ -147,7 +129,4 @@ int gcli_issue_get_attachments(gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue, gcli_attachment_list *attachments); -void gcli_attachments_free(gcli_attachment_list *list); -void gcli_attachment_free(gcli_attachment *attachment); - #endif /* ISSUES_H */ diff --git a/src/attachments.c b/src/attachments.c new file mode 100644 index 00000000..3f3be240 --- /dev/null +++ b/src/attachments.c @@ -0,0 +1,55 @@ +/* + * Copyright 2023 Nico Sonack + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +#include + +void +gcli_attachments_free(gcli_attachment_list *list) +{ + for (size_t i = 0; i < list->attachments_size; ++i) { + gcli_attachment_free(&list->attachments[i]); + } + + free(list->attachments); + list->attachments = NULL; + list->attachments_size = 0; +} + +void +gcli_attachment_free(gcli_attachment *it) +{ + free(it->created_at); + free(it->author); + free(it->file_name); + free(it->summary); + free(it->content_type); + free(it->data); +} diff --git a/src/issues.c b/src/issues.c index 4346a900..3bcb9582 100644 --- a/src/issues.c +++ b/src/issues.c @@ -176,25 +176,3 @@ gcli_issue_get_attachments(gcli_ctx *ctx, char const *owner, char const *repo, } } -void -gcli_attachments_free(gcli_attachment_list *list) -{ - for (size_t i = 0; i < list->attachments_size; ++i) { - gcli_attachment_free(&list->attachments[i]); - } - - free(list->attachments); - list->attachments = NULL; - list->attachments_size = 0; -} - -void -gcli_attachment_free(gcli_attachment *it) -{ - free(it->created_at); - free(it->author); - free(it->file_name); - free(it->summary); - free(it->content_type); - free(it->data); -} From 4f6481f136289f0f76962d72d0eb10b58b8a737b Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Tue, 19 Dec 2023 15:04:13 +0100 Subject: [PATCH 088/158] Add gcli_attachment_get_content and wire it up to the cmd frontend This adds a new forge dispatch for fetching the content of an attachment. This will at the moment be only available on Bugzilla. --- include/gcli/attachments.h | 1 + include/gcli/forges.h | 5 +++++ src/attachments.c | 13 +++++++++++++ src/cmd/attachments.c | 21 +++++++++++++++++---- 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/include/gcli/attachments.h b/include/gcli/attachments.h index ad1d089b..cb161fc3 100644 --- a/include/gcli/attachments.h +++ b/include/gcli/attachments.h @@ -64,5 +64,6 @@ struct gcli_attachment_list { void gcli_attachments_free(gcli_attachment_list *list); void gcli_attachment_free(gcli_attachment *attachment); +int gcli_attachment_get_content(gcli_ctx *const ctx, gcli_id const id, FILE *out); #endif /* GCLI_ATTACHMENTS_H */ diff --git a/include/gcli/forges.h b/include/gcli/forges.h index 8cab3c82..30421da0 100644 --- a/include/gcli/forges.h +++ b/include/gcli/forges.h @@ -182,6 +182,11 @@ struct gcli_forge_descriptor { gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue, gcli_attachment_list *out); + /** + * Dump the contents of the attachment to the given file */ + int (*attachment_get_content)( + gcli_ctx *ctx, gcli_id id, FILE *out); + /* Issue quirk bitmask */ enum { GCLI_ISSUE_QUIRKS_LOCKED = 0x1, diff --git a/src/attachments.c b/src/attachments.c index 3f3be240..f2b6dfb6 100644 --- a/src/attachments.c +++ b/src/attachments.c @@ -28,6 +28,7 @@ */ #include +#include #include @@ -53,3 +54,15 @@ gcli_attachment_free(gcli_attachment *it) free(it->content_type); free(it->data); } + +int +gcli_attachment_get_content(gcli_ctx *const ctx, gcli_id const id, FILE *out) +{ + gcli_forge_descriptor const *const forge = gcli_forge(ctx); + + /* FIXME: this is not entirely correct. Add a separate quirks category. */ + if (forge->issue_quirks & GCLI_ISSUE_QUIRKS_ATTACHMENTS) + return gcli_error(ctx, "forge does not support attachements"); + else + return gcli_forge(ctx)->attachment_get_content(ctx, id, out); +} diff --git a/src/cmd/attachments.c b/src/cmd/attachments.c index d5f66011..7d5b5d1b 100644 --- a/src/cmd/attachments.c +++ b/src/cmd/attachments.c @@ -30,6 +30,8 @@ #include #include +#include + #include #include #include @@ -50,7 +52,8 @@ usage(void) static int action_attachment_get(int *argc, char ***argv, gcli_id const id) { - int ch; + int ch, rc = 0; + bool oflag_seen = false; FILE *outfile = NULL; struct option options[] = { { .name = "output", .has_arg = required_argument, .flag = NULL, .val = 'o' }, @@ -66,6 +69,7 @@ action_attachment_get(int *argc, char ***argv, gcli_id const id) optarg, strerror(errno)); return EXIT_FAILURE; } + oflag_seen = true; } break; default: { usage(); @@ -82,10 +86,19 @@ action_attachment_get(int *argc, char ***argv, gcli_id const id) if (outfile == NULL) outfile = stdout; - (void) id; + rc = gcli_attachment_get_content(g_clictx, id, outfile); + if (rc < 0) { + fprintf(stderr, "gcli: failed to get attachment: %s\n", + gcli_get_error(g_clictx)); + return EXIT_FAILURE; + } + + if (oflag_seen) + fclose(outfile); + + outfile = NULL; - fprintf(stderr, "gcli: get action is not yet implemented\n"); - return EXIT_FAILURE; + return EXIT_SUCCESS; } static struct action { From d6f8484cab3e7f2ff6a2bbf4b2bd50a7f976197d Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Tue, 19 Dec 2023 15:01:09 +0100 Subject: [PATCH 089/158] Implement fetching attachment content for Bugzilla --- Makefile.am | 1 + include/gcli/attachments.h | 3 +- include/gcli/bugzilla/attachments.h | 38 +++++++++++++++ include/gcli/bugzilla/bugs-parser.h | 3 ++ src/attachments.c | 2 +- src/bugzilla/attachments.c | 71 +++++++++++++++++++++++++++++ src/bugzilla/bugs-parser.c | 22 +++++++++ src/forges.c | 3 ++ templates/bugzilla/bugs.t | 7 ++- 9 files changed, 146 insertions(+), 4 deletions(-) create mode 100644 include/gcli/bugzilla/attachments.h create mode 100644 src/bugzilla/attachments.c diff --git a/Makefile.am b/Makefile.am index cf58347e..e7afc951 100644 --- a/Makefile.am +++ b/Makefile.am @@ -195,6 +195,7 @@ libgcli_la_SOURCES = \ src/gitea/status.c include/gcli/gitea/status.h \ src/gitea/milestones.c include/gcli/gitea/milestones.h \ src/bugzilla/api.c include/gcli/bugzilla/api.h \ + src/bugzilla/attachments.c include/gcli/bugzilla/attachments.h \ src/bugzilla/bugs.c include/gcli/bugzilla/bugs.h \ src/bugzilla/bugs-parser.c include/gcli/bugzilla/bugs-parser.h \ src/bugzilla/config.c include/gcli/bugzilla/config.h \ diff --git a/include/gcli/attachments.h b/include/gcli/attachments.h index cb161fc3..f528eb56 100644 --- a/include/gcli/attachments.h +++ b/include/gcli/attachments.h @@ -53,8 +53,7 @@ struct gcli_attachment { char *summary; char *content_type; - uint8_t *data; - size_t data_size; + char *data_base64; }; struct gcli_attachment_list { diff --git a/include/gcli/bugzilla/attachments.h b/include/gcli/bugzilla/attachments.h new file mode 100644 index 00000000..e8218be6 --- /dev/null +++ b/include/gcli/bugzilla/attachments.h @@ -0,0 +1,38 @@ +/* + * Copyright 2023 Nico Sonack + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef GCLI_BUGZILLA_ATTACHMENTS_H +#define GCLI_BUGZILLA_ATTACHMENTS_H + +#include + +int bugzilla_attachment_get_content(gcli_ctx *ctx, gcli_id attachment_id, + FILE *output); + +#endif /* GCLI_BUGZILLA_ATTACHMENTS_H */ diff --git a/include/gcli/bugzilla/bugs-parser.h b/include/gcli/bugzilla/bugs-parser.h index 23f4b1c8..93dbb5b9 100644 --- a/include/gcli/bugzilla/bugs-parser.h +++ b/include/gcli/bugzilla/bugs-parser.h @@ -60,4 +60,7 @@ int parse_bugzilla_assignee(gcli_ctx *ctx, struct json_stream *stream, int parse_bugzilla_bug_attachments_dict(gcli_ctx *ctx, json_stream *stream, gcli_attachment_list *out); +int parse_bugzilla_attachment_content_only_first(gcli_ctx *ctx, json_stream *stream, + gcli_attachment *out); + #endif /* GCLI_BUGZILLA_BUGS_PARSER_H */ diff --git a/src/attachments.c b/src/attachments.c index f2b6dfb6..e4ec529d 100644 --- a/src/attachments.c +++ b/src/attachments.c @@ -52,7 +52,7 @@ gcli_attachment_free(gcli_attachment *it) free(it->file_name); free(it->summary); free(it->content_type); - free(it->data); + free(it->data_base64); } int diff --git a/src/bugzilla/attachments.c b/src/bugzilla/attachments.c new file mode 100644 index 00000000..51bdfeab --- /dev/null +++ b/src/bugzilla/attachments.c @@ -0,0 +1,71 @@ +/* + * Copyright 2023 Nico Sonack + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +#include +#include + +#include + +int +bugzilla_attachment_get_content(gcli_ctx *ctx, gcli_id attachment_id, + FILE *output) +{ + int rc = 0; + char *url; + gcli_fetch_buffer buffer = {0}; + json_stream stream = {0}; + gcli_attachment attachment = {0}; + + url = sn_asprintf("%s/rest/bug/attachment/%"PRIid, + gcli_get_apibase(ctx), attachment_id); + + rc = gcli_fetch(ctx, url, NULL, &buffer); + if (rc < 0) + goto error_fetch; + + json_open_buffer(&stream, buffer.data, buffer.length); + rc = parse_bugzilla_attachment_content(ctx, &stream, &attachment); + if (rc < 0) + goto error_parse; + + rc = gcli_base64_decode_print(ctx, output, attachment.data_base64); + + gcli_attachment_free(&attachment); + +error_parse: + json_close(&stream); + free(buffer.data); + +error_fetch: + free(url); + + return rc; +} diff --git a/src/bugzilla/bugs-parser.c b/src/bugzilla/bugs-parser.c index 6bbf27b5..6dc60a8f 100644 --- a/src/bugzilla/bugs-parser.c +++ b/src/bugzilla/bugs-parser.c @@ -164,3 +164,25 @@ parse_bugzilla_bug_attachments_dict(gcli_ctx *ctx, json_stream *stream, return rc; } + +int +parse_bugzilla_attachment_content_only_first(gcli_ctx *ctx, json_stream *stream, + gcli_attachment *out) +{ + enum json_type next = JSON_NULL; + int rc = 0; + + if ((next = json_next(stream)) != JSON_OBJECT) + return gcli_error(ctx, "expected bugzilla attachments dictionary"); + + while ((next = json_next(stream)) == JSON_STRING) { + rc = parse_bugzilla_bug_attachment(ctx, stream, out); + if (rc < 0) + return rc; + } + + if (next != JSON_OBJECT_END) + return gcli_error(ctx, "unclosed bugzilla attachments dictionary"); + + return rc; +} diff --git a/src/forges.c b/src/forges.c index 7c603393..ca280369 100644 --- a/src/forges.c +++ b/src/forges.c @@ -71,6 +71,7 @@ #include #include +#include #include #include @@ -366,6 +367,8 @@ bugzilla_forge_descriptor = .issue_quirks = GCLI_ISSUE_QUIRKS_COMMENTS | GCLI_ISSUE_QUIRKS_LOCKED, + .attachment_get_content = bugzilla_attachment_get_content, + /* Internal stuff */ .make_authheader = bugzilla_make_authheader, .get_api_error_string = bugzilla_api_error_string, diff --git a/templates/bugzilla/bugs.t b/templates/bugzilla/bugs.t index 66a23763..43da5158 100644 --- a/templates/bugzilla/bugs.t +++ b/templates/bugzilla/bugs.t @@ -68,7 +68,12 @@ object of gcli_attachment with "creation_time" => created_at as string, "creator" => author as string, "content_type" => content_type as string, - "is_obsolete" => is_obsolete as bool_relaxed); + "is_obsolete" => is_obsolete as bool_relaxed, + "data" => data_base64 as string); parser bugzilla_bug_attachments_internal is array of gcli_attachment use parse_bugzilla_bug_attachment; + +parser bugzilla_attachment_content is +object of gcli_attachment with + ("attachments" => use parse_bugzilla_attachment_content_only_first); From 160d2ecf5293820f82d2f266fe01f3132f6d41ac Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Tue, 26 Dec 2023 13:37:53 +0100 Subject: [PATCH 090/158] Create bugs on Bugzilla This is far from complete: - Unhardcode various fields - Provide a way to pass in optional values --- include/gcli/bugzilla/bugs.h | 4 ++ include/gcli/ctx.h | 1 + src/bugzilla/bugs.c | 83 ++++++++++++++++++++++++++++++++++++ src/bugzilla/config.c | 3 +- src/ctx.c | 8 +++- src/forges.c | 1 + 6 files changed, 98 insertions(+), 2 deletions(-) diff --git a/include/gcli/bugzilla/bugs.h b/include/gcli/bugzilla/bugs.h index 5e2619db..3bf0af2b 100644 --- a/include/gcli/bugzilla/bugs.h +++ b/include/gcli/bugzilla/bugs.h @@ -33,6 +33,7 @@ #include #include +#include #include #include @@ -53,4 +54,7 @@ int bugzilla_bug_get_attachments(gcli_ctx *ctx, char const *const product, gcli_id const bug_id, gcli_attachment_list *const out); +int bugzilla_bug_submit(gcli_ctx *ctx, gcli_submit_issue_options opts, + gcli_fetch_buffer *out); + #endif /* GCLI_BUGZILLA_BUGS_H */ diff --git a/include/gcli/ctx.h b/include/gcli/ctx.h index edc89cb7..f5310b75 100644 --- a/include/gcli/ctx.h +++ b/include/gcli/ctx.h @@ -55,5 +55,6 @@ int gcli_error(struct gcli_ctx *ctx, char const *const fmt, ...); char *gcli_get_apibase(struct gcli_ctx *ctx); char *gcli_get_authheader(struct gcli_ctx *ctx); +char *gcli_get_token(struct gcli_ctx *ctx); #endif /* GCLI_CTX_H */ diff --git a/src/bugzilla/bugs.c b/src/bugzilla/bugs.c index 0a6227f6..b44e1afc 100644 --- a/src/bugzilla/bugs.c +++ b/src/bugzilla/bugs.c @@ -31,10 +31,13 @@ #include +#include + #include #include #include +#include #include @@ -241,3 +244,83 @@ bugzilla_bug_get_attachments(gcli_ctx *ctx, char const *const product, return rc; } +int +bugzilla_bug_submit(gcli_ctx *ctx, gcli_submit_issue_options opts, + gcli_fetch_buffer *out) +{ + char *payload = NULL, *url = NULL; + char *token; /* bugzilla wants the api token as a parameter in the url or the json payload */ + char const *product = opts.owner, *component = opts.repo, + *summary = opts.title, *description = opts.body; + gcli_jsongen gen = {0}; + int rc = 0; + + /* prepare data for payload generation */ + if (product == NULL) + return gcli_error(ctx, "product must not be empty"); + + if (component == NULL) + return gcli_error(ctx, "component must not be empty"); + + token = gcli_get_token(ctx); + if (!token) + return gcli_error(ctx, "creating bugs on bugzilla requires a token"); + + /* generate payload */ + rc = gcli_jsongen_init(&gen); + if (rc < 0) { + gcli_error(ctx, "failed to init json generator"); + goto err_jsongen_init; + } + + /* + * { + * "product" : "TestProduct", + * "component" : "TestComponent", + * "summary" : "'This is a test bug - please disregard", + * "description": ..., + * } */ + gcli_jsongen_begin_object(&gen); + { + gcli_jsongen_objmember(&gen, "product"); + gcli_jsongen_string(&gen, product); + + gcli_jsongen_objmember(&gen, "component"); + gcli_jsongen_string(&gen, component); + + gcli_jsongen_objmember(&gen, "summary"); + gcli_jsongen_string(&gen, summary); + + gcli_jsongen_objmember(&gen, "description"); + gcli_jsongen_string(&gen, description); + + /* TODO: don't hardcode */ + gcli_jsongen_objmember(&gen, "op_sys"); + gcli_jsongen_string(&gen, "All"); + + gcli_jsongen_objmember(&gen, "rep_platform"); + gcli_jsongen_string(&gen, "All"); + + gcli_jsongen_objmember(&gen, "version"); + gcli_jsongen_string(&gen, "unspecified"); + + gcli_jsongen_objmember(&gen, "api_key"); + gcli_jsongen_string(&gen, token); + } + gcli_jsongen_end_object(&gen); + + payload = gcli_jsongen_to_string(&gen); + gcli_jsongen_free(&gen); + + /* generate url and perform request */ + url = sn_asprintf("%s/rest/bug", gcli_get_apibase(ctx)); + rc = gcli_fetch_with_method(ctx, "POST", url, payload, NULL, out); + + free(url); + free(payload); + +err_jsongen_init: + free(token); + + return rc; +} diff --git a/src/bugzilla/config.c b/src/bugzilla/config.c index ad84b053..70eab11f 100644 --- a/src/bugzilla/config.c +++ b/src/bugzilla/config.c @@ -34,5 +34,6 @@ char * bugzilla_make_authheader(gcli_ctx *ctx, char const *const token) { (void) ctx; - return sn_asprintf("X-BUGZILLA-API-KEY: %s", token); + (void) token; + return NULL; } diff --git a/src/ctx.c b/src/ctx.c index 8713689a..f5ea5d8c 100644 --- a/src/ctx.c +++ b/src/ctx.c @@ -87,11 +87,17 @@ gcli_get_apibase(struct gcli_ctx *ctx) return ctx->apibase; } +char * +gcli_get_token(struct gcli_ctx *ctx) +{ + return ctx->get_token(ctx); +} + char * gcli_get_authheader(struct gcli_ctx *ctx) { char *hdr = NULL; - char *token = ctx->get_token(ctx); + char *token = gcli_get_token(ctx); if (token && gcli_forge(ctx)->make_authheader) { hdr = gcli_forge(ctx)->make_authheader(ctx, token); diff --git a/src/forges.c b/src/forges.c index ca280369..4f86a904 100644 --- a/src/forges.c +++ b/src/forges.c @@ -364,6 +364,7 @@ bugzilla_forge_descriptor = .get_issue_summary = bugzilla_get_bug, .get_issue_comments = bugzilla_bug_get_comments, .get_issue_attachments = bugzilla_bug_get_attachments, + .perform_submit_issue = bugzilla_bug_submit, .issue_quirks = GCLI_ISSUE_QUIRKS_COMMENTS | GCLI_ISSUE_QUIRKS_LOCKED, From ab07c8de8f11819098c8e3426d2291c6cde4c0fc Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Thu, 21 Dec 2023 15:52:11 +0100 Subject: [PATCH 091/158] Add a NVList This is going to be used for forge-specific fields passed to backends (e.g. creating issues on Bugzilla may require supplying extra fields). Most of these make no sense to be put into the big options struct and appear as if the are available everywhere. --- Makefile.am | 1 + include/gcli/nvlist.h | 58 +++++++++++++++++++++++ src/nvlist.c | 105 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 164 insertions(+) create mode 100644 include/gcli/nvlist.h create mode 100644 src/nvlist.c diff --git a/Makefile.am b/Makefile.am index e7afc951..842682d3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -150,6 +150,7 @@ libgcli_la_SOURCES = \ src/json_util.c include/gcli/json_util.h \ src/labels.c include/gcli/labels.h \ src/milestones.c include/gcli/milestones.h \ + src/nvlist.c include/gcli/nvlist.h \ src/pulls.c include/gcli/pulls.h \ src/releases.c include/gcli/releases.h \ src/repos.c include/gcli/repos.h \ diff --git a/include/gcli/nvlist.h b/include/gcli/nvlist.h new file mode 100644 index 00000000..27f464d6 --- /dev/null +++ b/include/gcli/nvlist.h @@ -0,0 +1,58 @@ +/* + * Copyright 2023 Nico Sonack + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef GCLI_NVLIST_H +#define GCLI_NVLIST_H + +#ifdef HAVE_CONFIG_H +#include +#endif /* HAVE_CONFIG_H */ + +#include + +typedef struct gcli_nvpair gcli_nvpair; +typedef struct gcli_nvlist gcli_nvlist; + +struct gcli_nvpair { + TAILQ_ENTRY(gcli_nvpair) next; + + char *key; + char *value; +}; + +TAILQ_HEAD(gcli_nvlist, gcli_nvpair); + +int gcli_nvlist_init(gcli_nvlist *list); +int gcli_nvlist_free(gcli_nvlist *list); +int gcli_nvlist_append(gcli_nvlist *list, char *key, char *value); +char const *gcli_nvlist_find(gcli_nvlist const *list, char const *key); +char const *gcli_nvlist_find_or(gcli_nvlist const *list, char const *key, + char const *alternative); + +#endif /* GCLI_NVLIST_H */ diff --git a/src/nvlist.c b/src/nvlist.c new file mode 100644 index 00000000..7ed36750 --- /dev/null +++ b/src/nvlist.c @@ -0,0 +1,105 @@ +/* + * Copyright 2023 Nico Sonack + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +#include + +#include +#include + +int +gcli_nvlist_init(gcli_nvlist *list) +{ + TAILQ_INIT(list); + + return 0; +} + +int +gcli_nvlist_free(gcli_nvlist *list) +{ + gcli_nvpair *p1, *p2; + + p1 = TAILQ_FIRST(list); + while (p1 != NULL) { + p2 = TAILQ_NEXT(p1, next); + + free(p1->key); + free(p1->value); + free(p1); + + p1 = p2; + } + + TAILQ_INIT(list); + + return 0; +} + +int +gcli_nvlist_append(gcli_nvlist *list, char *key, char *value) +{ + /* TODO: handle the case where a pair with an already existing + * key is inserted. */ + + gcli_nvpair *pair = calloc(1, sizeof(*pair)); + if (pair == NULL) + return -1; + + pair->key = key; + pair->value = value; + + TAILQ_INSERT_TAIL(list, pair, next); + + return 0; +} + +char const * +gcli_nvlist_find(gcli_nvlist const *list, char const *key) +{ + gcli_nvpair const *pair; + + TAILQ_FOREACH(pair, list,next) { + if (strcmp(pair->key, key) == 0) + return pair->value; + } + return NULL; +} + +char const * +gcli_nvlist_find_or(gcli_nvlist const *list, char const *const key, + char const *const alternative) +{ + char const *const result = gcli_nvlist_find(list, key); + if (result) + return result; + else + return alternative; +} From 2dc2aff35b73b6ee39b0b93718dea7c67984f8dd Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Thu, 21 Dec 2023 15:56:13 +0100 Subject: [PATCH 092/158] Parse extra options in create issue subcommand This will allow us to pass extra options like OS, hardware or version to a backend. --- include/gcli/issues.h | 4 ++++ src/cmd/issues.c | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/include/gcli/issues.h b/include/gcli/issues.h index c4654cb7..8463f652 100644 --- a/include/gcli/issues.h +++ b/include/gcli/issues.h @@ -35,6 +35,7 @@ #endif #include +#include #include #include @@ -46,6 +47,7 @@ typedef struct gcli_issue gcli_issue; typedef struct gcli_submit_issue_options gcli_submit_issue_options; typedef struct gcli_issue_list gcli_issue_list; typedef struct gcli_issue_fetch_details gcli_issue_fetch_details; + struct gcli_issue { gcli_id number; char *title; @@ -72,6 +74,8 @@ struct gcli_submit_issue_options { char const *repo; char *title; char *body; + + gcli_nvlist extra; }; struct gcli_issue_list { diff --git a/src/cmd/issues.c b/src/cmd/issues.c index fbc8ef94..6b5abcd6 100644 --- a/src/cmd/issues.c +++ b/src/cmd/issues.c @@ -39,6 +39,7 @@ #include #include +#include #include #ifdef HAVE_GETOPT_H @@ -258,6 +259,27 @@ create_issue(gcli_submit_issue_options opts, int always_yes) return rc; } +static int +parse_submit_issue_option(gcli_submit_issue_options *opts) +{ + char *hd = strdup(optarg); + char *key = hd; + char *value = NULL; + + hd = strchr(hd, '='); + if (hd == NULL || *hd != '=') { + fprintf(stderr, "gcli: -O expects a key-value-pair as key=value\n"); + return -1; + } + + *hd++ = '\0'; + value = strdup(hd); /* make key and value separate allocations */ + + gcli_nvlist_append(&opts->extra, key, value); + + return 0; +} + static int subcommand_issue_create(int argc, char *argv[]) { @@ -265,6 +287,12 @@ subcommand_issue_create(int argc, char *argv[]) gcli_submit_issue_options opts = {0}; int always_yes = 0; + if (gcli_nvlist_init(&opts.extra) < 0) { + fprintf(stderr, "gcli: failed to init nvlist: %s\n", + strerror(errno)); + return EXIT_FAILURE; + } + const struct option options[] = { { .name = "owner", .has_arg = required_argument, @@ -281,7 +309,7 @@ subcommand_issue_create(int argc, char *argv[]) {0}, }; - while ((ch = getopt_long(argc, argv, "o:r:", options, NULL)) != -1) { + while ((ch = getopt_long(argc, argv, "o:r:O:", options, NULL)) != -1) { switch (ch) { case 'o': opts.owner = optarg; @@ -292,6 +320,11 @@ subcommand_issue_create(int argc, char *argv[]) case 'y': always_yes = 1; break; + case 'O': { + int rc = parse_submit_issue_option(&opts); + if (rc < 0) + return EXIT_FAILURE; + } break; default: usage(); return EXIT_FAILURE; @@ -315,6 +348,8 @@ subcommand_issue_create(int argc, char *argv[]) errx(1, "gcli: error: failed to submit issue: %s", gcli_get_error(g_clictx)); + gcli_nvlist_free(&opts.extra); + return EXIT_SUCCESS; } From 8e26d33c7bbea79de13011541fe0eb077365f5ac Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Thu, 21 Dec 2023 16:05:03 +0100 Subject: [PATCH 093/158] Unhardcode extra options for bugzilla bug creation --- src/bugzilla/bugs.c | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/src/bugzilla/bugs.c b/src/bugzilla/bugs.c index b44e1afc..78ee9b36 100644 --- a/src/bugzilla/bugs.c +++ b/src/bugzilla/bugs.c @@ -244,6 +244,36 @@ bugzilla_bug_get_attachments(gcli_ctx *ctx, char const *const product, return rc; } +static void +add_extra_options(gcli_nvlist const *list, gcli_jsongen *gen) +{ + static struct extra_opt { + char const *json_name; + char const *cli_name; + char const *default_value; + } extra_opts[] = { + { .json_name = "op_sys", + .cli_name = "os", + .default_value = "All" }, + { .json_name = "rep_platform", + .cli_name = "hardware", + .default_value = "All" }, + { .json_name = "version", + .cli_name = "version", + .default_value = "unspecified" }, + }; + static size_t extra_opts_size = ARRAY_SIZE(extra_opts); + + for (size_t i = 0; i < extra_opts_size; ++i) { + struct extra_opt const *o = &extra_opts[i]; + char const *const val = gcli_nvlist_find_or( + list, o->json_name, o->default_value); + + gcli_jsongen_objmember(gen, o->json_name); + gcli_jsongen_string(gen, val); + } +} + int bugzilla_bug_submit(gcli_ctx *ctx, gcli_submit_issue_options opts, gcli_fetch_buffer *out) @@ -294,18 +324,10 @@ bugzilla_bug_submit(gcli_ctx *ctx, gcli_submit_issue_options opts, gcli_jsongen_objmember(&gen, "description"); gcli_jsongen_string(&gen, description); - /* TODO: don't hardcode */ - gcli_jsongen_objmember(&gen, "op_sys"); - gcli_jsongen_string(&gen, "All"); - - gcli_jsongen_objmember(&gen, "rep_platform"); - gcli_jsongen_string(&gen, "All"); - - gcli_jsongen_objmember(&gen, "version"); - gcli_jsongen_string(&gen, "unspecified"); - gcli_jsongen_objmember(&gen, "api_key"); gcli_jsongen_string(&gen, token); + + add_extra_options(&opts.extra, &gen); } gcli_jsongen_end_object(&gen); From f13cb58b72b21df1c56df5693d1a5f4b66bf9fc0 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Wed, 27 Dec 2023 18:47:04 +0100 Subject: [PATCH 094/158] issues: use sn_strempty when checking for empty strings --- src/cmd/issues.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cmd/issues.c b/src/cmd/issues.c index 6b5abcd6..8a3a8b9f 100644 --- a/src/cmd/issues.c +++ b/src/cmd/issues.c @@ -170,7 +170,7 @@ gcli_issue_print_summary(gcli_issue const *const it) gcli_dict_add(dict, "STATE", GCLI_TBLCOL_STATECOLOURED, 0, "%s", it->state); - if ((quirks & GCLI_ISSUE_QUIRKS_URL) == 0 && it->url) + if ((quirks & GCLI_ISSUE_QUIRKS_URL) == 0 && !sn_strempty(it->url)) gcli_dict_add(dict, "URL", 0, 0, "%s", it->url); if ((quirks & GCLI_ISSUE_QUIRKS_COMMENTS) == 0) @@ -179,7 +179,7 @@ gcli_issue_print_summary(gcli_issue const *const it) if ((quirks & GCLI_ISSUE_QUIRKS_LOCKED) == 0) gcli_dict_add(dict, "LOCKED", 0, 0, "%s", sn_bool_yesno(it->locked)); - if (it->milestone) + if (!sn_strempty(it->milestone)) gcli_dict_add(dict, "MILESTONE", 0, 0, "%s", it->milestone); if (it->labels_size) { From 13e7fc4b04f223a91b3c95e7920c2e8a043221a1 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Sun, 31 Dec 2023 13:23:00 +0100 Subject: [PATCH 095/158] Update Changelog for preliminary Bugzilla support --- Changelog.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Changelog.md b/Changelog.md index 65c78740..b02202c1 100644 --- a/Changelog.md +++ b/Changelog.md @@ -7,6 +7,12 @@ This changelog does not follow semantic versioning. ### Added +- Preliminary (and thus experimental) support for Bugzilla has been + added. For this a new yet undocumented `attachments` subcommand + has been introduced. + Currently if now account has been specified it will default to + the FreeBSD Bugzilla - this may however change in the future. + ### Fixed - Fixed a segmentation fault when getting a 404 on Gitlab. This bug From 770d33cc8f8fdaa7c5a7b7078169da4e8b07057e Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 5 Jan 2024 17:08:19 +0100 Subject: [PATCH 096/158] Remove struct typedef for gcli_ctx --- include/gcli/attachments.h | 3 +- include/gcli/base64.h | 5 +- include/gcli/bugzilla/api.h | 2 +- include/gcli/bugzilla/attachments.h | 2 +- include/gcli/bugzilla/bugs-parser.h | 16 ++-- include/gcli/bugzilla/bugs.h | 14 +-- include/gcli/bugzilla/config.h | 2 +- include/gcli/cmd/cmd.h | 2 +- include/gcli/cmd/cmdconfig.h | 32 +++---- include/gcli/cmd/editor.h | 4 +- include/gcli/cmd/gitconfig.h | 2 +- include/gcli/cmd/milestones.h | 4 +- include/gcli/comments.h | 12 +-- include/gcli/curl.h | 21 ++--- include/gcli/date_time.h | 2 +- include/gcli/forges.h | 124 ++++++++++++++------------- include/gcli/forks.h | 6 +- include/gcli/gcli.h | 14 +-- include/gcli/gitea/comments.h | 5 +- include/gcli/gitea/config.h | 2 +- include/gcli/gitea/forks.h | 4 +- include/gcli/gitea/issues.h | 29 ++++--- include/gcli/gitea/labels.h | 6 +- include/gcli/gitea/milestones.h | 14 +-- include/gcli/gitea/pulls.h | 40 +++++---- include/gcli/gitea/releases.h | 8 +- include/gcli/gitea/repos.h | 15 ++-- include/gcli/gitea/sshkeys.h | 6 +- include/gcli/gitea/status.h | 4 +- include/gcli/github/api.h | 2 +- include/gcli/github/checks.h | 2 +- include/gcli/github/comments.h | 5 +- include/gcli/github/config.h | 2 +- include/gcli/github/forks.h | 4 +- include/gcli/github/gists.h | 12 +-- include/gcli/github/issues.h | 42 +++++---- include/gcli/github/labels.h | 6 +- include/gcli/github/milestones.h | 19 ++-- include/gcli/github/pulls.h | 40 +++++---- include/gcli/github/releases.h | 10 +-- include/gcli/github/repos.h | 10 +-- include/gcli/github/sshkeys.h | 6 +- include/gcli/github/status.h | 4 +- include/gcli/gitlab/api.h | 4 +- include/gcli/gitlab/comments.h | 10 ++- include/gcli/gitlab/config.h | 2 +- include/gcli/gitlab/forks.h | 4 +- include/gcli/gitlab/issues.h | 45 +++++----- include/gcli/gitlab/labels.h | 10 +-- include/gcli/gitlab/merge_requests.h | 49 ++++++----- include/gcli/gitlab/milestones.h | 18 ++-- include/gcli/gitlab/pipelines.h | 26 +++--- include/gcli/gitlab/releases.h | 12 +-- include/gcli/gitlab/repos.h | 14 +-- include/gcli/gitlab/snippets.h | 6 +- include/gcli/gitlab/sshkeys.h | 6 +- include/gcli/gitlab/status.h | 5 +- include/gcli/issues.h | 34 ++++---- include/gcli/json_util.h | 38 ++++---- include/gcli/labels.h | 6 +- include/gcli/milestones.h | 18 ++-- include/gcli/pulls.h | 49 +++++------ include/gcli/releases.h | 10 +-- include/gcli/repos.h | 10 +-- include/gcli/sshkeys.h | 6 +- include/gcli/status.h | 5 +- src/attachments.c | 2 +- src/base64.c | 4 +- src/bugzilla/api.c | 2 +- src/bugzilla/attachments.c | 2 +- src/bugzilla/bugs-parser.c | 16 ++-- src/bugzilla/bugs.c | 14 +-- src/bugzilla/config.c | 2 +- src/cmd/cmdconfig.c | 47 +++++----- src/cmd/comment.c | 2 +- src/cmd/editor.c | 4 +- src/cmd/gcli.c | 2 +- src/cmd/gitconfig.c | 2 +- src/cmd/issues.c | 2 +- src/cmd/pulls.c | 2 +- src/cmd/releases.c | 2 +- src/cmd/table.c | 2 +- src/comments.c | 6 +- src/curl.c | 25 +++--- src/date_time.c | 2 +- src/forges.c | 2 +- src/forks.c | 4 +- src/gcli.c | 10 ++- src/gitea/comments.c | 4 +- src/gitea/config.c | 2 +- src/gitea/forks.c | 4 +- src/gitea/issues.c | 33 +++---- src/gitea/labels.c | 6 +- src/gitea/milestones.c | 12 +-- src/gitea/pulls.c | 44 +++++----- src/gitea/releases.c | 10 +-- src/gitea/repos.c | 11 +-- src/gitea/sshkeys.c | 6 +- src/gitea/status.c | 4 +- src/github/api.c | 2 +- src/github/checks.c | 2 +- src/github/comments.c | 5 +- src/github/config.c | 2 +- src/github/forks.c | 4 +- src/github/gists.c | 10 +-- src/github/issues.c | 43 +++++----- src/github/labels.c | 6 +- src/github/milestones.c | 12 +-- src/github/pulls.c | 36 ++++---- src/github/releases.c | 12 +-- src/github/repos.c | 11 +-- src/github/sshkeys.c | 6 +- src/github/status.c | 4 +- src/gitlab/api.c | 4 +- src/gitlab/comments.c | 9 +- src/gitlab/config.c | 2 +- src/gitlab/forks.c | 4 +- src/gitlab/issues.c | 42 ++++----- src/gitlab/labels.c | 6 +- src/gitlab/merge_requests.c | 55 ++++++------ src/gitlab/milestones.c | 12 +-- src/gitlab/pipelines.c | 22 ++--- src/gitlab/releases.c | 13 +-- src/gitlab/repos.c | 10 +-- src/gitlab/snippets.c | 7 +- src/gitlab/sshkeys.c | 6 +- src/gitlab/status.c | 4 +- src/issues.c | 32 +++---- src/json_util.c | 39 ++++----- src/labels.c | 6 +- src/milestones.c | 12 +-- src/pgen/dump_c.c | 6 +- src/pgen/dump_h.c | 4 +- src/pulls.c | 45 +++++----- src/releases.c | 8 +- src/repos.c | 8 +- src/sshkeys.c | 6 +- src/status.c | 4 +- tests/bugzilla-parse-tests.c | 12 +-- tests/gitea-parse-tests.c | 8 +- tests/github-parse-tests.c | 24 +++--- tests/gitlab-parse-tests.c | 24 +++--- 142 files changed, 952 insertions(+), 880 deletions(-) diff --git a/include/gcli/attachments.h b/include/gcli/attachments.h index f528eb56..b37d569a 100644 --- a/include/gcli/attachments.h +++ b/include/gcli/attachments.h @@ -63,6 +63,7 @@ struct gcli_attachment_list { void gcli_attachments_free(gcli_attachment_list *list); void gcli_attachment_free(gcli_attachment *attachment); -int gcli_attachment_get_content(gcli_ctx *const ctx, gcli_id const id, FILE *out); +int gcli_attachment_get_content(struct gcli_ctx *const ctx, gcli_id const id, + FILE *out); #endif /* GCLI_ATTACHMENTS_H */ diff --git a/include/gcli/base64.h b/include/gcli/base64.h index ef1b5623..160e1e67 100644 --- a/include/gcli/base64.h +++ b/include/gcli/base64.h @@ -34,9 +34,10 @@ #include -int gcli_decode_base64(gcli_ctx *ctx, char const *input, char *buffer, +int gcli_decode_base64(struct gcli_ctx *ctx, char const *input, char *buffer, size_t buffer_size); -int gcli_base64_decode_print(gcli_ctx *ctx, FILE *out, char const *const input); +int gcli_base64_decode_print(struct gcli_ctx *ctx, FILE *out, + char const *const input); #endif /* GCLI_BASE64_H */ diff --git a/include/gcli/bugzilla/api.h b/include/gcli/bugzilla/api.h index 36fdac5c..e6aafd10 100644 --- a/include/gcli/bugzilla/api.h +++ b/include/gcli/bugzilla/api.h @@ -36,6 +36,6 @@ #include -char const *bugzilla_api_error_string(gcli_ctx *ctx, gcli_fetch_buffer *it); +char const *bugzilla_api_error_string(struct gcli_ctx *ctx, gcli_fetch_buffer *it); #endif /* GCLI_BUGZILLA_API_H */ diff --git a/include/gcli/bugzilla/attachments.h b/include/gcli/bugzilla/attachments.h index e8218be6..383d5fc3 100644 --- a/include/gcli/bugzilla/attachments.h +++ b/include/gcli/bugzilla/attachments.h @@ -32,7 +32,7 @@ #include -int bugzilla_attachment_get_content(gcli_ctx *ctx, gcli_id attachment_id, +int bugzilla_attachment_get_content(struct gcli_ctx *ctx, gcli_id attachment_id, FILE *output); #endif /* GCLI_BUGZILLA_ATTACHMENTS_H */ diff --git a/include/gcli/bugzilla/bugs-parser.h b/include/gcli/bugzilla/bugs-parser.h index 93dbb5b9..f38f019a 100644 --- a/include/gcli/bugzilla/bugs-parser.h +++ b/include/gcli/bugzilla/bugs-parser.h @@ -38,29 +38,31 @@ #include -int parse_bugzilla_bug_comments_dictionary_skip_first(gcli_ctx *const ctx, +int parse_bugzilla_bug_comments_dictionary_skip_first(struct gcli_ctx *const ctx, json_stream *stream, gcli_comment_list *out); -int parse_bugzilla_comments_array_skip_first(gcli_ctx *ctx, +int parse_bugzilla_comments_array_skip_first(struct gcli_ctx *ctx, struct json_stream *stream, gcli_comment_list *out); -int parse_bugzilla_bug_comments_dictionary_only_first(gcli_ctx *const ctx, +int parse_bugzilla_bug_comments_dictionary_only_first(struct gcli_ctx *const ctx, json_stream *stream, char **out); -int parse_bugzilla_comments_array_only_first(gcli_ctx *ctx, +int parse_bugzilla_comments_array_only_first(struct gcli_ctx *ctx, struct json_stream *stream, char **out); -int parse_bugzilla_assignee(gcli_ctx *ctx, struct json_stream *stream, +int parse_bugzilla_assignee(struct gcli_ctx *ctx, struct json_stream *stream, gcli_issue *out); -int parse_bugzilla_bug_attachments_dict(gcli_ctx *ctx, json_stream *stream, +int parse_bugzilla_bug_attachments_dict(struct gcli_ctx *ctx, + struct json_stream *stream, gcli_attachment_list *out); -int parse_bugzilla_attachment_content_only_first(gcli_ctx *ctx, json_stream *stream, +int parse_bugzilla_attachment_content_only_first(struct gcli_ctx *ctx, + json_stream *stream, gcli_attachment *out); #endif /* GCLI_BUGZILLA_BUGS_PARSER_H */ diff --git a/include/gcli/bugzilla/bugs.h b/include/gcli/bugzilla/bugs.h index 3bf0af2b..23acb5c5 100644 --- a/include/gcli/bugzilla/bugs.h +++ b/include/gcli/bugzilla/bugs.h @@ -38,23 +38,25 @@ #include -int bugzilla_get_bugs(gcli_ctx *ctx, char const *product, char const *component, +int bugzilla_get_bugs(struct gcli_ctx *ctx, char const *product, + char const *component, gcli_issue_fetch_details const *details, int const max, gcli_issue_list *out); -int bugzilla_get_bug(gcli_ctx *ctx, char const *product, char const *component, - gcli_id bug_id, gcli_issue *out); +int bugzilla_get_bug(struct gcli_ctx *ctx, char const *product, + char const *component, gcli_id bug_id, gcli_issue *out); -int bugzilla_bug_get_comments(gcli_ctx *const ctx, char const *const product, +int bugzilla_bug_get_comments(struct gcli_ctx *const ctx, + char const *const product, char const *const component, gcli_id const bug_id, gcli_comment_list *out); -int bugzilla_bug_get_attachments(gcli_ctx *ctx, char const *const product, +int bugzilla_bug_get_attachments(struct gcli_ctx *ctx, char const *const product, char const *const component, gcli_id const bug_id, gcli_attachment_list *const out); -int bugzilla_bug_submit(gcli_ctx *ctx, gcli_submit_issue_options opts, +int bugzilla_bug_submit(struct gcli_ctx *ctx, gcli_submit_issue_options opts, gcli_fetch_buffer *out); #endif /* GCLI_BUGZILLA_BUGS_H */ diff --git a/include/gcli/bugzilla/config.h b/include/gcli/bugzilla/config.h index d0bf76af..ba507d08 100644 --- a/include/gcli/bugzilla/config.h +++ b/include/gcli/bugzilla/config.h @@ -32,6 +32,6 @@ #include -char *bugzilla_make_authheader(gcli_ctx *ctx, char const *token); +char *bugzilla_make_authheader(struct gcli_ctx *ctx, char const *token); #endif /* GCLI_BUGZILLA_CONFIG_H */ diff --git a/include/gcli/cmd/cmd.h b/include/gcli/cmd/cmd.h index fe0ea150..1767bb11 100644 --- a/include/gcli/cmd/cmd.h +++ b/include/gcli/cmd/cmd.h @@ -38,7 +38,7 @@ #include -extern gcli_ctx *g_clictx; +extern struct gcli_ctx *g_clictx; static inline char * shift(int *argc, char ***argv) diff --git a/include/gcli/cmd/cmdconfig.h b/include/gcli/cmd/cmdconfig.h index 5c00e029..26aebee2 100644 --- a/include/gcli/cmd/cmdconfig.h +++ b/include/gcli/cmd/cmdconfig.h @@ -49,24 +49,24 @@ struct gcli_config_entry { TAILQ_HEAD(gcli_config_entries, gcli_config_entry); -int gcli_config_parse_args(gcli_ctx *ctx, int *argc, char ***argv); -int gcli_config_init_ctx(gcli_ctx *ctx); -void gcli_config_get_upstream_parts(gcli_ctx *ctx, sn_sv *owner, sn_sv *repo); -char *gcli_config_get_apibase(gcli_ctx *); -sn_sv gcli_config_find_by_key(gcli_ctx *ctx, char const *section_name, +int gcli_config_parse_args(struct gcli_ctx *ctx, int *argc, char ***argv); +int gcli_config_init_ctx(struct gcli_ctx *ctx); +void gcli_config_get_upstream_parts(struct gcli_ctx *ctx, sn_sv *owner, sn_sv *repo); +char *gcli_config_get_apibase(struct gcli_ctx *); +sn_sv gcli_config_find_by_key(struct gcli_ctx *ctx, char const *section_name, char const *key); -char *gcli_config_get_editor(gcli_ctx *ctx); -char *gcli_config_get_token(gcli_ctx *ctx); -char *gcli_config_get_account_name(gcli_ctx *ctx); -sn_sv gcli_config_get_upstream(gcli_ctx *ctx); -sn_sv gcli_config_get_base(gcli_ctx *ctx); -gcli_forge_type gcli_config_get_forge_type(gcli_ctx *ctx); -sn_sv gcli_config_get_override_default_account(gcli_ctx *ctx); -bool gcli_config_pr_inhibit_delete_source_branch(gcli_ctx *ctx); -void gcli_config_get_repo(gcli_ctx *ctx, char const **, char const **); -int gcli_config_have_colours(gcli_ctx *ctx); +char *gcli_config_get_editor(struct gcli_ctx *ctx); +char *gcli_config_get_token(struct gcli_ctx *ctx); +char *gcli_config_get_account_name(struct gcli_ctx *ctx); +sn_sv gcli_config_get_upstream(struct gcli_ctx *ctx); +sn_sv gcli_config_get_base(struct gcli_ctx *ctx); +gcli_forge_type gcli_config_get_forge_type(struct gcli_ctx *ctx); +sn_sv gcli_config_get_override_default_account(struct gcli_ctx *ctx); +bool gcli_config_pr_inhibit_delete_source_branch(struct gcli_ctx *ctx); +void gcli_config_get_repo(struct gcli_ctx *ctx, char const **, char const **); +int gcli_config_have_colours(struct gcli_ctx *ctx); struct gcli_config_entries const *gcli_config_get_section_entries( - gcli_ctx *ctx, char const *section_name); + struct gcli_ctx *ctx, char const *section_name); #endif /* GCLI_CMD_CMDCONFIG_H */ diff --git a/include/gcli/cmd/editor.h b/include/gcli/cmd/editor.h index aff2d90c..dc8e0cd6 100644 --- a/include/gcli/cmd/editor.h +++ b/include/gcli/cmd/editor.h @@ -37,8 +37,8 @@ #include char *gcli_editor_get_user_message( - gcli_ctx *ctx, - void (*initializer)(gcli_ctx *, FILE *, void *), + struct gcli_ctx *ctx, + void (*initializer)(struct gcli_ctx *, FILE *, void *), void *user_data); #endif /* GCLI_CMD_EDITOR_H */ diff --git a/include/gcli/cmd/gitconfig.h b/include/gcli/cmd/gitconfig.h index 084feaa0..aa94ba86 100644 --- a/include/gcli/cmd/gitconfig.h +++ b/include/gcli/cmd/gitconfig.h @@ -50,7 +50,7 @@ sn_sv gcli_gitconfig_get_current_branch(void); void gcli_gitconfig_add_fork_remote(char const *org, char const *repo); -int gcli_gitconfig_get_forgetype(gcli_ctx *ctx, char const *remote_name); +int gcli_gitconfig_get_forgetype(struct gcli_ctx *ctx, char const *remote_name); int gcli_gitconfig_repo_by_remote(char const *remote_name, char const **owner, diff --git a/include/gcli/cmd/milestones.h b/include/gcli/cmd/milestones.h index 1ebd03f5..b79eb1b0 100644 --- a/include/gcli/cmd/milestones.h +++ b/include/gcli/cmd/milestones.h @@ -36,10 +36,10 @@ #include -void gcli_print_milestones(gcli_ctx *ctx, gcli_milestone_list const *it, +void gcli_print_milestones(struct gcli_ctx *ctx, gcli_milestone_list const *it, int max); -void gcli_print_milestone(gcli_ctx *ctx, gcli_milestone const *it); +void gcli_print_milestone(struct gcli_ctx *ctx, gcli_milestone const *it); int subcommand_milestones(int argc, char *argv[]); diff --git a/include/gcli/comments.h b/include/gcli/comments.h index 2383087b..8b88e08c 100644 --- a/include/gcli/comments.h +++ b/include/gcli/comments.h @@ -68,12 +68,14 @@ void gcli_comments_free(gcli_comment_list *list); void gcli_comment_free(gcli_comment *const it); -int gcli_get_issue_comments(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id issue, gcli_comment_list *out); +int gcli_get_issue_comments(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id issue, + gcli_comment_list *out); -int gcli_get_pull_comments(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id issue, gcli_comment_list *out); +int gcli_get_pull_comments(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id issue, + gcli_comment_list *out); -int gcli_comment_submit(gcli_ctx *ctx, gcli_submit_comment_opts opts); +int gcli_comment_submit(struct gcli_ctx *ctx, gcli_submit_comment_opts opts); #endif /* COMMENTS_H */ diff --git a/include/gcli/curl.h b/include/gcli/curl.h index 4920b5d0..3b67e79d 100644 --- a/include/gcli/curl.h +++ b/include/gcli/curl.h @@ -43,7 +43,7 @@ #include #include -typedef int (*parsefn)(gcli_ctx *, json_stream *stream, void *list, +typedef int (*parsefn)(struct gcli_ctx *, json_stream *stream, void *list, size_t *listsize); typedef void (*filterfn)(void *list, size_t *listsize, void const *userdata); typedef struct gcli_fetch_buffer gcli_fetch_buffer; @@ -64,27 +64,28 @@ struct gcli_fetch_list_ctx { void const *userdata; }; -int gcli_fetch(gcli_ctx *ctx, char const *url, char **pagination_next, +int gcli_fetch(struct gcli_ctx *ctx, char const *url, char **pagination_next, gcli_fetch_buffer *out); -int gcli_curl(gcli_ctx *ctx, FILE *stream, char const *url, +int gcli_curl(struct gcli_ctx *ctx, FILE *stream, char const *url, char const *content_type); -int gcli_fetch_with_method(gcli_ctx *ctx, char const *method, +int gcli_fetch_with_method(struct gcli_ctx *ctx, char const *method, char const *url, char const *data, char **pagination_next, gcli_fetch_buffer *out); -int gcli_post_upload(gcli_ctx *ctx, char const *url, char const *content_type, - void *buffer, size_t buffer_size, gcli_fetch_buffer *out); +int gcli_post_upload(struct gcli_ctx *ctx, char const *url, + char const *content_type, void *buffer, size_t buffer_size, + gcli_fetch_buffer *out); -int gcli_curl_gitea_upload_attachment(gcli_ctx *ctx, char const *url, +int gcli_curl_gitea_upload_attachment(struct gcli_ctx *ctx, char const *url, char const *filename, gcli_fetch_buffer *out); -int gcli_curl_test_success(gcli_ctx *ctx, char const *url); +int gcli_curl_test_success(struct gcli_ctx *ctx, char const *url); char *gcli_urlencode(char const *); sn_sv gcli_urlencode_sv(sn_sv const); -char *gcli_urldecode(gcli_ctx *ctx, char const *input); -int gcli_fetch_list(gcli_ctx *ctx, char *url, gcli_fetch_list_ctx *fctx); +char *gcli_urldecode(struct gcli_ctx *ctx, char const *input); +int gcli_fetch_list(struct gcli_ctx *ctx, char *url, gcli_fetch_list_ctx *fctx); #endif /* CURL_H */ diff --git a/include/gcli/date_time.h b/include/gcli/date_time.h index e8e790cb..4800dd33 100644 --- a/include/gcli/date_time.h +++ b/include/gcli/date_time.h @@ -41,7 +41,7 @@ enum { DATEFMT_GITLAB, }; -int gcli_normalize_date(gcli_ctx *ctx, int fmt, char const *const input, +int gcli_normalize_date(struct gcli_ctx *ctx, int fmt, char const *const input, char *output, size_t const output_size); #endif /* GCLI_DATE_TIME_H */ diff --git a/include/gcli/forges.h b/include/gcli/forges.h index 30421da0..837e33fa 100644 --- a/include/gcli/forges.h +++ b/include/gcli/forges.h @@ -50,7 +50,7 @@ typedef struct gcli_forge_descriptor gcli_forge_descriptor; /* Hopefully temporary hack */ typedef int (*gcli_get_pull_checks_cb)( - gcli_ctx *, char const *, char const *, gcli_id, + struct gcli_ctx *, char const *, char const *, gcli_id, gcli_pull_checks_list *); /** @@ -60,14 +60,14 @@ struct gcli_forge_descriptor { /** * Submit a comment to a pull/mr or issue */ int (*perform_submit_comment)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, gcli_submit_comment_opts opts, gcli_fetch_buffer *out); /** * List comments on the given issue */ int (*get_issue_comments)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue, @@ -76,7 +76,7 @@ struct gcli_forge_descriptor { /** * List comments on the given PR */ int (*get_pull_comments)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id pr, @@ -85,7 +85,7 @@ struct gcli_forge_descriptor { /** * List forks of the given repo */ int (*get_forks)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *owner, char const *repo, int max, @@ -94,7 +94,7 @@ struct gcli_forge_descriptor { /** * Fork the given repo into the owner _in */ int (*fork_create)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *owner, char const *repo, char const *_in); @@ -102,7 +102,7 @@ struct gcli_forge_descriptor { /** * Get a list of issues on the given repo */ int (*get_issues)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_issue_fetch_details const *details, @@ -112,7 +112,7 @@ struct gcli_forge_descriptor { /** * Get a summary of an issue */ int (*get_issue_summary)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue_number, @@ -121,7 +121,7 @@ struct gcli_forge_descriptor { /** * Close the given issue */ int (*issue_close)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue_number); @@ -129,7 +129,7 @@ struct gcli_forge_descriptor { /** * Reopen the given issue */ int (*issue_reopen)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue_number); @@ -137,7 +137,7 @@ struct gcli_forge_descriptor { /** * Assign an issue to a user */ int (*issue_assign)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue_number, @@ -146,7 +146,7 @@ struct gcli_forge_descriptor { /** * Add labels to issues */ int (*issue_add_labels)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue, @@ -156,7 +156,7 @@ struct gcli_forge_descriptor { /** * Removes labels from issues */ int (*issue_remove_labels)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue, @@ -166,26 +166,34 @@ struct gcli_forge_descriptor { /** * Submit an issue */ int (*perform_submit_issue)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, gcli_submit_issue_options opts, gcli_fetch_buffer *out); /** * Change the title of an issue */ int (*issue_set_title)( - gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue, + struct gcli_ctx *ctx, + char const *owner, + char const *repo, + gcli_id issue, char const *new_title); /** * Get attachments of an issue */ int (*get_issue_attachments)( - gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue, + struct gcli_ctx *ctx, + char const *owner, + char const *repo, + gcli_id issue, gcli_attachment_list *out); /** * Dump the contents of the attachment to the given file */ int (*attachment_get_content)( - gcli_ctx *ctx, gcli_id id, FILE *out); + struct gcli_ctx *ctx, + gcli_id id, + FILE *out); /* Issue quirk bitmask */ enum { @@ -208,7 +216,7 @@ struct gcli_forge_descriptor { /** * Get list of milestones */ int (*get_milestones)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *owner, char const *repo, int max, @@ -217,7 +225,7 @@ struct gcli_forge_descriptor { /** * Get a single milestone */ int (*get_milestone)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id milestone, @@ -226,13 +234,13 @@ struct gcli_forge_descriptor { /** * create a milestone */ int (*create_milestone)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, struct gcli_milestone_create_args const *args); /** * delete a milestone */ int (*delete_milestone)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id milestone); @@ -240,7 +248,7 @@ struct gcli_forge_descriptor { /** * delete a milestone */ int (*milestone_set_duedate)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id milestone, @@ -249,7 +257,7 @@ struct gcli_forge_descriptor { /** * Get list of issues attached to this milestone */ int (*get_milestone_issues)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id milestone, @@ -257,7 +265,7 @@ struct gcli_forge_descriptor { /** Assign an issue to a milestone */ int (*issue_set_milestone)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue, @@ -266,7 +274,7 @@ struct gcli_forge_descriptor { /** * Clear the milestones of an issue */ int (*issue_clear_milestone)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue); @@ -274,7 +282,7 @@ struct gcli_forge_descriptor { /** * Get a list of PRs/MRs on the given repo */ int (*get_pulls)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *owner, char const *reponame, gcli_pull_fetch_details const *details, @@ -284,7 +292,7 @@ struct gcli_forge_descriptor { /** * Fetch the PR diff into the file */ int (*pull_get_diff)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, FILE *stream, char const *owner, char const *reponame, @@ -293,7 +301,7 @@ struct gcli_forge_descriptor { /** * Fetch the PR patch series into the file */ int (*pull_get_patch)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, FILE *stream, char const *owner, char const *repo, @@ -309,7 +317,7 @@ struct gcli_forge_descriptor { /** * Merge the given PR/MR */ int (*pull_merge)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *owner, char const *reponame, gcli_id pr_number, @@ -318,7 +326,7 @@ struct gcli_forge_descriptor { /** * Reopen the given PR/MR */ int (*pull_reopen)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *owner, char const *reponame, gcli_id pr_number); @@ -326,7 +334,7 @@ struct gcli_forge_descriptor { /** * Close the given PR/MR */ int (*pull_close)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *owner, char const *reponame, gcli_id pr_number); @@ -334,13 +342,13 @@ struct gcli_forge_descriptor { /** * Submit PR/MR */ int (*perform_submit_pull)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, gcli_submit_pull_options opts); /** * Get a list of commits in the given PR/MR */ int (*get_pull_commits)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id pr_number, @@ -360,7 +368,7 @@ struct gcli_forge_descriptor { /** * Get a summary of the given PR/MR */ int (*get_pull)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id pr_number, @@ -369,7 +377,7 @@ struct gcli_forge_descriptor { /** * Add labels to Pull Requests */ int (*pull_add_labels)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id pr, @@ -379,7 +387,7 @@ struct gcli_forge_descriptor { /** * Removes labels from Pull Requests */ int (*pull_remove_labels)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id pr, @@ -389,7 +397,7 @@ struct gcli_forge_descriptor { /** * Assign a PR to a milestone */ int (*pull_set_milestone)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id pull, @@ -398,7 +406,7 @@ struct gcli_forge_descriptor { /** * Clear a milestone on a PR */ int (*pull_clear_milestone)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id pull); @@ -406,7 +414,7 @@ struct gcli_forge_descriptor { /** * Request review of a given pull request by a user */ int (*pull_add_reviewer)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id pull, @@ -415,7 +423,7 @@ struct gcli_forge_descriptor { /** * Change the title of a pull request */ int (*pull_set_title)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id pull, @@ -424,7 +432,7 @@ struct gcli_forge_descriptor { /** * Get a list of releases in the given repo */ int (*get_releases)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *owner, char const *repo, int max, @@ -433,13 +441,13 @@ struct gcli_forge_descriptor { /** * Create a new release */ int (*create_release)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, gcli_new_release const *release); /** * Delete the release */ int (*delete_release)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *owner, char const *repo, char const *id); @@ -447,7 +455,7 @@ struct gcli_forge_descriptor { /** * Get a list of labels that are valid in the given repository */ int (*get_labels)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *owner, char const *repo, int max, @@ -458,7 +466,7 @@ struct gcli_forge_descriptor { * * The ID will be filled in for you */ int (*create_label)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_label *label); @@ -466,7 +474,7 @@ struct gcli_forge_descriptor { /** * Delete the given label */ int (*delete_label)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *owner, char const *repo, char const *label); @@ -474,7 +482,7 @@ struct gcli_forge_descriptor { /** * Get a list of repos of the given owner */ int (*get_repos)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *owner, int max, gcli_repo_list *out); @@ -482,21 +490,21 @@ struct gcli_forge_descriptor { /** * Create the given repo */ int (*repo_create)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, gcli_repo_create_options const *options, gcli_repo *out); /** * Delete the given repo */ int (*repo_delete)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *owner, char const *repo); /** * Change the visibility level of a repository */ int (*repo_set_visibility)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_repo_visibility vis); @@ -504,7 +512,7 @@ struct gcli_forge_descriptor { /** * Status summary for the account */ int (*get_notifications)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, int max, gcli_notification_list *notifications); @@ -513,33 +521,33 @@ struct gcli_forge_descriptor { * * Returns 0 on success or negative code on failure. */ int (*notification_mark_as_read)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *id); /** * Get an the http authentication header for use by curl */ - char *(*make_authheader)(gcli_ctx *ctx, char const *token); + char *(*make_authheader)(struct gcli_ctx *ctx, char const *token); /** * Get list of SSH keys */ - int (*get_sshkeys)(gcli_ctx *ctx, gcli_sshkey_list *); + int (*get_sshkeys)(struct gcli_ctx *ctx, gcli_sshkey_list *); /** * Add an SSH public key */ int (*add_sshkey)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *title, char const *public_key_path, gcli_sshkey *out); /** * Delete an SSH public key by its ID */ - int (*delete_sshkey)(gcli_ctx *ctx, gcli_id id); + int (*delete_sshkey)(struct gcli_ctx *ctx, gcli_id id); /** * Get the error string from the API */ char const *(*get_api_error_string)( - gcli_ctx *ctx, + struct gcli_ctx *ctx, gcli_fetch_buffer *); /** @@ -548,7 +556,7 @@ struct gcli_forge_descriptor { char const *user_object_key; }; -gcli_forge_descriptor const *gcli_forge(gcli_ctx *ctx); +gcli_forge_descriptor const *gcli_forge(struct gcli_ctx *ctx); /** A macro used for calling one of the dispatch points above. * diff --git a/include/gcli/forks.h b/include/gcli/forks.h index 06b6572d..b1612d07 100644 --- a/include/gcli/forks.h +++ b/include/gcli/forks.h @@ -52,10 +52,10 @@ struct gcli_fork_list { size_t forks_size; }; -int gcli_get_forks(gcli_ctx *ctx, char const *owner, char const *reponame, - int max, gcli_fork_list *out); +int gcli_get_forks(struct gcli_ctx *ctx, char const *owner, + char const *reponame, int max, gcli_fork_list *out); -int gcli_fork_create(gcli_ctx *ctx, char const *owner, char const *repo, +int gcli_fork_create(struct gcli_ctx *ctx, char const *owner, char const *repo, char const *in); void gcli_fork_delete(char const *owner, diff --git a/include/gcli/gcli.h b/include/gcli/gcli.h index 0a0941c6..68868f8e 100644 --- a/include/gcli/gcli.h +++ b/include/gcli/gcli.h @@ -58,17 +58,17 @@ typedef uint64_t gcli_id; #include #endif /* IN_LIBGCLI */ -typedef struct gcli_ctx gcli_ctx; +struct gcli_ctx; -char const *gcli_init(gcli_ctx **, - gcli_forge_type (*get_forge_type)(gcli_ctx *), - char *(*get_authheader)(gcli_ctx *), - char *(*get_apibase)(gcli_ctx *)); +char const *gcli_init(struct gcli_ctx **, + gcli_forge_type (*get_forge_type)(struct gcli_ctx *), + char *(*get_authheader)(struct gcli_ctx *), + char *(*get_apibase)(struct gcli_ctx *)); void *gcli_get_userdata(struct gcli_ctx const *); void gcli_set_userdata(struct gcli_ctx *, void *usrdata); void gcli_set_progress_func(struct gcli_ctx *, void (*pfunc)(bool done)); -void gcli_destroy(gcli_ctx **ctx); -char const *gcli_get_error(gcli_ctx *ctx); +void gcli_destroy(struct gcli_ctx **ctx); +char const *gcli_get_error(struct gcli_ctx *ctx); #endif /* GCLI_H */ diff --git a/include/gcli/gitea/comments.h b/include/gcli/gitea/comments.h index cf72f7c8..659f60b8 100644 --- a/include/gcli/gitea/comments.h +++ b/include/gcli/gitea/comments.h @@ -37,10 +37,11 @@ #include #include -int gitea_get_comments(gcli_ctx *ctx, char const *owner, char const *repo, +int gitea_get_comments(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue, gcli_comment_list *out); -int gitea_perform_submit_comment(gcli_ctx *ctx, gcli_submit_comment_opts opts, +int gitea_perform_submit_comment(struct gcli_ctx *ctx, + gcli_submit_comment_opts opts, gcli_fetch_buffer *out); #endif /* GITEA_COMMENTS_H */ diff --git a/include/gcli/gitea/config.h b/include/gcli/gitea/config.h index fc509606..eae5a6c5 100644 --- a/include/gcli/gitea/config.h +++ b/include/gcli/gitea/config.h @@ -38,6 +38,6 @@ #include -char *gitea_make_authheader(gcli_ctx *ctx, char const *token); +char *gitea_make_authheader(struct gcli_ctx *ctx, char const *token); #endif /* GITEA_CONFIG_H */ diff --git a/include/gcli/gitea/forks.h b/include/gcli/gitea/forks.h index 4e952975..28f29d34 100644 --- a/include/gcli/gitea/forks.h +++ b/include/gcli/gitea/forks.h @@ -36,10 +36,10 @@ #include -int gitea_get_forks(gcli_ctx *ctx, char const *owner, char const *repo, +int gitea_get_forks(struct gcli_ctx *ctx, char const *owner, char const *repo, int max, gcli_fork_list *out); -int gitea_fork_create(gcli_ctx *ctx, char const *owner, char const *repo, +int gitea_fork_create(struct gcli_ctx *ctx, char const *owner, char const *repo, char const *_in); #endif /* GITEA_FORKS_H */ diff --git a/include/gcli/gitea/issues.h b/include/gcli/gitea/issues.h index d50078a5..d52c8261 100644 --- a/include/gcli/gitea/issues.h +++ b/include/gcli/gitea/issues.h @@ -36,40 +36,41 @@ #include -int gitea_get_issues(gcli_ctx *ctx, char const *owner, char const *reponame, +int gitea_get_issues(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_issue_fetch_details const *details, int max, gcli_issue_list *out); -int gitea_get_issue_summary(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id issue_number, gcli_issue *out); +int gitea_get_issue_summary(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id issue_number, + gcli_issue *out); -int gitea_submit_issue(gcli_ctx *ctx, gcli_submit_issue_options opts, +int gitea_submit_issue(struct gcli_ctx *ctx, gcli_submit_issue_options opts, gcli_fetch_buffer *out); -int gitea_issue_close(gcli_ctx *ctx, char const *owner, char const *repo, +int gitea_issue_close(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue_number); -int gitea_issue_reopen(gcli_ctx *ctx, char const *owner, char const *repo, +int gitea_issue_reopen(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue_number); -int gitea_issue_assign(gcli_ctx *ctx, char const *owner, char const *repo, +int gitea_issue_assign(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue_number, char const *assignee); -int gitea_issue_add_labels(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id issue_number, char const *const labels[], - size_t labels_size); +int gitea_issue_add_labels(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id issue_number, + char const *const labels[], size_t labels_size); -int gitea_issue_remove_labels(gcli_ctx *ctx, char const *owner, +int gitea_issue_remove_labels(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue, char const *const labels[], size_t labels_size); -int gitea_issue_set_milestone(gcli_ctx *ctx, char const *owner, +int gitea_issue_set_milestone(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue, gcli_id milestone); -int gitea_issue_clear_milestone(gcli_ctx *ctx, char const *owner, +int gitea_issue_clear_milestone(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue); -int gitea_issue_set_title(gcli_ctx *ctx, char const *const owner, +int gitea_issue_set_title(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const issue, char const *const new_title); diff --git a/include/gcli/gitea/labels.h b/include/gcli/gitea/labels.h index 930662ab..a2555c8a 100644 --- a/include/gcli/gitea/labels.h +++ b/include/gcli/gitea/labels.h @@ -36,13 +36,13 @@ #include -int gitea_get_labels(gcli_ctx *ctx, char const *owner, char const *reponame, +int gitea_get_labels(struct gcli_ctx *ctx, char const *owner, char const *repo, int max, gcli_label_list *out); -int gitea_create_label(gcli_ctx *ctx, char const *owner, char const *repo, +int gitea_create_label(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_label *label); -int gitea_delete_label(gcli_ctx *ctx, char const *owner, char const *repo, +int gitea_delete_label(struct gcli_ctx *ctx, char const *owner, char const *repo, char const *label); #endif /* GITEA_LABELS_H */ diff --git a/include/gcli/gitea/milestones.h b/include/gcli/gitea/milestones.h index 6a26456a..24dcca0b 100644 --- a/include/gcli/gitea/milestones.h +++ b/include/gcli/gitea/milestones.h @@ -32,25 +32,25 @@ #include -int gitea_get_milestones(gcli_ctx *ctx, char const *const owner, +int gitea_get_milestones(struct gcli_ctx *ctx, char const *const owner, char const *const repo, int max, gcli_milestone_list *out); -int gitea_get_milestone(gcli_ctx *ctx, char const *const owner, +int gitea_get_milestone(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id milestone, gcli_milestone *out); -int gitea_create_milestone(gcli_ctx *ctx, +int gitea_create_milestone(struct gcli_ctx *ctx, struct gcli_milestone_create_args const *args); -int gitea_delete_milestone(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id milestone); +int gitea_delete_milestone(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id milestone); -int gitea_milestone_set_duedate(gcli_ctx *ctx, char const *owner, +int gitea_milestone_set_duedate(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id milestone, char const *date); -int gitea_milestone_get_issues(gcli_ctx *ctx, char const *owner, +int gitea_milestone_get_issues(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id milestone, gcli_issue_list *out); diff --git a/include/gcli/gitea/pulls.h b/include/gcli/gitea/pulls.h index cb942f7a..2b83b370 100644 --- a/include/gcli/gitea/pulls.h +++ b/include/gcli/gitea/pulls.h @@ -37,46 +37,50 @@ #include #include -int gitea_get_pulls(gcli_ctx *ctx, char const *owner, char const *reponame, +int gitea_get_pulls(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_pull_fetch_details const *details, int max, gcli_pull_list *out); -int gitea_get_pull(gcli_ctx *ctx, char const *owner, char const *repo, +int gitea_get_pull(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id pr_number, gcli_pull *out); -int gitea_get_pull_commits(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id pr_number, gcli_commit_list *out); +int gitea_get_pull_commits(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id pr_number, + gcli_commit_list *out); -int gitea_pull_submit(gcli_ctx *ctx, gcli_submit_pull_options opts); +int gitea_pull_submit(struct gcli_ctx *ctx, gcli_submit_pull_options opts); -int gitea_pull_merge(gcli_ctx *ctx, char const *owner, char const *reponame, +int gitea_pull_merge(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id pr_number, enum gcli_merge_flags flags); -int gitea_pull_close(gcli_ctx *ctx, char const *owner, char const *repo, +int gitea_pull_close(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id pr_number); -int gitea_pull_reopen(gcli_ctx *ctx, char const *owner, char const *repo, +int gitea_pull_reopen(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id pr_number); -int gitea_pull_get_diff(gcli_ctx *ctx, FILE *stream, char const *owner, +int gitea_pull_get_diff(struct gcli_ctx *ctx, FILE *stream, char const *owner, char const *repo, gcli_id pr_number); -int gitea_pull_get_patch(gcli_ctx *ctx, FILE *stream, char const *owner, +int gitea_pull_get_patch(struct gcli_ctx *ctx, FILE *stream, char const *owner, char const *repo, gcli_id pr_number); -int gitea_pull_get_checks(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id pr_number, gcli_pull_checks_list *out); +int gitea_pull_get_checks(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id pr_number, + gcli_pull_checks_list *out); -int gitea_pull_set_milestone(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id pr_number, gcli_id milestone_id); +int gitea_pull_set_milestone(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id pr_number, + gcli_id milestone_id); -int gitea_pull_clear_milestone(gcli_ctx *ctx, char const *owner, +int gitea_pull_clear_milestone(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id pr_number); -int gitea_pull_add_reviewer(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id pr_number, char const *username); +int gitea_pull_add_reviewer(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id pr_number, + char const *username); -int gitea_pull_set_title(gcli_ctx *ctx, char const *const owner, +int gitea_pull_set_title(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id pull, char const *const title); diff --git a/include/gcli/gitea/releases.h b/include/gcli/gitea/releases.h index 1a10ec1d..054205e0 100644 --- a/include/gcli/gitea/releases.h +++ b/include/gcli/gitea/releases.h @@ -36,12 +36,12 @@ #include -int gitea_get_releases(gcli_ctx *ctx, char const *owner, char const *repo, +int gitea_get_releases(struct gcli_ctx *ctx, char const *owner, char const *repo, int max, gcli_release_list *list); -int gitea_create_release(gcli_ctx *ctx, gcli_new_release const *release); +int gitea_create_release(struct gcli_ctx *ctx, gcli_new_release const *release); -int gitea_delete_release(gcli_ctx *ctx, char const *owner, char const *repo, - char const *id); +int gitea_delete_release(struct gcli_ctx *ctx, char const *owner, + char const *repo, char const *id); #endif /* GITEA_RELEASES_H */ diff --git a/include/gcli/gitea/repos.h b/include/gcli/gitea/repos.h index 5dcc4faa..d45194bb 100644 --- a/include/gcli/gitea/repos.h +++ b/include/gcli/gitea/repos.h @@ -36,18 +36,17 @@ #include -int gitea_get_repos(gcli_ctx *ctx, char const *owner, int max, +int gitea_get_repos(struct gcli_ctx *ctx, char const *owner, int max, gcli_repo_list *out); -int gitea_get_own_repos(gcli_ctx *ctx, int max, gcli_repo_list *out); +int gitea_get_own_repos(struct gcli_ctx *ctx, int max, gcli_repo_list *out); -int gitea_repo_create(gcli_ctx *ctx, gcli_repo_create_options const *options, - gcli_repo *out); +int gitea_repo_create(struct gcli_ctx *ctx, + gcli_repo_create_options const *options, gcli_repo *out); -int gitea_repo_delete(gcli_ctx *ctx, char const *owner, char const *repo); +int gitea_repo_delete(struct gcli_ctx *ctx, char const *owner, char const *repo); -int gitea_repo_set_visibility(gcli_ctx *ctx, char const *const owner, - char const *const repo, - gcli_repo_visibility vis); +int gitea_repo_set_visibility(struct gcli_ctx *ctx, char const *const owner, + char const *const repo, gcli_repo_visibility vis); #endif /* GITEA_REPOS_H */ diff --git a/include/gcli/gitea/sshkeys.h b/include/gcli/gitea/sshkeys.h index 46c8bc0f..3dbff012 100644 --- a/include/gcli/gitea/sshkeys.h +++ b/include/gcli/gitea/sshkeys.h @@ -32,11 +32,11 @@ #include -int gitea_get_sshkeys(gcli_ctx *ctx, gcli_sshkey_list *out); +int gitea_get_sshkeys(struct gcli_ctx *ctx, gcli_sshkey_list *out); -int gitea_add_sshkey(gcli_ctx *ctx, char const *title, +int gitea_add_sshkey(struct gcli_ctx *ctx, char const *title, char const *public_key_data, gcli_sshkey *out); -int gitea_delete_sshkey(gcli_ctx *ctx, gcli_id id); +int gitea_delete_sshkey(struct gcli_ctx *ctx, gcli_id id); #endif /* GCLI_GITEA_SSHKEYS_H */ diff --git a/include/gcli/gitea/status.h b/include/gcli/gitea/status.h index 88be8602..349b610b 100644 --- a/include/gcli/gitea/status.h +++ b/include/gcli/gitea/status.h @@ -32,9 +32,9 @@ #include -int gitea_get_notifications(gcli_ctx *ctx, int max, +int gitea_get_notifications(struct gcli_ctx *ctx, int max, gcli_notification_list *out); -int gitea_notification_mark_as_read(gcli_ctx *ctx, char const *id); +int gitea_notification_mark_as_read(struct gcli_ctx *ctx, char const *id); #endif /* GITEA_STATUS_H */ diff --git a/include/gcli/github/api.h b/include/gcli/github/api.h index d27269ba..6558f951 100644 --- a/include/gcli/github/api.h +++ b/include/gcli/github/api.h @@ -36,6 +36,6 @@ #include -char const *github_api_error_string(gcli_ctx *ctx, gcli_fetch_buffer *it); +char const *github_api_error_string(struct gcli_ctx *ctx, gcli_fetch_buffer *it); #endif /* GITHUB_API_H */ diff --git a/include/gcli/github/checks.h b/include/gcli/github/checks.h index b80a0a62..39a3855d 100644 --- a/include/gcli/github/checks.h +++ b/include/gcli/github/checks.h @@ -55,7 +55,7 @@ struct github_check_list { size_t checks_size; }; -int github_get_checks(gcli_ctx *ctx, char const *owner, char const *repo, +int github_get_checks(struct gcli_ctx *ctx, char const *owner, char const *repo, char const *ref, int max, github_check_list *checks); diff --git a/include/gcli/github/comments.h b/include/gcli/github/comments.h index 6bd6e05b..10eb3402 100644 --- a/include/gcli/github/comments.h +++ b/include/gcli/github/comments.h @@ -37,10 +37,11 @@ #include #include -int github_perform_submit_comment(gcli_ctx *ctx, gcli_submit_comment_opts opts, +int github_perform_submit_comment(struct gcli_ctx *ctx, + gcli_submit_comment_opts opts, gcli_fetch_buffer *out); -int github_get_comments(gcli_ctx *ctx, char const *owner, char const *repo, +int github_get_comments(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue, gcli_comment_list *out); #endif /* GITHUB_COMMENTS_H */ diff --git a/include/gcli/github/config.h b/include/gcli/github/config.h index 33a848b7..9e5b3fd4 100644 --- a/include/gcli/github/config.h +++ b/include/gcli/github/config.h @@ -38,6 +38,6 @@ #include -char *github_make_authheader(gcli_ctx *ctx, char const *token); +char *github_make_authheader(struct gcli_ctx *ctx, char const *token); #endif /* GITHUB_CONFIG_H */ diff --git a/include/gcli/github/forks.h b/include/gcli/github/forks.h index 4e02c582..40caffa8 100644 --- a/include/gcli/github/forks.h +++ b/include/gcli/github/forks.h @@ -36,10 +36,10 @@ #include -int github_get_forks(gcli_ctx *ctx, char const *owner, char const *repo, +int github_get_forks(struct gcli_ctx *ctx, char const *owner, char const *repo, int max, gcli_fork_list *out); -int github_fork_create(gcli_ctx *ctx, char const *owner, char const *repo, +int github_fork_create(struct gcli_ctx *ctx, char const *owner, char const *repo, char const *_in); #endif /* GITHUB_FORKS_H */ diff --git a/include/gcli/github/gists.h b/include/gcli/github/gists.h index 355684af..ef253310 100644 --- a/include/gcli/github/gists.h +++ b/include/gcli/github/gists.h @@ -74,14 +74,14 @@ struct gcli_new_gist { char const *gist_description; }; -int gcli_get_gists(gcli_ctx *ctx, char const *user, int max, +int gcli_get_gists(struct gcli_ctx *ctx, char const *user, int max, gcli_gist_list *list); -int gcli_get_gist(gcli_ctx *ctx, char const *gist_id, gcli_gist *out); +int gcli_get_gist(struct gcli_ctx *ctx, char const *gist_id, gcli_gist *out); -int gcli_create_gist(gcli_ctx *ctx, gcli_new_gist); +int gcli_create_gist(struct gcli_ctx *ctx, gcli_new_gist); -int gcli_delete_gist(gcli_ctx *ctx, char const *gist_id); +int gcli_delete_gist(struct gcli_ctx *ctx, char const *gist_id); void gcli_gists_free(gcli_gist_list *list); void gcli_gist_free(gcli_gist *g); @@ -92,7 +92,7 @@ void gcli_gist_free(gcli_gist *g); * file names. The objects describing the files obviously contain the * file name again. Whatever...here's a hack. Blame GitHub. */ -int parse_github_gist_files_idiot_hack(gcli_ctx *ctx, json_stream *stream, - gcli_gist *gist); +int parse_github_gist_files_idiot_hack(struct gcli_ctx *ctx, + json_stream *stream, gcli_gist *gist); #endif /* GCLI_GITHUB_GISTS_H */ diff --git a/include/gcli/github/issues.h b/include/gcli/github/issues.h index 6c4de0e4..5aef07a5 100644 --- a/include/gcli/github/issues.h +++ b/include/gcli/github/issues.h @@ -37,43 +37,47 @@ #include #include -int github_fetch_issues(gcli_ctx *ctx, char *url, int max, +int github_fetch_issues(struct gcli_ctx *ctx, char *url, int max, gcli_issue_list *out); -int github_get_issues(gcli_ctx *ctx, char const *owner, char const *repo, +int github_get_issues(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_issue_fetch_details const *details, int max, gcli_issue_list *out); -int github_get_issue_summary(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id issue_number, gcli_issue *out); +int github_get_issue_summary(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id issue_number, + gcli_issue *out); -int github_issue_close(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id issue_number); +int github_issue_close(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id issue_number); -int github_issue_reopen(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id issue_number); +int github_issue_reopen(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id issue_number); -int github_perform_submit_issue(gcli_ctx *ctx, gcli_submit_issue_options opts, +int github_perform_submit_issue(struct gcli_ctx *ctx, + gcli_submit_issue_options opts, gcli_fetch_buffer *out); -int github_issue_assign(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id issue_number, char const *assignee); +int github_issue_assign(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id issue_number, + char const *assignee); -int github_issue_add_labels(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id issue, char const *const labels[], - size_t labels_size); +int github_issue_add_labels(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id issue, + char const *const labels[], size_t labels_size); -int github_issue_remove_labels(gcli_ctx *ctx, char const *owner, +int github_issue_remove_labels(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue, char const *const labels[], size_t labels_size); -int github_issue_set_milestone(gcli_ctx *ctx, char const *owner, - char const *repo, gcli_id issue, gcli_id milestone); +int github_issue_set_milestone(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id issue, + gcli_id milestone); -int github_issue_clear_milestone(gcli_ctx *ctx, char const *owner, +int github_issue_clear_milestone(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue); -int github_issue_set_title(gcli_ctx *ctx, char const *const owner, +int github_issue_set_title(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const issue, char const *const new_title); diff --git a/include/gcli/github/labels.h b/include/gcli/github/labels.h index 1f318a77..42cfc281 100644 --- a/include/gcli/github/labels.h +++ b/include/gcli/github/labels.h @@ -36,13 +36,13 @@ #include -int github_get_labels(gcli_ctx *ctx, char const *owner, char const *reponame, +int github_get_labels(struct gcli_ctx *ctx, char const *owner, char const *repo, int max, gcli_label_list *out); -int github_create_label(gcli_ctx *ctx, char const *owner, char const *repo, +int github_create_label(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_label *label); -int github_delete_label(gcli_ctx *ctx, char const *owner, char const *repo, +int github_delete_label(struct gcli_ctx *ctx, char const *owner, char const *repo, char const *label); #endif /* GITHUB_LABELS_H */ diff --git a/include/gcli/github/milestones.h b/include/gcli/github/milestones.h index ad3310b0..7d6a6e0d 100644 --- a/include/gcli/github/milestones.h +++ b/include/gcli/github/milestones.h @@ -32,23 +32,24 @@ #include -int github_get_milestones(gcli_ctx *ctx, char const *owner, char const *repo, - int max, gcli_milestone_list *out); +int github_get_milestones(struct gcli_ctx *ctx, char const *owner, + char const *repo, int max, gcli_milestone_list *out); -int github_get_milestone(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id milestone, gcli_milestone *out); +int github_get_milestone(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id milestone, + gcli_milestone *out); -int github_create_milestone(gcli_ctx *ctx, +int github_create_milestone(struct gcli_ctx *ctx, struct gcli_milestone_create_args const *args); -int github_delete_milestone(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id milestone); +int github_delete_milestone(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id milestone); -int github_milestone_get_issues(gcli_ctx *ctx, char const *owner, +int github_milestone_get_issues(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id milestone, gcli_issue_list *out); -int github_milestone_set_duedate(gcli_ctx *ctx, char const *owner, +int github_milestone_set_duedate(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id milestone, char const *date); diff --git a/include/gcli/github/pulls.h b/include/gcli/github/pulls.h index 30092036..86f1dde2 100644 --- a/include/gcli/github/pulls.h +++ b/include/gcli/github/pulls.h @@ -37,42 +37,46 @@ #include #include -int github_get_pulls(gcli_ctx *ctx, char const *owner, char const *reponame, +int github_get_pulls(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_pull_fetch_details const *details, int max, gcli_pull_list *out); -int github_pull_get_diff(gcli_ctx *ctx, FILE *stream, char const *owner, +int github_pull_get_diff(struct gcli_ctx *ctx, FILE *stream, char const *owner, char const *reponame, gcli_id pr_number); -int github_pull_get_patch(gcli_ctx *ctx, FILE *stream, char const *owner, +int github_pull_get_patch(struct gcli_ctx *ctx, FILE *stream, char const *owner, char const *reponame, gcli_id pr_number); -int github_pull_get_checks(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id pr_number, gcli_pull_checks_list *out); +int github_pull_get_checks(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id pr_number, + gcli_pull_checks_list *out); -int github_pull_merge(gcli_ctx *ctx, char const *owner, char const *reponame, - gcli_id pr_number, enum gcli_merge_flags flags); +int github_pull_merge(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id pr_number, + enum gcli_merge_flags flags); -int github_pull_reopen(gcli_ctx *ctx, char const *owner, char const *reponame, - gcli_id pr_number); +int github_pull_reopen(struct gcli_ctx *ctx, char const *owner, + char const *reponame, gcli_id pr_number); -int github_pull_close(gcli_ctx *ctx, char const *owner, char const *reponame, +int github_pull_close(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id pr_number); -int github_perform_submit_pull(gcli_ctx *ctx, gcli_submit_pull_options opts); +int github_perform_submit_pull(struct gcli_ctx *ctx, gcli_submit_pull_options opts); -int github_get_pull_commits(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id pr_number, gcli_commit_list *out); +int github_get_pull_commits(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id pr_number, + gcli_commit_list *out); -int github_get_pull(gcli_ctx *ctx, char const *owner, char const *repo, +int github_get_pull(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id pr_number, gcli_pull *out); sn_sv github_pull_try_derive_head(void); -int github_pull_add_reviewer(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id pr_number, char const *username); +int github_pull_add_reviewer(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id pr_number, + char const *username); -int github_pull_set_title(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id pull, char const *new_title); +int github_pull_set_title(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id pull, char const *new_title); #endif /* GITHUB_PULLS_H */ diff --git a/include/gcli/github/releases.h b/include/gcli/github/releases.h index 526dee02..b2509d42 100644 --- a/include/gcli/github/releases.h +++ b/include/gcli/github/releases.h @@ -36,12 +36,12 @@ #include -int github_get_releases(gcli_ctx *ctx, char const *owner, char const *repo, - int max, gcli_release_list *list); +int github_get_releases(struct gcli_ctx *ctx, char const *owner, + char const *repo, int max, gcli_release_list *list); -int github_create_release(gcli_ctx *ctx, gcli_new_release const *release); +int github_create_release(struct gcli_ctx *ctx, gcli_new_release const *release); -int github_delete_release(gcli_ctx *ctx, char const *owner, char const *repo, - char const *id); +int github_delete_release(struct gcli_ctx *ctx, char const *owner, + char const *repo, char const *id); #endif /* GITHUB_RELEASES_H */ diff --git a/include/gcli/github/repos.h b/include/gcli/github/repos.h index 2b893c53..832de760 100644 --- a/include/gcli/github/repos.h +++ b/include/gcli/github/repos.h @@ -36,17 +36,17 @@ #include -int github_get_repos(gcli_ctx *ctx, char const *owner, int max, +int github_get_repos(struct gcli_ctx *ctx, char const *owner, int max, gcli_repo_list *out); -int github_get_own_repos(gcli_ctx *ctx, int max, gcli_repo_list *out); +int github_get_own_repos(struct gcli_ctx *ctx, int max, gcli_repo_list *out); -int github_repo_delete(gcli_ctx *ctx, char const *owner, char const *repo); +int github_repo_delete(struct gcli_ctx *ctx, char const *owner, char const *repo); -int github_repo_create(gcli_ctx *ctx, gcli_repo_create_options const *options, +int github_repo_create(struct gcli_ctx *ctx, gcli_repo_create_options const *options, gcli_repo *out); -int github_repo_set_visibility(gcli_ctx *ctx, char const *const owner, +int github_repo_set_visibility(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_repo_visibility vis); diff --git a/include/gcli/github/sshkeys.h b/include/gcli/github/sshkeys.h index e1730a60..579c7015 100644 --- a/include/gcli/github/sshkeys.h +++ b/include/gcli/github/sshkeys.h @@ -32,11 +32,11 @@ #include -int github_get_sshkeys(gcli_ctx *ctx, gcli_sshkey_list *out); +int github_get_sshkeys(struct gcli_ctx *ctx, gcli_sshkey_list *out); -int github_add_sshkey(gcli_ctx *ctx, char const *const title, +int github_add_sshkey(struct gcli_ctx *ctx, char const *const title, char const *const pubkey, gcli_sshkey *out); -int github_delete_sshkey(gcli_ctx *ctx, gcli_id id); +int github_delete_sshkey(struct gcli_ctx *ctx, gcli_id id); #endif /* GCLI_GITHUB_SSHKEYS_H */ diff --git a/include/gcli/github/status.h b/include/gcli/github/status.h index bd474bf8..1f5afdb5 100644 --- a/include/gcli/github/status.h +++ b/include/gcli/github/status.h @@ -36,7 +36,7 @@ #include -int github_get_notifications(gcli_ctx *ctx, int max, gcli_notification_list *out); -int github_notification_mark_as_read(gcli_ctx *ctx, char const *id); +int github_get_notifications(struct gcli_ctx *ctx, int max, gcli_notification_list *out); +int github_notification_mark_as_read(struct gcli_ctx *ctx, char const *id); #endif /* GITHUB_STATUS_H */ diff --git a/include/gcli/gitlab/api.h b/include/gcli/gitlab/api.h index 8d98b90f..c6e28803 100644 --- a/include/gcli/gitlab/api.h +++ b/include/gcli/gitlab/api.h @@ -36,7 +36,7 @@ #include -char const *gitlab_api_error_string(gcli_ctx *ctx, gcli_fetch_buffer *buf); -int gitlab_user_id(gcli_ctx *ctx, char const *user_name); +char const *gitlab_api_error_string(struct gcli_ctx *ctx, gcli_fetch_buffer *buf); +int gitlab_user_id(struct gcli_ctx *ctx, char const *user_name); #endif /* GITLAB_API_H */ diff --git a/include/gcli/gitlab/comments.h b/include/gcli/gitlab/comments.h index 53318116..3e1542f7 100644 --- a/include/gcli/gitlab/comments.h +++ b/include/gcli/gitlab/comments.h @@ -37,14 +37,16 @@ #include #include -int gitlab_perform_submit_comment(gcli_ctx *ctx, gcli_submit_comment_opts opts, +int gitlab_perform_submit_comment(struct gcli_ctx *ctx, + gcli_submit_comment_opts opts, gcli_fetch_buffer *out); -int gitlab_get_issue_comments(gcli_ctx *ctx, char const *owner, +int gitlab_get_issue_comments(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue, gcli_comment_list *out); -int gitlab_get_mr_comments(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id issue, gcli_comment_list *out); +int gitlab_get_mr_comments(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id issue, + gcli_comment_list *out); #endif /* GITLAB_COMMENTS_H */ diff --git a/include/gcli/gitlab/config.h b/include/gcli/gitlab/config.h index 981dac26..47ca3b47 100644 --- a/include/gcli/gitlab/config.h +++ b/include/gcli/gitlab/config.h @@ -38,6 +38,6 @@ #include -char *gitlab_make_authheader(gcli_ctx *ctx, char const *token); +char *gitlab_make_authheader(struct gcli_ctx *ctx, char const *token); #endif /* GITLAB_CONFIG_H */ diff --git a/include/gcli/gitlab/forks.h b/include/gcli/gitlab/forks.h index 5bc49269..586fe176 100644 --- a/include/gcli/gitlab/forks.h +++ b/include/gcli/gitlab/forks.h @@ -36,10 +36,10 @@ #include -int gitlab_get_forks(gcli_ctx *ctx, char const *owner, char const *repo, +int gitlab_get_forks(struct gcli_ctx *ctx, char const *owner, char const *repo, int max, gcli_fork_list *out); -int gitlab_fork_create(gcli_ctx *ctx, char const *owner, char const *repo, +int gitlab_fork_create(struct gcli_ctx *ctx, char const *owner, char const *repo, char const *_in); #endif /* GITLAB_FORKS_H */ diff --git a/include/gcli/gitlab/issues.h b/include/gcli/gitlab/issues.h index 7f4264da..cf69f9be 100644 --- a/include/gcli/gitlab/issues.h +++ b/include/gcli/gitlab/issues.h @@ -37,43 +37,48 @@ #include #include -int gitlab_fetch_issues(gcli_ctx *ctx, char *url, int max, +int gitlab_fetch_issues(struct gcli_ctx *ctx, char *url, int max, gcli_issue_list *out); -int gitlab_get_issues(gcli_ctx *ctx, char const *owner, char const *repo, +int gitlab_get_issues(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_issue_fetch_details const *details, int max, gcli_issue_list *out); -int gitlab_get_issue_summary(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id issue_number, gcli_issue *out); +int gitlab_get_issue_summary(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id issue_number, + gcli_issue *out); -int gitlab_issue_close(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id issue_number); +int gitlab_issue_close(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id issue_number); -int gitlab_issue_reopen(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id issue_number); +int gitlab_issue_reopen(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id issue_number); -int gitlab_issue_assign(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id issue_number, char const *assignee); +int gitlab_issue_assign(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id issue_number, + char const *assignee); -int gitlab_perform_submit_issue(gcli_ctx *ctx, gcli_submit_issue_options opts, +int gitlab_perform_submit_issue(struct gcli_ctx *ctx, + gcli_submit_issue_options opts, gcli_fetch_buffer *out); -int gitlab_issue_add_labels(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id issue, char const *const labels[], - size_t labels_size); +int gitlab_issue_add_labels(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id issue, + char const *const labels[], size_t labels_size); -int gitlab_issue_remove_labels(gcli_ctx *ctx, char const *owner, +int gitlab_issue_remove_labels(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue, char const *const labels[], size_t labels_size); -int gitlab_issue_set_milestone(gcli_ctx *ctx, char const *owner, - char const *repo, gcli_id issue, gcli_id milestone); +int gitlab_issue_set_milestone(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id issue, + gcli_id milestone); -int gitlab_issue_clear_milestone(gcli_ctx *ctx, char const *owner, +int gitlab_issue_clear_milestone(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue); -int gitlab_issue_set_title(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id issue, char const *new_title); +int gitlab_issue_set_title(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id issue, + char const *new_title); #endif /* GITLAB_ISSUES_H */ diff --git a/include/gcli/gitlab/labels.h b/include/gcli/gitlab/labels.h index e0323327..82502f8b 100644 --- a/include/gcli/gitlab/labels.h +++ b/include/gcli/gitlab/labels.h @@ -36,13 +36,13 @@ #include -int gitlab_get_labels(gcli_ctx *ctx, char const *owner, char const *reponame, +int gitlab_get_labels(struct gcli_ctx *ctx, char const *owner, char const *repo, int max, gcli_label_list *out); -int gitlab_create_label(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_label *label); +int gitlab_create_label(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_label *label); -int gitlab_delete_label(gcli_ctx *ctx, char const *owner, char const *repo, - char const *label); +int gitlab_delete_label(struct gcli_ctx *ctx, char const *owner, + char const *repo, char const *label); #endif /* GITLAB_LABELS_H */ diff --git a/include/gcli/gitlab/merge_requests.h b/include/gcli/gitlab/merge_requests.h index 507c3542..63f5e010 100644 --- a/include/gcli/gitlab/merge_requests.h +++ b/include/gcli/gitlab/merge_requests.h @@ -62,56 +62,59 @@ struct gitlab_diff_list { size_t diffs_size; }; -int gitlab_fetch_mrs(gcli_ctx *ctx, char *url, int max, +int gitlab_fetch_mrs(struct gcli_ctx *ctx, char *url, int max, gcli_pull_list *list); -int gitlab_get_mrs(gcli_ctx *ctx, char const *owner, +int gitlab_get_mrs(struct gcli_ctx *ctx, char const *owner, char const *reponame, gcli_pull_fetch_details const *details, int max, gcli_pull_list *out); -int gitlab_mr_get_diff(gcli_ctx *ctx, FILE *stream, char const *owner, +int gitlab_mr_get_diff(struct gcli_ctx *ctx, FILE *stream, char const *owner, char const *reponame, gcli_id mr_number); -int gitlab_mr_get_patch(gcli_ctx *ctx, FILE *stream, char const *owner, +int gitlab_mr_get_patch(struct gcli_ctx *ctx, FILE *stream, char const *owner, char const *reponame, gcli_id mr_number); -int gitlab_mr_merge(gcli_ctx *ctx, char const *owner, char const *reponame, +int gitlab_mr_merge(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id mr_number, enum gcli_merge_flags flags); -int gitlab_mr_close(gcli_ctx *ctx, char const *owner, char const *reponame, +int gitlab_mr_close(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id mr_number); -int gitlab_mr_reopen(gcli_ctx *ctx, char const *owner, char const *reponame, +int gitlab_mr_reopen(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id mr_number); -int gitlab_get_pull(gcli_ctx *ctx, char const *owner, char const *repo, +int gitlab_get_pull(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id mr_number, gcli_pull *out); -int gitlab_get_pull_commits(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id mr_number, gcli_commit_list *out); +int gitlab_get_pull_commits(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id mr_number, + gcli_commit_list *out); -int gitlab_perform_submit_mr(gcli_ctx *ctx, gcli_submit_pull_options opts); +int gitlab_perform_submit_mr(struct gcli_ctx *ctx, gcli_submit_pull_options opts); -int gitlab_mr_add_labels(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id mr_number, char const *const labels[], - size_t labels_size); +int gitlab_mr_add_labels(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id mr_number, + char const *const labels[], size_t labels_size); -int gitlab_mr_remove_labels(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id mr_number, char const *const labels[], - size_t labels_size); +int gitlab_mr_remove_labels(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id mr_number, + char const *const labels[], size_t labels_size); -int gitlab_mr_set_milestone(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id mr_number, gcli_id milestone_id); +int gitlab_mr_set_milestone(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id mr_number, + gcli_id milestone_id); -int gitlab_mr_clear_milestone(gcli_ctx *ctx, char const *owner, +int gitlab_mr_clear_milestone(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id mr_number); -int gitlab_mr_add_reviewer(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id mr_number, char const *username); +int gitlab_mr_add_reviewer(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id mr_number, + char const *username); -int gitlab_mr_set_title(gcli_ctx *ctx, char const *const owner, +int gitlab_mr_set_title(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const id, char const *const new_title); diff --git a/include/gcli/gitlab/milestones.h b/include/gcli/gitlab/milestones.h index 81d6dc93..62af9eec 100644 --- a/include/gcli/gitlab/milestones.h +++ b/include/gcli/gitlab/milestones.h @@ -36,23 +36,25 @@ #include -int gitlab_get_milestones(gcli_ctx *ctx, char const *owner, char const *repo, - int max, gcli_milestone_list *const out); +int gitlab_get_milestones(struct gcli_ctx *ctx, char const *owner, + char const *repo, int max, + gcli_milestone_list *const out); -int gitlab_create_milestone(gcli_ctx *ctx, +int gitlab_create_milestone(struct gcli_ctx *ctx, struct gcli_milestone_create_args const *args); -int gitlab_delete_milestone(gcli_ctx *ctx, char const *owner, +int gitlab_delete_milestone(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id milestone); -int gitlab_get_milestone(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id milestone, gcli_milestone *out); +int gitlab_get_milestone(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id milestone, + gcli_milestone *out); -int gitlab_milestone_get_issues(gcli_ctx *ctx, char const *owner, +int gitlab_milestone_get_issues(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id milestone, gcli_issue_list *out); -int gitlab_milestone_set_duedate(gcli_ctx *ctx, char const *owner, +int gitlab_milestone_set_duedate(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id milestone, char const *date); diff --git a/include/gcli/gitlab/pipelines.h b/include/gcli/gitlab/pipelines.h index 05fe6cef..aad9fbe4 100644 --- a/include/gcli/gitlab/pipelines.h +++ b/include/gcli/gitlab/pipelines.h @@ -76,35 +76,37 @@ struct gitlab_job_list { size_t jobs_size; }; -int gitlab_get_pipelines(gcli_ctx *ctx, char const *owner, char const *repo, - int max, gitlab_pipeline_list *out); +int gitlab_get_pipelines(struct gcli_ctx *ctx, char const *owner, + char const *repo, int max, gitlab_pipeline_list *out); void gitlab_pipeline_free(gitlab_pipeline *pipeline); void gitlab_pipelines_free(gitlab_pipeline_list *list); -int gitlab_get_pipeline_jobs(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id pipeline, int count, gitlab_job_list *out); +int gitlab_get_pipeline_jobs(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id pipeline, int count, + gitlab_job_list *out); void gitlab_free_jobs(gitlab_job_list *jobs); void gitlab_free_job(gitlab_job *job); -int gitlab_job_get_log(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id job_id, FILE *stream); +int gitlab_job_get_log(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id job_id, FILE *stream); -int gitlab_job_cancel(gcli_ctx *ctx, char const *owner, char const *repo, +int gitlab_job_cancel(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id job_id); -int gitlab_job_retry(gcli_ctx *ctx, char const *owner, char const *repo, +int gitlab_job_retry(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id job_id); -int gitlab_job_download_artifacts(gcli_ctx *ctx, char const *owner, +int gitlab_job_download_artifacts(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id jid, char const *outfile); -int gitlab_get_mr_pipelines(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id mr_id, gitlab_pipeline_list *list); +int gitlab_get_mr_pipelines(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id mr_id, + gitlab_pipeline_list *list); -int gitlab_get_job(gcli_ctx *ctx, char const *owner, char const *repo, +int gitlab_get_job(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const jid, gitlab_job *const out); #endif /* GITLAB_PIPELINES_H */ diff --git a/include/gcli/gitlab/releases.h b/include/gcli/gitlab/releases.h index e586c7ec..cfab8adc 100644 --- a/include/gcli/gitlab/releases.h +++ b/include/gcli/gitlab/releases.h @@ -36,14 +36,14 @@ #include -int gitlab_get_releases(gcli_ctx *ctx, char const *owner, char const *repo, - int max, gcli_release_list *list); +int gitlab_get_releases(struct gcli_ctx *ctx, char const *owner, + char const *repo, int max, gcli_release_list *list); -int gitlab_create_release(gcli_ctx *ctx, gcli_new_release const *release); +int gitlab_create_release(struct gcli_ctx *ctx, gcli_new_release const *release); -int gitlab_delete_release(gcli_ctx *ctx, char const *owner, char const *repo, - char const *id); +int gitlab_delete_release(struct gcli_ctx *ctx, char const *owner, + char const *repo, char const *id); -void gitlab_fixup_release_assets(gcli_ctx *ctx, gcli_release *const release); +void gitlab_fixup_release_assets(struct gcli_ctx *ctx, gcli_release *const release); #endif /* GITLAB_RELEASES_H */ diff --git a/include/gcli/gitlab/repos.h b/include/gcli/gitlab/repos.h index c1e0664a..4c1fb1f8 100644 --- a/include/gcli/gitlab/repos.h +++ b/include/gcli/gitlab/repos.h @@ -36,20 +36,20 @@ #include -int gitlab_get_repo(gcli_ctx *ctx, char const *owner, char const *repo, +int gitlab_get_repo(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_repo *out); -int gitlab_get_repos(gcli_ctx *ctx, char const *owner, int max, +int gitlab_get_repos(struct gcli_ctx *ctx, char const *owner, int max, gcli_repo_list *out); -int gitlab_get_own_repos(gcli_ctx *ctx, int max, gcli_repo_list *out); +int gitlab_get_own_repos(struct gcli_ctx *ctx, int max, gcli_repo_list *out); -int gitlab_repo_delete(gcli_ctx *ctx, char const *owner, char const *repo); +int gitlab_repo_delete(struct gcli_ctx *ctx, char const *owner, char const *repo); -int gitlab_repo_create(gcli_ctx *ctx, gcli_repo_create_options const *options, - gcli_repo *out); +int gitlab_repo_create(struct gcli_ctx *ctx, + gcli_repo_create_options const *options, gcli_repo *out); -int gitlab_repo_set_visibility(gcli_ctx *ctx, char const *const owner, +int gitlab_repo_set_visibility(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_repo_visibility vis); diff --git a/include/gcli/gitlab/snippets.h b/include/gcli/gitlab/snippets.h index fdedae4a..ff36be29 100644 --- a/include/gcli/gitlab/snippets.h +++ b/include/gcli/gitlab/snippets.h @@ -56,11 +56,11 @@ struct gcli_gitlab_snippet_list { void gcli_snippets_free(gcli_gitlab_snippet_list *list); -int gcli_snippets_get(gcli_ctx *ctx, int max, gcli_gitlab_snippet_list *out); +int gcli_snippets_get(struct gcli_ctx *ctx, int max, gcli_gitlab_snippet_list *out); -int gcli_snippet_delete(gcli_ctx *ctx, char const *snippet_id); +int gcli_snippet_delete(struct gcli_ctx *ctx, char const *snippet_id); -int gcli_snippet_get(gcli_ctx *ctx, char const *snippet_id, FILE *stream); +int gcli_snippet_get(struct gcli_ctx *ctx, char const *snippet_id, FILE *stream); void gcli_gitlab_snippet_free(gcli_gitlab_snippet *snippet); #endif /* GITLAB_SNIPPETS_H */ diff --git a/include/gcli/gitlab/sshkeys.h b/include/gcli/gitlab/sshkeys.h index 482fa645..2e3c29b0 100644 --- a/include/gcli/gitlab/sshkeys.h +++ b/include/gcli/gitlab/sshkeys.h @@ -36,11 +36,11 @@ #include -int gitlab_get_sshkeys(gcli_ctx *ctx, gcli_sshkey_list *list); +int gitlab_get_sshkeys(struct gcli_ctx *ctx, gcli_sshkey_list *list); -int gitlab_add_sshkey(gcli_ctx *ctx, char const *const title, +int gitlab_add_sshkey(struct gcli_ctx *ctx, char const *const title, char const *const pubkey, gcli_sshkey *const out); -int gitlab_delete_sshkey(gcli_ctx *ctx, gcli_id id); +int gitlab_delete_sshkey(struct gcli_ctx *ctx, gcli_id id); #endif /* GCLI_GITLAB_SSHKEYS_H */ diff --git a/include/gcli/gitlab/status.h b/include/gcli/gitlab/status.h index 83667ed6..cc95c776 100644 --- a/include/gcli/gitlab/status.h +++ b/include/gcli/gitlab/status.h @@ -36,7 +36,8 @@ #include -int gitlab_get_notifications(gcli_ctx *ctx, int max, gcli_notification_list *out); -int gitlab_notification_mark_as_read(gcli_ctx *ctx, char const *id); +int gitlab_get_notifications(struct gcli_ctx *ctx, int max, + gcli_notification_list *out); +int gitlab_notification_mark_as_read(struct gcli_ctx *ctx, char const *id); #endif /* GITLAB_STATUS_H */ diff --git a/include/gcli/issues.h b/include/gcli/issues.h index 8463f652..aaba9eb0 100644 --- a/include/gcli/issues.h +++ b/include/gcli/issues.h @@ -90,46 +90,46 @@ struct gcli_issue_fetch_details { char const *milestone; /* filter by the given milestone */ }; -int gcli_get_issues(gcli_ctx *ctx, char const *owner, char const *reponame, +int gcli_get_issues(struct gcli_ctx *ctx, char const *owner, char const *reponame, gcli_issue_fetch_details const *details, int max, gcli_issue_list *out); void gcli_issues_free(gcli_issue_list *); -int gcli_get_issue(gcli_ctx *ctx, char const *owner, char const *reponame, +int gcli_get_issue(struct gcli_ctx *ctx, char const *owner, char const *reponame, gcli_id issue_number, gcli_issue *out); void gcli_issue_free(gcli_issue *it); -int gcli_issue_close(gcli_ctx *ctx, char const *owner, char const *repo, +int gcli_issue_close(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue_number); -int gcli_issue_reopen(gcli_ctx *ctx, char const *owner, char const *repo, +int gcli_issue_reopen(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue_number); -int gcli_issue_submit(gcli_ctx *ctx, gcli_submit_issue_options); +int gcli_issue_submit(struct gcli_ctx *ctx, gcli_submit_issue_options); -int gcli_issue_assign(gcli_ctx *ctx, char const *owner, char const *repo, +int gcli_issue_assign(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue_number, char const *assignee); -int gcli_issue_add_labels(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id issue_number, char const *const labels[], - size_t labels_size); +int gcli_issue_add_labels(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id issue_number, + char const *const labels[], size_t labels_size); -int gcli_issue_remove_labels(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id issue_number, char const *const labels[], - size_t labels_size); +int gcli_issue_remove_labels(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id issue_number, + char const *const labels[], size_t labels_size); -int gcli_issue_set_milestone(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id issue, int milestone); +int gcli_issue_set_milestone(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id issue, int milestone); -int gcli_issue_clear_milestone(gcli_ctx *cxt, char const *owner, +int gcli_issue_clear_milestone(struct gcli_ctx *cxt, char const *owner, char const *repo, gcli_id issue); -int gcli_issue_set_title(gcli_ctx *ctx, char const *owner, char const *repo, +int gcli_issue_set_title(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue, char const *new_title); -int gcli_issue_get_attachments(gcli_ctx *ctx, char const *owner, +int gcli_issue_get_attachments(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue, gcli_attachment_list *attachments); diff --git a/include/gcli/json_util.h b/include/gcli/json_util.h index 208b39bc..0adf824e 100644 --- a/include/gcli/json_util.h +++ b/include/gcli/json_util.h @@ -57,26 +57,26 @@ #define get_is_string(ctx, input, out) ((void)ctx, (*out = json_next(input) == JSON_STRING), 1) #define get_int_to_string(ctx, input, out) get_int_to_string_(ctx, input, out, __func__) -int get_int_(gcli_ctx *ctx, json_stream *input, int *out, char const *function); -int get_id_(gcli_ctx *ctx, json_stream *input, gcli_id *out, char const *function); -int get_long_(gcli_ctx *ctx, json_stream *input, long *out, char const *function); -int get_size_t_(gcli_ctx *ctx, json_stream *input, size_t *out, char const *function); -int get_double_(gcli_ctx *ctx, json_stream *input, double *out, char const *function); -int get_parse_int_(gcli_ctx *ctx, json_stream *input, long *out, char const *function); -int get_bool_(gcli_ctx *ctx, json_stream *input, bool *out, char const *function); -int get_bool_relaxed_(gcli_ctx *ctx, json_stream *input, bool *out, char const *function); -int get_string_(gcli_ctx *ctx, json_stream *input, char **out, char const *function); -int get_sv_(gcli_ctx *ctx, json_stream *input, sn_sv *out, char const *function); -int get_user_(gcli_ctx *ctx, json_stream *input, char **out, char const *function); -int get_label_(gcli_ctx *ctx, json_stream *input, char const **out, char const *function); -int get_github_style_colour(gcli_ctx *ctx, json_stream *input, uint32_t *out); -int get_gitlab_style_colour(gcli_ctx *ctx, json_stream *input, uint32_t *out); -int get_github_is_pr(gcli_ctx *ctx, json_stream *input, int *out); -int get_gitlab_can_be_merged(gcli_ctx *ctx, json_stream *input, bool *out); -int get_gitea_visibility(gcli_ctx *ctx, json_stream *input, char **out); +int get_int_(struct gcli_ctx *ctx, json_stream *input, int *out, char const *function); +int get_id_(struct gcli_ctx *ctx, json_stream *input, gcli_id *out, char const *function); +int get_long_(struct gcli_ctx *ctx, json_stream *input, long *out, char const *function); +int get_size_t_(struct gcli_ctx *ctx, json_stream *input, size_t *out, char const *function); +int get_double_(struct gcli_ctx *ctx, json_stream *input, double *out, char const *function); +int get_parse_int_(struct gcli_ctx *ctx, json_stream *input, long *out, char const *function); +int get_bool_(struct gcli_ctx *ctx, json_stream *input, bool *out, char const *function); +int get_bool_relaxed_(struct gcli_ctx *ctx, json_stream *input, bool *out, char const *function); +int get_string_(struct gcli_ctx *ctx, json_stream *input, char **out, char const *function); +int get_sv_(struct gcli_ctx *ctx, json_stream *input, sn_sv *out, char const *function); +int get_user_(struct gcli_ctx *ctx, json_stream *input, char **out, char const *function); +int get_label_(struct gcli_ctx *ctx, json_stream *input, char const **out, char const *function); +int get_github_style_colour(struct gcli_ctx *ctx, json_stream *input, uint32_t *out); +int get_gitlab_style_colour(struct gcli_ctx *ctx, json_stream *input, uint32_t *out); +int get_github_is_pr(struct gcli_ctx *ctx, json_stream *input, int *out); +int get_gitlab_can_be_merged(struct gcli_ctx *ctx, json_stream *input, bool *out); +int get_gitea_visibility(struct gcli_ctx *ctx, json_stream *input, char **out); sn_sv gcli_json_escape(sn_sv); #define gcli_json_escape_cstr(x) (gcli_json_escape(SV((char *)(x))).data) -int gcli_json_advance(gcli_ctx *ctx, json_stream *input, char const *fmt, ...); +int gcli_json_advance(struct gcli_ctx *ctx, json_stream *input, char const *fmt, ...); static inline char const * gcli_json_bool(bool it) @@ -85,7 +85,7 @@ gcli_json_bool(bool it) } static inline int -get_int_to_string_(gcli_ctx *ctx, json_stream *input, char **out, +get_int_to_string_(struct gcli_ctx *ctx, json_stream *input, char **out, char const *const fn) { int rc; diff --git a/include/gcli/labels.h b/include/gcli/labels.h index 8b7a3935..c8c15812 100644 --- a/include/gcli/labels.h +++ b/include/gcli/labels.h @@ -55,17 +55,17 @@ struct gcli_label_list { size_t labels_size; }; -int gcli_get_labels(gcli_ctx *ctx, char const *owner, char const *reponame, +int gcli_get_labels(struct gcli_ctx *ctx, char const *owner, char const *repo, int max, gcli_label_list *out); void gcli_free_label(gcli_label *label); void gcli_free_labels(gcli_label_list *labels); -int gcli_create_label(gcli_ctx *ctx, char const *owner, char const *repo, +int gcli_create_label(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_label *label); -int gcli_delete_label(gcli_ctx *ctx, char const *owner, char const *repo, +int gcli_delete_label(struct gcli_ctx *ctx, char const *owner, char const *repo, char const *label); #endif /* LABELS_H */ diff --git a/include/gcli/milestones.h b/include/gcli/milestones.h index c7345ecc..d459ed2e 100644 --- a/include/gcli/milestones.h +++ b/include/gcli/milestones.h @@ -75,26 +75,26 @@ struct gcli_milestone_create_args { char const *repo; }; -int gcli_get_milestones(gcli_ctx *ctx, char const *owner, char const *repo, - int max, gcli_milestone_list *out); +int gcli_get_milestones(struct gcli_ctx *ctx, char const *owner, + char const *repo, int max, gcli_milestone_list *out); -int gcli_get_milestone(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id milestone, gcli_milestone *out); +int gcli_get_milestone(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id milestone, gcli_milestone *out); -int gcli_create_milestone(gcli_ctx *ctx, +int gcli_create_milestone(struct gcli_ctx *ctx, struct gcli_milestone_create_args const *args); -int gcli_delete_milestone(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id milestone); +int gcli_delete_milestone(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id milestone); void gcli_free_milestone(gcli_milestone *it); void gcli_free_milestones(gcli_milestone_list *it); -int gcli_milestone_get_issues(gcli_ctx *ctx, char const *owner, +int gcli_milestone_get_issues(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id milestone, gcli_issue_list *out); -int gcli_milestone_set_duedate(gcli_ctx *ctx, char const *owner, +int gcli_milestone_set_duedate(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id milestone, char const *date); diff --git a/include/gcli/pulls.h b/include/gcli/pulls.h index e87ad917..2f94595f 100644 --- a/include/gcli/pulls.h +++ b/include/gcli/pulls.h @@ -129,7 +129,7 @@ struct gcli_pull_checks_list { int forge_type; }; -int gcli_get_pulls(gcli_ctx *ctx, char const *owner, char const *reponame, +int gcli_get_pulls(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_pull_fetch_details const *details, int max, gcli_pull_list *out); @@ -137,59 +137,60 @@ void gcli_pull_free(gcli_pull *it); void gcli_pulls_free(gcli_pull_list *list); -int gcli_pull_get_diff(gcli_ctx *ctx, FILE *fout, char const *owner, +int gcli_pull_get_diff(struct gcli_ctx *ctx, FILE *fout, char const *owner, char const *repo, gcli_id pr_number); -int gcli_pull_get_checks(gcli_ctx *ctx, char const *owner, char const *repo, +int gcli_pull_get_checks(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id pr_number, gcli_pull_checks_list *out); void gcli_pull_checks_free(gcli_pull_checks_list *list); -int gcli_pull_get_commits(gcli_ctx *ctx, char const *owner, char const *repo, +int gcli_pull_get_commits(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id pr_number, gcli_commit_list *out); void gcli_commits_free(gcli_commit_list *list); -int gcli_get_pull(gcli_ctx *ctx, char const *owner, char const *repo, +int gcli_get_pull(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id pr_number, gcli_pull *out); -int gcli_pull_submit(gcli_ctx *ctx, gcli_submit_pull_options); +int gcli_pull_submit(struct gcli_ctx *ctx, gcli_submit_pull_options); enum gcli_merge_flags { GCLI_PULL_MERGE_SQUASH = 0x1, /* squash commits when merging */ GCLI_PULL_MERGE_DELETEHEAD = 0x2, /* delete the source branch after merging */ }; -int gcli_pull_merge(gcli_ctx *ctx, char const *owner, char const *reponame, +int gcli_pull_merge(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id pr_number, enum gcli_merge_flags flags); -int gcli_pull_close(gcli_ctx *ctx, char const *owner, char const *reponame, +int gcli_pull_close(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id pr_number); -int gcli_pull_reopen(gcli_ctx *ctx, char const *owner, char const *reponame, +int gcli_pull_reopen(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id pr_number); -int gcli_pull_add_labels(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id pr_number, char const *const labels[], - size_t labels_size); +int gcli_pull_add_labels(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id pr_number, + char const *const labels[], size_t labels_size); -int gcli_pull_remove_labels(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id pr_number, char const *const labels[], - size_t labels_size); +int gcli_pull_remove_labels(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id pr_number, + char const *const labels[], size_t labels_size); -int gcli_pull_set_milestone(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id pr_number, int milestone_id); +int gcli_pull_set_milestone(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id pr_number, int milestone_id); -int gcli_pull_clear_milestone(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id pr_number); +int gcli_pull_clear_milestone(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id pr_number); -int gcli_pull_add_reviewer(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id pr_number, char const *username); +int gcli_pull_add_reviewer(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id pr_number, + char const *username); -int gcli_pull_get_patch(gcli_ctx *ctx, FILE *out, char const *owner, +int gcli_pull_get_patch(struct gcli_ctx *ctx, FILE *out, char const *owner, char const *repo, gcli_id pr_number); -int gcli_pull_set_title(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id pull, char const *new_title); +int gcli_pull_set_title(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id pull, char const *new_title); #endif /* PULLS_H */ diff --git a/include/gcli/releases.h b/include/gcli/releases.h index 9bae7b95..d1987e7c 100644 --- a/include/gcli/releases.h +++ b/include/gcli/releases.h @@ -86,18 +86,18 @@ struct gcli_new_release { size_t assets_size; }; -int gcli_get_releases(gcli_ctx *ctx, char const *owner, char const *repo, +int gcli_get_releases(struct gcli_ctx *ctx, char const *owner, char const *repo, int max, gcli_release_list *list); void gcli_free_releases(gcli_release_list *); -int gcli_create_release(gcli_ctx *ctx, gcli_new_release const *); +int gcli_create_release(struct gcli_ctx *ctx, gcli_new_release const *); -int gcli_release_push_asset(gcli_ctx *, gcli_new_release *, +int gcli_release_push_asset(struct gcli_ctx *, gcli_new_release *, gcli_release_asset_upload); -int gcli_delete_release(gcli_ctx *ctx, char const *owner, char const *repo, - char const *id); +int gcli_delete_release(struct gcli_ctx *ctx, char const *owner, + char const *repo, char const *id); void gcli_release_free(gcli_release *release); diff --git a/include/gcli/repos.h b/include/gcli/repos.h index 7d6e1640..29769ce9 100644 --- a/include/gcli/repos.h +++ b/include/gcli/repos.h @@ -67,18 +67,18 @@ typedef enum { GCLI_REPO_VISIBILITY_PUBLIC, } gcli_repo_visibility; -int gcli_get_repos(gcli_ctx *ctx, char const *owner, int max, +int gcli_get_repos(struct gcli_ctx *ctx, char const *owner, int max, gcli_repo_list *list); void gcli_repos_free(gcli_repo_list *list); void gcli_repo_free(gcli_repo *it); -int gcli_repo_delete(gcli_ctx *ctx, char const *owner, char const *repo); +int gcli_repo_delete(struct gcli_ctx *ctx, char const *owner, char const *repo); -int gcli_repo_create(gcli_ctx *ctx, gcli_repo_create_options const *, +int gcli_repo_create(struct gcli_ctx *ctx, gcli_repo_create_options const *, gcli_repo *out); -int gcli_repo_set_visibility(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_repo_visibility visibility); +int gcli_repo_set_visibility(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_repo_visibility visibility); #endif /* REPOS_H */ diff --git a/include/gcli/sshkeys.h b/include/gcli/sshkeys.h index fb91d788..326611d8 100644 --- a/include/gcli/sshkeys.h +++ b/include/gcli/sshkeys.h @@ -53,10 +53,10 @@ struct gcli_sshkey_list { typedef struct gcli_sshkey gcli_sshkey; typedef struct gcli_sshkey_list gcli_sshkey_list; -int gcli_sshkeys_get_keys(gcli_ctx *ctx, gcli_sshkey_list *out); -int gcli_sshkeys_add_key(gcli_ctx *ctx, char const *title, +int gcli_sshkeys_get_keys(struct gcli_ctx *ctx, gcli_sshkey_list *out); +int gcli_sshkeys_add_key(struct gcli_ctx *ctx, char const *title, char const *public_key_path, gcli_sshkey *out); -int gcli_sshkeys_delete_key(gcli_ctx *ctx, gcli_id id); +int gcli_sshkeys_delete_key(struct gcli_ctx *ctx, gcli_id id); void gcli_sshkeys_free_keys(gcli_sshkey_list *list); #endif /* GCLI_SSHKEYS_H */ diff --git a/include/gcli/status.h b/include/gcli/status.h index c2c4bbe0..9ffcea46 100644 --- a/include/gcli/status.h +++ b/include/gcli/status.h @@ -55,8 +55,9 @@ struct gcli_notification_list { size_t notifications_size; }; -int gcli_get_notifications(gcli_ctx *ctx, int count, gcli_notification_list *out); -int gcli_notification_mark_as_read(gcli_ctx *ctx, char const *id); +int gcli_get_notifications(struct gcli_ctx *ctx, int count, + gcli_notification_list *out); +int gcli_notification_mark_as_read(struct gcli_ctx *ctx, char const *id); void gcli_free_notification(gcli_notification *); void gcli_free_notifications(gcli_notification_list *); diff --git a/src/attachments.c b/src/attachments.c index e4ec529d..5a35834a 100644 --- a/src/attachments.c +++ b/src/attachments.c @@ -56,7 +56,7 @@ gcli_attachment_free(gcli_attachment *it) } int -gcli_attachment_get_content(gcli_ctx *const ctx, gcli_id const id, FILE *out) +gcli_attachment_get_content(struct gcli_ctx *const ctx, gcli_id const id, FILE *out) { gcli_forge_descriptor const *const forge = gcli_forge(ctx); diff --git a/src/base64.c b/src/base64.c index 2d1103c7..c99bdceb 100644 --- a/src/base64.c +++ b/src/base64.c @@ -35,7 +35,7 @@ /* The code below is taken from my IRC chat bot and was originally written by * raym aka. Aritra Sarkar in 2022. */ int -gcli_decode_base64(gcli_ctx *ctx, char const *input, char *buffer, +gcli_decode_base64(struct gcli_ctx *ctx, char const *input, char *buffer, size_t buffer_size) { char const digits[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxy" @@ -128,7 +128,7 @@ gcli_decode_base64(gcli_ctx *ctx, char const *input, char *buffer, } int -gcli_base64_decode_print(gcli_ctx *ctx, FILE *out, char const *const input) +gcli_base64_decode_print(struct gcli_ctx *ctx, FILE *out, char const *const input) { int rc = 0; char *buffer = NULL; diff --git a/src/bugzilla/api.c b/src/bugzilla/api.c index b6288457..cd313902 100644 --- a/src/bugzilla/api.c +++ b/src/bugzilla/api.c @@ -35,7 +35,7 @@ #include char const * -bugzilla_api_error_string(gcli_ctx *ctx, gcli_fetch_buffer *const buf) +bugzilla_api_error_string(struct gcli_ctx *ctx, gcli_fetch_buffer *const buf) { json_stream stream = {0}; int rc; diff --git a/src/bugzilla/attachments.c b/src/bugzilla/attachments.c index 51bdfeab..b8415c3b 100644 --- a/src/bugzilla/attachments.c +++ b/src/bugzilla/attachments.c @@ -35,7 +35,7 @@ #include int -bugzilla_attachment_get_content(gcli_ctx *ctx, gcli_id attachment_id, +bugzilla_attachment_get_content(struct gcli_ctx *ctx, gcli_id attachment_id, FILE *output) { int rc = 0; diff --git a/src/bugzilla/bugs-parser.c b/src/bugzilla/bugs-parser.c index 6dc60a8f..c25028bf 100644 --- a/src/bugzilla/bugs-parser.c +++ b/src/bugzilla/bugs-parser.c @@ -37,7 +37,7 @@ #include int -parse_bugzilla_comments_array_skip_first(gcli_ctx *ctx, +parse_bugzilla_comments_array_skip_first(struct gcli_ctx *ctx, struct json_stream *stream, gcli_comment_list *out) { @@ -63,7 +63,7 @@ parse_bugzilla_comments_array_skip_first(gcli_ctx *ctx, } int -parse_bugzilla_comments_array_only_first(gcli_ctx *ctx, +parse_bugzilla_comments_array_only_first(struct gcli_ctx *ctx, struct json_stream *stream, char **out) { int rc = 0; @@ -86,7 +86,7 @@ parse_bugzilla_comments_array_only_first(gcli_ctx *ctx, } int -parse_bugzilla_bug_comments_dictionary_skip_first(gcli_ctx *const ctx, +parse_bugzilla_bug_comments_dictionary_skip_first(struct gcli_ctx *const ctx, json_stream *stream, gcli_comment_list *out) { @@ -109,7 +109,7 @@ parse_bugzilla_bug_comments_dictionary_skip_first(gcli_ctx *const ctx, } int -parse_bugzilla_bug_comments_dictionary_only_first(gcli_ctx *const ctx, +parse_bugzilla_bug_comments_dictionary_only_first(struct gcli_ctx *const ctx, json_stream *stream, char **out) { @@ -132,7 +132,7 @@ parse_bugzilla_bug_comments_dictionary_only_first(gcli_ctx *const ctx, } int -parse_bugzilla_assignee(gcli_ctx *ctx, struct json_stream *stream, +parse_bugzilla_assignee(struct gcli_ctx *ctx, struct json_stream *stream, gcli_issue *out) { out->assignees = calloc(1, sizeof (*out->assignees)); @@ -142,7 +142,8 @@ parse_bugzilla_assignee(gcli_ctx *ctx, struct json_stream *stream, } int -parse_bugzilla_bug_attachments_dict(gcli_ctx *ctx, json_stream *stream, +parse_bugzilla_bug_attachments_dict(struct gcli_ctx *ctx, + struct json_stream *stream, gcli_attachment_list *out) { enum json_type next = JSON_NULL; @@ -166,7 +167,8 @@ parse_bugzilla_bug_attachments_dict(gcli_ctx *ctx, json_stream *stream, } int -parse_bugzilla_attachment_content_only_first(gcli_ctx *ctx, json_stream *stream, +parse_bugzilla_attachment_content_only_first(struct gcli_ctx *ctx, + struct json_stream *stream, gcli_attachment *out) { enum json_type next = JSON_NULL; diff --git a/src/bugzilla/bugs.c b/src/bugzilla/bugs.c index 78ee9b36..936208b4 100644 --- a/src/bugzilla/bugs.c +++ b/src/bugzilla/bugs.c @@ -42,7 +42,7 @@ #include int -bugzilla_get_bugs(gcli_ctx *ctx, char const *product, char const *component, +bugzilla_get_bugs(struct gcli_ctx *ctx, char const *product, char const *component, gcli_issue_fetch_details const *details, int const max, gcli_issue_list *out) { @@ -100,7 +100,7 @@ bugzilla_get_bugs(gcli_ctx *ctx, char const *product, char const *component, } int -bugzilla_bug_get_comments(gcli_ctx *const ctx, char const *const product, +bugzilla_bug_get_comments(struct gcli_ctx *const ctx, char const *const product, char const *const component, gcli_id const bug_id, gcli_comment_list *out) { @@ -132,7 +132,7 @@ bugzilla_bug_get_comments(gcli_ctx *const ctx, char const *const product, } static int -bugzilla_bug_get_op(gcli_ctx *ctx, gcli_id const bug_id, char **out) +bugzilla_bug_get_op(struct gcli_ctx *ctx, gcli_id const bug_id, char **out) { int rc = 0; gcli_fetch_buffer buffer = {0}; @@ -159,8 +159,8 @@ bugzilla_bug_get_op(gcli_ctx *ctx, gcli_id const bug_id, char **out) } int -bugzilla_get_bug(gcli_ctx *ctx, char const *product, char const *component, - gcli_id bug_id, gcli_issue *out) +bugzilla_get_bug(struct gcli_ctx *ctx, char const *product, + char const *component, gcli_id bug_id, gcli_issue *out) { int rc = 0; char *url; @@ -213,7 +213,7 @@ bugzilla_get_bug(gcli_ctx *ctx, char const *product, char const *component, } int -bugzilla_bug_get_attachments(gcli_ctx *ctx, char const *const product, +bugzilla_bug_get_attachments(struct gcli_ctx *ctx, char const *const product, char const *const component, gcli_id const bug_id, gcli_attachment_list *const out) { @@ -275,7 +275,7 @@ add_extra_options(gcli_nvlist const *list, gcli_jsongen *gen) } int -bugzilla_bug_submit(gcli_ctx *ctx, gcli_submit_issue_options opts, +bugzilla_bug_submit(struct gcli_ctx *ctx, gcli_submit_issue_options opts, gcli_fetch_buffer *out) { char *payload = NULL, *url = NULL; diff --git a/src/bugzilla/config.c b/src/bugzilla/config.c index 70eab11f..d3b4c30c 100644 --- a/src/bugzilla/config.c +++ b/src/bugzilla/config.c @@ -31,7 +31,7 @@ #include char * -bugzilla_make_authheader(gcli_ctx *ctx, char const *const token) +bugzilla_make_authheader(struct gcli_ctx *ctx, char const *const token) { (void) ctx; (void) token; diff --git a/src/cmd/cmdconfig.c b/src/cmd/cmdconfig.c index 35d5cfc2..fdf99051 100644 --- a/src/cmd/cmdconfig.c +++ b/src/cmd/cmdconfig.c @@ -97,7 +97,7 @@ ctx_config(struct gcli_ctx *ctx) } static bool -should_init_dotgcli(gcli_ctx *ctx) +should_init_dotgcli(struct gcli_ctx *ctx) { struct gcli_dotgcli *dgcli = ctx_dotgcli(ctx); @@ -178,7 +178,7 @@ find_dotgcli(void) } static void -init_local_config(gcli_ctx *ctx) +init_local_config(struct gcli_ctx *ctx) { if (!should_init_dotgcli(ctx)) { return; @@ -378,7 +378,7 @@ parse_config_file(struct gcli_config *cfg, * return 0. Otherwise return -1. */ static struct gcli_config * -ensure_config(gcli_ctx *ctx) +ensure_config(struct gcli_ctx *ctx) { struct gcli_config *cfg = ctx_config(ctx); char *file_path = NULL; @@ -490,7 +490,7 @@ gcli_config_init_ctx(struct gcli_ctx *ctx) } int -gcli_config_parse_args(gcli_ctx *ctx, int *argc, char ***argv) +gcli_config_parse_args(struct gcli_ctx *ctx, int *argc, char ***argv) { /* These are the very first options passed to the gcli command * itself. It is the first ever getopt call we do to parse any @@ -606,7 +606,7 @@ find_section(struct gcli_config *cfg, char const *name) } struct gcli_config_entries const * -gcli_config_get_section_entries(gcli_ctx *ctx, char const *section_name) +gcli_config_get_section_entries(struct gcli_ctx *ctx, char const *section_name) { struct gcli_config_section const *s; struct gcli_config *cfg; @@ -621,7 +621,8 @@ gcli_config_get_section_entries(gcli_ctx *ctx, char const *section_name) } sn_sv -gcli_config_find_by_key(gcli_ctx *ctx, char const *section_name, char const *key) +gcli_config_find_by_key(struct gcli_ctx *ctx, char const *section_name, + char const *key) { struct gcli_config_entry *entry; struct gcli_config *cfg = ensure_config(ctx); @@ -643,7 +644,7 @@ gcli_config_find_by_key(gcli_ctx *ctx, char const *section_name, char const *key } static sn_sv -gcli_local_config_find_by_key(gcli_ctx *ctx, char const *const key) +gcli_local_config_find_by_key(struct gcli_ctx *ctx, char const *const key) { struct gcli_dotgcli *lcfg = ctx_dotgcli(ctx); struct gcli_config_entry *entry; @@ -657,7 +658,7 @@ gcli_local_config_find_by_key(gcli_ctx *ctx, char const *const key) } char * -gcli_config_get_editor(gcli_ctx *ctx) +gcli_config_get_editor(struct gcli_ctx *ctx) { ensure_config(ctx); @@ -672,7 +673,7 @@ default_account_entry_names[] = { [GCLI_FORGE_BUGZILLA] = "bugzilla-default-account",}; static char * -get_default_account(gcli_ctx *ctx, gcli_forge_type ftype) +get_default_account(struct gcli_ctx *ctx, gcli_forge_type ftype) { char const *const defaultname = default_account_entry_names[ftype]; sn_sv act = gcli_config_find_by_key(ctx, "defaults", defaultname); @@ -684,7 +685,7 @@ get_default_account(gcli_ctx *ctx, gcli_forge_type ftype) } static char * -gcli_config_get_account(gcli_ctx *ctx) +gcli_config_get_account(struct gcli_ctx *ctx) { struct gcli_config *cfg = ctx_config(ctx); gcli_forge_type ftype = gcli_config_get_forge_type(ctx); @@ -707,7 +708,7 @@ static char const *const default_urls[] = { }; char * -gcli_config_get_apibase(gcli_ctx *ctx) +gcli_config_get_apibase(struct gcli_ctx *ctx) { char *acct = gcli_config_get_account(ctx); char *url = NULL; @@ -728,7 +729,7 @@ gcli_config_get_apibase(gcli_ctx *ctx) } char * -gcli_config_get_account_name(gcli_ctx *ctx) +gcli_config_get_account_name(struct gcli_ctx *ctx) { char *account = gcli_config_get_account(ctx); sn_sv actname = gcli_config_find_by_key( @@ -740,7 +741,7 @@ gcli_config_get_account_name(gcli_ctx *ctx) } static char * -get_account_token(gcli_ctx *ctx) +get_account_token(struct gcli_ctx *ctx) { char *account; sn_sv token; @@ -757,7 +758,7 @@ get_account_token(gcli_ctx *ctx) } char * -gcli_config_get_token(gcli_ctx *ctx) +gcli_config_get_token(struct gcli_ctx *ctx) { ensure_config(ctx); @@ -765,7 +766,7 @@ gcli_config_get_token(gcli_ctx *ctx) } sn_sv -gcli_config_get_upstream(gcli_ctx *ctx) +gcli_config_get_upstream(struct gcli_ctx *ctx) { init_local_config(ctx); @@ -773,7 +774,7 @@ gcli_config_get_upstream(gcli_ctx *ctx) } bool -gcli_config_pr_inhibit_delete_source_branch(gcli_ctx *ctx) +gcli_config_pr_inhibit_delete_source_branch(struct gcli_ctx *ctx) { sn_sv val; @@ -785,7 +786,7 @@ gcli_config_pr_inhibit_delete_source_branch(gcli_ctx *ctx) } void -gcli_config_get_upstream_parts(gcli_ctx *ctx, sn_sv *const owner, +gcli_config_get_upstream_parts(struct gcli_ctx *ctx, sn_sv *const owner, sn_sv *const repo) { ensure_config(ctx); @@ -803,7 +804,7 @@ gcli_config_get_upstream_parts(gcli_ctx *ctx, sn_sv *const owner, } sn_sv -gcli_config_get_base(gcli_ctx *ctx) +gcli_config_get_base(struct gcli_ctx *ctx) { init_local_config(ctx); @@ -811,7 +812,7 @@ gcli_config_get_base(gcli_ctx *ctx) } sn_sv -gcli_config_get_override_default_account(gcli_ctx *ctx) +gcli_config_get_override_default_account(struct gcli_ctx *ctx) { struct gcli_config *cfg; @@ -825,7 +826,7 @@ gcli_config_get_override_default_account(gcli_ctx *ctx) } static gcli_forge_type -gcli_config_get_forge_type_internal(gcli_ctx *ctx) +gcli_config_get_forge_type_internal(struct gcli_ctx *ctx) { struct gcli_config *cfg = ctx_config(ctx); @@ -872,7 +873,7 @@ gcli_config_get_forge_type_internal(gcli_ctx *ctx) } gcli_forge_type -gcli_config_get_forge_type(gcli_ctx *ctx) +gcli_config_get_forge_type(struct gcli_ctx *ctx) { gcli_forge_type const result = gcli_config_get_forge_type_internal(ctx); @@ -896,7 +897,7 @@ gcli_config_get_forge_type(gcli_ctx *ctx) } void -gcli_config_get_repo(gcli_ctx *ctx, char const **const owner, +gcli_config_get_repo(struct gcli_ctx *ctx, char const **const owner, char const **const repo) { sn_sv upstream = {0}; @@ -932,7 +933,7 @@ gcli_config_get_repo(gcli_ctx *ctx, char const **const owner, } int -gcli_config_have_colours(gcli_ctx *ctx) +gcli_config_have_colours(struct gcli_ctx *ctx) { static int tested_tty = 0; struct gcli_config *cfg; diff --git a/src/cmd/comment.c b/src/cmd/comment.c index b4c1e71f..7b429dbe 100644 --- a/src/cmd/comment.c +++ b/src/cmd/comment.c @@ -58,7 +58,7 @@ usage(void) } static void -comment_init(gcli_ctx *ctx, FILE *f, void *_data) +comment_init(struct gcli_ctx *ctx, FILE *f, void *_data) { gcli_submit_comment_opts *info = _data; const char *target_type = NULL; diff --git a/src/cmd/editor.c b/src/cmd/editor.c index 8a82c328..fa9dbd34 100644 --- a/src/cmd/editor.c +++ b/src/cmd/editor.c @@ -52,8 +52,8 @@ sv_append(sn_sv this, sn_sv const that) char * gcli_editor_get_user_message( - gcli_ctx *ctx, - void (*file_initializer)(gcli_ctx *, FILE *, void *), + struct gcli_ctx *ctx, + void (*file_initializer)(struct gcli_ctx *, FILE *, void *), void *user_data) { char *editor = getenv("EDITOR"); diff --git a/src/cmd/gcli.c b/src/cmd/gcli.c index 0e4ad230..deee76f0 100644 --- a/src/cmd/gcli.c +++ b/src/cmd/gcli.c @@ -159,7 +159,7 @@ usage(void) } /** The CMD global gcli context */ -gcli_ctx *g_clictx = NULL; +struct gcli_ctx *g_clictx = NULL; static void gcli_progress_func(bool const done) diff --git a/src/cmd/gitconfig.c b/src/cmd/gitconfig.c index d83fb747..119e8d49 100644 --- a/src/cmd/gitconfig.c +++ b/src/cmd/gitconfig.c @@ -486,7 +486,7 @@ gcli_gitconfig_add_fork_remote(char const *org, char const *repo) * Return the gcli_forge_type for the given remote or -1 if * unknown */ int -gcli_gitconfig_get_forgetype(gcli_ctx *ctx, char const *const remote_name) +gcli_gitconfig_get_forgetype(struct gcli_ctx *ctx, char const *const remote_name) { (void) ctx; gcli_gitconfig_read_gitconfig(); diff --git a/src/cmd/issues.c b/src/cmd/issues.c index 8a3a8b9f..e3777f32 100644 --- a/src/cmd/issues.c +++ b/src/cmd/issues.c @@ -211,7 +211,7 @@ gcli_issue_print_op(gcli_issue const *const it) } static void -issue_init_user_file(gcli_ctx *ctx, FILE *stream, void *_opts) +issue_init_user_file(struct gcli_ctx *ctx, FILE *stream, void *_opts) { (void) ctx; gcli_submit_issue_options *opts = _opts; diff --git a/src/cmd/pulls.c b/src/cmd/pulls.c index 7a5c10e7..497f0f0c 100644 --- a/src/cmd/pulls.c +++ b/src/cmd/pulls.c @@ -357,7 +357,7 @@ gcli_pull_commits(char const *owner, char const *repo, } static void -pull_init_user_file(gcli_ctx *ctx, FILE *stream, void *_opts) +pull_init_user_file(struct gcli_ctx *ctx, FILE *stream, void *_opts) { gcli_submit_pull_options *opts = _opts; diff --git a/src/cmd/releases.c b/src/cmd/releases.c index c481d011..3dfd7fed 100644 --- a/src/cmd/releases.c +++ b/src/cmd/releases.c @@ -185,7 +185,7 @@ gcli_releases_print(enum gcli_output_flags const flags, } static void -releasemsg_init(gcli_ctx *ctx, FILE *f, void *_data) +releasemsg_init(struct gcli_ctx *ctx, FILE *f, void *_data) { gcli_new_release const *info = _data; diff --git a/src/cmd/table.c b/src/cmd/table.c index 789d2700..0d413d6b 100644 --- a/src/cmd/table.c +++ b/src/cmd/table.c @@ -355,7 +355,7 @@ struct gcli_dict { size_t max_key_len; - gcli_ctx *ctx; + struct gcli_ctx *ctx; }; /* Create a new long list printer and return a handle to it */ diff --git a/src/comments.c b/src/comments.c index de06eca2..10b6706d 100644 --- a/src/comments.c +++ b/src/comments.c @@ -56,21 +56,21 @@ gcli_comments_free(gcli_comment_list *const list) } int -gcli_get_issue_comments(gcli_ctx *ctx, char const *owner, char const *repo, +gcli_get_issue_comments(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const issue, gcli_comment_list *out) { gcli_null_check_call(get_issue_comments, ctx, owner, repo, issue, out); } int -gcli_get_pull_comments(gcli_ctx *ctx, char const *owner, char const *repo, +gcli_get_pull_comments(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const pull, gcli_comment_list *out) { gcli_null_check_call(get_pull_comments, ctx, owner, repo, pull, out); } int -gcli_comment_submit(gcli_ctx *ctx, gcli_submit_comment_opts opts) +gcli_comment_submit(struct gcli_ctx *ctx, gcli_submit_comment_opts opts) { gcli_null_check_call(perform_submit_comment, ctx, opts, NULL); } diff --git a/src/curl.c b/src/curl.c index c8295019..59e670af 100644 --- a/src/curl.c +++ b/src/curl.c @@ -60,7 +60,7 @@ gcli_curl_isalnum(char const c) /* XXX move to gcli_ctx destructor */ void -gcli_curl_ctx_destroy(gcli_ctx *ctx) +gcli_curl_ctx_destroy(struct gcli_ctx *ctx) { if (ctx->curl) curl_easy_cleanup(ctx->curl); @@ -70,7 +70,7 @@ gcli_curl_ctx_destroy(gcli_ctx *ctx) /* Ensures a clean cURL handle. Call this whenever you wanna use the * ctx->curl */ static int -gcli_curl_ensure(gcli_ctx *ctx) +gcli_curl_ensure(struct gcli_ctx *ctx) { if (ctx->curl) { curl_easy_reset(ctx->curl); @@ -86,7 +86,7 @@ gcli_curl_ensure(gcli_ctx *ctx) /* Check the given curl code for an OK result. If not, print an * appropriate error message and exit */ static int -gcli_curl_check_api_error(gcli_ctx *ctx, CURLcode code, char const *url, +gcli_curl_check_api_error(struct gcli_ctx *ctx, CURLcode code, char const *url, gcli_fetch_buffer *const result) { long status_code = 0; @@ -131,7 +131,7 @@ fetch_write_callback(char *in, size_t size, size_t nmemb, void *data) * pagination_next returns the next url to query for paged results. * Results are placed into the gcli_fetch_buffer. */ int -gcli_fetch(gcli_ctx *ctx, char const *url, char **const pagination_next, +gcli_fetch(struct gcli_ctx *ctx, char const *url, char **const pagination_next, gcli_fetch_buffer *out) { return gcli_fetch_with_method(ctx, "GET", url, NULL, pagination_next, out); @@ -141,7 +141,7 @@ static int gcli_report_progress(void *_ctx, double dltotal, double dlnow, double ultotal, double ulnow) { - gcli_ctx *ctx = _ctx; + struct gcli_ctx *ctx = _ctx; (void) dltotal; (void) dlnow; @@ -156,7 +156,7 @@ gcli_report_progress(void *_ctx, double dltotal, double dlnow, /* Check the given url for a successful query */ int -gcli_curl_test_success(gcli_ctx *ctx, char const *url) +gcli_curl_test_success(struct gcli_ctx *ctx, char const *url) { CURLcode ret; gcli_fetch_buffer buffer = {0}; @@ -213,7 +213,8 @@ gcli_curl_test_success(gcli_ctx *ctx, char const *url) * * content_type may be NULL. */ int -gcli_curl(gcli_ctx *ctx, FILE *stream, char const *url, char const *content_type) +gcli_curl(struct gcli_ctx *ctx, FILE *stream, char const *url, + char const *content_type) { CURLcode ret; struct curl_slist *headers; @@ -351,7 +352,7 @@ parse_link_header(char *_header) * will be set to NULL. */ int gcli_fetch_with_method( - gcli_ctx *ctx, + struct gcli_ctx *ctx, char const *method, /* HTTP method. e.g. POST, GET, DELETE etc. */ char const *url, /* Endpoint */ char const *data, /* Form data */ @@ -454,7 +455,7 @@ gcli_fetch_with_method( * content_type may not be NULL. */ int -gcli_post_upload(gcli_ctx *ctx, char const *url, char const *content_type, +gcli_post_upload(struct gcli_ctx *ctx, char const *url, char const *content_type, void *buffer, size_t const buffer_size, gcli_fetch_buffer *const out) { @@ -522,7 +523,7 @@ gcli_post_upload(gcli_ctx *ctx, char const *url, char const *content_type, * code. */ int -gcli_curl_gitea_upload_attachment(gcli_ctx *ctx, char const *url, +gcli_curl_gitea_upload_attachment(struct gcli_ctx *ctx, char const *url, char const *filename, gcli_fetch_buffer *const out) { @@ -625,7 +626,7 @@ gcli_urlencode(char const *input) } char * -gcli_urldecode(gcli_ctx *ctx, char const *input) +gcli_urldecode(struct gcli_ctx *ctx, char const *input) { char *curlresult, *result; @@ -657,7 +658,7 @@ gcli_urldecode(gcli_ctx *ctx, char const *input) * * If max is -1 then everything will be fetched. */ int -gcli_fetch_list(gcli_ctx *ctx, char *url, gcli_fetch_list_ctx *fl) +gcli_fetch_list(struct gcli_ctx *ctx, char *url, gcli_fetch_list_ctx *fl) { char *next_url = NULL; int rc; diff --git a/src/date_time.c b/src/date_time.c index 713a2bf9..c0266261 100644 --- a/src/date_time.c +++ b/src/date_time.c @@ -35,7 +35,7 @@ #include int -gcli_normalize_date(gcli_ctx *ctx, int fmt, char const *const input, +gcli_normalize_date(struct gcli_ctx *ctx, int fmt, char const *const input, char *output, size_t const output_size) { struct tm tm_buf = {0}; diff --git a/src/forges.c b/src/forges.c index 4f86a904..9584bb42 100644 --- a/src/forges.c +++ b/src/forges.c @@ -377,7 +377,7 @@ bugzilla_forge_descriptor = }; gcli_forge_descriptor const * -gcli_forge(gcli_ctx *ctx) +gcli_forge(struct gcli_ctx *ctx) { switch (ctx->get_forge_type(ctx)) { case GCLI_FORGE_GITHUB: diff --git a/src/forks.c b/src/forks.c index 2afc4810..2b69824f 100644 --- a/src/forks.c +++ b/src/forks.c @@ -34,14 +34,14 @@ #include int -gcli_get_forks(gcli_ctx *ctx, char const *owner, char const *repo, +gcli_get_forks(struct gcli_ctx *ctx, char const *owner, char const *repo, int const max, gcli_fork_list *const out) { gcli_null_check_call(get_forks, ctx, owner, repo, max, out); } int -gcli_fork_create(gcli_ctx *ctx, char const *owner, char const *repo, +gcli_fork_create(struct gcli_ctx *ctx, char const *owner, char const *repo, char const *_in) { gcli_null_check_call(fork_create, ctx, owner, repo, _in); diff --git a/src/gcli.c b/src/gcli.c index b3846876..c956c057 100644 --- a/src/gcli.c +++ b/src/gcli.c @@ -34,8 +34,10 @@ #include char const * -gcli_init(gcli_ctx **ctx, gcli_forge_type (*get_forge_type)(gcli_ctx *), - char *(*get_token)(gcli_ctx *), char *(*get_apibase)(gcli_ctx *)) +gcli_init(struct gcli_ctx **ctx, + gcli_forge_type (*get_forge_type)(struct gcli_ctx *), + char *(*get_token)(struct gcli_ctx *), + char *(*get_apibase)(struct gcli_ctx *)) { *ctx = calloc(sizeof (struct gcli_ctx), 1); if (!(*ctx)) @@ -51,7 +53,7 @@ gcli_init(gcli_ctx **ctx, gcli_forge_type (*get_forge_type)(gcli_ctx *), } void -gcli_destroy(gcli_ctx **ctx) +gcli_destroy(struct gcli_ctx **ctx) { if (ctx && *ctx) { free((*ctx)->apibase); @@ -64,7 +66,7 @@ gcli_destroy(gcli_ctx **ctx) } char const * -gcli_get_error(gcli_ctx *ctx) +gcli_get_error(struct gcli_ctx *ctx) { if (ctx->last_error) return ctx->last_error; diff --git a/src/gitea/comments.c b/src/gitea/comments.c index 7be342e3..7b1a7afd 100644 --- a/src/gitea/comments.c +++ b/src/gitea/comments.c @@ -31,14 +31,14 @@ #include int -gitea_get_comments(gcli_ctx *ctx, char const *owner, char const *repo, +gitea_get_comments(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const issue, gcli_comment_list *const out) { return github_get_comments(ctx, owner, repo, issue, out); } int -gitea_perform_submit_comment(gcli_ctx *ctx, gcli_submit_comment_opts opts, +gitea_perform_submit_comment(struct gcli_ctx *ctx, gcli_submit_comment_opts opts, gcli_fetch_buffer *const out) { return github_perform_submit_comment(ctx, opts, out); diff --git a/src/gitea/config.c b/src/gitea/config.c index 5b22ec09..158e2600 100644 --- a/src/gitea/config.c +++ b/src/gitea/config.c @@ -32,7 +32,7 @@ #include char * -gitea_make_authheader(gcli_ctx *ctx, char const *token) +gitea_make_authheader(struct gcli_ctx *ctx, char const *token) { (void) ctx; return sn_asprintf("Authorization: token %s", token); diff --git a/src/gitea/forks.c b/src/gitea/forks.c index 8c9b5017..b283be15 100644 --- a/src/gitea/forks.c +++ b/src/gitea/forks.c @@ -33,14 +33,14 @@ #include int -gitea_get_forks(gcli_ctx *ctx, char const *owner, char const *repo, +gitea_get_forks(struct gcli_ctx *ctx, char const *owner, char const *repo, int const max, gcli_fork_list *const out) { return github_get_forks(ctx, owner, repo, max, out); } int -gitea_fork_create(gcli_ctx *ctx, char const *owner, char const *repo, +gitea_fork_create(struct gcli_ctx *ctx, char const *owner, char const *repo, char const *_in) { return github_fork_create(ctx, owner, repo, _in); diff --git a/src/gitea/issues.c b/src/gitea/issues.c index 2df99bb7..6399338c 100644 --- a/src/gitea/issues.c +++ b/src/gitea/issues.c @@ -39,7 +39,7 @@ #include int -gitea_get_issues(gcli_ctx *ctx, char const *owner, char const *repo, +gitea_get_issues(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_issue_fetch_details const *details, int const max, gcli_issue_list *const out) { @@ -47,14 +47,15 @@ gitea_get_issues(gcli_ctx *ctx, char const *owner, char const *repo, } int -gitea_get_issue_summary(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const issue_number, gcli_issue *const out) +gitea_get_issue_summary(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id const issue_number, + gcli_issue *const out) { return github_get_issue_summary(ctx, owner, repo, issue_number, out); } int -gitea_submit_issue(gcli_ctx *ctx, gcli_submit_issue_options opts, +gitea_submit_issue(struct gcli_ctx *ctx, gcli_submit_issue_options opts, gcli_fetch_buffer *const out) { return github_perform_submit_issue(ctx,opts, out); @@ -62,7 +63,7 @@ gitea_submit_issue(gcli_ctx *ctx, gcli_submit_issue_options opts, /* Gitea has closed, Github has close ... go figure */ static int -gitea_issue_patch_state(gcli_ctx *ctx, char const *owner, char const *repo, +gitea_issue_patch_state(struct gcli_ctx *ctx, char const *owner, char const *repo, int const issue_number, char const *const state) { char *url = NULL, *payload = NULL, *e_owner = NULL, *e_repo = NULL; @@ -98,21 +99,21 @@ gitea_issue_patch_state(gcli_ctx *ctx, char const *owner, char const *repo, } int -gitea_issue_close(gcli_ctx *ctx, char const *owner, char const *repo, +gitea_issue_close(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const issue_number) { return gitea_issue_patch_state(ctx, owner, repo, issue_number, "closed"); } int -gitea_issue_reopen(gcli_ctx *ctx, char const *owner, char const *repo, +gitea_issue_reopen(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const issue_number) { return gitea_issue_patch_state(ctx, owner, repo, issue_number, "open"); } int -gitea_issue_assign(gcli_ctx *ctx, char const *owner, char const *repo, +gitea_issue_assign(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const issue_number, char const *const assignee) { char *url = NULL, *e_owner = NULL, *e_repo = NULL, *payload = NULL; @@ -172,7 +173,7 @@ free_id_list(char *list[], size_t const list_size) } static char ** -label_names_to_ids(gcli_ctx *ctx, char const *owner, char const *repo, +label_names_to_ids(struct gcli_ctx *ctx, char const *owner, char const *repo, char const *const names[], size_t const names_size) { gcli_label_list list = {0}; @@ -202,7 +203,7 @@ label_names_to_ids(gcli_ctx *ctx, char const *owner, char const *repo, } int -gitea_issue_add_labels(gcli_ctx *ctx, char const *owner, char const *repo, +gitea_issue_add_labels(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const issue, char const *const labels[], size_t const labels_size) { @@ -250,9 +251,9 @@ gitea_issue_add_labels(gcli_ctx *ctx, char const *owner, char const *repo, } int -gitea_issue_remove_labels(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const issue, char const *const labels[], - size_t const labels_size) +gitea_issue_remove_labels(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id const issue, + char const *const labels[], size_t const labels_size) { int rc = 0; char *e_owner, *e_repo; @@ -289,7 +290,7 @@ gitea_issue_remove_labels(gcli_ctx *ctx, char const *owner, char const *repo, } int -gitea_issue_set_milestone(gcli_ctx *ctx, char const *const owner, +gitea_issue_set_milestone(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const issue, gcli_id const milestone) { @@ -297,14 +298,14 @@ gitea_issue_set_milestone(gcli_ctx *ctx, char const *const owner, } int -gitea_issue_clear_milestone(gcli_ctx *ctx, char const *owner, +gitea_issue_clear_milestone(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue) { return github_issue_set_milestone(ctx, owner, repo, issue, 0); } int -gitea_issue_set_title(gcli_ctx *ctx, char const *const owner, +gitea_issue_set_title(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const issue, char const *const new_title) { diff --git a/src/gitea/labels.c b/src/gitea/labels.c index b5d5ccdc..77160e35 100644 --- a/src/gitea/labels.c +++ b/src/gitea/labels.c @@ -36,21 +36,21 @@ #include int -gitea_get_labels(gcli_ctx *ctx, char const *owner, char const *reponame, +gitea_get_labels(struct gcli_ctx *ctx, char const *owner, char const *reponame, int max, gcli_label_list *const list) { return github_get_labels(ctx, owner, reponame, max, list); } int -gitea_create_label(gcli_ctx *ctx, char const *owner, char const *repo, +gitea_create_label(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_label *const label) { return github_create_label(ctx, owner, repo, label); } int -gitea_delete_label(gcli_ctx *ctx, char const *owner, char const *repo, +gitea_delete_label(struct gcli_ctx *ctx, char const *owner, char const *repo, char const *label) { char *url = NULL; diff --git a/src/gitea/milestones.c b/src/gitea/milestones.c index 2e33dd72..dd6a57a7 100644 --- a/src/gitea/milestones.c +++ b/src/gitea/milestones.c @@ -39,7 +39,7 @@ #include int -gitea_get_milestones(gcli_ctx *ctx, char const *const owner, +gitea_get_milestones(struct gcli_ctx *ctx, char const *const owner, char const *const repo, int const max, gcli_milestone_list *const out) { @@ -66,7 +66,7 @@ gitea_get_milestones(gcli_ctx *ctx, char const *const owner, } int -gitea_get_milestone(gcli_ctx *ctx, char const *const owner, +gitea_get_milestone(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const milestone, gcli_milestone *const out) { @@ -100,14 +100,14 @@ gitea_get_milestone(gcli_ctx *ctx, char const *const owner, } int -gitea_create_milestone(gcli_ctx *ctx, +gitea_create_milestone(struct gcli_ctx *ctx, struct gcli_milestone_create_args const *args) { return github_create_milestone(ctx, args); } int -gitea_milestone_get_issues(gcli_ctx *ctx, char const *const owner, +gitea_milestone_get_issues(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const milestone, gcli_issue_list *const out) { @@ -126,14 +126,14 @@ gitea_milestone_get_issues(gcli_ctx *ctx, char const *const owner, } int -gitea_delete_milestone(gcli_ctx *ctx, char const *const owner, +gitea_delete_milestone(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const milestone) { return github_delete_milestone(ctx, owner, repo, milestone); } int -gitea_milestone_set_duedate(gcli_ctx *ctx, char const *const owner, +gitea_milestone_set_duedate(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const milestone, char const *const date) { diff --git a/src/gitea/pulls.c b/src/gitea/pulls.c index 155ffd24..c3dd7631 100644 --- a/src/gitea/pulls.c +++ b/src/gitea/pulls.c @@ -34,7 +34,7 @@ #include int -gitea_get_pulls(gcli_ctx *ctx, char const *owner, char const *repo, +gitea_get_pulls(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_pull_fetch_details const *const details, int const max, gcli_pull_list *const out) { @@ -42,21 +42,22 @@ gitea_get_pulls(gcli_ctx *ctx, char const *owner, char const *repo, } int -gitea_get_pull(gcli_ctx *ctx, char const *owner, char const *repo, +gitea_get_pull(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const pr_number, gcli_pull *const out) { return github_get_pull(ctx, owner, repo, pr_number, out); } int -gitea_get_pull_commits(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const pr_number, gcli_commit_list *const out) +gitea_get_pull_commits(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id const pr_number, + gcli_commit_list *const out) { return github_get_pull_commits(ctx, owner, repo, pr_number, out); } int -gitea_pull_submit(gcli_ctx *ctx, gcli_submit_pull_options opts) +gitea_pull_submit(struct gcli_ctx *ctx, gcli_submit_pull_options opts) { warnx("In case the following process errors out, see: " "https://github.com/go-gitea/gitea/issues/20175"); @@ -64,7 +65,7 @@ gitea_pull_submit(gcli_ctx *ctx, gcli_submit_pull_options opts) } int -gitea_pull_merge(gcli_ctx *ctx, char const *owner, char const *repo, +gitea_pull_merge(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const pr, enum gcli_merge_flags const flags) { bool const delete_branch = flags & GCLI_PULL_MERGE_DELETEHEAD; @@ -107,8 +108,9 @@ gitea_pull_merge(gcli_ctx *ctx, char const *owner, char const *repo, } static int -gitea_pulls_patch_state(gcli_ctx *ctx, char const *owner, char const *repo, - int const pr_number, char const *state) +gitea_pulls_patch_state(struct gcli_ctx *ctx, char const *owner, + char const *repo, int const pr_number, + char const *state) { char *url = NULL; char *data = NULL; @@ -137,21 +139,21 @@ gitea_pulls_patch_state(gcli_ctx *ctx, char const *owner, char const *repo, } int -gitea_pull_close(gcli_ctx *ctx, char const *owner, char const *repo, +gitea_pull_close(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const pr_number) { return gitea_pulls_patch_state(ctx, owner, repo, pr_number, "closed"); } int -gitea_pull_reopen(gcli_ctx *ctx, char const *owner, char const *repo, +gitea_pull_reopen(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const pr_number) { return gitea_pulls_patch_state(ctx, owner, repo, pr_number, "open"); } int -gitea_pull_get_patch(gcli_ctx *ctx, FILE *const stream, char const *owner, +gitea_pull_get_patch(struct gcli_ctx *ctx, FILE *const stream, char const *owner, char const *repo, gcli_id const pr_number) { char *url = NULL; @@ -176,7 +178,7 @@ gitea_pull_get_patch(gcli_ctx *ctx, FILE *const stream, char const *owner, return rc; } int -gitea_pull_get_diff(gcli_ctx *ctx, FILE *const stream, char const *owner, +gitea_pull_get_diff(struct gcli_ctx *ctx, FILE *const stream, char const *owner, char const *repo, gcli_id const pr_number) { char *url = NULL; @@ -202,7 +204,7 @@ gitea_pull_get_diff(gcli_ctx *ctx, FILE *const stream, char const *owner, } int -gitea_pull_get_checks(gcli_ctx *ctx, char const *owner, char const *repo, +gitea_pull_get_checks(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const pr_number, gcli_pull_checks_list *out) { (void) ctx; @@ -215,16 +217,17 @@ gitea_pull_get_checks(gcli_ctx *ctx, char const *owner, char const *repo, } int -gitea_pull_set_milestone(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id pr_number, gcli_id milestone_id) +gitea_pull_set_milestone(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id pr_number, + gcli_id milestone_id) { return github_issue_set_milestone(ctx, owner, repo, pr_number, milestone_id); } int -gitea_pull_clear_milestone(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id pr_number) +gitea_pull_clear_milestone(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id pr_number) { /* NOTE: The github routine for clearing issues sets the milestone * to null (not the integer zero). However this does not work in @@ -234,14 +237,15 @@ gitea_pull_clear_milestone(gcli_ctx *ctx, char const *owner, char const *repo, } int -gitea_pull_add_reviewer(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id pr_number, char const *username) +gitea_pull_add_reviewer(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id pr_number, + char const *username) { return github_pull_add_reviewer(ctx, owner, repo, pr_number, username); } int -gitea_pull_set_title(gcli_ctx *ctx, char const *const owner, +gitea_pull_set_title(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id pull, char const *const title) { diff --git a/src/gitea/releases.c b/src/gitea/releases.c index 51c0006a..04758753 100644 --- a/src/gitea/releases.c +++ b/src/gitea/releases.c @@ -37,14 +37,14 @@ #include int -gitea_get_releases(gcli_ctx *ctx, char const *owner, char const *repo, +gitea_get_releases(struct gcli_ctx *ctx, char const *owner, char const *repo, int const max, gcli_release_list *const list) { return github_get_releases(ctx, owner, repo, max, list); } static void -gitea_parse_release(gcli_ctx *ctx, gcli_fetch_buffer const *const buffer, +gitea_parse_release(struct gcli_ctx *ctx, gcli_fetch_buffer const *const buffer, gcli_release *const out) { json_stream stream = {0}; @@ -54,7 +54,7 @@ gitea_parse_release(gcli_ctx *ctx, gcli_fetch_buffer const *const buffer, } static int -gitea_upload_release_asset(gcli_ctx *ctx, char *const url, +gitea_upload_release_asset(struct gcli_ctx *ctx, char *const url, gcli_release_asset_upload const asset) { char *e_assetname = NULL; @@ -75,7 +75,7 @@ gitea_upload_release_asset(gcli_ctx *ctx, char *const url, } int -gitea_create_release(gcli_ctx *ctx, gcli_new_release const *release) +gitea_create_release(struct gcli_ctx *ctx, gcli_new_release const *release) { char *e_owner = NULL, *e_repo = NULL, *payload = NULL, *upload_url = NULL, *url = NULL; gcli_fetch_buffer buffer = {0}; @@ -152,7 +152,7 @@ gitea_create_release(gcli_ctx *ctx, gcli_new_release const *release) } int -gitea_delete_release(gcli_ctx *ctx, char const *owner, char const *repo, +gitea_delete_release(struct gcli_ctx *ctx, char const *owner, char const *repo, char const *id) { return github_delete_release(ctx, owner, repo, id); diff --git a/src/gitea/repos.c b/src/gitea/repos.c index f2afef9d..aab44c06 100644 --- a/src/gitea/repos.c +++ b/src/gitea/repos.c @@ -35,27 +35,28 @@ #include int -gitea_get_repos(gcli_ctx *ctx, char const *owner, int const max, +gitea_get_repos(struct gcli_ctx *ctx, char const *owner, int const max, gcli_repo_list *const list) { return github_get_repos(ctx, owner, max, list); } int -gitea_get_own_repos(gcli_ctx *ctx, int const max, gcli_repo_list *const list) +gitea_get_own_repos(struct gcli_ctx *ctx, int const max, + gcli_repo_list *const list) { return github_get_own_repos(ctx, max, list); } int -gitea_repo_create(gcli_ctx *ctx, gcli_repo_create_options const *options, +gitea_repo_create(struct gcli_ctx *ctx, gcli_repo_create_options const *options, gcli_repo *const out) { return github_repo_create(ctx, options, out); } int -gitea_repo_delete(gcli_ctx *ctx, char const *owner, char const *repo) +gitea_repo_delete(struct gcli_ctx *ctx, char const *owner, char const *repo) { return github_repo_delete(ctx, owner, repo); } @@ -63,7 +64,7 @@ gitea_repo_delete(gcli_ctx *ctx, char const *owner, char const *repo) /* Unlike Github and Gitlab, Gitea only supports private or non-private * (thus public) repositories. Separate implementation required. */ int -gitea_repo_set_visibility(gcli_ctx *ctx, char const *const owner, +gitea_repo_set_visibility(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_repo_visibility vis) { char *url; diff --git a/src/gitea/sshkeys.c b/src/gitea/sshkeys.c index 53715b46..25a87c77 100644 --- a/src/gitea/sshkeys.c +++ b/src/gitea/sshkeys.c @@ -37,20 +37,20 @@ #include int -gitea_get_sshkeys(gcli_ctx *ctx, gcli_sshkey_list *list) +gitea_get_sshkeys(struct gcli_ctx *ctx, gcli_sshkey_list *list) { return gitlab_get_sshkeys(ctx, list); } int -gitea_add_sshkey(gcli_ctx *ctx, char const *const title, +gitea_add_sshkey(struct gcli_ctx *ctx, char const *const title, char const *const pubkey, gcli_sshkey *const out) { return gitlab_add_sshkey(ctx, title, pubkey, out); } int -gitea_delete_sshkey(gcli_ctx *ctx, gcli_id const id) +gitea_delete_sshkey(struct gcli_ctx *ctx, gcli_id const id) { return gitlab_delete_sshkey(ctx, id); } diff --git a/src/gitea/status.c b/src/gitea/status.c index dd54263d..3f659e0f 100644 --- a/src/gitea/status.c +++ b/src/gitea/status.c @@ -36,7 +36,7 @@ #include int -gitea_get_notifications(gcli_ctx *ctx, int const max, +gitea_get_notifications(struct gcli_ctx *ctx, int const max, gcli_notification_list *const out) { char *url = NULL; @@ -53,7 +53,7 @@ gitea_get_notifications(gcli_ctx *ctx, int const max, } int -gitea_notification_mark_as_read(gcli_ctx *ctx, char const *id) +gitea_notification_mark_as_read(struct gcli_ctx *ctx, char const *id) { return github_notification_mark_as_read(ctx, id); } diff --git a/src/github/api.c b/src/github/api.c index 251e3d0d..7bc6d78d 100644 --- a/src/github/api.c +++ b/src/github/api.c @@ -35,7 +35,7 @@ #include char const * -github_api_error_string(gcli_ctx *ctx, gcli_fetch_buffer *const buf) +github_api_error_string(struct gcli_ctx *ctx, gcli_fetch_buffer *const buf) { json_stream stream = {0}; int rc; diff --git a/src/github/checks.c b/src/github/checks.c index d3378069..ef3c11db 100644 --- a/src/github/checks.c +++ b/src/github/checks.c @@ -41,7 +41,7 @@ #include int -github_get_checks(gcli_ctx *ctx, char const *owner, char const *repo, +github_get_checks(struct gcli_ctx *ctx, char const *owner, char const *repo, char const *ref, int const max, github_check_list *const out) { gcli_fetch_buffer buffer = {0}; diff --git a/src/github/comments.c b/src/github/comments.c index 07109545..058af4c4 100644 --- a/src/github/comments.c +++ b/src/github/comments.c @@ -37,7 +37,8 @@ #include int -github_perform_submit_comment(gcli_ctx *ctx, gcli_submit_comment_opts opts, +github_perform_submit_comment(struct gcli_ctx *ctx, + gcli_submit_comment_opts opts, gcli_fetch_buffer *out) { int rc = 0; @@ -71,7 +72,7 @@ github_perform_submit_comment(gcli_ctx *ctx, gcli_submit_comment_opts opts, } int -github_get_comments(gcli_ctx *ctx, char const *owner, char const *repo, +github_get_comments(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const issue, gcli_comment_list *const out) { char *e_owner = NULL; diff --git a/src/github/config.c b/src/github/config.c index edcc0f68..a90387af 100644 --- a/src/github/config.c +++ b/src/github/config.c @@ -31,7 +31,7 @@ #include char * -github_make_authheader(gcli_ctx *ctx, char const *token) +github_make_authheader(struct gcli_ctx *ctx, char const *token) { (void) ctx; return sn_asprintf("Authorization: token %s", token); diff --git a/src/github/forks.c b/src/github/forks.c index 68373f49..8c81ba19 100644 --- a/src/github/forks.c +++ b/src/github/forks.c @@ -37,7 +37,7 @@ #include int -github_get_forks(gcli_ctx *ctx, char const *owner, char const *repo, +github_get_forks(struct gcli_ctx *ctx, char const *owner, char const *repo, int const max, gcli_fork_list *const list) { char *url = NULL; @@ -68,7 +68,7 @@ github_get_forks(gcli_ctx *ctx, char const *owner, char const *repo, } int -github_fork_create(gcli_ctx *ctx, char const *owner, char const *repo, +github_fork_create(struct gcli_ctx *ctx, char const *owner, char const *repo, char const *_in) { char *url = NULL; diff --git a/src/github/gists.c b/src/github/gists.c index d7abfd5d..9a377aea 100644 --- a/src/github/gists.c +++ b/src/github/gists.c @@ -41,7 +41,7 @@ /* /!\ Before changing this, see comment in gists.h /!\ */ int -parse_github_gist_files_idiot_hack(gcli_ctx *ctx, json_stream *stream, +parse_github_gist_files_idiot_hack(struct gcli_ctx *ctx, json_stream *stream, gcli_gist *const gist) { (void) ctx; @@ -68,7 +68,7 @@ parse_github_gist_files_idiot_hack(gcli_ctx *ctx, json_stream *stream, } int -gcli_get_gists(gcli_ctx *ctx, char const *user, int const max, +gcli_get_gists(struct gcli_ctx *ctx, char const *user, int const max, gcli_gist_list *const list) { char *url = NULL; @@ -88,7 +88,7 @@ gcli_get_gists(gcli_ctx *ctx, char const *user, int const max, } int -gcli_get_gist(gcli_ctx *ctx, char const *gist_id, gcli_gist *out) +gcli_get_gist(struct gcli_ctx *ctx, char const *gist_id, gcli_gist *out) { char *url = NULL; gcli_fetch_buffer buffer = {0}; @@ -134,7 +134,7 @@ read_file(FILE *f, char **out) } int -gcli_create_gist(gcli_ctx *ctx, gcli_new_gist opts) +gcli_create_gist(struct gcli_ctx *ctx, gcli_new_gist opts) { char *url = NULL; char *post_data = NULL; @@ -184,7 +184,7 @@ gcli_create_gist(gcli_ctx *ctx, gcli_new_gist opts) } int -gcli_delete_gist(gcli_ctx *ctx, char const *gist_id) +gcli_delete_gist(struct gcli_ctx *ctx, char const *gist_id) { char *url = NULL; gcli_fetch_buffer buffer = {0}; diff --git a/src/github/issues.c b/src/github/issues.c index f0a14b49..ad573712 100644 --- a/src/github/issues.c +++ b/src/github/issues.c @@ -67,7 +67,7 @@ github_hack_fixup_issues_that_are_actually_pulls(gcli_issue **list, size_t *size } int -github_fetch_issues(gcli_ctx *ctx, char *url, int const max, +github_fetch_issues(struct gcli_ctx *ctx, char *url, int const max, gcli_issue_list *const out) { gcli_fetch_list_ctx fl = { @@ -82,7 +82,7 @@ github_fetch_issues(gcli_ctx *ctx, char *url, int const max, } static int -get_milestone_id(gcli_ctx *ctx, char const *owner, char const *repo, +get_milestone_id(struct gcli_ctx *ctx, char const *owner, char const *repo, char const *milestone_name, gcli_id *out) { int rc = 0; @@ -108,8 +108,8 @@ get_milestone_id(gcli_ctx *ctx, char const *owner, char const *repo, } static int -parse_github_milestone(gcli_ctx *ctx, char const *owner, char const *repo, - char const *milestone, gcli_id *out) +parse_github_milestone(struct gcli_ctx *ctx, char const *owner, + char const *repo, char const *milestone, gcli_id *out) { char *endptr = NULL; size_t const m_len = strlen(milestone); @@ -124,7 +124,7 @@ parse_github_milestone(gcli_ctx *ctx, char const *owner, char const *repo, } int -github_get_issues(gcli_ctx *ctx, char const *owner, char const *repo, +github_get_issues(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_issue_fetch_details const *details, int const max, gcli_issue_list *const out) { @@ -180,8 +180,9 @@ github_get_issues(gcli_ctx *ctx, char const *owner, char const *repo, } int -github_get_issue_summary(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const issue_number, gcli_issue *const out) +github_get_issue_summary(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id const issue_number, + gcli_issue *const out) { char *url = NULL; char *e_owner = NULL; @@ -215,7 +216,7 @@ github_get_issue_summary(gcli_ctx *ctx, char const *owner, char const *repo, } static int -github_issue_patch_state(gcli_ctx *ctx, char const *const owner, +github_issue_patch_state(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const issue, char const *const state) { @@ -240,21 +241,21 @@ github_issue_patch_state(gcli_ctx *ctx, char const *const owner, } int -github_issue_close(gcli_ctx *ctx, char const *owner, char const *repo, +github_issue_close(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const issue) { return github_issue_patch_state(ctx, owner, repo, issue, "closed"); } int -github_issue_reopen(gcli_ctx *ctx, char const *owner, char const *repo, +github_issue_reopen(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const issue) { return github_issue_patch_state(ctx, owner, repo, issue, "open"); } int -github_perform_submit_issue(gcli_ctx *ctx, gcli_submit_issue_options opts, +github_perform_submit_issue(struct gcli_ctx *ctx, gcli_submit_issue_options opts, gcli_fetch_buffer *out) { char *e_owner = NULL, *e_repo = NULL, *payload = NULL, *url = NULL; @@ -295,7 +296,7 @@ github_perform_submit_issue(gcli_ctx *ctx, gcli_submit_issue_options opts, } int -github_issue_assign(gcli_ctx *ctx, char const *owner, char const *repo, +github_issue_assign(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const issue_number, char const *assignee) { gcli_jsongen gen = {0}; @@ -335,9 +336,9 @@ github_issue_assign(gcli_ctx *ctx, char const *owner, char const *repo, } int -github_issue_add_labels(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const issue, char const *const labels[], - size_t const labels_size) +github_issue_add_labels(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id const issue, + char const *const labels[], size_t const labels_size) { char *url = NULL; char *data = NULL; @@ -362,9 +363,9 @@ github_issue_add_labels(gcli_ctx *ctx, char const *owner, char const *repo, } int -github_issue_remove_labels(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const issue, char const *const labels[], - size_t const labels_size) +github_issue_remove_labels(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id const issue, + char const *const labels[], size_t const labels_size) { char *url = NULL; char *e_label = NULL; @@ -389,7 +390,7 @@ github_issue_remove_labels(gcli_ctx *ctx, char const *owner, char const *repo, } int -github_issue_set_milestone(gcli_ctx *ctx, char const *const owner, +github_issue_set_milestone(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const issue, gcli_id const milestone) { @@ -416,7 +417,7 @@ github_issue_set_milestone(gcli_ctx *ctx, char const *const owner, } int -github_issue_clear_milestone(gcli_ctx *ctx, char const *const owner, +github_issue_clear_milestone(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const issue) { char *url, *e_owner, *e_repo; @@ -442,7 +443,7 @@ github_issue_clear_milestone(gcli_ctx *ctx, char const *const owner, } int -github_issue_set_title(gcli_ctx *ctx, char const *const owner, +github_issue_set_title(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const issue, char const *const new_title) { diff --git a/src/github/labels.c b/src/github/labels.c index 6d6dbe36..4a0643fd 100644 --- a/src/github/labels.c +++ b/src/github/labels.c @@ -36,7 +36,7 @@ #include int -github_get_labels(gcli_ctx *ctx, char const *owner, char const *reponame, +github_get_labels(struct gcli_ctx *ctx, char const *owner, char const *reponame, int const max, gcli_label_list *const out) { char *url = NULL; @@ -57,7 +57,7 @@ github_get_labels(gcli_ctx *ctx, char const *owner, char const *reponame, } int -github_create_label(gcli_ctx *ctx, char const *owner, char const *repo, +github_create_label(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_label *const label) { char *url = NULL, *payload = NULL, *e_owner = NULL, *e_repo = NULL, @@ -116,7 +116,7 @@ github_create_label(gcli_ctx *ctx, char const *owner, char const *repo, } int -github_delete_label(gcli_ctx *ctx, char const *owner, char const *repo, +github_delete_label(struct gcli_ctx *ctx, char const *owner, char const *repo, char const *label) { char *url = NULL; diff --git a/src/github/milestones.c b/src/github/milestones.c index d3e7d02e..de46887e 100644 --- a/src/github/milestones.c +++ b/src/github/milestones.c @@ -43,7 +43,7 @@ #include int -github_get_milestones(gcli_ctx *ctx, char const *const owner, +github_get_milestones(struct gcli_ctx *ctx, char const *const owner, char const *const repo, int const max, gcli_milestone_list *const out) { @@ -69,7 +69,7 @@ github_get_milestones(gcli_ctx *ctx, char const *const owner, } int -github_get_milestone(gcli_ctx *ctx, char const *const owner, +github_get_milestone(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const milestone, gcli_milestone *const out) { @@ -102,7 +102,7 @@ github_get_milestone(gcli_ctx *ctx, char const *const owner, } int -github_milestone_get_issues(gcli_ctx *ctx, char const *const owner, +github_milestone_get_issues(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const milestone, gcli_issue_list *const out) { @@ -122,7 +122,7 @@ github_milestone_get_issues(gcli_ctx *ctx, char const *const owner, } int -github_create_milestone(gcli_ctx *ctx, +github_create_milestone(struct gcli_ctx *ctx, struct gcli_milestone_create_args const *args) { char *url, *e_owner, *e_repo; @@ -162,7 +162,7 @@ github_create_milestone(gcli_ctx *ctx, } int -github_delete_milestone(gcli_ctx *ctx, char const *const owner, +github_delete_milestone(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const milestone) { char *url, *e_owner, *e_repo; @@ -186,7 +186,7 @@ github_delete_milestone(gcli_ctx *ctx, char const *const owner, } int -github_milestone_set_duedate(gcli_ctx *ctx, char const *const owner, +github_milestone_set_duedate(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const milestone, char const *const date) { diff --git a/src/github/pulls.c b/src/github/pulls.c index 19582cf9..8d9d6f98 100644 --- a/src/github/pulls.c +++ b/src/github/pulls.c @@ -91,7 +91,7 @@ github_pulls_filter(gcli_pull **listp, size_t *sizep, } static int -github_fetch_pulls(gcli_ctx *ctx, char *url, +github_fetch_pulls(struct gcli_ctx *ctx, char *url, gcli_pull_fetch_details const *details, int max, gcli_pull_list *const list) { @@ -108,7 +108,7 @@ github_fetch_pulls(gcli_ctx *ctx, char *url, } int -github_get_pulls(gcli_ctx *ctx, char const *owner, char const *repo, +github_get_pulls(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_pull_fetch_details const *const details, int const max, gcli_pull_list *const list) { @@ -131,7 +131,7 @@ github_get_pulls(gcli_ctx *ctx, char const *owner, char const *repo, } int -github_pull_get_patch(gcli_ctx *ctx, FILE *stream, char const *owner, +github_pull_get_patch(struct gcli_ctx *ctx, FILE *stream, char const *owner, char const *repo, gcli_id const pr_number) { char *url = NULL; @@ -156,7 +156,7 @@ github_pull_get_patch(gcli_ctx *ctx, FILE *stream, char const *owner, } int -github_pull_get_diff(gcli_ctx *ctx, FILE *stream, char const *owner, +github_pull_get_diff(struct gcli_ctx *ctx, FILE *stream, char const *owner, char const *repo, gcli_id const pr_number) { char *url = NULL; @@ -183,7 +183,7 @@ github_pull_get_diff(gcli_ctx *ctx, FILE *stream, char const *owner, /* TODO: figure out a way to get rid of the 3 consecutive urlencode * calls */ static int -github_pull_delete_head_branch(gcli_ctx *ctx, char const *owner, +github_pull_delete_head_branch(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const pr_number) { gcli_pull pull = {0}; @@ -213,7 +213,7 @@ github_pull_delete_head_branch(gcli_ctx *ctx, char const *owner, } int -github_pull_merge(gcli_ctx *ctx, char const *owner, char const *repo, +github_pull_merge(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const pr_number, enum gcli_merge_flags const flags) { char *url = NULL; @@ -246,7 +246,7 @@ github_pull_merge(gcli_ctx *ctx, char const *owner, char const *repo, } static int -github_pull_patch_state(gcli_ctx *const ctx, char const *const owner, +github_pull_patch_state(struct gcli_ctx *const ctx, char const *const owner, char const *const repo, gcli_id const pr, char const *const new_state) { @@ -285,21 +285,21 @@ github_pull_patch_state(gcli_ctx *const ctx, char const *const owner, } int -github_pull_close(gcli_ctx *ctx, char const *owner, char const *repo, +github_pull_close(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const pr) { return github_pull_patch_state(ctx, owner, repo, pr, "closed"); } int -github_pull_reopen(gcli_ctx *ctx, char const *owner, char const *repo, +github_pull_reopen(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const pr) { return github_pull_patch_state(ctx, owner, repo, pr, "open"); } int -github_perform_submit_pull(gcli_ctx *ctx, gcli_submit_pull_options opts) +github_perform_submit_pull(struct gcli_ctx *ctx, gcli_submit_pull_options opts) { char *url = NULL, *payload = NULL, *e_owner = NULL, *e_repo = NULL; gcli_fetch_buffer fetch_buffer = {0}; @@ -371,8 +371,9 @@ filter_commit_short_sha(gcli_commit **listp, size_t *sizep, void *_data) } int -github_get_pull_commits(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const pr, gcli_commit_list *const out) +github_get_pull_commits(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id const pr, + gcli_commit_list *const out) { char *url = NULL; char *e_owner = NULL; @@ -399,7 +400,7 @@ github_get_pull_commits(gcli_ctx *ctx, char const *owner, char const *repo, } int -github_get_pull(gcli_ctx *ctx, char const *owner, char const *repo, +github_get_pull(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const pr, gcli_pull *const out) { int rc = 0; @@ -431,7 +432,7 @@ github_get_pull(gcli_ctx *ctx, char const *owner, char const *repo, } int -github_pull_get_checks(gcli_ctx *ctx, char const *owner, char const *repo, +github_pull_get_checks(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const pr_number, gcli_pull_checks_list *out) { char refname[64] = {0}; @@ -445,8 +446,9 @@ github_pull_get_checks(gcli_ctx *ctx, char const *owner, char const *repo, } int -github_pull_add_reviewer(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id pr_number, char const *username) +github_pull_add_reviewer(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id pr_number, + char const *username) { int rc = 0; char *url, *payload, *e_owner, *e_repo; @@ -487,7 +489,7 @@ github_pull_add_reviewer(gcli_ctx *ctx, char const *owner, char const *repo, } int -github_pull_set_title(gcli_ctx *ctx, char const *owner, char const *repo, +github_pull_set_title(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id pull, char const *new_title) { char *url, *e_owner, *e_repo, *payload; diff --git a/src/github/releases.c b/src/github/releases.c index f13d5292..75113474 100644 --- a/src/github/releases.c +++ b/src/github/releases.c @@ -39,7 +39,7 @@ #include int -github_get_releases(gcli_ctx *ctx, char const *owner, char const *repo, +github_get_releases(struct gcli_ctx *ctx, char const *owner, char const *repo, int const max, gcli_release_list *const list) { char *url = NULL; @@ -70,7 +70,7 @@ github_get_releases(gcli_ctx *ctx, char const *owner, char const *repo, } static void -github_parse_single_release(gcli_ctx *ctx, gcli_fetch_buffer buffer, +github_parse_single_release(struct gcli_ctx *ctx, gcli_fetch_buffer buffer, gcli_release *const out) { struct json_stream stream = {0}; @@ -82,7 +82,7 @@ github_parse_single_release(gcli_ctx *ctx, gcli_fetch_buffer buffer, } static int -github_get_upload_url(gcli_ctx *ctx, gcli_release *const it, char **out) +github_get_upload_url(struct gcli_ctx *ctx, gcli_release *const it, char **out) { char *delim = strchr(it->upload_url, '{'); if (delim == NULL) @@ -95,7 +95,7 @@ github_get_upload_url(gcli_ctx *ctx, gcli_release *const it, char **out) } static int -github_upload_release_asset(gcli_ctx *ctx, char const *url, +github_upload_release_asset(struct gcli_ctx *ctx, char const *url, gcli_release_asset_upload const asset) { char *req = NULL; @@ -125,7 +125,7 @@ github_upload_release_asset(gcli_ctx *ctx, char const *url, } int -github_create_release(gcli_ctx *ctx, gcli_new_release const *release) +github_create_release(struct gcli_ctx *ctx, gcli_new_release const *release) { char *url = NULL, *e_owner = NULL, *e_repo = NULL, *upload_url = NULL, *payload = NULL; @@ -204,7 +204,7 @@ github_create_release(gcli_ctx *ctx, gcli_new_release const *release) } int -github_delete_release(gcli_ctx *ctx, char const *owner, char const *repo, +github_delete_release(struct gcli_ctx *ctx, char const *owner, char const *repo, char const *id) { char *url = NULL; diff --git a/src/github/repos.c b/src/github/repos.c index 05bc8004..d88511f1 100644 --- a/src/github/repos.c +++ b/src/github/repos.c @@ -40,7 +40,7 @@ #include int -github_get_repos(gcli_ctx *ctx, char const *owner, int const max, +github_get_repos(struct gcli_ctx *ctx, char const *owner, int const max, gcli_repo_list *const list) { char *url = NULL; @@ -89,7 +89,8 @@ github_get_repos(gcli_ctx *ctx, char const *owner, int const max, } int -github_get_own_repos(gcli_ctx *ctx, int const max, gcli_repo_list *const list) +github_get_own_repos(struct gcli_ctx *ctx, int const max, + gcli_repo_list *const list) { char *url = NULL; gcli_fetch_list_ctx fl = { @@ -105,7 +106,7 @@ github_get_own_repos(gcli_ctx *ctx, int const max, gcli_repo_list *const list) } int -github_repo_delete(gcli_ctx *ctx, char const *owner, char const *repo) +github_repo_delete(struct gcli_ctx *ctx, char const *owner, char const *repo) { char *url = NULL; char *e_owner = NULL; @@ -129,7 +130,7 @@ github_repo_delete(gcli_ctx *ctx, char const *owner, char const *repo) } int -github_repo_create(gcli_ctx *ctx, gcli_repo_create_options const *options, +github_repo_create(struct gcli_ctx *ctx, gcli_repo_create_options const *options, gcli_repo *const out) { char *url, *payload; @@ -178,7 +179,7 @@ github_repo_create(gcli_ctx *ctx, gcli_repo_create_options const *options, } int -github_repo_set_visibility(gcli_ctx *ctx, char const *const owner, +github_repo_set_visibility(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_repo_visibility vis) { char *url; diff --git a/src/github/sshkeys.c b/src/github/sshkeys.c index 33bbc481..de347b0c 100644 --- a/src/github/sshkeys.c +++ b/src/github/sshkeys.c @@ -34,20 +34,20 @@ #include int -github_get_sshkeys(gcli_ctx *ctx, gcli_sshkey_list *out) +github_get_sshkeys(struct gcli_ctx *ctx, gcli_sshkey_list *out) { return gitlab_get_sshkeys(ctx, out); } int -github_add_sshkey(gcli_ctx *ctx, char const *const title, +github_add_sshkey(struct gcli_ctx *ctx, char const *const title, char const *const pubkey, gcli_sshkey *out) { return gitlab_add_sshkey(ctx, title, pubkey, out); } int -github_delete_sshkey(gcli_ctx *ctx, gcli_id const id) +github_delete_sshkey(struct gcli_ctx *ctx, gcli_id const id) { return gitlab_delete_sshkey(ctx, id); } diff --git a/src/github/status.c b/src/github/status.c index 8e0d4757..b0b6f6f2 100644 --- a/src/github/status.c +++ b/src/github/status.c @@ -37,7 +37,7 @@ #include int -github_get_notifications(gcli_ctx *ctx, int const max, +github_get_notifications(struct gcli_ctx *ctx, int const max, gcli_notification_list *const out) { char *url = NULL; @@ -54,7 +54,7 @@ github_get_notifications(gcli_ctx *ctx, int const max, } int -github_notification_mark_as_read(gcli_ctx *ctx, char const *id) +github_notification_mark_as_read(struct gcli_ctx *ctx, char const *id) { char *url = NULL; int rc = 0; diff --git a/src/gitlab/api.c b/src/gitlab/api.c index f4c0c1e2..2cab03c6 100644 --- a/src/gitlab/api.c +++ b/src/gitlab/api.c @@ -35,7 +35,7 @@ #include char const * -gitlab_api_error_string(gcli_ctx *ctx, gcli_fetch_buffer *const buf) +gitlab_api_error_string(struct gcli_ctx *ctx, gcli_fetch_buffer *const buf) { char *msg = NULL; int rc; @@ -60,7 +60,7 @@ gitlab_api_error_string(gcli_ctx *ctx, gcli_fetch_buffer *const buf) } int -gitlab_user_id(gcli_ctx *ctx, char const *user_name) +gitlab_user_id(struct gcli_ctx *ctx, char const *user_name) { gcli_fetch_buffer buffer = {0}; struct json_stream stream = {0}; diff --git a/src/gitlab/comments.c b/src/gitlab/comments.c index 86f852a5..5c9d09d2 100644 --- a/src/gitlab/comments.c +++ b/src/gitlab/comments.c @@ -35,7 +35,7 @@ #include int -gitlab_perform_submit_comment(gcli_ctx *ctx, gcli_submit_comment_opts opts, +gitlab_perform_submit_comment(struct gcli_ctx *ctx, gcli_submit_comment_opts opts, gcli_fetch_buffer *const out) { char *url = NULL, *payload = NULL, *e_owner = NULL, *e_repo = NULL; @@ -81,7 +81,7 @@ gitlab_perform_submit_comment(gcli_ctx *ctx, gcli_submit_comment_opts opts, } int -gitlab_get_mr_comments(gcli_ctx *ctx, char const *owner, char const *repo, +gitlab_get_mr_comments(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const mr, gcli_comment_list *const out) { char *e_owner = gcli_urlencode(owner); @@ -106,8 +106,9 @@ gitlab_get_mr_comments(gcli_ctx *ctx, char const *owner, char const *repo, } int -gitlab_get_issue_comments(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const issue, gcli_comment_list *const out) +gitlab_get_issue_comments(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id const issue, + gcli_comment_list *const out) { char *e_owner = gcli_urlencode(owner); char *e_repo = gcli_urlencode(repo); diff --git a/src/gitlab/config.c b/src/gitlab/config.c index dc911f16..0161b034 100644 --- a/src/gitlab/config.c +++ b/src/gitlab/config.c @@ -32,7 +32,7 @@ #include char * -gitlab_make_authheader(gcli_ctx *ctx, char const *token) +gitlab_make_authheader(struct gcli_ctx *ctx, char const *token) { (void) ctx; return sn_asprintf("PRIVATE-TOKEN: %s", token); diff --git a/src/gitlab/forks.c b/src/gitlab/forks.c index a0a63d1e..ac59335b 100644 --- a/src/gitlab/forks.c +++ b/src/gitlab/forks.c @@ -37,7 +37,7 @@ #include int -gitlab_get_forks(gcli_ctx *ctx, char const *owner, char const *repo, +gitlab_get_forks(struct gcli_ctx *ctx, char const *owner, char const *repo, int const max, gcli_fork_list *const list) { char *url = NULL; @@ -66,7 +66,7 @@ gitlab_get_forks(gcli_ctx *ctx, char const *owner, char const *repo, } int -gitlab_fork_create(gcli_ctx *ctx, char const *owner, char const *repo, +gitlab_fork_create(struct gcli_ctx *ctx, char const *owner, char const *repo, char const *_in) { char *url = NULL; diff --git a/src/gitlab/issues.c b/src/gitlab/issues.c index c84fba65..712c775f 100644 --- a/src/gitlab/issues.c +++ b/src/gitlab/issues.c @@ -40,7 +40,7 @@ /** Given the url fetch issues */ int -gitlab_fetch_issues(gcli_ctx *ctx, char *url, int const max, +gitlab_fetch_issues(struct gcli_ctx *ctx, char *url, int const max, gcli_issue_list *const out) { gcli_fetch_list_ctx fl = { @@ -54,7 +54,7 @@ gitlab_fetch_issues(gcli_ctx *ctx, char *url, int const max, } int -gitlab_get_issues(gcli_ctx *ctx, char const *owner, char const *repo, +gitlab_get_issues(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_issue_fetch_details const *details, int const max, gcli_issue_list *const out) { @@ -110,8 +110,9 @@ gitlab_get_issues(gcli_ctx *ctx, char const *owner, char const *repo, } int -gitlab_get_issue_summary(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const issue_number, gcli_issue *const out) +gitlab_get_issue_summary(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id const issue_number, + gcli_issue *const out) { char *url = NULL; char *e_owner = NULL; @@ -143,7 +144,7 @@ gitlab_get_issue_summary(gcli_ctx *ctx, char const *owner, char const *repo, } static int -gitlab_issue_patch_state(gcli_ctx *const ctx, char const *const owner, +gitlab_issue_patch_state(struct gcli_ctx *const ctx, char const *const owner, char const *const repo, gcli_id const issue, char const *const new_state) { @@ -182,21 +183,21 @@ gitlab_issue_patch_state(gcli_ctx *const ctx, char const *const owner, } int -gitlab_issue_close(gcli_ctx *ctx, char const *owner, char const *repo, +gitlab_issue_close(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const issue) { return gitlab_issue_patch_state(ctx, owner, repo, issue, "close"); } int -gitlab_issue_reopen(gcli_ctx *ctx, char const *owner, char const *repo, +gitlab_issue_reopen(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const issue) { return gitlab_issue_patch_state(ctx, owner, repo, issue, "reopen"); } int -gitlab_perform_submit_issue(gcli_ctx *ctx, gcli_submit_issue_options opts, +gitlab_perform_submit_issue(struct gcli_ctx *ctx, gcli_submit_issue_options opts, gcli_fetch_buffer *const out) { char *e_owner = NULL, *e_repo = NULL, *url = NULL, *payload = NULL; @@ -235,7 +236,7 @@ gitlab_perform_submit_issue(gcli_ctx *ctx, gcli_submit_issue_options opts, } int -gitlab_issue_assign(gcli_ctx *ctx, char const *owner, char const *repo, +gitlab_issue_assign(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const issue_number, char const *assignee) { char *url = NULL, *payload = NULL, *e_owner = NULL, *e_repo = NULL; @@ -279,7 +280,7 @@ gitlab_issue_assign(gcli_ctx *ctx, char const *owner, char const *repo, } static int -gitlab_issues_update_labels(gcli_ctx *const ctx, char const *const owner, +gitlab_issues_update_labels(struct gcli_ctx *const ctx, char const *const owner, char const *const repo, gcli_id const issue, char const *const labels[], size_t const labels_size, char const *const what) @@ -325,25 +326,25 @@ gitlab_issues_update_labels(gcli_ctx *const ctx, char const *const owner, } int -gitlab_issue_add_labels(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const issue, char const *const labels[], - size_t const labels_size) +gitlab_issue_add_labels(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id const issue, + char const *const labels[], size_t const labels_size) { return gitlab_issues_update_labels(ctx, owner, repo, issue, labels, labels_size, "add_labels"); } int -gitlab_issue_remove_labels(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const issue, char const *const labels[], - size_t const labels_size) +gitlab_issue_remove_labels(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id const issue, + char const *const labels[], size_t const labels_size) { return gitlab_issues_update_labels(ctx, owner, repo, issue, labels, labels_size, "remove_labels"); } int -gitlab_issue_set_milestone(gcli_ctx *ctx, char const *const owner, +gitlab_issue_set_milestone(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const issue, gcli_id const milestone) { @@ -365,7 +366,7 @@ gitlab_issue_set_milestone(gcli_ctx *ctx, char const *const owner, } int -gitlab_issue_clear_milestone(gcli_ctx *ctx, char const *const owner, +gitlab_issue_clear_milestone(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const issue) { char *url, *e_owner, *e_repo; @@ -400,8 +401,9 @@ gitlab_issue_clear_milestone(gcli_ctx *ctx, char const *const owner, } int -gitlab_issue_set_title(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id issue, char const *const new_title) +gitlab_issue_set_title(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id issue, + char const *const new_title) { char *url, *e_owner, *e_repo, *payload; gcli_jsongen gen = {0}; diff --git a/src/gitlab/labels.c b/src/gitlab/labels.c index 4f22345f..f8a83bae 100644 --- a/src/gitlab/labels.c +++ b/src/gitlab/labels.c @@ -37,7 +37,7 @@ #include int -gitlab_get_labels(gcli_ctx *ctx, char const *owner, char const *repo, +gitlab_get_labels(struct gcli_ctx *ctx, char const *owner, char const *repo, int const max, gcli_label_list *const out) { char *url = NULL; @@ -57,7 +57,7 @@ gitlab_get_labels(gcli_ctx *ctx, char const *owner, char const *repo, } int -gitlab_create_label(gcli_ctx *ctx, char const *owner, char const *repo, +gitlab_create_label(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_label *const label) { char *url = NULL, *payload = NULL, *colour_string = NULL, *e_owner = NULL, @@ -116,7 +116,7 @@ gitlab_create_label(gcli_ctx *ctx, char const *owner, char const *repo, } int -gitlab_delete_label(gcli_ctx *ctx, char const *owner, char const *repo, +gitlab_delete_label(struct gcli_ctx *ctx, char const *owner, char const *repo, char const *label) { char *url = NULL; diff --git a/src/gitlab/merge_requests.c b/src/gitlab/merge_requests.c index 8e5e325b..1b5e7376 100644 --- a/src/gitlab/merge_requests.c +++ b/src/gitlab/merge_requests.c @@ -50,7 +50,7 @@ gitlab_mrs_fixup(gcli_pull_list *const list) } int -gitlab_fetch_mrs(gcli_ctx *ctx, char *url, int const max, +gitlab_fetch_mrs(struct gcli_ctx *ctx, char *url, int const max, gcli_pull_list *const list) { int rc = 0; @@ -72,7 +72,7 @@ gitlab_fetch_mrs(gcli_ctx *ctx, char *url, int const max, } int -gitlab_get_mrs(gcli_ctx *ctx, char const *owner, char const *repo, +gitlab_get_mrs(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_pull_fetch_details const *const details, int const max, gcli_pull_list *const list) { @@ -172,7 +172,7 @@ gitlab_make_commit_diff(gcli_commit const *const commit, } static int -gitlab_make_commit_patch(gcli_ctx *ctx, FILE *stream, +gitlab_make_commit_patch(struct gcli_ctx *ctx, FILE *stream, char const *const e_owner, char const *const e_repo, char const *const prev_commit_sha, gcli_commit const *const commit) @@ -216,7 +216,7 @@ gitlab_make_commit_patch(gcli_ctx *ctx, FILE *stream, } int -gitlab_mr_get_patch(gcli_ctx *ctx, FILE *stream, char const *owner, +gitlab_mr_get_patch(struct gcli_ctx *ctx, FILE *stream, char const *owner, char const *reponame, gcli_id mr_number) { int rc = 0; @@ -262,7 +262,7 @@ gitlab_mr_get_patch(gcli_ctx *ctx, FILE *stream, char const *owner, } int -gitlab_mr_get_diff(gcli_ctx *ctx, FILE *stream, char const *owner, +gitlab_mr_get_diff(struct gcli_ctx *ctx, FILE *stream, char const *owner, char const *reponame, gcli_id mr_number) { (void) stream; @@ -274,7 +274,7 @@ gitlab_mr_get_diff(gcli_ctx *ctx, FILE *stream, char const *owner, } int -gitlab_mr_merge(gcli_ctx *ctx, char const *owner, char const *repo, +gitlab_mr_merge(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const mr_number, enum gcli_merge_flags const flags) { gcli_fetch_buffer buffer = {0}; @@ -309,7 +309,7 @@ gitlab_mr_merge(gcli_ctx *ctx, char const *owner, char const *repo, } int -gitlab_get_pull(gcli_ctx *ctx, char const *owner, char const *repo, +gitlab_get_pull(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const pr_number, gcli_pull *const out) { gcli_fetch_buffer json_buffer = {0}; @@ -343,7 +343,7 @@ gitlab_get_pull(gcli_ctx *ctx, char const *owner, char const *repo, } int -gitlab_get_pull_commits(gcli_ctx *ctx, char const *owner, char const *repo, +gitlab_get_pull_commits(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const pr_number, gcli_commit_list *const out) { char *url = NULL; @@ -371,7 +371,7 @@ gitlab_get_pull_commits(gcli_ctx *ctx, char const *owner, char const *repo, } static int -gitlab_mr_patch_state(gcli_ctx *const ctx, char const *const owner, +gitlab_mr_patch_state(struct gcli_ctx *const ctx, char const *const owner, char const *const repo, gcli_id const mr, char const *const new_state) { @@ -410,21 +410,21 @@ gitlab_mr_patch_state(gcli_ctx *const ctx, char const *const owner, } int -gitlab_mr_close(gcli_ctx *ctx, char const *owner, char const *repo, +gitlab_mr_close(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const mr) { return gitlab_mr_patch_state(ctx, owner, repo, mr, "close"); } int -gitlab_mr_reopen(gcli_ctx *ctx, char const *owner, char const *repo, +gitlab_mr_reopen(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const mr) { return gitlab_mr_patch_state(ctx, owner, repo, mr, "reopen"); } int -gitlab_perform_submit_mr(gcli_ctx *ctx, gcli_submit_pull_options opts) +gitlab_perform_submit_mr(struct gcli_ctx *ctx, gcli_submit_pull_options opts) { /* Note: this doesn't really allow merging into repos with * different names. We need to figure out a way to make this @@ -504,9 +504,9 @@ gitlab_perform_submit_mr(gcli_ctx *ctx, gcli_submit_pull_options opts) } static int -gitlab_mr_update_labels(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const mr, char const *const labels[], - size_t const labels_size, +gitlab_mr_update_labels(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id const mr, + char const *const labels[], size_t const labels_size, char const *const update_action) { char *url = NULL, *payload = NULL, *list = NULL, *e_owner = NULL, @@ -547,7 +547,7 @@ gitlab_mr_update_labels(gcli_ctx *ctx, char const *owner, char const *repo, } int -gitlab_mr_add_labels(gcli_ctx *ctx, char const *owner, char const *repo, +gitlab_mr_add_labels(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const mr, char const *const labels[], size_t const labels_size) { @@ -556,17 +556,17 @@ gitlab_mr_add_labels(gcli_ctx *ctx, char const *owner, char const *repo, } int -gitlab_mr_remove_labels(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const mr, char const *const labels[], - size_t const labels_size) +gitlab_mr_remove_labels(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id const mr, + char const *const labels[], size_t const labels_size) { return gitlab_mr_update_labels(ctx, owner, repo, mr, labels, labels_size, "remove_labels"); } int -gitlab_mr_set_milestone(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id mr, gcli_id milestone_id) +gitlab_mr_set_milestone(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id mr, gcli_id milestone_id) { char *url = NULL, *payload = NULL, *e_owner = NULL, *e_repo = NULL; gcli_jsongen gen = {0}; @@ -603,8 +603,8 @@ gitlab_mr_set_milestone(gcli_ctx *ctx, char const *owner, char const *repo, } int -gitlab_mr_clear_milestone(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const mr) +gitlab_mr_clear_milestone(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id const mr) { /* GitLab's REST API docs state: * @@ -617,8 +617,9 @@ gitlab_mr_clear_milestone(gcli_ctx *ctx, char const *owner, char const *repo, /* Helper function to fetch the list of user ids that are reviewers * of a merge requests. */ static int -gitlab_mr_get_reviewers(gcli_ctx *ctx, char const *e_owner, char const *e_repo, - gcli_id const mr, gitlab_reviewer_id_list *const out) +gitlab_mr_get_reviewers(struct gcli_ctx *ctx, char const *e_owner, + char const *e_repo, gcli_id const mr, + gitlab_reviewer_id_list *const out) { char *url; int rc; @@ -650,7 +651,7 @@ gitlab_reviewer_list_free(gitlab_reviewer_id_list *const list) } int -gitlab_mr_add_reviewer(gcli_ctx *ctx, char const *owner, char const *repo, +gitlab_mr_add_reviewer(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id mr_number, char const *username) { char *url, *e_owner, *e_repo, *payload; @@ -713,7 +714,7 @@ gitlab_mr_add_reviewer(gcli_ctx *ctx, char const *owner, char const *repo, } int -gitlab_mr_set_title(gcli_ctx *ctx, char const *const owner, +gitlab_mr_set_title(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const id, char const *const new_title) { diff --git a/src/gitlab/milestones.c b/src/gitlab/milestones.c index 8de8e819..a7b63d63 100644 --- a/src/gitlab/milestones.c +++ b/src/gitlab/milestones.c @@ -43,7 +43,7 @@ #include int -gitlab_get_milestones(gcli_ctx *ctx, char const *owner, char const *repo, +gitlab_get_milestones(struct gcli_ctx *ctx, char const *owner, char const *repo, int max, gcli_milestone_list *const out) { char *url; @@ -69,7 +69,7 @@ gitlab_get_milestones(gcli_ctx *ctx, char const *owner, char const *repo, } int -gitlab_get_milestone(gcli_ctx *ctx, char const *owner, char const *repo, +gitlab_get_milestone(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const milestone, gcli_milestone *const out) { char *url, *e_owner, *e_repo; @@ -99,7 +99,7 @@ gitlab_get_milestone(gcli_ctx *ctx, char const *owner, char const *repo, } int -gitlab_milestone_get_issues(gcli_ctx *ctx, char const *const owner, +gitlab_milestone_get_issues(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const milestone, gcli_issue_list *const out) { @@ -119,7 +119,7 @@ gitlab_milestone_get_issues(gcli_ctx *ctx, char const *const owner, } int -gitlab_create_milestone(gcli_ctx *ctx, +gitlab_create_milestone(struct gcli_ctx *ctx, struct gcli_milestone_create_args const *args) { char *url, *e_owner, *e_repo, *e_title, *json_body, *description = NULL; @@ -159,7 +159,7 @@ gitlab_create_milestone(gcli_ctx *ctx, } int -gitlab_delete_milestone(gcli_ctx *ctx, char const *const owner, +gitlab_delete_milestone(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const milestone) { char *url, *e_owner, *e_repo; @@ -181,7 +181,7 @@ gitlab_delete_milestone(gcli_ctx *ctx, char const *const owner, } int -gitlab_milestone_set_duedate(gcli_ctx *ctx, char const *const owner, +gitlab_milestone_set_duedate(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const milestone, char const *const date) { diff --git a/src/gitlab/pipelines.c b/src/gitlab/pipelines.c index 55dbd171..894338fe 100644 --- a/src/gitlab/pipelines.c +++ b/src/gitlab/pipelines.c @@ -44,7 +44,7 @@ #include static int -fetch_pipelines(gcli_ctx *ctx, char *url, int const max, +fetch_pipelines(struct gcli_ctx *ctx, char *url, int const max, gitlab_pipeline_list *const list) { gcli_fetch_list_ctx fl = { @@ -58,7 +58,7 @@ fetch_pipelines(gcli_ctx *ctx, char *url, int const max, } int -gitlab_get_pipelines(gcli_ctx *ctx, char const *owner, char const *repo, +gitlab_get_pipelines(struct gcli_ctx *ctx, char const *owner, char const *repo, int const max, gitlab_pipeline_list *const list) { char *url = NULL; @@ -74,7 +74,7 @@ gitlab_get_pipelines(gcli_ctx *ctx, char const *owner, char const *repo, } int -gitlab_get_mr_pipelines(gcli_ctx *ctx, char const *owner, char const *repo, +gitlab_get_mr_pipelines(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const mr_id, gitlab_pipeline_list *const list) { char *url = NULL; @@ -115,9 +115,9 @@ gitlab_pipelines_free(gitlab_pipeline_list *const list) } int -gitlab_get_pipeline_jobs(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const pipeline, int const max, - gitlab_job_list *const out) +gitlab_get_pipeline_jobs(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id const pipeline, + int const max, gitlab_job_list *const out) { char *url = NULL, *e_owner = NULL, *e_repo = NULL; gcli_fetch_list_ctx fl = { @@ -166,7 +166,7 @@ gitlab_free_jobs(gitlab_job_list *list) } int -gitlab_job_get_log(gcli_ctx *ctx, char const *owner, char const *repo, +gitlab_job_get_log(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const job_id, FILE *stream) { char *url = NULL, *e_owner = NULL, *e_repo = NULL; @@ -189,7 +189,7 @@ gitlab_job_get_log(gcli_ctx *ctx, char const *owner, char const *repo, } int -gitlab_get_job(gcli_ctx *ctx, char const *owner, char const *repo, +gitlab_get_job(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const jid, gitlab_job *const out) { gcli_fetch_buffer buffer = {0}; @@ -222,7 +222,7 @@ gitlab_get_job(gcli_ctx *ctx, char const *owner, char const *repo, } int -gitlab_job_cancel(gcli_ctx *ctx, char const *owner, char const *repo, +gitlab_job_cancel(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const jid) { char *url = NULL, *e_owner = NULL, *e_repo = NULL; @@ -245,7 +245,7 @@ gitlab_job_cancel(gcli_ctx *ctx, char const *owner, char const *repo, } int -gitlab_job_retry(gcli_ctx *ctx, char const *owner, char const *repo, +gitlab_job_retry(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const jid) { int rc = 0; @@ -268,7 +268,7 @@ gitlab_job_retry(gcli_ctx *ctx, char const *owner, char const *repo, } int -gitlab_job_download_artifacts(gcli_ctx *ctx, char const *owner, +gitlab_job_download_artifacts(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const jid, char const *const outfile) { diff --git a/src/gitlab/releases.c b/src/gitlab/releases.c index 626415ac..6df237ba 100644 --- a/src/gitlab/releases.c +++ b/src/gitlab/releases.c @@ -40,21 +40,21 @@ #include static void -fixup_asset_name(gcli_ctx *ctx, gcli_release_asset *const asset) +fixup_asset_name(struct gcli_ctx *ctx, gcli_release_asset *const asset) { if (!asset->name) asset->name = gcli_urldecode(ctx, strrchr(asset->url, '/') + 1); } void -gitlab_fixup_release_assets(gcli_ctx *ctx, gcli_release *const release) +gitlab_fixup_release_assets(struct gcli_ctx *ctx, gcli_release *const release) { for (size_t i = 0; i < release->assets_size; ++i) fixup_asset_name(ctx, &release->assets[i]); } static void -fixup_release_asset_names(gcli_ctx *ctx, gcli_release_list *list) +fixup_release_asset_names(struct gcli_ctx *ctx, gcli_release_list *list) { /* Iterate over releases */ for (size_t i = 0; i < list->releases_size; ++i) @@ -62,7 +62,7 @@ fixup_release_asset_names(gcli_ctx *ctx, gcli_release_list *list) } int -gitlab_get_releases(gcli_ctx *ctx, char const *owner, char const *repo, +gitlab_get_releases(struct gcli_ctx *ctx, char const *owner, char const *repo, int const max, gcli_release_list *const list) { char *url = NULL; @@ -97,7 +97,7 @@ gitlab_get_releases(gcli_ctx *ctx, char const *owner, char const *repo, } int -gitlab_create_release(gcli_ctx *ctx, gcli_new_release const *release) +gitlab_create_release(struct gcli_ctx *ctx, gcli_new_release const *release) { char *e_owner = NULL, *e_repo = NULL, *url = NULL, *payload = NULL; gcli_jsongen gen = {0}; @@ -157,7 +157,8 @@ gitlab_create_release(gcli_ctx *ctx, gcli_new_release const *release) } int -gitlab_delete_release(gcli_ctx *ctx, char const *owner, char const *repo, char const *id) +gitlab_delete_release(struct gcli_ctx *ctx, char const *owner, + char const *repo, char const *id) { char *url = NULL; char *e_owner = NULL; diff --git a/src/gitlab/repos.c b/src/gitlab/repos.c index d8578509..e6e7ee6b 100644 --- a/src/gitlab/repos.c +++ b/src/gitlab/repos.c @@ -40,7 +40,7 @@ #include int -gitlab_get_repo(gcli_ctx *ctx, char const *owner, char const *repo, +gitlab_get_repo(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_repo *const out) { /* GET /projects/:id */ @@ -88,7 +88,7 @@ gitlab_repos_fixup_missing_visibility(gcli_repo_list *const list) } int -gitlab_get_repos(gcli_ctx *ctx, char const *owner, int const max, +gitlab_get_repos(struct gcli_ctx *ctx, char const *owner, int const max, gcli_repo_list *const list) { char *url = NULL; @@ -114,7 +114,7 @@ gitlab_get_repos(gcli_ctx *ctx, char const *owner, int const max, } int -gitlab_repo_delete(gcli_ctx *ctx, char const *owner, char const *repo) +gitlab_repo_delete(struct gcli_ctx *ctx, char const *owner, char const *repo) { char *url = NULL; char *e_owner = NULL; @@ -137,7 +137,7 @@ gitlab_repo_delete(gcli_ctx *ctx, char const *owner, char const *repo) } int -gitlab_repo_create(gcli_ctx *ctx, gcli_repo_create_options const *options, +gitlab_repo_create(struct gcli_ctx *ctx, gcli_repo_create_options const *options, gcli_repo *out) { char *url, *payload; @@ -183,7 +183,7 @@ gitlab_repo_create(gcli_ctx *ctx, gcli_repo_create_options const *options, } int -gitlab_repo_set_visibility(gcli_ctx *ctx, char const *const owner, +gitlab_repo_set_visibility(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_repo_visibility vis) { char *url; diff --git a/src/gitlab/snippets.c b/src/gitlab/snippets.c index c2703ab1..397a37dd 100644 --- a/src/gitlab/snippets.c +++ b/src/gitlab/snippets.c @@ -65,7 +65,8 @@ gcli_snippets_free(gcli_gitlab_snippet_list *const list) } int -gcli_snippets_get(gcli_ctx *ctx, int const max, gcli_gitlab_snippet_list *const out) +gcli_snippets_get(struct gcli_ctx *ctx, int const max, + gcli_gitlab_snippet_list *const out) { char *url = NULL; @@ -83,7 +84,7 @@ gcli_snippets_get(gcli_ctx *ctx, int const max, gcli_gitlab_snippet_list *const } int -gcli_snippet_delete(gcli_ctx *ctx, char const *snippet_id) +gcli_snippet_delete(struct gcli_ctx *ctx, char const *snippet_id) { int rc = 0; char *url; @@ -97,7 +98,7 @@ gcli_snippet_delete(gcli_ctx *ctx, char const *snippet_id) } int -gcli_snippet_get(gcli_ctx *ctx, char const *snippet_id, FILE *stream) +gcli_snippet_get(struct gcli_ctx *ctx, char const *snippet_id, FILE *stream) { int rc = 0; char *url = sn_asprintf("%s/snippets/%s/raw", diff --git a/src/gitlab/sshkeys.c b/src/gitlab/sshkeys.c index dd7792c6..db727219 100644 --- a/src/gitlab/sshkeys.c +++ b/src/gitlab/sshkeys.c @@ -41,7 +41,7 @@ #include int -gitlab_get_sshkeys(gcli_ctx *ctx, gcli_sshkey_list *list) +gitlab_get_sshkeys(struct gcli_ctx *ctx, gcli_sshkey_list *list) { char *url; gcli_fetch_list_ctx fl = { @@ -58,7 +58,7 @@ gitlab_get_sshkeys(gcli_ctx *ctx, gcli_sshkey_list *list) } int -gitlab_add_sshkey(gcli_ctx *ctx, char const *const title, +gitlab_add_sshkey(struct gcli_ctx *ctx, char const *const title, char const *const pubkey, gcli_sshkey *const out) { char *url, *payload; @@ -92,7 +92,7 @@ gitlab_add_sshkey(gcli_ctx *ctx, char const *const title, } int -gitlab_delete_sshkey(gcli_ctx *ctx, gcli_id id) +gitlab_delete_sshkey(struct gcli_ctx *ctx, gcli_id id) { char *url; int rc = 0; diff --git a/src/gitlab/status.c b/src/gitlab/status.c index ee53bc74..309ef8c7 100644 --- a/src/gitlab/status.c +++ b/src/gitlab/status.c @@ -38,7 +38,7 @@ #include int -gitlab_get_notifications(gcli_ctx *ctx, int const max, +gitlab_get_notifications(struct gcli_ctx *ctx, int const max, gcli_notification_list *const out) { char *url = NULL; @@ -56,7 +56,7 @@ gitlab_get_notifications(gcli_ctx *ctx, int const max, } int -gitlab_notification_mark_as_read(gcli_ctx *ctx, char const *id) +gitlab_notification_mark_as_read(struct gcli_ctx *ctx, char const *id) { char *url = NULL; int rc = 0; diff --git a/src/issues.c b/src/issues.c index 3bcb9582..ddd296a1 100644 --- a/src/issues.c +++ b/src/issues.c @@ -72,7 +72,7 @@ gcli_issues_free(gcli_issue_list *const list) } int -gcli_get_issues(gcli_ctx *ctx, char const *owner, char const *repo, +gcli_get_issues(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_issue_fetch_details const *details, int const max, gcli_issue_list *const out) { @@ -80,7 +80,7 @@ gcli_get_issues(gcli_ctx *ctx, char const *owner, char const *repo, } int -gcli_get_issue(gcli_ctx *ctx, char const *owner, char const *repo, +gcli_get_issue(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const issue_number, gcli_issue *const out) { gcli_null_check_call(get_issue_summary, ctx, owner, repo, issue_number, @@ -88,27 +88,27 @@ gcli_get_issue(gcli_ctx *ctx, char const *owner, char const *repo, } int -gcli_issue_close(gcli_ctx *ctx, char const *owner, char const *repo, +gcli_issue_close(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const issue_number) { gcli_null_check_call(issue_close, ctx, owner, repo, issue_number); } int -gcli_issue_reopen(gcli_ctx *ctx, char const *owner, char const *repo, +gcli_issue_reopen(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const issue_number) { gcli_null_check_call(issue_reopen, ctx, owner, repo, issue_number); } int -gcli_issue_submit(gcli_ctx *ctx, gcli_submit_issue_options opts) +gcli_issue_submit(struct gcli_ctx *ctx, gcli_submit_issue_options opts) { gcli_null_check_call(perform_submit_issue, ctx, opts, NULL); } int -gcli_issue_assign(gcli_ctx *ctx, char const *owner, char const *repo, +gcli_issue_assign(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const issue_number, char const *assignee) { gcli_null_check_call(issue_assign, ctx, owner, repo, issue_number, @@ -116,7 +116,7 @@ gcli_issue_assign(gcli_ctx *ctx, char const *owner, char const *repo, } int -gcli_issue_add_labels(gcli_ctx *ctx, char const *owner, char const *repo, +gcli_issue_add_labels(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const issue, char const *const labels[], size_t const labels_size) { @@ -125,16 +125,16 @@ gcli_issue_add_labels(gcli_ctx *ctx, char const *owner, char const *repo, } int -gcli_issue_remove_labels(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const issue, char const *const labels[], - size_t const labels_size) +gcli_issue_remove_labels(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id const issue, + char const *const labels[], size_t const labels_size) { gcli_null_check_call(issue_remove_labels, ctx, owner, repo, issue, labels, labels_size); } int -gcli_issue_set_milestone(gcli_ctx *ctx, char const *const owner, +gcli_issue_set_milestone(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const issue, int const milestone) { @@ -143,14 +143,14 @@ gcli_issue_set_milestone(gcli_ctx *ctx, char const *const owner, } int -gcli_issue_clear_milestone(gcli_ctx *ctx, char const *const owner, +gcli_issue_clear_milestone(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const issue) { gcli_null_check_call(issue_clear_milestone, ctx, owner, repo, issue); } int -gcli_issue_set_title(gcli_ctx *ctx, char const *owner, char const *repo, +gcli_issue_set_title(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue, char const *new_title) { gcli_null_check_call(issue_set_title, ctx, owner, repo, issue, @@ -158,8 +158,9 @@ gcli_issue_set_title(gcli_ctx *ctx, char const *owner, char const *repo, } int -gcli_issue_get_attachments(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id issue, gcli_attachment_list *out) +gcli_issue_get_attachments(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id issue, + gcli_attachment_list *out) { gcli_forge_descriptor const *const forge = gcli_forge(ctx); @@ -175,4 +176,3 @@ gcli_issue_get_attachments(gcli_ctx *ctx, char const *owner, char const *repo, issue, out); } } - diff --git a/src/json_util.c b/src/json_util.c index 6055af4b..87836d50 100644 --- a/src/json_util.c +++ b/src/json_util.c @@ -37,7 +37,7 @@ #include int -get_int_(gcli_ctx *ctx, json_stream *const input, int *out, char const *where) +get_int_(struct gcli_ctx *ctx, json_stream *const input, int *out, char const *where) { if (json_next(input) != JSON_NUMBER) return gcli_error(ctx, "unexpected non-integer field in %s", where); @@ -48,7 +48,7 @@ get_int_(gcli_ctx *ctx, json_stream *const input, int *out, char const *where) } int -get_id_(gcli_ctx *ctx, json_stream *const input, gcli_id *out, char const *where) +get_id_(struct gcli_ctx *ctx, json_stream *const input, gcli_id *out, char const *where) { if (json_next(input) != JSON_NUMBER) return gcli_error(ctx, "unexpected non-integer ID field in %s", where); @@ -59,7 +59,7 @@ get_id_(gcli_ctx *ctx, json_stream *const input, gcli_id *out, char const *where } int -get_long_(gcli_ctx *ctx, json_stream *const input, long *out, char const *where) +get_long_(struct gcli_ctx *ctx, json_stream *const input, long *out, char const *where) { if (json_next(input) != JSON_NUMBER) return gcli_error(ctx, "unexpected non-integer field in %s", where); @@ -70,7 +70,7 @@ get_long_(gcli_ctx *ctx, json_stream *const input, long *out, char const *where) } int -get_size_t_(gcli_ctx *ctx, json_stream *const input, size_t *out, char const *where) +get_size_t_(struct gcli_ctx *ctx, json_stream *const input, size_t *out, char const *where) { if (json_next(input) != JSON_NUMBER) return gcli_error(ctx, "unexpected non-integer field in %s", where); @@ -81,7 +81,7 @@ get_size_t_(gcli_ctx *ctx, json_stream *const input, size_t *out, char const *wh } int -get_double_(gcli_ctx *ctx, json_stream *const input, double *out, char const *where) +get_double_(struct gcli_ctx *ctx, json_stream *const input, double *out, char const *where) { enum json_type type = json_next(input); @@ -100,7 +100,7 @@ get_double_(gcli_ctx *ctx, json_stream *const input, double *out, char const *wh } int -get_string_(gcli_ctx *ctx, json_stream *const input, char **out, +get_string_(struct gcli_ctx *ctx, json_stream *const input, char **out, char const *where) { enum json_type const type = json_next(input); @@ -124,7 +124,7 @@ get_string_(gcli_ctx *ctx, json_stream *const input, char **out, } int -get_bool_(gcli_ctx *ctx,json_stream *const input, bool *out, char const *where) +get_bool_(struct gcli_ctx *ctx,json_stream *const input, bool *out, char const *where) { enum json_type value_type = json_next(input); if (value_type == JSON_TRUE) { @@ -139,7 +139,7 @@ get_bool_(gcli_ctx *ctx,json_stream *const input, bool *out, char const *where) } int -get_bool_relaxed_(gcli_ctx *ctx,json_stream *const input, bool *out, char const *where) +get_bool_relaxed_(struct gcli_ctx *ctx,json_stream *const input, bool *out, char const *where) { enum json_type value_type = json_next(input); if (value_type == JSON_TRUE) { @@ -157,7 +157,7 @@ get_bool_relaxed_(gcli_ctx *ctx,json_stream *const input, bool *out, char const } int -get_user_(gcli_ctx *ctx, json_stream *const input, char **out, +get_user_(struct gcli_ctx *ctx, json_stream *const input, char **out, char const *where) { if (json_next(input) != JSON_OBJECT) @@ -225,7 +225,7 @@ gcli_json_escape(sn_sv const it) } int -get_sv_(gcli_ctx *ctx, json_stream *const input, sn_sv *out, char const *where) +get_sv_(struct gcli_ctx *ctx, json_stream *const input, sn_sv *out, char const *where) { enum json_type type = json_next(input); if (type == JSON_NULL) { @@ -245,7 +245,7 @@ get_sv_(gcli_ctx *ctx, json_stream *const input, sn_sv *out, char const *where) } int -get_label_(gcli_ctx *ctx, json_stream *const input, char const **out, +get_label_(struct gcli_ctx *ctx, json_stream *const input, char const **out, char const *where) { if (json_next(input) != JSON_OBJECT) @@ -271,7 +271,7 @@ get_label_(gcli_ctx *ctx, json_stream *const input, char const **out, } int -gcli_json_advance(gcli_ctx *ctx, json_stream *const stream, char const *fmt, ...) +gcli_json_advance(struct gcli_ctx *ctx, json_stream *const stream, char const *fmt, ...) { va_list ap; va_start(ap, fmt); @@ -317,7 +317,7 @@ gcli_json_advance(gcli_ctx *ctx, json_stream *const stream, char const *fmt, ... } int -get_parse_int_(gcli_ctx *ctx, json_stream *const input, long *out, +get_parse_int_(struct gcli_ctx *ctx, json_stream *const input, long *out, char const *function) { char *endptr = NULL; @@ -336,7 +336,7 @@ get_parse_int_(gcli_ctx *ctx, json_stream *const input, long *out, } int -get_github_style_colour(gcli_ctx *ctx, json_stream *const input, uint32_t *out) +get_github_style_colour(struct gcli_ctx *ctx, json_stream *const input, uint32_t *out) { char *colour_str; char *endptr = NULL; @@ -358,7 +358,7 @@ get_github_style_colour(gcli_ctx *ctx, json_stream *const input, uint32_t *out) } int -get_gitlab_style_colour(gcli_ctx *ctx, json_stream *const input, uint32_t *out) +get_gitlab_style_colour(struct gcli_ctx *ctx, json_stream *const input, uint32_t *out) { char *colour; char *endptr = NULL; @@ -381,7 +381,7 @@ get_gitlab_style_colour(gcli_ctx *ctx, json_stream *const input, uint32_t *out) } int -get_gitea_visibility(gcli_ctx *ctx, json_stream *const input, char **out) +get_gitea_visibility(struct gcli_ctx *ctx, json_stream *const input, char **out) { bool is_private; int rc = get_bool(ctx, input, &is_private); @@ -394,7 +394,7 @@ get_gitea_visibility(gcli_ctx *ctx, json_stream *const input, char **out) } int -get_gitlab_can_be_merged(gcli_ctx *ctx, json_stream *const input, bool *out) +get_gitlab_can_be_merged(struct gcli_ctx *ctx, json_stream *const input, bool *out) { sn_sv tmp; int rc = 0; @@ -410,7 +410,7 @@ get_gitlab_can_be_merged(gcli_ctx *ctx, json_stream *const input, bool *out) } int -get_github_is_pr(gcli_ctx *ctx, json_stream *input, int *out) +get_github_is_pr(struct gcli_ctx *ctx, json_stream *input, int *out) { enum json_type next = json_peek(input); @@ -427,7 +427,7 @@ get_github_is_pr(gcli_ctx *ctx, json_stream *input, int *out) } int -get_int_to_sv_(gcli_ctx *ctx, json_stream *input, sn_sv *out, +get_int_to_sv_(struct gcli_ctx *ctx, json_stream *input, sn_sv *out, char const *function) { int rc, val; @@ -440,4 +440,3 @@ get_int_to_sv_(gcli_ctx *ctx, json_stream *input, sn_sv *out, return 0; } - diff --git a/src/labels.c b/src/labels.c index 0478907e..0028aff1 100644 --- a/src/labels.c +++ b/src/labels.c @@ -31,7 +31,7 @@ #include int -gcli_get_labels(gcli_ctx *ctx, char const *owner, char const *reponame, +gcli_get_labels(struct gcli_ctx *ctx, char const *owner, char const *reponame, int const max, gcli_label_list *const out) { gcli_null_check_call(get_labels, ctx, owner, reponame, max, out); @@ -56,14 +56,14 @@ gcli_free_labels(gcli_label_list *const list) } int -gcli_create_label(gcli_ctx *ctx, char const *owner, char const *repo, +gcli_create_label(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_label *const label) { gcli_null_check_call(create_label, ctx, owner, repo, label); } int -gcli_delete_label(gcli_ctx *ctx, char const *owner, char const *repo, +gcli_delete_label(struct gcli_ctx *ctx, char const *owner, char const *repo, char const *const label) { gcli_null_check_call(delete_label, ctx, owner, repo, label); diff --git a/src/milestones.c b/src/milestones.c index 89465bca..0bcb5b24 100644 --- a/src/milestones.c +++ b/src/milestones.c @@ -31,7 +31,7 @@ #include int -gcli_get_milestones(gcli_ctx *ctx, char const *const owner, +gcli_get_milestones(struct gcli_ctx *ctx, char const *const owner, char const *const repo, int const max, gcli_milestone_list *const out) { @@ -39,21 +39,21 @@ gcli_get_milestones(gcli_ctx *ctx, char const *const owner, } int -gcli_get_milestone(gcli_ctx *ctx, char const *owner, char const *repo, +gcli_get_milestone(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const milestone, gcli_milestone *const out) { gcli_null_check_call(get_milestone, ctx, owner, repo, milestone, out); } int -gcli_create_milestone(gcli_ctx *ctx, +gcli_create_milestone(struct gcli_ctx *ctx, struct gcli_milestone_create_args const *args) { gcli_null_check_call(create_milestone, ctx, args); } int -gcli_delete_milestone(gcli_ctx *ctx, char const *const owner, +gcli_delete_milestone(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const milestone) { gcli_null_check_call(delete_milestone, ctx, owner, repo, milestone); @@ -89,7 +89,7 @@ gcli_free_milestones(gcli_milestone_list *const it) } int -gcli_milestone_get_issues(gcli_ctx *ctx, char const *const owner, +gcli_milestone_get_issues(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const milestone, gcli_issue_list *const out) { @@ -98,7 +98,7 @@ gcli_milestone_get_issues(gcli_ctx *ctx, char const *const owner, } int -gcli_milestone_set_duedate(gcli_ctx *ctx, char const *const owner, +gcli_milestone_set_duedate(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const milestone, char const *const date) { diff --git a/src/pgen/dump_c.c b/src/pgen/dump_c.c index c555484b..5eea05f8 100644 --- a/src/pgen/dump_c.c +++ b/src/pgen/dump_c.c @@ -37,7 +37,7 @@ pregen_array_parser(struct objparser *p, struct objentry *it) { fprintf(outfile, "static int\n" - "parse_%s_%s_array(gcli_ctx *ctx, struct json_stream *stream, " + "parse_%s_%s_array(struct gcli_ctx *ctx, struct json_stream *stream, " "%s *out)\n", p->name, it->name, p->returntype); fprintf(outfile, "{\n"); @@ -139,7 +139,7 @@ objparser_dump_c(struct objparser *p) fprintf(outfile, "int\n" - "parse_%s(gcli_ctx *ctx, struct json_stream *stream, %s *out)\n", + "parse_%s(struct gcli_ctx *ctx, struct json_stream *stream, %s *out)\n", p->name, p->returntype); fprintf(outfile, "{\n"); fprintf(outfile, "\tenum json_type key_type;\n"); @@ -166,7 +166,7 @@ arrayparser_dump_c(struct arrayparser *p) { fprintf(outfile, "int\n" - "parse_%s(gcli_ctx *ctx, struct json_stream *stream, %s **out, " + "parse_%s(struct gcli_ctx *ctx, struct json_stream *stream, %s **out, " "size_t *out_size)\n", p->name, p->returntype); fprintf(outfile, "{\n"); diff --git a/src/pgen/dump_h.c b/src/pgen/dump_h.c index 0ce194e0..6bbbefed 100644 --- a/src/pgen/dump_h.c +++ b/src/pgen/dump_h.c @@ -73,7 +73,7 @@ header_dump_h(void) void objparser_dump_h(struct objparser *p) { - fprintf(outfile, "int parse_%s(gcli_ctx *ctx, struct json_stream *, %s *);\n", + fprintf(outfile, "int parse_%s(struct gcli_ctx *ctx, struct json_stream *, %s *);\n", p->name, p->returntype); } @@ -96,7 +96,7 @@ footer_dump_h(void) void arrayparser_dump_h(struct arrayparser *p) { - fprintf(outfile, "int parse_%s(gcli_ctx *ctx, struct json_stream *, " + fprintf(outfile, "int parse_%s(struct gcli_ctx *ctx, struct json_stream *, " "%s **out, size_t *out_size);\n", p->name, p->returntype); } diff --git a/src/pulls.c b/src/pulls.c index 60231b21..8bf546b5 100644 --- a/src/pulls.c +++ b/src/pulls.c @@ -50,7 +50,7 @@ gcli_pulls_free(gcli_pull_list *const it) } int -gcli_get_pulls(gcli_ctx *ctx, char const *owner, char const *repo, +gcli_get_pulls(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_pull_fetch_details const *const details, int const max, gcli_pull_list *const out) { @@ -58,7 +58,7 @@ gcli_get_pulls(gcli_ctx *ctx, char const *owner, char const *repo, } int -gcli_pull_get_diff(gcli_ctx *ctx, FILE *stream, char const *owner, +gcli_pull_get_diff(struct gcli_ctx *ctx, FILE *stream, char const *owner, char const *reponame, gcli_id const pr_number) { gcli_null_check_call(pull_get_diff, ctx, stream, owner, reponame, @@ -66,7 +66,7 @@ gcli_pull_get_diff(gcli_ctx *ctx, FILE *stream, char const *owner, } int -gcli_pull_get_commits(gcli_ctx *ctx, char const *owner, char const *repo, +gcli_pull_get_commits(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const pr_number, gcli_commit_list *const out) { gcli_null_check_call(get_pull_commits, ctx, owner, repo, pr_number, out); @@ -113,14 +113,14 @@ gcli_pull_free(gcli_pull *const it) } int -gcli_get_pull(gcli_ctx *ctx, char const *owner, char const *repo, +gcli_get_pull(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const pr_number, gcli_pull *const out) { gcli_null_check_call(get_pull, ctx, owner, repo, pr_number, out); } int -gcli_pull_get_checks(gcli_ctx *ctx, char const *owner, char const *repo, +gcli_pull_get_checks(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const pr_number, gcli_pull_checks_list *out) { gcli_null_check_call(get_pull_checks, ctx, owner, repo, pr_number, out); @@ -142,13 +142,13 @@ gcli_pull_checks_free(gcli_pull_checks_list *list) } int -gcli_pull_submit(gcli_ctx *ctx, gcli_submit_pull_options opts) +gcli_pull_submit(struct gcli_ctx *ctx, gcli_submit_pull_options opts) { gcli_null_check_call(perform_submit_pull, ctx, opts); } int -gcli_pull_merge(gcli_ctx *ctx, char const *owner, char const *reponame, +gcli_pull_merge(struct gcli_ctx *ctx, char const *owner, char const *reponame, gcli_id const pr_number, enum gcli_merge_flags flags) { gcli_null_check_call(pull_merge, ctx, owner, reponame, pr_number, @@ -156,21 +156,21 @@ gcli_pull_merge(gcli_ctx *ctx, char const *owner, char const *reponame, } int -gcli_pull_close(gcli_ctx *ctx, char const *owner, char const *reponame, +gcli_pull_close(struct gcli_ctx *ctx, char const *owner, char const *reponame, gcli_id const pr_number) { gcli_null_check_call(pull_close, ctx, owner, reponame, pr_number); } int -gcli_pull_reopen(gcli_ctx *ctx, char const *owner, char const *reponame, +gcli_pull_reopen(struct gcli_ctx *ctx, char const *owner, char const *reponame, gcli_id const pr_number) { gcli_null_check_call(pull_reopen, ctx, owner, reponame, pr_number); } int -gcli_pull_add_labels(gcli_ctx *ctx, char const *owner, char const *repo, +gcli_pull_add_labels(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const pr_number, char const *const labels[], size_t const labels_size) { @@ -179,46 +179,47 @@ gcli_pull_add_labels(gcli_ctx *ctx, char const *owner, char const *repo, } int -gcli_pull_remove_labels(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const pr_number, char const *const labels[], - size_t const labels_size) +gcli_pull_remove_labels(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id const pr_number, + char const *const labels[], size_t const labels_size) { gcli_null_check_call(pull_remove_labels, ctx, owner, repo, pr_number, labels, labels_size); } int -gcli_pull_set_milestone(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const pr_number, int milestone_id) +gcli_pull_set_milestone(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id const pr_number, + int milestone_id) { gcli_null_check_call(pull_set_milestone, ctx, owner, repo, pr_number, milestone_id); } int -gcli_pull_clear_milestone(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const pr_number) +gcli_pull_clear_milestone(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id const pr_number) { gcli_null_check_call(pull_clear_milestone, ctx, owner, repo, pr_number); } int -gcli_pull_add_reviewer(gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id pr_number, char const *username) +gcli_pull_add_reviewer(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id pr_number, char const *username) { gcli_null_check_call(pull_add_reviewer, ctx, owner, repo, pr_number, username); } int -gcli_pull_get_patch(gcli_ctx *ctx, FILE *out, char const *owner, char const *repo, - gcli_id pull_id) +gcli_pull_get_patch(struct gcli_ctx *ctx, FILE *out, char const *owner, + char const *repo, gcli_id pull_id) { gcli_null_check_call(pull_get_patch, ctx, out, owner, repo, pull_id); } int -gcli_pull_set_title(gcli_ctx *ctx, char const *const owner, +gcli_pull_set_title(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const pull, char const *new_title) { diff --git a/src/releases.c b/src/releases.c index 0df5f0a7..26147dd3 100644 --- a/src/releases.c +++ b/src/releases.c @@ -35,7 +35,7 @@ #include int -gcli_get_releases(gcli_ctx *ctx, char const *owner, char const *repo, +gcli_get_releases(struct gcli_ctx *ctx, char const *owner, char const *repo, int const max, gcli_release_list *const list) { gcli_null_check_call(get_releases, ctx, owner, repo, max, list); @@ -73,13 +73,13 @@ gcli_free_releases(gcli_release_list *const list) } int -gcli_create_release(gcli_ctx *ctx, gcli_new_release const *release) +gcli_create_release(struct gcli_ctx *ctx, gcli_new_release const *release) { gcli_null_check_call(create_release, ctx, release); } int -gcli_release_push_asset(gcli_ctx *ctx, gcli_new_release *const release, +gcli_release_push_asset(struct gcli_ctx *ctx, gcli_new_release *const release, gcli_release_asset_upload const asset) { if (release->assets_size == GCLI_RELEASE_MAX_ASSETS) @@ -91,7 +91,7 @@ gcli_release_push_asset(gcli_ctx *ctx, gcli_new_release *const release, } int -gcli_delete_release(gcli_ctx *ctx, char const *const owner, +gcli_delete_release(struct gcli_ctx *ctx, char const *const owner, char const *const repo, char const *const id) { gcli_null_check_call(delete_release, ctx, owner, repo, id); diff --git a/src/repos.c b/src/repos.c index 1546fdff..8bd22699 100644 --- a/src/repos.c +++ b/src/repos.c @@ -35,7 +35,7 @@ #include int -gcli_get_repos(gcli_ctx *ctx, char const *owner, int const max, +gcli_get_repos(struct gcli_ctx *ctx, char const *owner, int const max, gcli_repo_list *const out) { gcli_null_check_call(get_repos, ctx, owner, max, out); @@ -66,20 +66,20 @@ gcli_repos_free(gcli_repo_list *const list) } int -gcli_repo_delete(gcli_ctx *ctx, char const *owner, char const *repo) +gcli_repo_delete(struct gcli_ctx *ctx, char const *owner, char const *repo) { gcli_null_check_call(repo_delete, ctx, owner, repo); } int -gcli_repo_create(gcli_ctx *ctx, gcli_repo_create_options const *options, +gcli_repo_create(struct gcli_ctx *ctx, gcli_repo_create_options const *options, gcli_repo *out) { gcli_null_check_call(repo_create, ctx, options, out); } int -gcli_repo_set_visibility(gcli_ctx *ctx, char const *const owner, +gcli_repo_set_visibility(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_repo_visibility vis) { gcli_null_check_call(repo_set_visibility, ctx, owner, repo, vis); diff --git a/src/sshkeys.c b/src/sshkeys.c index 2f50ae84..57251556 100644 --- a/src/sshkeys.c +++ b/src/sshkeys.c @@ -36,7 +36,7 @@ #include int -gcli_sshkeys_get_keys(gcli_ctx *ctx, gcli_sshkey_list *out) +gcli_sshkeys_get_keys(struct gcli_ctx *ctx, gcli_sshkey_list *out) { gcli_null_check_call(get_sshkeys, ctx, out); } @@ -57,7 +57,7 @@ gcli_sshkeys_free_keys(gcli_sshkey_list *list) } int -gcli_sshkeys_add_key(gcli_ctx *ctx, char const *title, +gcli_sshkeys_add_key(struct gcli_ctx *ctx, char const *title, char const *public_key_path, gcli_sshkey *out) { int rc; @@ -79,7 +79,7 @@ gcli_sshkeys_add_key(gcli_ctx *ctx, char const *title, } int -gcli_sshkeys_delete_key(gcli_ctx *ctx, gcli_id const id) +gcli_sshkeys_delete_key(struct gcli_ctx *ctx, gcli_id const id) { gcli_null_check_call(delete_sshkey, ctx, id); } diff --git a/src/status.c b/src/status.c index 69a16e1e..c24d6a12 100644 --- a/src/status.c +++ b/src/status.c @@ -31,7 +31,7 @@ #include int -gcli_get_notifications(gcli_ctx *ctx, int const max, +gcli_get_notifications(struct gcli_ctx *ctx, int const max, gcli_notification_list *const out) { gcli_null_check_call(get_notifications, ctx, max, out); @@ -61,7 +61,7 @@ gcli_free_notifications(gcli_notification_list *list) } int -gcli_notification_mark_as_read(gcli_ctx *ctx, char const *id) +gcli_notification_mark_as_read(struct gcli_ctx *ctx, char const *id) { gcli_null_check_call(notification_mark_as_read, ctx, id); } diff --git a/tests/bugzilla-parse-tests.c b/tests/bugzilla-parse-tests.c index c0627c5d..5e2fb2aa 100644 --- a/tests/bugzilla-parse-tests.c +++ b/tests/bugzilla-parse-tests.c @@ -41,16 +41,16 @@ #include "gcli_tests.h" static gcli_forge_type -get_bugzilla_forge_type(gcli_ctx *ctx) +get_bugzilla_forge_type(struct gcli_ctx *ctx) { (void) ctx; return GCLI_FORGE_BUGZILLA; } -static gcli_ctx * +static struct gcli_ctx * test_context(void) { - gcli_ctx *ctx; + struct gcli_ctx *ctx; ATF_REQUIRE(gcli_init(&ctx, get_bugzilla_forge_type, NULL, NULL) == NULL); return ctx; } @@ -74,7 +74,7 @@ ATF_TC_BODY(simple_bugzilla_issue, tc) gcli_issue const *issue; FILE *f; json_stream stream; - gcli_ctx *ctx = test_context(); + struct gcli_ctx *ctx = test_context(); ATF_REQUIRE(f = open_sample("bugzilla_simple_bug.json")); json_open_stream(&stream, f); @@ -103,7 +103,7 @@ ATF_TC_BODY(bugzilla_comments, tc) FILE *f; gcli_comment const *cmt = NULL; gcli_comment_list list = {0}; - gcli_ctx *ctx = test_context(); + struct gcli_ctx *ctx = test_context(); json_stream stream; ATF_REQUIRE(f = open_sample("bugzilla_comments.json")); @@ -132,7 +132,7 @@ ATF_TC_BODY(bugzilla_attachments, tc) FILE *f = NULL; gcli_attachment const *it; gcli_attachment_list list = {0}; - gcli_ctx *ctx = test_context(); + struct gcli_ctx *ctx = test_context(); json_stream stream = {0}; ATF_REQUIRE(f = open_sample("bugzilla_attachments.json")); diff --git a/tests/gitea-parse-tests.c b/tests/gitea-parse-tests.c index f0a2badc..f4e84f39 100644 --- a/tests/gitea-parse-tests.c +++ b/tests/gitea-parse-tests.c @@ -12,16 +12,16 @@ #include static gcli_forge_type -get_gitea_forge_type(gcli_ctx *ctx) +get_gitea_forge_type(struct gcli_ctx *ctx) { (void) ctx; return GCLI_FORGE_GITEA; } -static gcli_ctx * +static struct gcli_ctx * test_context(void) { - gcli_ctx *ctx; + struct gcli_ctx *ctx; ATF_REQUIRE(gcli_init(&ctx, get_gitea_forge_type, NULL, NULL) == NULL); return ctx; } @@ -45,7 +45,7 @@ ATF_TC_BODY(gitea_simple_notification, tc) gcli_notification notification = {0}; FILE *sample; json_stream stream = {0}; - gcli_ctx *ctx; + struct gcli_ctx *ctx; ctx = test_context(); sample = open_sample("gitea_simple_notification.json"); diff --git a/tests/github-parse-tests.c b/tests/github-parse-tests.c index 77ee184d..cf8a194d 100644 --- a/tests/github-parse-tests.c +++ b/tests/github-parse-tests.c @@ -45,16 +45,16 @@ #include "gcli_tests.h" static gcli_forge_type -get_github_forge_type(gcli_ctx *ctx) +get_github_forge_type(struct gcli_ctx *ctx) { (void) ctx; return GCLI_FORGE_GITHUB; } -static gcli_ctx * +static struct gcli_ctx * test_context(void) { - gcli_ctx *ctx; + struct gcli_ctx *ctx; ATF_REQUIRE(gcli_init(&ctx, get_github_forge_type, NULL, NULL) == NULL); return ctx; } @@ -77,7 +77,7 @@ ATF_TC_BODY(simple_github_issue, tc) gcli_issue issue = {0}; FILE *f; json_stream stream; - gcli_ctx *ctx = test_context(); + struct gcli_ctx *ctx = test_context(); ATF_REQUIRE(f = open_sample("github_simple_issue.json")); json_open_stream(&stream, f); @@ -118,7 +118,7 @@ ATF_TC_BODY(simple_github_pull, tc) gcli_pull pull = {0}; FILE *f; json_stream stream; - gcli_ctx *ctx = test_context(); + struct gcli_ctx *ctx = test_context(); ATF_REQUIRE(f = open_sample("github_simple_pull.json")); json_open_stream(&stream, f); @@ -158,7 +158,7 @@ ATF_TC_BODY(simple_github_label, tc) gcli_label label = {0}; FILE *f; json_stream stream; - gcli_ctx *ctx = test_context(); + struct gcli_ctx *ctx = test_context(); ATF_REQUIRE(f = open_sample("github_simple_label.json")); json_open_stream(&stream, f); @@ -181,7 +181,7 @@ ATF_TC_BODY(simple_github_milestone, tc) gcli_milestone milestone = {0}; FILE *f; json_stream stream; - gcli_ctx *ctx = test_context(); + struct gcli_ctx *ctx = test_context(); ATF_REQUIRE(f = open_sample("github_simple_milestone.json")); json_open_stream(&stream, f); @@ -210,7 +210,7 @@ ATF_TC_BODY(simple_github_release, tc) gcli_release release = {0}; FILE *f; json_stream stream; - gcli_ctx *ctx = test_context(); + struct gcli_ctx *ctx = test_context(); ATF_REQUIRE(f = open_sample("github_simple_release.json")); json_open_stream(&stream, f); @@ -239,7 +239,7 @@ ATF_TC_BODY(simple_github_repo, tc) gcli_repo repo = {0}; FILE *f; json_stream stream; - gcli_ctx *ctx = test_context(); + struct gcli_ctx *ctx = test_context(); ATF_REQUIRE(f = open_sample("github_simple_repo.json")); json_open_stream(&stream, f); @@ -265,7 +265,7 @@ ATF_TC_BODY(simple_github_fork, tc) gcli_fork fork = {0}; FILE *f; json_stream stream; - gcli_ctx *ctx = test_context(); + struct gcli_ctx *ctx = test_context(); ATF_REQUIRE(f = open_sample("github_simple_fork.json")); json_open_stream(&stream, f); @@ -288,7 +288,7 @@ ATF_TC_BODY(simple_github_comment, tc) gcli_comment comment = {0}; FILE *f; json_stream stream; - gcli_ctx *ctx = test_context(); + struct gcli_ctx *ctx = test_context(); ATF_REQUIRE(f = open_sample("github_simple_comment.json")); json_open_stream(&stream, f); @@ -311,7 +311,7 @@ ATF_TC_BODY(simple_github_check, tc) gcli_github_check check = {0}; FILE *f; json_stream stream; - gcli_ctx *ctx = test_context(); + struct gcli_ctx *ctx = test_context(); ATF_REQUIRE(f = open_sample("github_simple_check.json")); json_open_stream(&stream, f); diff --git a/tests/gitlab-parse-tests.c b/tests/gitlab-parse-tests.c index 6e7d3bfa..9a87defb 100644 --- a/tests/gitlab-parse-tests.c +++ b/tests/gitlab-parse-tests.c @@ -16,16 +16,16 @@ #include "gcli_tests.h" static gcli_forge_type -get_gitlab_forge_type(gcli_ctx *ctx) +get_gitlab_forge_type(struct gcli_ctx *ctx) { (void) ctx; return GCLI_FORGE_GITLAB; } -static gcli_ctx * +static struct gcli_ctx * test_context(void) { - gcli_ctx *ctx; + struct gcli_ctx *ctx; ATF_REQUIRE(gcli_init(&ctx, get_gitlab_forge_type, NULL, NULL) == NULL); return ctx; } @@ -47,7 +47,7 @@ ATF_TC_WITHOUT_HEAD(gitlab_simple_merge_request); ATF_TC_BODY(gitlab_simple_merge_request, tc) { json_stream stream = {0}; - gcli_ctx *ctx = test_context(); + struct gcli_ctx *ctx = test_context(); FILE *f = open_sample("gitlab_simple_merge_request.json"); gcli_pull pull = {0}; @@ -87,7 +87,7 @@ ATF_TC_WITHOUT_HEAD(gitlab_simple_issue); ATF_TC_BODY(gitlab_simple_issue, tc) { json_stream stream = {0}; - gcli_ctx *ctx = test_context(); + struct gcli_ctx *ctx = test_context(); FILE *f = open_sample("gitlab_simple_issue.json"); gcli_issue issue = {0}; @@ -118,7 +118,7 @@ ATF_TC_WITHOUT_HEAD(gitlab_simple_label); ATF_TC_BODY(gitlab_simple_label, tc) { json_stream stream = {0}; - gcli_ctx *ctx = test_context(); + struct gcli_ctx *ctx = test_context(); FILE *f = open_sample("gitlab_simple_label.json"); gcli_label label = {0}; @@ -139,7 +139,7 @@ ATF_TC_WITHOUT_HEAD(gitlab_simple_release); ATF_TC_BODY(gitlab_simple_release, tc) { json_stream stream = {0}; - gcli_ctx *ctx = test_context(); + struct gcli_ctx *ctx = test_context(); FILE *f = open_sample("gitlab_simple_release.json"); gcli_release release = {0}; @@ -192,7 +192,7 @@ ATF_TC_WITHOUT_HEAD(gitlab_simple_fork); ATF_TC_BODY(gitlab_simple_fork, tc) { json_stream stream = {0}; - gcli_ctx *ctx = test_context(); + struct gcli_ctx *ctx = test_context(); FILE *f = open_sample("gitlab_simple_fork.json"); gcli_fork fork = {0}; @@ -213,7 +213,7 @@ ATF_TC_WITHOUT_HEAD(gitlab_simple_milestone); ATF_TC_BODY(gitlab_simple_milestone, tc) { json_stream stream = {0}; - gcli_ctx *ctx = test_context(); + struct gcli_ctx *ctx = test_context(); FILE *f = open_sample("gitlab_simple_milestone.json"); gcli_milestone milestone = {0}; @@ -242,7 +242,7 @@ ATF_TC_WITHOUT_HEAD(gitlab_simple_pipeline); ATF_TC_BODY(gitlab_simple_pipeline, tc) { json_stream stream = {0}; - gcli_ctx *ctx = test_context(); + struct gcli_ctx *ctx = test_context(); FILE *f = open_sample("gitlab_simple_pipeline.json"); gitlab_pipeline pipeline = {0}; @@ -266,7 +266,7 @@ ATF_TC_WITHOUT_HEAD(gitlab_simple_repo); ATF_TC_BODY(gitlab_simple_repo, tc) { json_stream stream = {0}; - gcli_ctx *ctx = test_context(); + struct gcli_ctx *ctx = test_context(); FILE *f = open_sample("gitlab_simple_repo.json"); gcli_repo repo = {0}; @@ -290,7 +290,7 @@ ATF_TC_WITHOUT_HEAD(gitlab_simple_snippet); ATF_TC_BODY(gitlab_simple_snippet, tc) { json_stream stream = {0}; - gcli_ctx *ctx = test_context(); + struct gcli_ctx *ctx = test_context(); FILE *f = open_sample("gitlab_simple_snippet.json"); gcli_gitlab_snippet snippet = {0}; From 00410e39974699b574d176f2e9d534f524c0be29 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 5 Jan 2024 17:46:00 +0100 Subject: [PATCH 097/158] pgen: Add support for struct tags in array- and object parsers --- include/gcli/pgen.h | 3 +++ src/pgen/dump_c.c | 14 +++++++------- src/pgen/dump_h.c | 8 ++++---- src/pgen/lexer.l | 1 + src/pgen/parser.y | 19 ++++++++++++++++++- 5 files changed, 33 insertions(+), 12 deletions(-) diff --git a/include/gcli/pgen.h b/include/gcli/pgen.h index a4c021f7..5c5cd19f 100644 --- a/include/gcli/pgen.h +++ b/include/gcli/pgen.h @@ -5,6 +5,7 @@ #include #endif +#include #include /* PGen command line options */ @@ -30,6 +31,7 @@ struct objparser { enum { OBJPARSER_ENTRIES, OBJPARSER_SELECT } kind; char *name; char *returntype; + bool is_struct; struct objentry *entries; struct { char *fieldtype; @@ -39,6 +41,7 @@ struct objparser { struct arrayparser { char *name; + bool is_struct; char *returntype; char *parser; }; diff --git a/src/pgen/dump_c.c b/src/pgen/dump_c.c index 5eea05f8..6de3ec61 100644 --- a/src/pgen/dump_c.c +++ b/src/pgen/dump_c.c @@ -38,8 +38,8 @@ pregen_array_parser(struct objparser *p, struct objentry *it) fprintf(outfile, "static int\n" "parse_%s_%s_array(struct gcli_ctx *ctx, struct json_stream *stream, " - "%s *out)\n", - p->name, it->name, p->returntype); + "%s%s *out)\n", + p->name, it->name, p->is_struct ? "struct " : "", p->returntype); fprintf(outfile, "{\n"); fprintf(outfile, "\tint rc = 0;\n"); fprintf(outfile, "\tif (json_peek(stream) == JSON_NULL) {\n"); @@ -139,8 +139,8 @@ objparser_dump_c(struct objparser *p) fprintf(outfile, "int\n" - "parse_%s(struct gcli_ctx *ctx, struct json_stream *stream, %s *out)\n", - p->name, p->returntype); + "parse_%s(struct gcli_ctx *ctx, struct json_stream *stream, %s%s *out)\n", + p->name, p->is_struct ? "struct " : "", p->returntype); fprintf(outfile, "{\n"); fprintf(outfile, "\tenum json_type key_type;\n"); fprintf(outfile, "\tconst char *key;\n\n"); @@ -166,9 +166,9 @@ arrayparser_dump_c(struct arrayparser *p) { fprintf(outfile, "int\n" - "parse_%s(struct gcli_ctx *ctx, struct json_stream *stream, %s **out, " + "parse_%s(struct gcli_ctx *ctx, struct json_stream *stream, %s%s **out, " "size_t *out_size)\n", - p->name, p->returntype); + p->name, p->is_struct ? "struct " : "", p->returntype); fprintf(outfile, "{\n"); fprintf(outfile, "\tif (json_peek(stream) == JSON_NULL) {\n"); fprintf(outfile, "\t\tjson_next(stream);\n"); @@ -183,7 +183,7 @@ arrayparser_dump_c(struct arrayparser *p) fprintf(outfile, "\twhile (json_peek(stream) != JSON_ARRAY_END) {\n"); fprintf(outfile, "\t\tint rc;\n"); - fprintf(outfile, "\t\t%s *it;\n", p->returntype); + fprintf(outfile, "\t\t%s%s *it;\n", p->is_struct ? "struct " : "", p->returntype); fprintf(outfile, "\t\t*out = realloc(*out, sizeof(**out) * (*out_size + 1));\n"); fprintf(outfile, "\t\tit = &(*out)[(*out_size)++];\n"); fprintf(outfile, "\t\tmemset(it, 0, sizeof(*it));\n"); diff --git a/src/pgen/dump_h.c b/src/pgen/dump_h.c index 6bbbefed..3c85843f 100644 --- a/src/pgen/dump_h.c +++ b/src/pgen/dump_h.c @@ -73,8 +73,8 @@ header_dump_h(void) void objparser_dump_h(struct objparser *p) { - fprintf(outfile, "int parse_%s(struct gcli_ctx *ctx, struct json_stream *, %s *);\n", - p->name, p->returntype); + fprintf(outfile, "int parse_%s(struct gcli_ctx *ctx, struct json_stream *, %s%s *);\n", + p->name, p->is_struct ? "struct " : "", p->returntype); } void @@ -97,6 +97,6 @@ void arrayparser_dump_h(struct arrayparser *p) { fprintf(outfile, "int parse_%s(struct gcli_ctx *ctx, struct json_stream *, " - "%s **out, size_t *out_size);\n", - p->name, p->returntype); + "%s%s **out, size_t *out_size);\n", + p->name, p->is_struct ? "struct " : "", p->returntype); } diff --git a/src/pgen/lexer.l b/src/pgen/lexer.l index ed0234d9..c4f145c7 100644 --- a/src/pgen/lexer.l +++ b/src/pgen/lexer.l @@ -61,6 +61,7 @@ use { yycol += yyleng; return USE; } array { yycol += yyleng; return ARRAY; } of { yycol += yyleng; return OF; } select { yycol += yyleng; return SELECT; } +struct { yycol += yyleng; return STRUCT; } => { yycol += yyleng; return FATARROW; } "(" { yycol += yyleng; return OPAREN; } ")" { yycol += yyleng; return CPAREN; } diff --git a/src/pgen/parser.y b/src/pgen/parser.y index dff6b13f..d600408c 100644 --- a/src/pgen/parser.y +++ b/src/pgen/parser.y @@ -48,7 +48,7 @@ static void footer_dump(void); %} %token PARSER IS OBJECT WITH AS USE FATARROW INCLUDE -%token OPAREN CPAREN SEMICOLON ARRAY OF COMMA SELECT +%token OPAREN CPAREN SEMICOLON ARRAY OF COMMA SELECT STRUCT %union { struct strlit strlit; @@ -91,9 +91,18 @@ objparser: PARSER IDENT IS OBJECT OF IDENT WITH OPAREN obj_entries CPAREN { $$.kind = OBJPARSER_ENTRIES; $$.name = $2.text; + $$.is_struct = false; $$.returntype = $6.text; $$.entries = $9; } + | PARSER IDENT IS OBJECT OF STRUCT IDENT WITH OPAREN obj_entries CPAREN + { + $$.kind = OBJPARSER_ENTRIES; + $$.name = $2.text; + $$.is_struct = true; + $$.returntype = $7.text; + $$.entries = $10; + } | PARSER IDENT IS OBJECT OF IDENT SELECT STRLIT AS IDENT { $$.kind = OBJPARSER_SELECT; @@ -107,9 +116,17 @@ objparser: PARSER IDENT IS OBJECT OF IDENT WITH OPAREN obj_entries CPAREN arrayparser: PARSER IDENT IS ARRAY OF IDENT USE IDENT { $$.name = $2.text; + $$.is_struct = false; $$.returntype = $6.text; $$.parser = $8.text; } + | PARSER IDENT IS ARRAY OF STRUCT IDENT USE IDENT + { + $$.name = $2.text; + $$.is_struct = true; + $$.returntype = $7.text; + $$.parser = $9.text; + } ; obj_entries: obj_entries COMMA obj_entry From ac842fc5b860fb2419c4333211b9a2756e0e7c52 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 5 Jan 2024 17:26:19 +0100 Subject: [PATCH 098/158] Remove typedefs for structs in gcli_attachements --- include/gcli/attachments.h | 9 +++------ include/gcli/bugzilla/bugs-parser.h | 4 ++-- include/gcli/bugzilla/bugs.h | 2 +- include/gcli/forges.h | 2 +- include/gcli/issues.h | 2 +- src/attachments.c | 4 ++-- src/bugzilla/attachments.c | 2 +- src/bugzilla/bugs-parser.c | 4 ++-- src/bugzilla/bugs.c | 2 +- src/cmd/issues.c | 6 +++--- src/issues.c | 2 +- templates/bugzilla/bugs.t | 8 ++++---- tests/bugzilla-parse-tests.c | 4 ++-- 13 files changed, 24 insertions(+), 27 deletions(-) diff --git a/include/gcli/attachments.h b/include/gcli/attachments.h index b37d569a..1b93f0aa 100644 --- a/include/gcli/attachments.h +++ b/include/gcli/attachments.h @@ -41,9 +41,6 @@ #include -typedef struct gcli_attachment gcli_attachment; -typedef struct gcli_attachment_list gcli_attachment_list; - struct gcli_attachment { gcli_id id; bool is_obsolete; @@ -57,12 +54,12 @@ struct gcli_attachment { }; struct gcli_attachment_list { - gcli_attachment *attachments; + struct gcli_attachment *attachments; size_t attachments_size; }; -void gcli_attachments_free(gcli_attachment_list *list); -void gcli_attachment_free(gcli_attachment *attachment); +void gcli_attachments_free(struct gcli_attachment_list *list); +void gcli_attachment_free(struct gcli_attachment *attachment); int gcli_attachment_get_content(struct gcli_ctx *const ctx, gcli_id const id, FILE *out); diff --git a/include/gcli/bugzilla/bugs-parser.h b/include/gcli/bugzilla/bugs-parser.h index f38f019a..ab6a8c1c 100644 --- a/include/gcli/bugzilla/bugs-parser.h +++ b/include/gcli/bugzilla/bugs-parser.h @@ -59,10 +59,10 @@ int parse_bugzilla_assignee(struct gcli_ctx *ctx, struct json_stream *stream, int parse_bugzilla_bug_attachments_dict(struct gcli_ctx *ctx, struct json_stream *stream, - gcli_attachment_list *out); + struct gcli_attachment_list *out); int parse_bugzilla_attachment_content_only_first(struct gcli_ctx *ctx, json_stream *stream, - gcli_attachment *out); + struct gcli_attachment *out); #endif /* GCLI_BUGZILLA_BUGS_PARSER_H */ diff --git a/include/gcli/bugzilla/bugs.h b/include/gcli/bugzilla/bugs.h index 23acb5c5..293c8a56 100644 --- a/include/gcli/bugzilla/bugs.h +++ b/include/gcli/bugzilla/bugs.h @@ -54,7 +54,7 @@ int bugzilla_bug_get_comments(struct gcli_ctx *const ctx, int bugzilla_bug_get_attachments(struct gcli_ctx *ctx, char const *const product, char const *const component, gcli_id const bug_id, - gcli_attachment_list *const out); + struct gcli_attachment_list *const out); int bugzilla_bug_submit(struct gcli_ctx *ctx, gcli_submit_issue_options opts, gcli_fetch_buffer *out); diff --git a/include/gcli/forges.h b/include/gcli/forges.h index 837e33fa..32b24ce8 100644 --- a/include/gcli/forges.h +++ b/include/gcli/forges.h @@ -186,7 +186,7 @@ struct gcli_forge_descriptor { char const *owner, char const *repo, gcli_id issue, - gcli_attachment_list *out); + struct gcli_attachment_list *out); /** * Dump the contents of the attachment to the given file */ diff --git a/include/gcli/issues.h b/include/gcli/issues.h index aaba9eb0..1b0dfcd7 100644 --- a/include/gcli/issues.h +++ b/include/gcli/issues.h @@ -131,6 +131,6 @@ int gcli_issue_set_title(struct gcli_ctx *ctx, char const *owner, char const *re int gcli_issue_get_attachments(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue, - gcli_attachment_list *attachments); + struct gcli_attachment_list *attachments); #endif /* ISSUES_H */ diff --git a/src/attachments.c b/src/attachments.c index 5a35834a..e6339f42 100644 --- a/src/attachments.c +++ b/src/attachments.c @@ -33,7 +33,7 @@ #include void -gcli_attachments_free(gcli_attachment_list *list) +gcli_attachments_free(struct gcli_attachment_list *list) { for (size_t i = 0; i < list->attachments_size; ++i) { gcli_attachment_free(&list->attachments[i]); @@ -45,7 +45,7 @@ gcli_attachments_free(gcli_attachment_list *list) } void -gcli_attachment_free(gcli_attachment *it) +gcli_attachment_free(struct gcli_attachment *it) { free(it->created_at); free(it->author); diff --git a/src/bugzilla/attachments.c b/src/bugzilla/attachments.c index b8415c3b..c8c63041 100644 --- a/src/bugzilla/attachments.c +++ b/src/bugzilla/attachments.c @@ -42,7 +42,7 @@ bugzilla_attachment_get_content(struct gcli_ctx *ctx, gcli_id attachment_id, char *url; gcli_fetch_buffer buffer = {0}; json_stream stream = {0}; - gcli_attachment attachment = {0}; + struct gcli_attachment attachment = {0}; url = sn_asprintf("%s/rest/bug/attachment/%"PRIid, gcli_get_apibase(ctx), attachment_id); diff --git a/src/bugzilla/bugs-parser.c b/src/bugzilla/bugs-parser.c index c25028bf..d7c3b32a 100644 --- a/src/bugzilla/bugs-parser.c +++ b/src/bugzilla/bugs-parser.c @@ -144,7 +144,7 @@ parse_bugzilla_assignee(struct gcli_ctx *ctx, struct json_stream *stream, int parse_bugzilla_bug_attachments_dict(struct gcli_ctx *ctx, struct json_stream *stream, - gcli_attachment_list *out) + struct gcli_attachment_list *out) { enum json_type next = JSON_NULL; int rc = 0; @@ -169,7 +169,7 @@ parse_bugzilla_bug_attachments_dict(struct gcli_ctx *ctx, int parse_bugzilla_attachment_content_only_first(struct gcli_ctx *ctx, struct json_stream *stream, - gcli_attachment *out) + struct gcli_attachment *out) { enum json_type next = JSON_NULL; int rc = 0; diff --git a/src/bugzilla/bugs.c b/src/bugzilla/bugs.c index 936208b4..88134d28 100644 --- a/src/bugzilla/bugs.c +++ b/src/bugzilla/bugs.c @@ -215,7 +215,7 @@ bugzilla_get_bug(struct gcli_ctx *ctx, char const *product, int bugzilla_bug_get_attachments(struct gcli_ctx *ctx, char const *const product, char const *const component, gcli_id const bug_id, - gcli_attachment_list *const out) + struct gcli_attachment_list *const out) { int rc = 0; char *url = NULL; diff --git a/src/cmd/issues.c b/src/cmd/issues.c index e3777f32..01dfbdde 100644 --- a/src/cmd/issues.c +++ b/src/cmd/issues.c @@ -607,7 +607,7 @@ handle_issue_milestone_action(int *argc, char ***argv, } static void -gcli_print_attachments(gcli_attachment_list const *const list) +gcli_print_attachments(struct gcli_attachment_list const *const list) { gcli_tbl tbl; gcli_tblcoldef columns[] = { @@ -622,7 +622,7 @@ gcli_print_attachments(gcli_attachment_list const *const list) tbl = gcli_tbl_begin(columns, ARRAY_SIZE(columns)); for (size_t i = 0; i < list->attachments_size; ++i) { - gcli_attachment const *const it = &list->attachments[i]; + struct gcli_attachment const *const it = &list->attachments[i]; gcli_tbl_add_row(tbl, it->id, it->author, it->created_at, it->content_type, it->is_obsolete, it->file_name); } @@ -720,7 +720,7 @@ handle_issues_actions(int argc, char *argv[], } else if (strcmp("attachments", operation) == 0) { - gcli_attachment_list list = {0}; + struct gcli_attachment_list list = {0}; int rc = gcli_issue_get_attachments(g_clictx, owner, repo, issue_id, &list); if (rc < 0) { diff --git a/src/issues.c b/src/issues.c index ddd296a1..ac14ec23 100644 --- a/src/issues.c +++ b/src/issues.c @@ -160,7 +160,7 @@ gcli_issue_set_title(struct gcli_ctx *ctx, char const *owner, char const *repo, int gcli_issue_get_attachments(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue, - gcli_attachment_list *out) + struct gcli_attachment_list *out) { gcli_forge_descriptor const *const forge = gcli_forge(ctx); diff --git a/templates/bugzilla/bugs.t b/templates/bugzilla/bugs.t index 43da5158..cb9a6547 100644 --- a/templates/bugzilla/bugs.t +++ b/templates/bugzilla/bugs.t @@ -57,11 +57,11 @@ object of char* with ("bugs" => use parse_bugzilla_bug_comments_dictionary_only_first); parser bugzilla_bug_attachments is -object of gcli_attachment_list with +object of struct gcli_attachment_list with ("bugs" => use parse_bugzilla_bug_attachments_dict); parser bugzilla_bug_attachment is -object of gcli_attachment with +object of struct gcli_attachment with ("id" => id as id, "summary" => summary as string, "file_name" => file_name as string, @@ -72,8 +72,8 @@ object of gcli_attachment with "data" => data_base64 as string); parser bugzilla_bug_attachments_internal is -array of gcli_attachment use parse_bugzilla_bug_attachment; +array of struct gcli_attachment use parse_bugzilla_bug_attachment; parser bugzilla_attachment_content is -object of gcli_attachment with +object of struct gcli_attachment with ("attachments" => use parse_bugzilla_attachment_content_only_first); diff --git a/tests/bugzilla-parse-tests.c b/tests/bugzilla-parse-tests.c index 5e2fb2aa..0f7d7205 100644 --- a/tests/bugzilla-parse-tests.c +++ b/tests/bugzilla-parse-tests.c @@ -130,8 +130,8 @@ ATF_TC_WITHOUT_HEAD(bugzilla_attachments); ATF_TC_BODY(bugzilla_attachments, tc) { FILE *f = NULL; - gcli_attachment const *it; - gcli_attachment_list list = {0}; + struct gcli_attachment const *it; + struct gcli_attachment_list list = {0}; struct gcli_ctx *ctx = test_context(); json_stream stream = {0}; From 9704027e987be91ee3a82a345a26418f139c377a Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 5 Jan 2024 17:46:12 +0100 Subject: [PATCH 099/158] Remove struct typedefs in releases --- include/gcli/cmd/releases.h | 2 +- include/gcli/forges.h | 4 ++-- include/gcli/gitea/releases.h | 5 ++-- include/gcli/github/releases.h | 6 +++-- include/gcli/gitlab/releases.h | 9 +++++--- include/gcli/releases.h | 42 +++++++++++++++------------------- src/cmd/releases.c | 29 +++++++++++------------ src/gitea/releases.c | 10 ++++---- src/github/releases.c | 15 ++++++------ src/gitlab/releases.c | 12 +++++----- src/releases.c | 12 +++++----- templates/github/releases.t | 6 ++--- templates/gitlab/releases.t | 8 +++---- tests/github-parse-tests.c | 2 +- tests/gitlab-parse-tests.c | 2 +- 15 files changed, 83 insertions(+), 81 deletions(-) diff --git a/include/gcli/cmd/releases.h b/include/gcli/cmd/releases.h index 6b1c7414..b82662f0 100644 --- a/include/gcli/cmd/releases.h +++ b/include/gcli/cmd/releases.h @@ -37,7 +37,7 @@ #include void gcli_releases_print(enum gcli_output_flags flags, - gcli_release_list const *list, int max); + struct gcli_release_list const *list, int max); int subcommand_releases(int argc, char *argv[]); diff --git a/include/gcli/forges.h b/include/gcli/forges.h index 32b24ce8..1f5b0c2c 100644 --- a/include/gcli/forges.h +++ b/include/gcli/forges.h @@ -436,13 +436,13 @@ struct gcli_forge_descriptor { char const *owner, char const *repo, int max, - gcli_release_list *out); + struct gcli_release_list *out); /** * Create a new release */ int (*create_release)( struct gcli_ctx *ctx, - gcli_new_release const *release); + struct gcli_new_release const *release); /** * Delete the release */ diff --git a/include/gcli/gitea/releases.h b/include/gcli/gitea/releases.h index 054205e0..8087d6d5 100644 --- a/include/gcli/gitea/releases.h +++ b/include/gcli/gitea/releases.h @@ -37,9 +37,10 @@ #include int gitea_get_releases(struct gcli_ctx *ctx, char const *owner, char const *repo, - int max, gcli_release_list *list); + int max, struct gcli_release_list *list); -int gitea_create_release(struct gcli_ctx *ctx, gcli_new_release const *release); +int gitea_create_release(struct gcli_ctx *ctx, + struct gcli_new_release const *release); int gitea_delete_release(struct gcli_ctx *ctx, char const *owner, char const *repo, char const *id); diff --git a/include/gcli/github/releases.h b/include/gcli/github/releases.h index b2509d42..16a322a7 100644 --- a/include/gcli/github/releases.h +++ b/include/gcli/github/releases.h @@ -37,9 +37,11 @@ #include int github_get_releases(struct gcli_ctx *ctx, char const *owner, - char const *repo, int max, gcli_release_list *list); + char const *repo, int max, + struct gcli_release_list *list); -int github_create_release(struct gcli_ctx *ctx, gcli_new_release const *release); +int github_create_release(struct gcli_ctx *ctx, + struct gcli_new_release const *release); int github_delete_release(struct gcli_ctx *ctx, char const *owner, char const *repo, char const *id); diff --git a/include/gcli/gitlab/releases.h b/include/gcli/gitlab/releases.h index cfab8adc..bde9e872 100644 --- a/include/gcli/gitlab/releases.h +++ b/include/gcli/gitlab/releases.h @@ -37,13 +37,16 @@ #include int gitlab_get_releases(struct gcli_ctx *ctx, char const *owner, - char const *repo, int max, gcli_release_list *list); + char const *repo, int max, + struct gcli_release_list *list); -int gitlab_create_release(struct gcli_ctx *ctx, gcli_new_release const *release); +int gitlab_create_release(struct gcli_ctx *ctx, + struct gcli_new_release const *release); int gitlab_delete_release(struct gcli_ctx *ctx, char const *owner, char const *repo, char const *id); -void gitlab_fixup_release_assets(struct gcli_ctx *ctx, gcli_release *const release); +void gitlab_fixup_release_assets(struct gcli_ctx *ctx, + struct gcli_release *const release); #endif /* GITLAB_RELEASES_H */ diff --git a/include/gcli/releases.h b/include/gcli/releases.h index d1987e7c..5ac509a3 100644 --- a/include/gcli/releases.h +++ b/include/gcli/releases.h @@ -37,32 +37,26 @@ #include #include -typedef struct gcli_release gcli_release; -typedef struct gcli_release_list gcli_release_list; -typedef struct gcli_new_release gcli_new_release; -typedef struct gcli_release_asset gcli_release_asset; -typedef struct gcli_release_asset_upload gcli_release_asset_upload; - struct gcli_release_asset { char *name; char *url; }; struct gcli_release { - char *id; /* Probably shouldn't be called id */ - gcli_release_asset *assets; - size_t assets_size; - char *name; - char *body; - char *author; - char *date; - char *upload_url; - bool draft; - bool prerelease; + char *id; /* Probably shouldn't be called id */ + struct gcli_release_asset *assets; + size_t assets_size; + char *name; + char *body; + char *author; + char *date; + char *upload_url; + bool draft; + bool prerelease; }; struct gcli_release_list { - gcli_release *releases; + struct gcli_release *releases; size_t releases_size; }; @@ -82,23 +76,23 @@ struct gcli_new_release { char const *commitish; bool draft; bool prerelease; - gcli_release_asset_upload assets[GCLI_RELEASE_MAX_ASSETS]; + struct gcli_release_asset_upload assets[GCLI_RELEASE_MAX_ASSETS]; size_t assets_size; }; int gcli_get_releases(struct gcli_ctx *ctx, char const *owner, char const *repo, - int max, gcli_release_list *list); + int max, struct gcli_release_list *list); -void gcli_free_releases(gcli_release_list *); +void gcli_free_releases(struct gcli_release_list *); -int gcli_create_release(struct gcli_ctx *ctx, gcli_new_release const *); +int gcli_create_release(struct gcli_ctx *ctx, struct gcli_new_release const *); -int gcli_release_push_asset(struct gcli_ctx *, gcli_new_release *, - gcli_release_asset_upload); +int gcli_release_push_asset(struct gcli_ctx *, struct gcli_new_release *, + struct gcli_release_asset_upload); int gcli_delete_release(struct gcli_ctx *ctx, char const *owner, char const *repo, char const *id); -void gcli_release_free(gcli_release *release); +void gcli_release_free(struct gcli_release *release); #endif /* RELEASES_H */ diff --git a/src/cmd/releases.c b/src/cmd/releases.c index 3dfd7fed..4dc8d7e3 100644 --- a/src/cmd/releases.c +++ b/src/cmd/releases.c @@ -69,7 +69,7 @@ usage(void) static void gcli_print_release(enum gcli_output_flags const flags, - gcli_release const *const it) + struct gcli_release const *const it) { gcli_dict dict; @@ -104,7 +104,7 @@ gcli_print_release(enum gcli_output_flags const flags, static void gcli_releases_print_long(enum gcli_output_flags const flags, - gcli_release_list const *const list, int const max) + struct gcli_release_list const *const list, int const max) { int n; @@ -125,7 +125,8 @@ gcli_releases_print_long(enum gcli_output_flags const flags, static void gcli_releases_print_short(enum gcli_output_flags const flags, - gcli_release_list const *const list, int const max) + struct gcli_release_list const *const list, + int const max) { size_t n; gcli_tbl table; @@ -171,7 +172,7 @@ gcli_releases_print_short(enum gcli_output_flags const flags, void gcli_releases_print(enum gcli_output_flags const flags, - gcli_release_list const *const list, int const max) + struct gcli_release_list const *const list, int const max) { if (list->releases_size == 0) { puts("No releases"); @@ -187,7 +188,7 @@ gcli_releases_print(enum gcli_output_flags const flags, static void releasemsg_init(struct gcli_ctx *ctx, FILE *f, void *_data) { - gcli_new_release const *info = _data; + struct gcli_new_release const *info = _data; (void) ctx; @@ -203,7 +204,7 @@ releasemsg_init(struct gcli_ctx *ctx, FILE *f, void *_data) } static char * -get_release_message(gcli_new_release const *info) +get_release_message(struct gcli_new_release const *info) { return gcli_editor_get_user_message(g_clictx, releasemsg_init, (void *)info); @@ -212,7 +213,7 @@ get_release_message(gcli_new_release const *info) static int subcommand_releases_create(int argc, char *argv[]) { - gcli_new_release release = {0}; + struct gcli_new_release release = {0}; int ch; bool always_yes = false; @@ -281,7 +282,7 @@ subcommand_releases_create(int argc, char *argv[]) release.owner = optarg; break; case 'a': { - gcli_release_asset_upload asset = { + struct gcli_release_asset_upload asset = { .path = optarg, .name = optarg, .label = "unused", @@ -402,12 +403,12 @@ static struct { int subcommand_releases(int argc, char *argv[]) { - int ch; - int count = 30; - char const *owner = NULL; - char const *repo = NULL; - gcli_release_list releases = {0}; - enum gcli_output_flags flags = 0; + int ch; + int count = 30; + char const *owner = NULL; + char const *repo = NULL; + struct gcli_release_list releases = {0}; + enum gcli_output_flags flags = 0; if (argc > 1) { for (size_t i = 0; i < ARRAY_SIZE(releases_subcommands); ++i) { diff --git a/src/gitea/releases.c b/src/gitea/releases.c index 04758753..484e7a2f 100644 --- a/src/gitea/releases.c +++ b/src/gitea/releases.c @@ -38,14 +38,14 @@ int gitea_get_releases(struct gcli_ctx *ctx, char const *owner, char const *repo, - int const max, gcli_release_list *const list) + int const max, struct gcli_release_list *const list) { return github_get_releases(ctx, owner, repo, max, list); } static void gitea_parse_release(struct gcli_ctx *ctx, gcli_fetch_buffer const *const buffer, - gcli_release *const out) + struct gcli_release *const out) { json_stream stream = {0}; json_open_buffer(&stream, buffer->data, buffer->length); @@ -55,7 +55,7 @@ gitea_parse_release(struct gcli_ctx *ctx, gcli_fetch_buffer const *const buffer, static int gitea_upload_release_asset(struct gcli_ctx *ctx, char *const url, - gcli_release_asset_upload const asset) + struct gcli_release_asset_upload const asset) { char *e_assetname = NULL; char *request = NULL; @@ -75,12 +75,12 @@ gitea_upload_release_asset(struct gcli_ctx *ctx, char *const url, } int -gitea_create_release(struct gcli_ctx *ctx, gcli_new_release const *release) +gitea_create_release(struct gcli_ctx *ctx, struct gcli_new_release const *release) { char *e_owner = NULL, *e_repo = NULL, *payload = NULL, *upload_url = NULL, *url = NULL; gcli_fetch_buffer buffer = {0}; gcli_jsongen gen = {0}; - gcli_release response = {0}; + struct gcli_release response = {0}; int rc = 0; /* Payload */ diff --git a/src/github/releases.c b/src/github/releases.c index 75113474..70f14bb3 100644 --- a/src/github/releases.c +++ b/src/github/releases.c @@ -40,7 +40,7 @@ int github_get_releases(struct gcli_ctx *ctx, char const *owner, char const *repo, - int const max, gcli_release_list *const list) + int const max, struct gcli_release_list *const list) { char *url = NULL; char *e_owner = NULL; @@ -53,7 +53,7 @@ github_get_releases(struct gcli_ctx *ctx, char const *owner, char const *repo, .parse = (parsefn)(parse_github_releases), }; - *list = (gcli_release_list) {0}; + *list = (struct gcli_release_list) {0}; e_owner = gcli_urlencode(owner); e_repo = gcli_urlencode(repo); @@ -71,7 +71,7 @@ github_get_releases(struct gcli_ctx *ctx, char const *owner, char const *repo, static void github_parse_single_release(struct gcli_ctx *ctx, gcli_fetch_buffer buffer, - gcli_release *const out) + struct gcli_release *const out) { struct json_stream stream = {0}; @@ -82,7 +82,8 @@ github_parse_single_release(struct gcli_ctx *ctx, gcli_fetch_buffer buffer, } static int -github_get_upload_url(struct gcli_ctx *ctx, gcli_release *const it, char **out) +github_get_upload_url(struct gcli_ctx *ctx, struct gcli_release *const it, + char **out) { char *delim = strchr(it->upload_url, '{'); if (delim == NULL) @@ -96,7 +97,7 @@ github_get_upload_url(struct gcli_ctx *ctx, gcli_release *const it, char **out) static int github_upload_release_asset(struct gcli_ctx *ctx, char const *url, - gcli_release_asset_upload const asset) + struct gcli_release_asset_upload const asset) { char *req = NULL; sn_sv file_content = {0}; @@ -125,13 +126,13 @@ github_upload_release_asset(struct gcli_ctx *ctx, char const *url, } int -github_create_release(struct gcli_ctx *ctx, gcli_new_release const *release) +github_create_release(struct gcli_ctx *ctx, struct gcli_new_release const *release) { char *url = NULL, *e_owner = NULL, *e_repo = NULL, *upload_url = NULL, *payload = NULL; gcli_fetch_buffer buffer = {0}; gcli_jsongen gen = {0}; - gcli_release response = {0}; + struct gcli_release response = {0}; int rc = 0; /* Payload */ diff --git a/src/gitlab/releases.c b/src/gitlab/releases.c index 6df237ba..4d87c1fa 100644 --- a/src/gitlab/releases.c +++ b/src/gitlab/releases.c @@ -40,21 +40,21 @@ #include static void -fixup_asset_name(struct gcli_ctx *ctx, gcli_release_asset *const asset) +fixup_asset_name(struct gcli_ctx *ctx, struct gcli_release_asset *const asset) { if (!asset->name) asset->name = gcli_urldecode(ctx, strrchr(asset->url, '/') + 1); } void -gitlab_fixup_release_assets(struct gcli_ctx *ctx, gcli_release *const release) +gitlab_fixup_release_assets(struct gcli_ctx *ctx, struct gcli_release *const release) { for (size_t i = 0; i < release->assets_size; ++i) fixup_asset_name(ctx, &release->assets[i]); } static void -fixup_release_asset_names(struct gcli_ctx *ctx, gcli_release_list *list) +fixup_release_asset_names(struct gcli_ctx *ctx, struct gcli_release_list *list) { /* Iterate over releases */ for (size_t i = 0; i < list->releases_size; ++i) @@ -63,7 +63,7 @@ fixup_release_asset_names(struct gcli_ctx *ctx, gcli_release_list *list) int gitlab_get_releases(struct gcli_ctx *ctx, char const *owner, char const *repo, - int const max, gcli_release_list *const list) + int const max, struct gcli_release_list *const list) { char *url = NULL; char *e_owner = NULL; @@ -77,7 +77,7 @@ gitlab_get_releases(struct gcli_ctx *ctx, char const *owner, char const *repo, .parse = (parsefn)(parse_gitlab_releases), }; - *list = (gcli_release_list) {0}; + *list = (struct gcli_release_list) {0}; e_owner = gcli_urlencode(owner); e_repo = gcli_urlencode(repo); @@ -97,7 +97,7 @@ gitlab_get_releases(struct gcli_ctx *ctx, char const *owner, char const *repo, } int -gitlab_create_release(struct gcli_ctx *ctx, gcli_new_release const *release) +gitlab_create_release(struct gcli_ctx *ctx, struct gcli_new_release const *release) { char *e_owner = NULL, *e_repo = NULL, *url = NULL, *payload = NULL; gcli_jsongen gen = {0}; diff --git a/src/releases.c b/src/releases.c index 26147dd3..b6130f6b 100644 --- a/src/releases.c +++ b/src/releases.c @@ -36,13 +36,13 @@ int gcli_get_releases(struct gcli_ctx *ctx, char const *owner, char const *repo, - int const max, gcli_release_list *const list) + int const max, struct gcli_release_list *const list) { gcli_null_check_call(get_releases, ctx, owner, repo, max, list); } void -gcli_release_free(gcli_release *release) +gcli_release_free(struct gcli_release *release) { free(release->id); free(release->name); @@ -60,7 +60,7 @@ gcli_release_free(gcli_release *release) } void -gcli_free_releases(gcli_release_list *const list) +gcli_free_releases(struct gcli_release_list *const list) { for (size_t i = 0; i < list->releases_size; ++i) { gcli_release_free(&list->releases[i]); @@ -73,14 +73,14 @@ gcli_free_releases(gcli_release_list *const list) } int -gcli_create_release(struct gcli_ctx *ctx, gcli_new_release const *release) +gcli_create_release(struct gcli_ctx *ctx, struct gcli_new_release const *release) { gcli_null_check_call(create_release, ctx, release); } int -gcli_release_push_asset(struct gcli_ctx *ctx, gcli_new_release *const release, - gcli_release_asset_upload const asset) +gcli_release_push_asset(struct gcli_ctx *ctx, struct gcli_new_release *const release, + struct gcli_release_asset_upload const asset) { if (release->assets_size == GCLI_RELEASE_MAX_ASSETS) return gcli_error(ctx, "too many assets"); diff --git a/templates/github/releases.t b/templates/github/releases.t index 0565a9f4..4c176aaf 100644 --- a/templates/github/releases.t +++ b/templates/github/releases.t @@ -1,12 +1,12 @@ include "gcli/releases.h"; parser github_release_asset is -object of gcli_release_asset with +object of struct gcli_release_asset with ("browser_download_url" => url as string, "name" => name as string); parser github_release is -object of gcli_release with +object of struct gcli_release with ("name" => name as string, "body" => body as string, "id" => id as int_to_string, @@ -18,5 +18,5 @@ object of gcli_release with use parse_github_release_asset, "upload_url" => upload_url as string); -parser github_releases is array of gcli_release +parser github_releases is array of struct gcli_release use parse_github_release; diff --git a/templates/gitlab/releases.t b/templates/gitlab/releases.t index f533ec42..ad67b732 100644 --- a/templates/gitlab/releases.t +++ b/templates/gitlab/releases.t @@ -1,16 +1,16 @@ include "gcli/gitlab/releases.h"; parser gitlab_release_asset is -object of gcli_release_asset with +object of struct gcli_release_asset with ("url" => url as string); parser gitlab_release_assets is -object of gcli_release with +object of struct gcli_release with ("sources" => assets as array of gcli_release_asset use parse_gitlab_release_asset); parser gitlab_release is -object of gcli_release with +object of struct gcli_release with ("name" => name as string, "tag_name" => id as string, "description" => body as string, @@ -20,4 +20,4 @@ object of gcli_release with "upcoming_release" => prerelease as bool); parser gitlab_releases is -array of gcli_release use parse_gitlab_release; +array of struct gcli_release use parse_gitlab_release; diff --git a/tests/github-parse-tests.c b/tests/github-parse-tests.c index cf8a194d..75380c1b 100644 --- a/tests/github-parse-tests.c +++ b/tests/github-parse-tests.c @@ -207,7 +207,7 @@ ATF_TC_BODY(simple_github_milestone, tc) ATF_TC_WITHOUT_HEAD(simple_github_release); ATF_TC_BODY(simple_github_release, tc) { - gcli_release release = {0}; + struct gcli_release release = {0}; FILE *f; json_stream stream; struct gcli_ctx *ctx = test_context(); diff --git a/tests/gitlab-parse-tests.c b/tests/gitlab-parse-tests.c index 9a87defb..8420ad34 100644 --- a/tests/gitlab-parse-tests.c +++ b/tests/gitlab-parse-tests.c @@ -141,7 +141,7 @@ ATF_TC_BODY(gitlab_simple_release, tc) json_stream stream = {0}; struct gcli_ctx *ctx = test_context(); FILE *f = open_sample("gitlab_simple_release.json"); - gcli_release release = {0}; + struct gcli_release release = {0}; json_open_stream(&stream, f); ATF_REQUIRE(parse_gitlab_release(ctx, &stream, &release) == 0); From 8fd6ff20ed1a8e873ec8d82748b623244ea180b5 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 5 Jan 2024 18:03:07 +0100 Subject: [PATCH 100/158] Remove struct typedef for gcli_gitremote --- include/gcli/cmd/gitconfig.h | 2 -- src/cmd/gitconfig.c | 10 +++++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/include/gcli/cmd/gitconfig.h b/include/gcli/cmd/gitconfig.h index aa94ba86..efe13055 100644 --- a/include/gcli/cmd/gitconfig.h +++ b/include/gcli/cmd/gitconfig.h @@ -36,8 +36,6 @@ #include -typedef struct gcli_gitremote gcli_gitremote; - struct gcli_gitremote { sn_sv name; sn_sv owner; diff --git a/src/cmd/gitconfig.c b/src/cmd/gitconfig.c index 119e8d49..1f2813d7 100644 --- a/src/cmd/gitconfig.c +++ b/src/cmd/gitconfig.c @@ -44,7 +44,7 @@ #include #define MAX_REMOTES 64 -static gcli_gitremote remotes[MAX_REMOTES]; +static struct gcli_gitremote remotes[MAX_REMOTES]; static size_t remotes_size; /* Resolve a worktree .git if needed */ @@ -256,7 +256,7 @@ gcli_gitconfig_get_current_branch(void) } static void -http_extractor(gcli_gitremote *const remote, char const *prefix) +http_extractor(struct gcli_gitremote *const remote, char const *prefix) { size_t prefix_size = strlen(prefix); sn_sv pair = remote->url; @@ -289,7 +289,7 @@ http_extractor(gcli_gitremote *const remote, char const *prefix) } static void -ssh_extractor(gcli_gitremote *const remote, char const *prefix) +ssh_extractor(struct gcli_gitremote *const remote, char const *prefix) { size_t prefix_size = strlen(prefix); @@ -320,7 +320,7 @@ ssh_extractor(gcli_gitremote *const remote, char const *prefix) struct forge_ex_def { char const *prefix; - void (*extractor)(gcli_gitremote *const, char const *); + void (*extractor)(struct gcli_gitremote *const, char const *); } url_extractors[] = { { .prefix = "git@", .extractor = ssh_extractor }, { .prefix = "ssh://", .extractor = ssh_extractor }, @@ -352,7 +352,7 @@ gitconfig_parse_remote(sn_sv section_title, sn_sv entry) if (remotes_size == MAX_REMOTES) errx(1, "error: too many remotes"); - gcli_gitremote *const remote = &remotes[remotes_size++]; + struct gcli_gitremote *const remote = &remotes[remotes_size++]; remote->name = remote_name; From e957f1773594a73ddc3fbc1a9544057044ad2247 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 5 Jan 2024 18:06:13 +0100 Subject: [PATCH 101/158] Remove struct typedefs in gcli_comments --- include/gcli/bugzilla/bugs-parser.h | 4 ++-- include/gcli/bugzilla/bugs.h | 2 +- include/gcli/cmd/comment.h | 2 +- include/gcli/comments.h | 18 +++++++----------- include/gcli/forges.h | 6 +++--- include/gcli/gitea/comments.h | 4 ++-- include/gcli/github/comments.h | 4 ++-- include/gcli/gitlab/comments.h | 6 +++--- src/bugzilla/bugs-parser.c | 4 ++-- src/bugzilla/bugs.c | 2 +- src/cmd/comment.c | 14 +++++++------- src/comments.c | 10 +++++----- src/gitea/comments.c | 4 ++-- src/github/comments.c | 4 ++-- src/gitlab/comments.c | 6 +++--- templates/bugzilla/bugs.t | 6 +++--- templates/github/checks.t | 2 +- templates/github/comments.t | 4 ++-- templates/github/status.t | 2 +- templates/gitlab/comments.t | 4 ++-- tests/bugzilla-parse-tests.c | 4 ++-- tests/github-parse-tests.c | 2 +- 22 files changed, 55 insertions(+), 59 deletions(-) diff --git a/include/gcli/bugzilla/bugs-parser.h b/include/gcli/bugzilla/bugs-parser.h index ab6a8c1c..7d4905cd 100644 --- a/include/gcli/bugzilla/bugs-parser.h +++ b/include/gcli/bugzilla/bugs-parser.h @@ -40,11 +40,11 @@ int parse_bugzilla_bug_comments_dictionary_skip_first(struct gcli_ctx *const ctx, json_stream *stream, - gcli_comment_list *out); + struct gcli_comment_list *out); int parse_bugzilla_comments_array_skip_first(struct gcli_ctx *ctx, struct json_stream *stream, - gcli_comment_list *out); + struct gcli_comment_list *out); int parse_bugzilla_bug_comments_dictionary_only_first(struct gcli_ctx *const ctx, json_stream *stream, diff --git a/include/gcli/bugzilla/bugs.h b/include/gcli/bugzilla/bugs.h index 293c8a56..4874f2aa 100644 --- a/include/gcli/bugzilla/bugs.h +++ b/include/gcli/bugzilla/bugs.h @@ -49,7 +49,7 @@ int bugzilla_get_bug(struct gcli_ctx *ctx, char const *product, int bugzilla_bug_get_comments(struct gcli_ctx *const ctx, char const *const product, char const *const component, gcli_id const bug_id, - gcli_comment_list *out); + struct gcli_comment_list *out); int bugzilla_bug_get_attachments(struct gcli_ctx *ctx, char const *const product, char const *const component, diff --git a/include/gcli/cmd/comment.h b/include/gcli/cmd/comment.h index ce7a429b..9be3d2a1 100644 --- a/include/gcli/cmd/comment.h +++ b/include/gcli/cmd/comment.h @@ -39,7 +39,7 @@ int gcli_issue_comments(char const *owner, char const *repo, int issue); int gcli_pull_comments(char const *owner, char const *repo, int pull); -void gcli_print_comment_list(gcli_comment_list const *list); +void gcli_print_comment_list(struct gcli_comment_list const *list); int subcommand_comment(int argc, char *argv[]); #endif /* GCLI_CMD_COMMENT_H */ diff --git a/include/gcli/comments.h b/include/gcli/comments.h index 8b88e08c..f82b6363 100644 --- a/include/gcli/comments.h +++ b/include/gcli/comments.h @@ -41,10 +41,6 @@ #include -typedef struct gcli_comment gcli_comment; -typedef struct gcli_comment_list gcli_comment_list; -typedef struct gcli_submit_comment_opts gcli_submit_comment_opts; - struct gcli_comment { char *author; /* Login name of the comment author */ char *date; /* Creation date of the comment */ @@ -53,8 +49,8 @@ struct gcli_comment { }; struct gcli_comment_list { - gcli_comment *comments; /* List of comments */ - size_t comments_size; /* Size of the list */ + struct gcli_comment *comments; /* List of comments */ + size_t comments_size; /* Size of the list */ }; struct gcli_submit_comment_opts { @@ -64,18 +60,18 @@ struct gcli_submit_comment_opts { char const *message; }; -void gcli_comments_free(gcli_comment_list *list); +void gcli_comments_free(struct gcli_comment_list *list); -void gcli_comment_free(gcli_comment *const it); +void gcli_comment_free(struct gcli_comment *const it); int gcli_get_issue_comments(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue, - gcli_comment_list *out); + struct gcli_comment_list *out); int gcli_get_pull_comments(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue, - gcli_comment_list *out); + struct gcli_comment_list *out); -int gcli_comment_submit(struct gcli_ctx *ctx, gcli_submit_comment_opts opts); +int gcli_comment_submit(struct gcli_ctx *ctx, struct gcli_submit_comment_opts opts); #endif /* COMMENTS_H */ diff --git a/include/gcli/forges.h b/include/gcli/forges.h index 1f5b0c2c..534bd957 100644 --- a/include/gcli/forges.h +++ b/include/gcli/forges.h @@ -61,7 +61,7 @@ struct gcli_forge_descriptor { * Submit a comment to a pull/mr or issue */ int (*perform_submit_comment)( struct gcli_ctx *ctx, - gcli_submit_comment_opts opts, + struct gcli_submit_comment_opts opts, gcli_fetch_buffer *out); /** @@ -71,7 +71,7 @@ struct gcli_forge_descriptor { char const *owner, char const *repo, gcli_id issue, - gcli_comment_list *out); + struct gcli_comment_list *out); /** * List comments on the given PR */ @@ -80,7 +80,7 @@ struct gcli_forge_descriptor { char const *owner, char const *repo, gcli_id pr, - gcli_comment_list *out); + struct gcli_comment_list *out); /** * List forks of the given repo */ diff --git a/include/gcli/gitea/comments.h b/include/gcli/gitea/comments.h index 659f60b8..15991cc9 100644 --- a/include/gcli/gitea/comments.h +++ b/include/gcli/gitea/comments.h @@ -38,10 +38,10 @@ #include int gitea_get_comments(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id issue, gcli_comment_list *out); + gcli_id issue, struct gcli_comment_list *out); int gitea_perform_submit_comment(struct gcli_ctx *ctx, - gcli_submit_comment_opts opts, + struct gcli_submit_comment_opts opts, gcli_fetch_buffer *out); #endif /* GITEA_COMMENTS_H */ diff --git a/include/gcli/github/comments.h b/include/gcli/github/comments.h index 10eb3402..b9c726d1 100644 --- a/include/gcli/github/comments.h +++ b/include/gcli/github/comments.h @@ -38,10 +38,10 @@ #include int github_perform_submit_comment(struct gcli_ctx *ctx, - gcli_submit_comment_opts opts, + struct gcli_submit_comment_opts opts, gcli_fetch_buffer *out); int github_get_comments(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id issue, gcli_comment_list *out); + gcli_id issue, struct gcli_comment_list *out); #endif /* GITHUB_COMMENTS_H */ diff --git a/include/gcli/gitlab/comments.h b/include/gcli/gitlab/comments.h index 3e1542f7..254c5118 100644 --- a/include/gcli/gitlab/comments.h +++ b/include/gcli/gitlab/comments.h @@ -38,15 +38,15 @@ #include int gitlab_perform_submit_comment(struct gcli_ctx *ctx, - gcli_submit_comment_opts opts, + struct gcli_submit_comment_opts opts, gcli_fetch_buffer *out); int gitlab_get_issue_comments(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue, - gcli_comment_list *out); + struct gcli_comment_list *out); int gitlab_get_mr_comments(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue, - gcli_comment_list *out); + struct gcli_comment_list *out); #endif /* GITLAB_COMMENTS_H */ diff --git a/src/bugzilla/bugs-parser.c b/src/bugzilla/bugs-parser.c index d7c3b32a..451597f9 100644 --- a/src/bugzilla/bugs-parser.c +++ b/src/bugzilla/bugs-parser.c @@ -39,7 +39,7 @@ int parse_bugzilla_comments_array_skip_first(struct gcli_ctx *ctx, struct json_stream *stream, - gcli_comment_list *out) + struct gcli_comment_list *out) { int rc = 0; @@ -88,7 +88,7 @@ parse_bugzilla_comments_array_only_first(struct gcli_ctx *ctx, int parse_bugzilla_bug_comments_dictionary_skip_first(struct gcli_ctx *const ctx, json_stream *stream, - gcli_comment_list *out) + struct gcli_comment_list *out) { enum json_type next = JSON_NULL; int rc = 0; diff --git a/src/bugzilla/bugs.c b/src/bugzilla/bugs.c index 88134d28..78a3b6e9 100644 --- a/src/bugzilla/bugs.c +++ b/src/bugzilla/bugs.c @@ -102,7 +102,7 @@ bugzilla_get_bugs(struct gcli_ctx *ctx, char const *product, char const *compone int bugzilla_bug_get_comments(struct gcli_ctx *const ctx, char const *const product, char const *const component, gcli_id const bug_id, - gcli_comment_list *out) + struct gcli_comment_list *out) { int rc = 0; gcli_fetch_buffer buffer = {0}; diff --git a/src/cmd/comment.c b/src/cmd/comment.c index 7b429dbe..08005f9c 100644 --- a/src/cmd/comment.c +++ b/src/cmd/comment.c @@ -60,7 +60,7 @@ usage(void) static void comment_init(struct gcli_ctx *ctx, FILE *f, void *_data) { - gcli_submit_comment_opts *info = _data; + struct gcli_submit_comment_opts *info = _data; const char *target_type = NULL; switch (info->target_type) { @@ -94,13 +94,13 @@ comment_init(struct gcli_ctx *ctx, FILE *f, void *_data) } static char * -gcli_comment_get_message(gcli_submit_comment_opts *info) +gcli_comment_get_message(struct gcli_submit_comment_opts *info) { return gcli_editor_get_user_message(g_clictx, comment_init, info); } static int -comment_submit(gcli_submit_comment_opts opts, int always_yes) +comment_submit(struct gcli_submit_comment_opts opts, int always_yes) { int rc = 0; char *message; @@ -129,7 +129,7 @@ comment_submit(gcli_submit_comment_opts opts, int always_yes) int gcli_issue_comments(char const *owner, char const *repo, int const issue) { - gcli_comment_list list = {0}; + struct gcli_comment_list list = {0}; int rc = 0; rc = gcli_get_issue_comments(g_clictx, owner, repo, issue, &list); @@ -145,7 +145,7 @@ gcli_issue_comments(char const *owner, char const *repo, int const issue) int gcli_pull_comments(char const *owner, char const *repo, int const pull) { - gcli_comment_list list = {0}; + struct gcli_comment_list list = {0}; int rc = 0; rc = gcli_get_pull_comments(g_clictx, owner, repo, pull, &list); @@ -159,7 +159,7 @@ gcli_pull_comments(char const *owner, char const *repo, int const pull) } void -gcli_print_comment_list(gcli_comment_list const *const list) +gcli_print_comment_list(struct gcli_comment_list const *const list) { for (size_t i = 0; i < list->comments_size; ++i) { printf("AUTHOR : %s%s%s\n" @@ -242,7 +242,7 @@ subcommand_comment(int argc, char *argv[]) return EXIT_FAILURE; } - rc = comment_submit((gcli_submit_comment_opts) { + rc = comment_submit((struct gcli_submit_comment_opts) { .owner = owner, .repo = repo, .target_type = target_type, diff --git a/src/comments.c b/src/comments.c index 10b6706d..9677dbaf 100644 --- a/src/comments.c +++ b/src/comments.c @@ -37,7 +37,7 @@ #include void -gcli_comment_free(gcli_comment *const it) +gcli_comment_free(struct gcli_comment *const it) { free(it->author); free(it->date); @@ -45,7 +45,7 @@ gcli_comment_free(gcli_comment *const it) } void -gcli_comments_free(gcli_comment_list *const list) +gcli_comments_free(struct gcli_comment_list *const list) { for (size_t i = 0; i < list->comments_size; ++i) gcli_comment_free(&list->comments[i]); @@ -57,20 +57,20 @@ gcli_comments_free(gcli_comment_list *const list) int gcli_get_issue_comments(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const issue, gcli_comment_list *out) + gcli_id const issue, struct gcli_comment_list *out) { gcli_null_check_call(get_issue_comments, ctx, owner, repo, issue, out); } int gcli_get_pull_comments(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const pull, gcli_comment_list *out) + gcli_id const pull, struct gcli_comment_list *out) { gcli_null_check_call(get_pull_comments, ctx, owner, repo, pull, out); } int -gcli_comment_submit(struct gcli_ctx *ctx, gcli_submit_comment_opts opts) +gcli_comment_submit(struct gcli_ctx *ctx, struct gcli_submit_comment_opts opts) { gcli_null_check_call(perform_submit_comment, ctx, opts, NULL); } diff --git a/src/gitea/comments.c b/src/gitea/comments.c index 7b1a7afd..b0043966 100644 --- a/src/gitea/comments.c +++ b/src/gitea/comments.c @@ -32,13 +32,13 @@ int gitea_get_comments(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const issue, gcli_comment_list *const out) + gcli_id const issue, struct gcli_comment_list *const out) { return github_get_comments(ctx, owner, repo, issue, out); } int -gitea_perform_submit_comment(struct gcli_ctx *ctx, gcli_submit_comment_opts opts, +gitea_perform_submit_comment(struct gcli_ctx *ctx, struct gcli_submit_comment_opts opts, gcli_fetch_buffer *const out) { return github_perform_submit_comment(ctx, opts, out); diff --git a/src/github/comments.c b/src/github/comments.c index 058af4c4..59797d89 100644 --- a/src/github/comments.c +++ b/src/github/comments.c @@ -38,7 +38,7 @@ int github_perform_submit_comment(struct gcli_ctx *ctx, - gcli_submit_comment_opts opts, + struct gcli_submit_comment_opts opts, gcli_fetch_buffer *out) { int rc = 0; @@ -73,7 +73,7 @@ github_perform_submit_comment(struct gcli_ctx *ctx, int github_get_comments(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const issue, gcli_comment_list *const out) + gcli_id const issue, struct gcli_comment_list *const out) { char *e_owner = NULL; char *e_repo = NULL; diff --git a/src/gitlab/comments.c b/src/gitlab/comments.c index 5c9d09d2..89ccd3bc 100644 --- a/src/gitlab/comments.c +++ b/src/gitlab/comments.c @@ -35,7 +35,7 @@ #include int -gitlab_perform_submit_comment(struct gcli_ctx *ctx, gcli_submit_comment_opts opts, +gitlab_perform_submit_comment(struct gcli_ctx *ctx, struct gcli_submit_comment_opts opts, gcli_fetch_buffer *const out) { char *url = NULL, *payload = NULL, *e_owner = NULL, *e_repo = NULL; @@ -82,7 +82,7 @@ gitlab_perform_submit_comment(struct gcli_ctx *ctx, gcli_submit_comment_opts opt int gitlab_get_mr_comments(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const mr, gcli_comment_list *const out) + gcli_id const mr, struct gcli_comment_list *const out) { char *e_owner = gcli_urlencode(owner); char *e_repo = gcli_urlencode(repo); @@ -108,7 +108,7 @@ gitlab_get_mr_comments(struct gcli_ctx *ctx, char const *owner, char const *repo int gitlab_get_issue_comments(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const issue, - gcli_comment_list *const out) + struct gcli_comment_list *const out) { char *e_owner = gcli_urlencode(owner); char *e_repo = gcli_urlencode(repo); diff --git a/templates/bugzilla/bugs.t b/templates/bugzilla/bugs.t index cb9a6547..d0936d3d 100644 --- a/templates/bugzilla/bugs.t +++ b/templates/bugzilla/bugs.t @@ -31,18 +31,18 @@ object of gcli_issue_list with ("bugs" => issues as array of gcli_issue use parse_bugzilla_bug_item); parser bugzilla_comment is -object of gcli_comment with +object of struct gcli_comment with ("id" => id as id, "text" => body as string, "creation_time" => date as string, "creator" => author as string); parser bugzilla_comments_internal_skip_first is -object of gcli_comment_list with +object of struct gcli_comment_list with ("comments" => use parse_bugzilla_comments_array_skip_first); parser bugzilla_comments is -object of gcli_comment_list with +object of struct gcli_comment_list with ("bugs" => use parse_bugzilla_bug_comments_dictionary_skip_first); parser bugzilla_comment_text is diff --git a/templates/github/checks.t b/templates/github/checks.t index cd164e25..39153230 100644 --- a/templates/github/checks.t +++ b/templates/github/checks.t @@ -12,4 +12,4 @@ object of gcli_github_check with parser github_checks is object of github_check_list with ("check_runs" => checks as array of gcli_github_check - use parse_github_check); \ No newline at end of file + use parse_github_check); diff --git a/templates/github/comments.t b/templates/github/comments.t index a6e471c1..e06f87b4 100644 --- a/templates/github/comments.t +++ b/templates/github/comments.t @@ -1,11 +1,11 @@ include "gcli/github/comments.h"; parser github_comment is -object of gcli_comment with +object of struct gcli_comment with ("id" => id as id, "created_at" => date as string, "body" => body as string, "user" => author as user); -parser github_comments is array of gcli_comment +parser github_comments is array of struct gcli_comment use parse_github_comment; diff --git a/templates/github/status.t b/templates/github/status.t index f6faddab..f576fa24 100644 --- a/templates/github/status.t +++ b/templates/github/status.t @@ -18,4 +18,4 @@ object of gcli_notification with "repository" => use parse_github_notification_repository); parser github_notifications is array of gcli_notification - use parse_github_notification; \ No newline at end of file + use parse_github_notification; diff --git a/templates/gitlab/comments.t b/templates/gitlab/comments.t index 3896a99a..6ee0f3a9 100644 --- a/templates/gitlab/comments.t +++ b/templates/gitlab/comments.t @@ -1,11 +1,11 @@ include "gcli/gitlab/comments.h"; parser gitlab_comment is -object of gcli_comment with +object of struct gcli_comment with ("created_at" => date as string, "body" => body as string, "author" => author as user, "id" => id as id); parser gitlab_comments is -array of gcli_comment use parse_gitlab_comment; +array of struct gcli_comment use parse_gitlab_comment; diff --git a/tests/bugzilla-parse-tests.c b/tests/bugzilla-parse-tests.c index 0f7d7205..20178854 100644 --- a/tests/bugzilla-parse-tests.c +++ b/tests/bugzilla-parse-tests.c @@ -101,8 +101,8 @@ ATF_TC_WITHOUT_HEAD(bugzilla_comments); ATF_TC_BODY(bugzilla_comments, tc) { FILE *f; - gcli_comment const *cmt = NULL; - gcli_comment_list list = {0}; + struct gcli_comment const *cmt = NULL; + struct gcli_comment_list list = {0}; struct gcli_ctx *ctx = test_context(); json_stream stream; diff --git a/tests/github-parse-tests.c b/tests/github-parse-tests.c index 75380c1b..ce74d098 100644 --- a/tests/github-parse-tests.c +++ b/tests/github-parse-tests.c @@ -285,7 +285,7 @@ ATF_TC_BODY(simple_github_fork, tc) ATF_TC_WITHOUT_HEAD(simple_github_comment); ATF_TC_BODY(simple_github_comment, tc) { - gcli_comment comment = {0}; + struct gcli_comment comment = {0}; FILE *f; json_stream stream; struct gcli_ctx *ctx = test_context(); From 7d51d973eb848bf41dc667ba8aa3ff8bf8fda583 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 5 Jan 2024 18:08:39 +0100 Subject: [PATCH 102/158] Remove struct typedef for gcli_forge_descriptor --- include/gcli/forges.h | 6 ++---- src/attachments.c | 2 +- src/cmd/pulls.c | 2 +- src/forges.c | 10 +++++----- src/issues.c | 2 +- src/sshkeys.c | 2 +- 6 files changed, 11 insertions(+), 13 deletions(-) diff --git a/include/gcli/forges.h b/include/gcli/forges.h index 534bd957..c07c2533 100644 --- a/include/gcli/forges.h +++ b/include/gcli/forges.h @@ -46,8 +46,6 @@ #include #include -typedef struct gcli_forge_descriptor gcli_forge_descriptor; - /* Hopefully temporary hack */ typedef int (*gcli_get_pull_checks_cb)( struct gcli_ctx *, char const *, char const *, gcli_id, @@ -556,7 +554,7 @@ struct gcli_forge_descriptor { char const *user_object_key; }; -gcli_forge_descriptor const *gcli_forge(struct gcli_ctx *ctx); +struct gcli_forge_descriptor const *gcli_forge(struct gcli_ctx *ctx); /** A macro used for calling one of the dispatch points above. * @@ -565,7 +563,7 @@ gcli_forge_descriptor const *gcli_forge(struct gcli_ctx *ctx); * arguments. */ #define gcli_null_check_call(routine, ctx, ...) \ do { \ - gcli_forge_descriptor const *const forge = gcli_forge(ctx); \ + struct gcli_forge_descriptor const *const forge = gcli_forge(ctx); \ \ if (forge->routine) { \ return forge->routine(ctx, __VA_ARGS__); \ diff --git a/src/attachments.c b/src/attachments.c index e6339f42..8c32279e 100644 --- a/src/attachments.c +++ b/src/attachments.c @@ -58,7 +58,7 @@ gcli_attachment_free(struct gcli_attachment *it) int gcli_attachment_get_content(struct gcli_ctx *const ctx, gcli_id const id, FILE *out) { - gcli_forge_descriptor const *const forge = gcli_forge(ctx); + struct gcli_forge_descriptor const *const forge = gcli_forge(ctx); /* FIXME: this is not entirely correct. Add a separate quirks category. */ if (forge->issue_quirks & GCLI_ISSUE_QUIRKS_ATTACHMENTS) diff --git a/src/cmd/pulls.c b/src/cmd/pulls.c index 497f0f0c..5705a8b0 100644 --- a/src/cmd/pulls.c +++ b/src/cmd/pulls.c @@ -175,7 +175,7 @@ void gcli_pull_print(gcli_pull const *const it) { gcli_dict dict; - gcli_forge_descriptor const *const forge = gcli_forge(g_clictx); + struct gcli_forge_descriptor const *const forge = gcli_forge(g_clictx); int const quirks = forge->pull_summary_quirks; dict = gcli_dict_begin(); diff --git a/src/forges.c b/src/forges.c index 9584bb42..f13d0b84 100644 --- a/src/forges.c +++ b/src/forges.c @@ -75,7 +75,7 @@ #include #include -static gcli_forge_descriptor const +static struct gcli_forge_descriptor const github_forge_descriptor = { /* Comments */ @@ -170,7 +170,7 @@ github_forge_descriptor = .pull_summary_quirks = GCLI_PRS_QUIRK_COVERAGE, }; -static gcli_forge_descriptor const +static struct gcli_forge_descriptor const gitlab_forge_descriptor = { /* Comments */ @@ -262,7 +262,7 @@ gitlab_forge_descriptor = | GCLI_PRS_QUIRK_MERGED, }; -static gcli_forge_descriptor const +static struct gcli_forge_descriptor const gitea_forge_descriptor = { /* Comments */ @@ -356,7 +356,7 @@ gitea_forge_descriptor = | GCLI_PRS_QUIRK_COVERAGE, }; -static gcli_forge_descriptor const +static struct gcli_forge_descriptor const bugzilla_forge_descriptor = { /* Issues */ @@ -376,7 +376,7 @@ bugzilla_forge_descriptor = .user_object_key = "---dummy---", }; -gcli_forge_descriptor const * +struct gcli_forge_descriptor const * gcli_forge(struct gcli_ctx *ctx) { switch (ctx->get_forge_type(ctx)) { diff --git a/src/issues.c b/src/issues.c index ac14ec23..5ad88cde 100644 --- a/src/issues.c +++ b/src/issues.c @@ -162,7 +162,7 @@ gcli_issue_get_attachments(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue, struct gcli_attachment_list *out) { - gcli_forge_descriptor const *const forge = + struct gcli_forge_descriptor const *const forge = gcli_forge(ctx); bool const avail = diff --git a/src/sshkeys.c b/src/sshkeys.c index 57251556..392124ee 100644 --- a/src/sshkeys.c +++ b/src/sshkeys.c @@ -62,7 +62,7 @@ gcli_sshkeys_add_key(struct gcli_ctx *ctx, char const *title, { int rc; char *buffer; - gcli_forge_descriptor const *const forge = gcli_forge(ctx); + struct gcli_forge_descriptor const *const forge = gcli_forge(ctx); if (forge->add_sshkey == NULL) { return gcli_error(ctx, "ssh_add_key is not supported by this forge"); From 64bfaf2b1db5bb3013e028070444171c84b40713 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 5 Jan 2024 18:10:41 +0100 Subject: [PATCH 103/158] Remove struct typedef for gcli_forks --- include/gcli/cmd/forks.h | 2 +- include/gcli/forges.h | 2 +- include/gcli/forks.h | 11 ++++------- include/gcli/gitea/forks.h | 2 +- include/gcli/github/forks.h | 2 +- include/gcli/gitlab/forks.h | 2 +- src/cmd/forks.c | 4 ++-- src/forks.c | 6 +++--- src/gitea/forks.c | 2 +- src/github/forks.c | 4 ++-- src/gitlab/forks.c | 4 ++-- templates/github/forks.t | 4 ++-- templates/gitlab/forks.t | 6 +++--- tests/github-parse-tests.c | 2 +- tests/gitlab-parse-tests.c | 2 +- 15 files changed, 26 insertions(+), 29 deletions(-) diff --git a/include/gcli/cmd/forks.h b/include/gcli/cmd/forks.h index 9c40d781..21727e97 100644 --- a/include/gcli/cmd/forks.h +++ b/include/gcli/cmd/forks.h @@ -39,7 +39,7 @@ int subcommand_forks(int argc, char *argv[]); -void gcli_print_forks(enum gcli_output_flags flags, gcli_fork_list const *list, +void gcli_print_forks(enum gcli_output_flags flags, struct gcli_fork_list const *list, int max); #endif /* GCLI_CMD_FORKS_H */ diff --git a/include/gcli/forges.h b/include/gcli/forges.h index c07c2533..64aecc92 100644 --- a/include/gcli/forges.h +++ b/include/gcli/forges.h @@ -87,7 +87,7 @@ struct gcli_forge_descriptor { char const *owner, char const *repo, int max, - gcli_fork_list *out); + struct gcli_fork_list *out); /** * Fork the given repo into the owner _in */ diff --git a/include/gcli/forks.h b/include/gcli/forks.h index b1612d07..695452a3 100644 --- a/include/gcli/forks.h +++ b/include/gcli/forks.h @@ -37,9 +37,6 @@ #include #include -typedef struct gcli_fork gcli_fork; -typedef struct gcli_fork_list gcli_fork_list; - struct gcli_fork { char *full_name; char *owner; @@ -48,12 +45,12 @@ struct gcli_fork { }; struct gcli_fork_list { - gcli_fork *forks; + struct gcli_fork *forks; size_t forks_size; }; int gcli_get_forks(struct gcli_ctx *ctx, char const *owner, - char const *reponame, int max, gcli_fork_list *out); + char const *reponame, int max, struct gcli_fork_list *out); int gcli_fork_create(struct gcli_ctx *ctx, char const *owner, char const *repo, char const *in); @@ -61,8 +58,8 @@ int gcli_fork_create(struct gcli_ctx *ctx, char const *owner, char const *repo, void gcli_fork_delete(char const *owner, char const *repo); -void gcli_forks_free(gcli_fork_list *list); +void gcli_forks_free(struct gcli_fork_list *list); -void gcli_fork_free(gcli_fork *fork); +void gcli_fork_free(struct gcli_fork *fork); #endif /* FORK_H */ diff --git a/include/gcli/gitea/forks.h b/include/gcli/gitea/forks.h index 28f29d34..f840a44d 100644 --- a/include/gcli/gitea/forks.h +++ b/include/gcli/gitea/forks.h @@ -37,7 +37,7 @@ #include int gitea_get_forks(struct gcli_ctx *ctx, char const *owner, char const *repo, - int max, gcli_fork_list *out); + int max, struct gcli_fork_list *out); int gitea_fork_create(struct gcli_ctx *ctx, char const *owner, char const *repo, char const *_in); diff --git a/include/gcli/github/forks.h b/include/gcli/github/forks.h index 40caffa8..c05a5805 100644 --- a/include/gcli/github/forks.h +++ b/include/gcli/github/forks.h @@ -37,7 +37,7 @@ #include int github_get_forks(struct gcli_ctx *ctx, char const *owner, char const *repo, - int max, gcli_fork_list *out); + int max, struct gcli_fork_list *out); int github_fork_create(struct gcli_ctx *ctx, char const *owner, char const *repo, char const *_in); diff --git a/include/gcli/gitlab/forks.h b/include/gcli/gitlab/forks.h index 586fe176..4a03a619 100644 --- a/include/gcli/gitlab/forks.h +++ b/include/gcli/gitlab/forks.h @@ -37,7 +37,7 @@ #include int gitlab_get_forks(struct gcli_ctx *ctx, char const *owner, char const *repo, - int max, gcli_fork_list *out); + int max, struct gcli_fork_list *out); int gitlab_fork_create(struct gcli_ctx *ctx, char const *owner, char const *repo, char const *_in); diff --git a/src/cmd/forks.c b/src/cmd/forks.c index 01fb9542..53e1a52a 100644 --- a/src/cmd/forks.c +++ b/src/cmd/forks.c @@ -63,7 +63,7 @@ usage(void) void gcli_print_forks(enum gcli_output_flags const flags, - gcli_fork_list const *const list, int const max) + struct gcli_fork_list const *const list, int const max) { size_t n; gcli_tbl table; @@ -186,7 +186,7 @@ subcommand_forks_create(int argc, char *argv[]) int subcommand_forks(int argc, char *argv[]) { - gcli_fork_list forks = {0}; + struct gcli_fork_list forks = {0}; char const *owner = NULL, *repo = NULL; int ch = 0; int count = 30; diff --git a/src/forks.c b/src/forks.c index 2b69824f..b8ee77a1 100644 --- a/src/forks.c +++ b/src/forks.c @@ -35,7 +35,7 @@ int gcli_get_forks(struct gcli_ctx *ctx, char const *owner, char const *repo, - int const max, gcli_fork_list *const out) + int const max, struct gcli_fork_list *const out) { gcli_null_check_call(get_forks, ctx, owner, repo, max, out); } @@ -48,7 +48,7 @@ gcli_fork_create(struct gcli_ctx *ctx, char const *owner, char const *repo, } void -gcli_fork_free(gcli_fork *fork) +gcli_fork_free(struct gcli_fork *fork) { free(fork->full_name); free(fork->owner); @@ -56,7 +56,7 @@ gcli_fork_free(gcli_fork *fork) } void -gcli_forks_free(gcli_fork_list *const list) +gcli_forks_free(struct gcli_fork_list *const list) { for (size_t i = 0; i < list->forks_size; ++i) { gcli_fork_free(&list->forks[i]); diff --git a/src/gitea/forks.c b/src/gitea/forks.c index b283be15..1552a005 100644 --- a/src/gitea/forks.c +++ b/src/gitea/forks.c @@ -34,7 +34,7 @@ int gitea_get_forks(struct gcli_ctx *ctx, char const *owner, char const *repo, - int const max, gcli_fork_list *const out) + int const max, struct gcli_fork_list *const out) { return github_get_forks(ctx, owner, repo, max, out); } diff --git a/src/github/forks.c b/src/github/forks.c index 8c81ba19..5ffe82f6 100644 --- a/src/github/forks.c +++ b/src/github/forks.c @@ -38,7 +38,7 @@ int github_get_forks(struct gcli_ctx *ctx, char const *owner, char const *repo, - int const max, gcli_fork_list *const list) + int const max, struct gcli_fork_list *const list) { char *url = NULL; char *e_owner = NULL; @@ -51,7 +51,7 @@ github_get_forks(struct gcli_ctx *ctx, char const *owner, char const *repo, .parse = (parsefn)(parse_github_forks), }; - *list = (gcli_fork_list) {0}; + *list = (struct gcli_fork_list) {0}; e_owner = gcli_urlencode(owner); e_repo = gcli_urlencode(repo); diff --git a/src/gitlab/forks.c b/src/gitlab/forks.c index ac59335b..ffdacfb8 100644 --- a/src/gitlab/forks.c +++ b/src/gitlab/forks.c @@ -38,7 +38,7 @@ int gitlab_get_forks(struct gcli_ctx *ctx, char const *owner, char const *repo, - int const max, gcli_fork_list *const list) + int const max, struct gcli_fork_list *const list) { char *url = NULL; char *e_owner = NULL; @@ -54,7 +54,7 @@ gitlab_get_forks(struct gcli_ctx *ctx, char const *owner, char const *repo, e_owner = gcli_urlencode(owner); e_repo = gcli_urlencode(repo); - *list = (gcli_fork_list) {0}; + *list = (struct gcli_fork_list) {0}; url = sn_asprintf("%s/projects/%s%%2F%s/forks", gcli_get_apibase(ctx), e_owner, e_repo); diff --git a/templates/github/forks.t b/templates/github/forks.t index ef5fdf95..55e2a961 100644 --- a/templates/github/forks.t +++ b/templates/github/forks.t @@ -1,11 +1,11 @@ include "gcli/forks.h"; parser github_fork is -object of gcli_fork with +object of struct gcli_fork with ("full_name" => full_name as string, "owner" => owner as user, "created_at" => date as string, "forks_count" => forks as int); -parser github_forks is array of gcli_fork +parser github_forks is array of struct gcli_fork use parse_github_fork; diff --git a/templates/gitlab/forks.t b/templates/gitlab/forks.t index d4c1cff3..d63ab511 100644 --- a/templates/gitlab/forks.t +++ b/templates/gitlab/forks.t @@ -1,15 +1,15 @@ include "gcli/gitlab/forks.h"; parser gitlab_fork_namespace is -object of gcli_fork with +object of struct gcli_fork with ("full_path" => owner as string); parser gitlab_fork is -object of gcli_fork with +object of struct gcli_fork with ("path_with_namespace" => full_name as string, "namespace" => use parse_gitlab_fork_namespace, "created_at" => date as string, "forks_count" => forks as int); parser gitlab_forks is -array of gcli_fork use parse_gitlab_fork; +array of struct gcli_fork use parse_gitlab_fork; diff --git a/tests/github-parse-tests.c b/tests/github-parse-tests.c index ce74d098..92555803 100644 --- a/tests/github-parse-tests.c +++ b/tests/github-parse-tests.c @@ -262,7 +262,7 @@ ATF_TC_BODY(simple_github_repo, tc) ATF_TC_WITHOUT_HEAD(simple_github_fork); ATF_TC_BODY(simple_github_fork, tc) { - gcli_fork fork = {0}; + struct gcli_fork fork = {0}; FILE *f; json_stream stream; struct gcli_ctx *ctx = test_context(); diff --git a/tests/gitlab-parse-tests.c b/tests/gitlab-parse-tests.c index 8420ad34..5068419b 100644 --- a/tests/gitlab-parse-tests.c +++ b/tests/gitlab-parse-tests.c @@ -194,7 +194,7 @@ ATF_TC_BODY(gitlab_simple_fork, tc) json_stream stream = {0}; struct gcli_ctx *ctx = test_context(); FILE *f = open_sample("gitlab_simple_fork.json"); - gcli_fork fork = {0}; + struct gcli_fork fork = {0}; json_open_stream(&stream, f); ATF_REQUIRE(parse_gitlab_fork(ctx, &stream, &fork) == 0); From a0286560af53918df31d21b18cc0927e5a4ce2a4 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 5 Jan 2024 18:13:13 +0100 Subject: [PATCH 104/158] Remove struct typedef for gcli_github_check --- include/gcli/cmd/ci.h | 4 ++-- include/gcli/github/checks.h | 11 ++++------- src/cmd/ci.c | 4 ++-- src/cmd/pulls.c | 2 +- src/github/checks.c | 6 +++--- src/github/pulls.c | 2 +- src/pulls.c | 2 +- templates/github/checks.t | 4 ++-- tests/github-parse-tests.c | 2 +- 9 files changed, 17 insertions(+), 20 deletions(-) diff --git a/include/gcli/cmd/ci.h b/include/gcli/cmd/ci.h index e7767c98..fb0d1aca 100644 --- a/include/gcli/cmd/ci.h +++ b/include/gcli/cmd/ci.h @@ -36,8 +36,8 @@ #include -void github_print_checks(github_check_list const *checks); -void github_print_checks(github_check_list const *const list); +void github_print_checks(struct github_check_list const *checks); +void github_print_checks(struct github_check_list const *const list); int github_checks(char const *const owner, char const *const repo, char const *const ref, int const max); int subcommand_ci(int argc, char *argv[]); diff --git a/include/gcli/github/checks.h b/include/gcli/github/checks.h index 39a3855d..4fb66de8 100644 --- a/include/gcli/github/checks.h +++ b/include/gcli/github/checks.h @@ -38,9 +38,6 @@ #include -typedef struct gcli_github_check gcli_github_check; -typedef struct github_check_list github_check_list; - struct gcli_github_check { char *name; char *status; @@ -51,16 +48,16 @@ struct gcli_github_check { }; struct github_check_list { - gcli_github_check *checks; + struct gcli_github_check *checks; size_t checks_size; }; int github_get_checks(struct gcli_ctx *ctx, char const *owner, char const *repo, char const *ref, int max, - github_check_list *checks); + struct github_check_list *checks); -void github_free_checks(github_check_list *checks); +void github_free_checks(struct github_check_list *checks); -void gcli_github_check_free(gcli_github_check *check); +void gcli_github_check_free(struct gcli_github_check *check); #endif /* GITHUB_CHECKS_H */ diff --git a/src/cmd/ci.c b/src/cmd/ci.c index 78d4bbc6..16ccc209 100644 --- a/src/cmd/ci.c +++ b/src/cmd/ci.c @@ -59,7 +59,7 @@ usage(void) } void -github_print_checks(github_check_list const *const list) +github_print_checks(struct github_check_list const *const list) { gcli_tbl table; gcli_tblcoldef cols[] = { @@ -93,7 +93,7 @@ int github_checks(char const *const owner, char const *const repo, char const *const ref, int const max) { - github_check_list list = {0}; + struct github_check_list list = {0}; int rc = 0; rc = github_get_checks(g_clictx, owner, repo, ref, max, &list); diff --git a/src/cmd/pulls.c b/src/cmd/pulls.c index 5705a8b0..2489617f 100644 --- a/src/cmd/pulls.c +++ b/src/cmd/pulls.c @@ -250,7 +250,7 @@ gcli_print_checks_list(gcli_pull_checks_list const *const list) { switch (list->forge_type) { case GCLI_FORGE_GITHUB: - github_print_checks((github_check_list const *)(list)); + github_print_checks((struct github_check_list const *)(list)); break; case GCLI_FORGE_GITLAB: gitlab_print_pipelines((gitlab_pipeline_list const*)(list)); diff --git a/src/github/checks.c b/src/github/checks.c index ef3c11db..8ac51350 100644 --- a/src/github/checks.c +++ b/src/github/checks.c @@ -42,7 +42,7 @@ int github_get_checks(struct gcli_ctx *ctx, char const *owner, char const *repo, - char const *ref, int const max, github_check_list *const out) + char const *ref, int const max, struct github_check_list *const out) { gcli_fetch_buffer buffer = {0}; char *url = NULL, *next_url = NULL; @@ -78,7 +78,7 @@ github_get_checks(struct gcli_ctx *ctx, char const *owner, char const *repo, } void -gcli_github_check_free(gcli_github_check *check) +gcli_github_check_free(struct gcli_github_check *check) { free(check->name); free(check->status); @@ -88,7 +88,7 @@ gcli_github_check_free(gcli_github_check *check) } void -github_free_checks(github_check_list *const list) +github_free_checks(struct github_check_list *const list) { for (size_t i = 0; i < list->checks_size; ++i) { gcli_github_check_free(&list->checks[i]); diff --git a/src/github/pulls.c b/src/github/pulls.c index 8d9d6f98..242c0131 100644 --- a/src/github/pulls.c +++ b/src/github/pulls.c @@ -442,7 +442,7 @@ github_pull_get_checks(struct gcli_ctx *ctx, char const *owner, char const *repo snprintf(refname, sizeof refname, "refs%%2Fpull%%2F%"PRIid"%%2Fhead", pr_number); return github_get_checks(ctx, owner, repo, refname, -1, - (github_check_list *)out); + (struct github_check_list *)out); } int diff --git a/src/pulls.c b/src/pulls.c index 8bf546b5..7bec4520 100644 --- a/src/pulls.c +++ b/src/pulls.c @@ -131,7 +131,7 @@ gcli_pull_checks_free(gcli_pull_checks_list *list) { switch (list->forge_type) { case GCLI_FORGE_GITHUB: - github_free_checks((github_check_list *)list); + github_free_checks((struct github_check_list *)list); break; case GCLI_FORGE_GITLAB: gitlab_pipelines_free((gitlab_pipeline_list *)list); diff --git a/templates/github/checks.t b/templates/github/checks.t index 39153230..81429e50 100644 --- a/templates/github/checks.t +++ b/templates/github/checks.t @@ -1,7 +1,7 @@ include "gcli/github/checks.h"; parser github_check is -object of gcli_github_check with +object of struct gcli_github_check with ("name" => name as string, "status" => status as string, "conclusion" => conclusion as string, @@ -10,6 +10,6 @@ object of gcli_github_check with "id" => id as id); parser github_checks is -object of github_check_list with +object of struct github_check_list with ("check_runs" => checks as array of gcli_github_check use parse_github_check); diff --git a/tests/github-parse-tests.c b/tests/github-parse-tests.c index 92555803..6f9e0080 100644 --- a/tests/github-parse-tests.c +++ b/tests/github-parse-tests.c @@ -308,7 +308,7 @@ ATF_TC_BODY(simple_github_comment, tc) ATF_TC_WITHOUT_HEAD(simple_github_check); ATF_TC_BODY(simple_github_check, tc) { - gcli_github_check check = {0}; + struct gcli_github_check check = {0}; FILE *f; json_stream stream; struct gcli_ctx *ctx = test_context(); From 80846f00b08622ea57b53fd71c70b4ff45b9fa98 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 5 Jan 2024 18:16:33 +0100 Subject: [PATCH 105/158] Remove struct typedefs for gcli_gist --- include/gcli/cmd/gists.h | 2 +- include/gcli/github/gists.h | 23 ++++++++++------------- src/cmd/gists.c | 18 +++++++++--------- src/github/gists.c | 14 +++++++------- templates/github/gists.t | 6 +++--- 5 files changed, 30 insertions(+), 33 deletions(-) diff --git a/include/gcli/cmd/gists.h b/include/gcli/cmd/gists.h index 61ad96b3..bf7c78eb 100644 --- a/include/gcli/cmd/gists.h +++ b/include/gcli/cmd/gists.h @@ -38,7 +38,7 @@ int subcommand_gists(int argc, char *argv[]); -void gcli_print_gists(enum gcli_output_flags flags, gcli_gist_list const *list, +void gcli_print_gists(enum gcli_output_flags flags, struct gcli_gist_list const *list, int max); #endif /* GCLI_CMD_GISTS_H */ diff --git a/include/gcli/github/gists.h b/include/gcli/github/gists.h index ef253310..f76dc58a 100644 --- a/include/gcli/github/gists.h +++ b/include/gcli/github/gists.h @@ -39,11 +39,6 @@ #include #include -typedef struct gcli_gist gcli_gist; -typedef struct gcli_gist_list gcli_gist_list; -typedef struct gcli_gist_file gcli_gist_file; -typedef struct gcli_new_gist gcli_new_gist; - struct gcli_gist_file { char *filename; char *language; @@ -53,7 +48,7 @@ struct gcli_gist_file { }; struct gcli_gist_list { - gcli_gist *gists; + struct gcli_gist *gists; size_t gists_size; }; @@ -64,7 +59,7 @@ struct gcli_gist { char *date; char *git_pull_url; char *description; - gcli_gist_file *files; + struct gcli_gist_file *files; size_t files_size; }; @@ -75,16 +70,17 @@ struct gcli_new_gist { }; int gcli_get_gists(struct gcli_ctx *ctx, char const *user, int max, - gcli_gist_list *list); + struct gcli_gist_list *list); -int gcli_get_gist(struct gcli_ctx *ctx, char const *gist_id, gcli_gist *out); +int gcli_get_gist(struct gcli_ctx *ctx, char const *gist_id, + struct gcli_gist *out); -int gcli_create_gist(struct gcli_ctx *ctx, gcli_new_gist); +int gcli_create_gist(struct gcli_ctx *ctx, struct gcli_new_gist); int gcli_delete_gist(struct gcli_ctx *ctx, char const *gist_id); -void gcli_gists_free(gcli_gist_list *list); -void gcli_gist_free(gcli_gist *g); +void gcli_gists_free(struct gcli_gist_list *list); +void gcli_gist_free(struct gcli_gist *g); /** * NOTE(Nico): Because of idiots designing a web API, we get a list of @@ -93,6 +89,7 @@ void gcli_gist_free(gcli_gist *g); * file name again. Whatever...here's a hack. Blame GitHub. */ int parse_github_gist_files_idiot_hack(struct gcli_ctx *ctx, - json_stream *stream, gcli_gist *gist); + struct json_stream *stream, + struct gcli_gist *gist); #endif /* GCLI_GITHUB_GISTS_H */ diff --git a/src/cmd/gists.c b/src/cmd/gists.c index a6d91e0a..d57917cb 100644 --- a/src/cmd/gists.c +++ b/src/cmd/gists.c @@ -89,7 +89,7 @@ language_fmt(char const *it) } static void -print_gist_file(gcli_gist_file const *const file) +print_gist_file(struct gcli_gist_file const *const file) { printf(" • %-15.15s %-8.8s %-s\n", language_fmt(file->language), @@ -98,7 +98,7 @@ print_gist_file(gcli_gist_file const *const file) } static void -print_gist(enum gcli_output_flags const flags, gcli_gist const *const gist) +print_gist(enum gcli_output_flags const flags, struct gcli_gist const *const gist) { (void) flags; @@ -125,7 +125,7 @@ print_gist(enum gcli_output_flags const flags, gcli_gist const *const gist) static void gcli_print_gists_long(enum gcli_output_flags const flags, - gcli_gist_list const *const list, int const max) + struct gcli_gist_list const *const list, int const max) { size_t n; @@ -145,7 +145,7 @@ gcli_print_gists_long(enum gcli_output_flags const flags, static void gcli_print_gists_short(enum gcli_output_flags const flags, - gcli_gist_list const *const list, int const max) + struct gcli_gist_list const *const list, int const max) { size_t n; gcli_tbl table; @@ -191,7 +191,7 @@ gcli_print_gists_short(enum gcli_output_flags const flags, void gcli_print_gists(enum gcli_output_flags const flags, - gcli_gist_list const *const list, int const max) + struct gcli_gist_list const *const list, int const max) { if (list->gists_size == 0) { puts("No Gists"); @@ -211,8 +211,8 @@ subcommand_gist_get(int argc, char *argv[]) char const *gist_id = shift(&argc, &argv); char const *file_name = shift(&argc, &argv); - gcli_gist gist = {0}; - gcli_gist_file *file = NULL; + struct gcli_gist gist = {0}; + struct gcli_gist_file *file = NULL; if (gcli_get_gist(g_clictx, gist_id, &gist) < 0) errx(1, "gcli: error: failed to get gist: %s", gcli_get_error(g_clictx)); @@ -243,7 +243,7 @@ static int subcommand_gist_create(int argc, char *argv[]) { int ch; - gcli_new_gist opts = {0}; + struct gcli_new_gist opts = {0}; char const *file = NULL; struct option const options[] = { @@ -354,7 +354,7 @@ subcommand_gists(int argc, char *argv[]) { int ch; char const *user = NULL; - gcli_gist_list gists = {0}; + struct gcli_gist_list gists = {0}; int count = 30; enum gcli_output_flags flags = 0; diff --git a/src/github/gists.c b/src/github/gists.c index 9a377aea..4b74f1cf 100644 --- a/src/github/gists.c +++ b/src/github/gists.c @@ -42,7 +42,7 @@ /* /!\ Before changing this, see comment in gists.h /!\ */ int parse_github_gist_files_idiot_hack(struct gcli_ctx *ctx, json_stream *stream, - gcli_gist *const gist) + struct gcli_gist *const gist) { (void) ctx; @@ -56,7 +56,7 @@ parse_github_gist_files_idiot_hack(struct gcli_ctx *ctx, json_stream *stream, while ((next = json_next(stream)) == JSON_STRING) { gist->files = realloc(gist->files, sizeof(*gist->files) * (gist->files_size + 1)); - gcli_gist_file *it = &gist->files[gist->files_size++]; + struct gcli_gist_file *it = &gist->files[gist->files_size++]; if (parse_github_gist_file(ctx, stream, it) < 0) return -1; } @@ -69,7 +69,7 @@ parse_github_gist_files_idiot_hack(struct gcli_ctx *ctx, json_stream *stream, int gcli_get_gists(struct gcli_ctx *ctx, char const *user, int const max, - gcli_gist_list *const list) + struct gcli_gist_list *const list) { char *url = NULL; gcli_fetch_list_ctx fl = { @@ -88,7 +88,7 @@ gcli_get_gists(struct gcli_ctx *ctx, char const *user, int const max, } int -gcli_get_gist(struct gcli_ctx *ctx, char const *gist_id, gcli_gist *out) +gcli_get_gist(struct gcli_ctx *ctx, char const *gist_id, struct gcli_gist *out) { char *url = NULL; gcli_fetch_buffer buffer = {0}; @@ -134,7 +134,7 @@ read_file(FILE *f, char **out) } int -gcli_create_gist(struct gcli_ctx *ctx, gcli_new_gist opts) +gcli_create_gist(struct gcli_ctx *ctx, struct gcli_new_gist opts) { char *url = NULL; char *post_data = NULL; @@ -201,7 +201,7 @@ gcli_delete_gist(struct gcli_ctx *ctx, char const *gist_id) } void -gcli_gist_free(gcli_gist *g) +gcli_gist_free(struct gcli_gist *g) { free(g->id); free(g->owner); @@ -223,7 +223,7 @@ gcli_gist_free(gcli_gist *g) } void -gcli_gists_free(gcli_gist_list *const list) +gcli_gists_free(struct gcli_gist_list *const list) { for (size_t i = 0; i < list->gists_size; ++i) gcli_gist_free(&list->gists[i]); diff --git a/templates/github/gists.t b/templates/github/gists.t index 970563db..dd771fbc 100644 --- a/templates/github/gists.t +++ b/templates/github/gists.t @@ -2,7 +2,7 @@ include "gcli/json_util.h"; include "gcli/github/gists.h"; parser github_gist_file is -object of gcli_gist_file with +object of struct gcli_gist_file with ("filename" => filename as string, "language" => language as string, "raw_url" => url as string, @@ -10,7 +10,7 @@ object of gcli_gist_file with "type" => type as string); parser github_gist is -object of gcli_gist with +object of struct gcli_gist with ("owner" => owner as user, "html_url" => url as string, "id" => id as string, @@ -19,5 +19,5 @@ object of gcli_gist with "description" => description as string, "files" => use parse_github_gist_files_idiot_hack); -parser github_gists is array of gcli_gist +parser github_gists is array of struct gcli_gist use parse_github_gist; From 07eccb7a27d8be2a08a00a2f54362ea35ea2484f Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 5 Jan 2024 20:51:58 +0100 Subject: [PATCH 106/158] remove struct typedef for gcli_tblcoldef --- include/gcli/cmd/table.h | 3 +-- src/cmd/ci.c | 2 +- src/cmd/config.c | 2 +- src/cmd/forks.c | 2 +- src/cmd/gists.c | 2 +- src/cmd/issues.c | 4 ++-- src/cmd/labels.c | 2 +- src/cmd/milestones.c | 2 +- src/cmd/pipelines.c | 4 ++-- src/cmd/pulls.c | 4 ++-- src/cmd/releases.c | 2 +- src/cmd/repos.c | 2 +- src/cmd/snippets.c | 2 +- src/cmd/table.c | 8 ++++---- 14 files changed, 20 insertions(+), 21 deletions(-) diff --git a/include/gcli/cmd/table.h b/include/gcli/cmd/table.h index d0d5d2fd..2e36155d 100644 --- a/include/gcli/cmd/table.h +++ b/include/gcli/cmd/table.h @@ -41,7 +41,6 @@ #include -typedef struct gcli_tblcoldef gcli_tblcoldef; typedef void *gcli_tbl; typedef void *gcli_dict; @@ -81,7 +80,7 @@ struct gcli_tblcoldef { }; /* Init a table printer */ -gcli_tbl gcli_tbl_begin(gcli_tblcoldef const *cols, +gcli_tbl gcli_tbl_begin(struct gcli_tblcoldef const *cols, size_t cols_size); /* Print the table contents and free all the resources allocated in diff --git a/src/cmd/ci.c b/src/cmd/ci.c index 16ccc209..6516647e 100644 --- a/src/cmd/ci.c +++ b/src/cmd/ci.c @@ -62,7 +62,7 @@ void github_print_checks(struct github_check_list const *const list) { gcli_tbl table; - gcli_tblcoldef cols[] = { + struct gcli_tblcoldef cols[] = { { .name = "ID", .type = GCLI_TBLCOLTYPE_ID, .flags = GCLI_TBLCOL_JUSTIFYR }, { .name = "STATUS", .type = GCLI_TBLCOLTYPE_STRING, .flags = 0 }, { .name = "CONCLUSION", .type = GCLI_TBLCOLTYPE_STRING, .flags = GCLI_TBLCOL_STATECOLOURED }, diff --git a/src/cmd/config.c b/src/cmd/config.c index 852cebd9..7d5aa269 100644 --- a/src/cmd/config.c +++ b/src/cmd/config.c @@ -62,7 +62,7 @@ void gcli_sshkeys_print_keys(gcli_sshkey_list const *list) { gcli_tbl *tbl; - gcli_tblcoldef cols[] = { + struct gcli_tblcoldef cols[] = { { .name = "ID", .type = GCLI_TBLCOLTYPE_ID, .flags = 0 }, { .name = "CREATED", .type = GCLI_TBLCOLTYPE_STRING, .flags = 0 }, { .name = "TITLE", .type = GCLI_TBLCOLTYPE_STRING, .flags = 0 }, diff --git a/src/cmd/forks.c b/src/cmd/forks.c index 53e1a52a..a3cc6d58 100644 --- a/src/cmd/forks.c +++ b/src/cmd/forks.c @@ -67,7 +67,7 @@ gcli_print_forks(enum gcli_output_flags const flags, { size_t n; gcli_tbl table; - gcli_tblcoldef cols[] = { + struct gcli_tblcoldef cols[] = { { .name = "OWNER", .type = GCLI_TBLCOLTYPE_SV, .flags = GCLI_TBLCOL_BOLD }, { .name = "DATE", .type = GCLI_TBLCOLTYPE_SV, .flags = 0 }, { .name = "FORKS", .type = GCLI_TBLCOLTYPE_INT, .flags = GCLI_TBLCOL_JUSTIFYR }, diff --git a/src/cmd/gists.c b/src/cmd/gists.c index d57917cb..e3b6e84e 100644 --- a/src/cmd/gists.c +++ b/src/cmd/gists.c @@ -149,7 +149,7 @@ gcli_print_gists_short(enum gcli_output_flags const flags, { size_t n; gcli_tbl table; - gcli_tblcoldef cols[] = { + struct gcli_tblcoldef cols[] = { { .name = "ID", .type = GCLI_TBLCOLTYPE_SV, .flags = GCLI_TBLCOL_COLOUREXPL }, { .name = "OWNER", .type = GCLI_TBLCOLTYPE_SV, .flags = GCLI_TBLCOL_BOLD }, { .name = "DATE", .type = GCLI_TBLCOLTYPE_SV, .flags = 0 }, diff --git a/src/cmd/issues.c b/src/cmd/issues.c index 01dfbdde..f1b4592e 100644 --- a/src/cmd/issues.c +++ b/src/cmd/issues.c @@ -90,7 +90,7 @@ gcli_print_issues(enum gcli_output_flags const flags, { int n, pruned = 0; gcli_tbl table; - gcli_tblcoldef cols[] = { + struct gcli_tblcoldef cols[] = { { .name = "NUMBER", .type = GCLI_TBLCOLTYPE_ID, .flags = GCLI_TBLCOL_JUSTIFYR }, { .name = "NOTES", .type = GCLI_TBLCOLTYPE_INT, .flags = GCLI_TBLCOL_JUSTIFYR }, { .name = "STATE", .type = GCLI_TBLCOLTYPE_STRING, .flags = GCLI_TBLCOL_STATECOLOURED }, @@ -610,7 +610,7 @@ static void gcli_print_attachments(struct gcli_attachment_list const *const list) { gcli_tbl tbl; - gcli_tblcoldef columns[] = { + struct gcli_tblcoldef columns[] = { { .name = "ID", .type = GCLI_TBLCOLTYPE_ID, .flags = GCLI_TBLCOL_JUSTIFYR }, { .name = "AUTHOR", .type = GCLI_TBLCOLTYPE_STRING, .flags = GCLI_TBLCOL_BOLD }, { .name = "CREATED", .type = GCLI_TBLCOLTYPE_STRING, .flags = 0 }, diff --git a/src/cmd/labels.c b/src/cmd/labels.c index 339c3d58..1282cabf 100644 --- a/src/cmd/labels.c +++ b/src/cmd/labels.c @@ -66,7 +66,7 @@ gcli_labels_print(gcli_label_list const *const list, int const max) { size_t n; gcli_tbl table; - gcli_tblcoldef cols[] = { + struct gcli_tblcoldef cols[] = { { .name = "ID", .type = GCLI_TBLCOLTYPE_ID, .flags = GCLI_TBLCOL_JUSTIFYR }, { .name = "", .type = GCLI_TBLCOLTYPE_STRING, .flags = GCLI_TBLCOL_256COLOUR|GCLI_TBLCOL_TIGHT }, { .name = "NAME", .type = GCLI_TBLCOLTYPE_STRING, .flags = 0 }, diff --git a/src/cmd/milestones.c b/src/cmd/milestones.c index dc0a9731..a6bb3412 100644 --- a/src/cmd/milestones.c +++ b/src/cmd/milestones.c @@ -68,7 +68,7 @@ gcli_print_milestones(gcli_milestone_list const *const list, int max) { size_t n; gcli_tbl tbl; - gcli_tblcoldef cols[] = { + struct gcli_tblcoldef cols[] = { { .name = "ID", .type = GCLI_TBLCOLTYPE_ID, .flags = GCLI_TBLCOL_JUSTIFYR }, { .name = "STATE", .type = GCLI_TBLCOLTYPE_STRING, .flags = GCLI_TBLCOL_STATECOLOURED }, { .name = "CREATED", .type = GCLI_TBLCOLTYPE_STRING, .flags = 0 }, diff --git a/src/cmd/pipelines.c b/src/cmd/pipelines.c index 500e8a96..66015704 100644 --- a/src/cmd/pipelines.c +++ b/src/cmd/pipelines.c @@ -88,7 +88,7 @@ void gitlab_print_pipelines(gitlab_pipeline_list const *const list) { gcli_tbl table; - gcli_tblcoldef cols[] = { + struct gcli_tblcoldef cols[] = { { .name = "ID", .type = GCLI_TBLCOLTYPE_ID, .flags = GCLI_TBLCOL_JUSTIFYR }, { .name = "STATUS", .type = GCLI_TBLCOLTYPE_STRING, .flags = GCLI_TBLCOL_STATECOLOURED }, { .name = "CREATED", .type = GCLI_TBLCOLTYPE_STRING, .flags = 0 }, @@ -137,7 +137,7 @@ void gitlab_print_jobs(gitlab_job_list const *const list) { gcli_tbl table; - gcli_tblcoldef cols[] = { + struct gcli_tblcoldef cols[] = { { .name = "ID", .type = GCLI_TBLCOLTYPE_ID, .flags = GCLI_TBLCOL_JUSTIFYR }, { .name = "NAME", .type = GCLI_TBLCOLTYPE_STRING, .flags = 0 }, { .name = "STATUS", .type = GCLI_TBLCOLTYPE_STRING, .flags = GCLI_TBLCOL_STATECOLOURED }, diff --git a/src/cmd/pulls.c b/src/cmd/pulls.c index 2489617f..5d01beaa 100644 --- a/src/cmd/pulls.c +++ b/src/cmd/pulls.c @@ -107,7 +107,7 @@ gcli_print_pulls(enum gcli_output_flags const flags, { int n; gcli_tbl table; - gcli_tblcoldef cols[] = { + struct gcli_tblcoldef cols[] = { { .name = "NUMBER", .type = GCLI_TBLCOLTYPE_ID, .flags = GCLI_TBLCOL_JUSTIFYR }, { .name = "STATE", .type = GCLI_TBLCOLTYPE_STRING, .flags = GCLI_TBLCOL_STATECOLOURED }, { .name = "MERGED", .type = GCLI_TBLCOLTYPE_BOOL, .flags = 0 }, @@ -309,7 +309,7 @@ void gcli_print_commits(gcli_commit_list const *const list) { gcli_tbl table; - gcli_tblcoldef cols[] = { + struct gcli_tblcoldef cols[] = { { .name = "SHA", .type = GCLI_TBLCOLTYPE_STRING, .flags = GCLI_TBLCOL_COLOUREXPL }, { .name = "AUTHOR", .type = GCLI_TBLCOLTYPE_STRING, .flags = GCLI_TBLCOL_BOLD }, { .name = "EMAIL", .type = GCLI_TBLCOLTYPE_STRING, .flags = 0 }, diff --git a/src/cmd/releases.c b/src/cmd/releases.c index 4dc8d7e3..c7e456cf 100644 --- a/src/cmd/releases.c +++ b/src/cmd/releases.c @@ -130,7 +130,7 @@ gcli_releases_print_short(enum gcli_output_flags const flags, { size_t n; gcli_tbl table; - gcli_tblcoldef cols[] = { + struct gcli_tblcoldef cols[] = { { .name = "ID", .type = GCLI_TBLCOLTYPE_STRING, .flags = 0 }, { .name = "DATE", .type = GCLI_TBLCOLTYPE_STRING, .flags = 0 }, { .name = "DRAFT", .type = GCLI_TBLCOLTYPE_BOOL, .flags = 0 }, diff --git a/src/cmd/repos.c b/src/cmd/repos.c index 748a883a..e35e411c 100644 --- a/src/cmd/repos.c +++ b/src/cmd/repos.c @@ -71,7 +71,7 @@ gcli_print_repos(enum gcli_output_flags const flags, { size_t n; gcli_tbl table; - gcli_tblcoldef cols[] = { + struct gcli_tblcoldef cols[] = { { .name = "FORK", .type = GCLI_TBLCOLTYPE_BOOL, .flags = 0 }, { .name = "VISBLTY", .type = GCLI_TBLCOLTYPE_STRING, .flags = 0 }, { .name = "DATE", .type = GCLI_TBLCOLTYPE_STRING, .flags = 0 }, diff --git a/src/cmd/snippets.c b/src/cmd/snippets.c index 2a91ff15..a2a7c358 100644 --- a/src/cmd/snippets.c +++ b/src/cmd/snippets.c @@ -105,7 +105,7 @@ gcli_print_snippets_short(enum gcli_output_flags const flags, { int n; gcli_tbl table; - gcli_tblcoldef cols[] = { + struct gcli_tblcoldef cols[] = { { .name = "ID", .type = GCLI_TBLCOLTYPE_ID, .flags = GCLI_TBLCOL_JUSTIFYR }, { .name = "DATE", .type = GCLI_TBLCOLTYPE_STRING, .flags = 0 }, { .name = "VISIBILITY", .type = GCLI_TBLCOLTYPE_STRING, .flags = 0 }, diff --git a/src/cmd/table.c b/src/cmd/table.c index 0d413d6b..fa97de8a 100644 --- a/src/cmd/table.c +++ b/src/cmd/table.c @@ -45,9 +45,9 @@ struct gcli_tblrow; /* Internal state of a table printer. We return a handle to it in * gcli_table_init. */ struct gcli_tbl { - gcli_tblcoldef const *cols; /* user provided column definitons */ - int *col_widths; /* minimum width of the columns */ - size_t cols_size; /* size of above arrays */ + struct gcli_tblcoldef const *cols; /* user provided column definitons */ + int *col_widths; /* minimum width of the columns */ + size_t cols_size; /* size of above arrays */ struct gcli_tblrow *rows; /* list of rows */ size_t rows_size; /* number of rows */ @@ -76,7 +76,7 @@ table_pushrow(struct gcli_tbl *const table, struct gcli_tblrow row) /** Initialize the internal state structure of the table printer. */ gcli_tbl -gcli_tbl_begin(gcli_tblcoldef const *const cols, size_t const cols_size) +gcli_tbl_begin(struct gcli_tblcoldef const *const cols, size_t const cols_size) { struct gcli_tbl *tbl; From b28cabcb105dd19b3a6b89037575ab18ee756a71 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 5 Jan 2024 20:55:40 +0100 Subject: [PATCH 107/158] Remove typedef for gcli_fetch_buffer --- include/gcli/bugzilla/api.h | 2 +- include/gcli/bugzilla/bugs.h | 2 +- include/gcli/curl.h | 13 ++++++------ include/gcli/forges.h | 6 +++--- include/gcli/gitea/comments.h | 2 +- include/gcli/gitea/issues.h | 2 +- include/gcli/github/api.h | 2 +- include/gcli/github/comments.h | 2 +- include/gcli/github/issues.h | 2 +- include/gcli/gitlab/api.h | 2 +- include/gcli/gitlab/comments.h | 2 +- include/gcli/gitlab/issues.h | 2 +- src/bugzilla/api.c | 2 +- src/bugzilla/attachments.c | 2 +- src/bugzilla/bugs.c | 12 ++++++------ src/cmd/api.c | 2 +- src/curl.c | 36 +++++++++++++++++----------------- src/gitea/comments.c | 2 +- src/gitea/issues.c | 2 +- src/gitea/milestones.c | 2 +- src/gitea/releases.c | 6 +++--- src/github/api.c | 2 +- src/github/checks.c | 2 +- src/github/comments.c | 2 +- src/github/gists.c | 6 +++--- src/github/issues.c | 4 ++-- src/github/labels.c | 2 +- src/github/milestones.c | 2 +- src/github/pulls.c | 4 ++-- src/github/releases.c | 6 +++--- src/github/repos.c | 2 +- src/gitlab/api.c | 4 ++-- src/gitlab/comments.c | 2 +- src/gitlab/issues.c | 4 ++-- src/gitlab/labels.c | 2 +- src/gitlab/merge_requests.c | 6 +++--- src/gitlab/milestones.c | 2 +- src/gitlab/pipelines.c | 2 +- src/gitlab/repos.c | 4 ++-- src/gitlab/sshkeys.c | 2 +- 40 files changed, 82 insertions(+), 83 deletions(-) diff --git a/include/gcli/bugzilla/api.h b/include/gcli/bugzilla/api.h index e6aafd10..79dc6082 100644 --- a/include/gcli/bugzilla/api.h +++ b/include/gcli/bugzilla/api.h @@ -36,6 +36,6 @@ #include -char const *bugzilla_api_error_string(struct gcli_ctx *ctx, gcli_fetch_buffer *it); +char const *bugzilla_api_error_string(struct gcli_ctx *ctx, struct gcli_fetch_buffer *it); #endif /* GCLI_BUGZILLA_API_H */ diff --git a/include/gcli/bugzilla/bugs.h b/include/gcli/bugzilla/bugs.h index 4874f2aa..6ae08011 100644 --- a/include/gcli/bugzilla/bugs.h +++ b/include/gcli/bugzilla/bugs.h @@ -57,6 +57,6 @@ int bugzilla_bug_get_attachments(struct gcli_ctx *ctx, char const *const product struct gcli_attachment_list *const out); int bugzilla_bug_submit(struct gcli_ctx *ctx, gcli_submit_issue_options opts, - gcli_fetch_buffer *out); + struct gcli_fetch_buffer *out); #endif /* GCLI_BUGZILLA_BUGS_H */ diff --git a/include/gcli/curl.h b/include/gcli/curl.h index 3b67e79d..27353c67 100644 --- a/include/gcli/curl.h +++ b/include/gcli/curl.h @@ -46,12 +46,11 @@ typedef int (*parsefn)(struct gcli_ctx *, json_stream *stream, void *list, size_t *listsize); typedef void (*filterfn)(void *list, size_t *listsize, void const *userdata); -typedef struct gcli_fetch_buffer gcli_fetch_buffer; typedef struct gcli_fetch_list_ctx gcli_fetch_list_ctx; struct gcli_fetch_buffer { - char *data; - size_t length; + char *data; + size_t length; }; struct gcli_fetch_list_ctx { @@ -65,22 +64,22 @@ struct gcli_fetch_list_ctx { }; int gcli_fetch(struct gcli_ctx *ctx, char const *url, char **pagination_next, - gcli_fetch_buffer *out); + struct gcli_fetch_buffer *out); int gcli_curl(struct gcli_ctx *ctx, FILE *stream, char const *url, char const *content_type); int gcli_fetch_with_method(struct gcli_ctx *ctx, char const *method, char const *url, char const *data, - char **pagination_next, gcli_fetch_buffer *out); + char **pagination_next, struct gcli_fetch_buffer *out); int gcli_post_upload(struct gcli_ctx *ctx, char const *url, char const *content_type, void *buffer, size_t buffer_size, - gcli_fetch_buffer *out); + struct gcli_fetch_buffer *out); int gcli_curl_gitea_upload_attachment(struct gcli_ctx *ctx, char const *url, char const *filename, - gcli_fetch_buffer *out); + struct gcli_fetch_buffer *out); int gcli_curl_test_success(struct gcli_ctx *ctx, char const *url); char *gcli_urlencode(char const *); diff --git a/include/gcli/forges.h b/include/gcli/forges.h index 64aecc92..cc5a73d6 100644 --- a/include/gcli/forges.h +++ b/include/gcli/forges.h @@ -60,7 +60,7 @@ struct gcli_forge_descriptor { int (*perform_submit_comment)( struct gcli_ctx *ctx, struct gcli_submit_comment_opts opts, - gcli_fetch_buffer *out); + struct gcli_fetch_buffer *out); /** * List comments on the given issue */ @@ -166,7 +166,7 @@ struct gcli_forge_descriptor { int (*perform_submit_issue)( struct gcli_ctx *ctx, gcli_submit_issue_options opts, - gcli_fetch_buffer *out); + struct gcli_fetch_buffer *out); /** * Change the title of an issue */ @@ -546,7 +546,7 @@ struct gcli_forge_descriptor { * Get the error string from the API */ char const *(*get_api_error_string)( struct gcli_ctx *ctx, - gcli_fetch_buffer *); + struct gcli_fetch_buffer *); /** * A key in the user json object sent by the API that represents diff --git a/include/gcli/gitea/comments.h b/include/gcli/gitea/comments.h index 15991cc9..40520ae0 100644 --- a/include/gcli/gitea/comments.h +++ b/include/gcli/gitea/comments.h @@ -42,6 +42,6 @@ int gitea_get_comments(struct gcli_ctx *ctx, char const *owner, char const *repo int gitea_perform_submit_comment(struct gcli_ctx *ctx, struct gcli_submit_comment_opts opts, - gcli_fetch_buffer *out); + struct gcli_fetch_buffer *out); #endif /* GITEA_COMMENTS_H */ diff --git a/include/gcli/gitea/issues.h b/include/gcli/gitea/issues.h index d52c8261..397d682f 100644 --- a/include/gcli/gitea/issues.h +++ b/include/gcli/gitea/issues.h @@ -45,7 +45,7 @@ int gitea_get_issue_summary(struct gcli_ctx *ctx, char const *owner, gcli_issue *out); int gitea_submit_issue(struct gcli_ctx *ctx, gcli_submit_issue_options opts, - gcli_fetch_buffer *out); + struct gcli_fetch_buffer *out); int gitea_issue_close(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue_number); diff --git a/include/gcli/github/api.h b/include/gcli/github/api.h index 6558f951..84737e83 100644 --- a/include/gcli/github/api.h +++ b/include/gcli/github/api.h @@ -36,6 +36,6 @@ #include -char const *github_api_error_string(struct gcli_ctx *ctx, gcli_fetch_buffer *it); +char const *github_api_error_string(struct gcli_ctx *ctx, struct gcli_fetch_buffer *it); #endif /* GITHUB_API_H */ diff --git a/include/gcli/github/comments.h b/include/gcli/github/comments.h index b9c726d1..14a59aef 100644 --- a/include/gcli/github/comments.h +++ b/include/gcli/github/comments.h @@ -39,7 +39,7 @@ int github_perform_submit_comment(struct gcli_ctx *ctx, struct gcli_submit_comment_opts opts, - gcli_fetch_buffer *out); + struct gcli_fetch_buffer *out); int github_get_comments(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue, struct gcli_comment_list *out); diff --git a/include/gcli/github/issues.h b/include/gcli/github/issues.h index 5aef07a5..2db3ab62 100644 --- a/include/gcli/github/issues.h +++ b/include/gcli/github/issues.h @@ -56,7 +56,7 @@ int github_issue_reopen(struct gcli_ctx *ctx, char const *owner, int github_perform_submit_issue(struct gcli_ctx *ctx, gcli_submit_issue_options opts, - gcli_fetch_buffer *out); + struct gcli_fetch_buffer *out); int github_issue_assign(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue_number, diff --git a/include/gcli/gitlab/api.h b/include/gcli/gitlab/api.h index c6e28803..be6cfdeb 100644 --- a/include/gcli/gitlab/api.h +++ b/include/gcli/gitlab/api.h @@ -36,7 +36,7 @@ #include -char const *gitlab_api_error_string(struct gcli_ctx *ctx, gcli_fetch_buffer *buf); +char const *gitlab_api_error_string(struct gcli_ctx *ctx, struct gcli_fetch_buffer *buf); int gitlab_user_id(struct gcli_ctx *ctx, char const *user_name); #endif /* GITLAB_API_H */ diff --git a/include/gcli/gitlab/comments.h b/include/gcli/gitlab/comments.h index 254c5118..46646435 100644 --- a/include/gcli/gitlab/comments.h +++ b/include/gcli/gitlab/comments.h @@ -39,7 +39,7 @@ int gitlab_perform_submit_comment(struct gcli_ctx *ctx, struct gcli_submit_comment_opts opts, - gcli_fetch_buffer *out); + struct gcli_fetch_buffer *out); int gitlab_get_issue_comments(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue, diff --git a/include/gcli/gitlab/issues.h b/include/gcli/gitlab/issues.h index cf69f9be..4fc95fa3 100644 --- a/include/gcli/gitlab/issues.h +++ b/include/gcli/gitlab/issues.h @@ -60,7 +60,7 @@ int gitlab_issue_assign(struct gcli_ctx *ctx, char const *owner, int gitlab_perform_submit_issue(struct gcli_ctx *ctx, gcli_submit_issue_options opts, - gcli_fetch_buffer *out); + struct gcli_fetch_buffer *out); int gitlab_issue_add_labels(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue, diff --git a/src/bugzilla/api.c b/src/bugzilla/api.c index cd313902..6faa919b 100644 --- a/src/bugzilla/api.c +++ b/src/bugzilla/api.c @@ -35,7 +35,7 @@ #include char const * -bugzilla_api_error_string(struct gcli_ctx *ctx, gcli_fetch_buffer *const buf) +bugzilla_api_error_string(struct gcli_ctx *ctx, struct gcli_fetch_buffer *const buf) { json_stream stream = {0}; int rc; diff --git a/src/bugzilla/attachments.c b/src/bugzilla/attachments.c index c8c63041..f9a6146a 100644 --- a/src/bugzilla/attachments.c +++ b/src/bugzilla/attachments.c @@ -40,7 +40,7 @@ bugzilla_attachment_get_content(struct gcli_ctx *ctx, gcli_id attachment_id, { int rc = 0; char *url; - gcli_fetch_buffer buffer = {0}; + struct gcli_fetch_buffer buffer = {0}; json_stream stream = {0}; struct gcli_attachment attachment = {0}; diff --git a/src/bugzilla/bugs.c b/src/bugzilla/bugs.c index 78a3b6e9..28d2d7cf 100644 --- a/src/bugzilla/bugs.c +++ b/src/bugzilla/bugs.c @@ -47,7 +47,7 @@ bugzilla_get_bugs(struct gcli_ctx *ctx, char const *product, char const *compone gcli_issue_list *out) { char *url, *e_product = NULL, *e_component = NULL, *e_author = NULL; - gcli_fetch_buffer buffer = {0}; + struct gcli_fetch_buffer buffer = {0}; int rc = 0; if (product) { @@ -105,7 +105,7 @@ bugzilla_bug_get_comments(struct gcli_ctx *const ctx, char const *const product, struct gcli_comment_list *out) { int rc = 0; - gcli_fetch_buffer buffer = {0}; + struct gcli_fetch_buffer buffer = {0}; json_stream stream = {0}; char *url = NULL; @@ -135,7 +135,7 @@ static int bugzilla_bug_get_op(struct gcli_ctx *ctx, gcli_id const bug_id, char **out) { int rc = 0; - gcli_fetch_buffer buffer = {0}; + struct gcli_fetch_buffer buffer = {0}; json_stream stream = {0}; char *url = NULL; @@ -164,7 +164,7 @@ bugzilla_get_bug(struct gcli_ctx *ctx, char const *product, { int rc = 0; char *url; - gcli_fetch_buffer buffer = {0}; + struct gcli_fetch_buffer buffer = {0}; gcli_issue_list list = {0}; json_stream stream = {0}; @@ -219,7 +219,7 @@ bugzilla_bug_get_attachments(struct gcli_ctx *ctx, char const *const product, { int rc = 0; char *url = NULL; - gcli_fetch_buffer buffer = {0}; + struct gcli_fetch_buffer buffer = {0}; json_stream stream = {0}; (void) product; @@ -276,7 +276,7 @@ add_extra_options(gcli_nvlist const *list, gcli_jsongen *gen) int bugzilla_bug_submit(struct gcli_ctx *ctx, gcli_submit_issue_options opts, - gcli_fetch_buffer *out) + struct gcli_fetch_buffer *out) { char *payload = NULL, *url = NULL; char *token; /* bugzilla wants the api token as a parameter in the url or the json payload */ diff --git a/src/cmd/api.c b/src/cmd/api.c index dc58a343..55953448 100644 --- a/src/cmd/api.c +++ b/src/cmd/api.c @@ -64,7 +64,7 @@ fetch_all(char *_url) url = _url; do { - gcli_fetch_buffer buffer = {0}; + struct gcli_fetch_buffer buffer = {0}; if (gcli_fetch(g_clictx, url, &next_url, &buffer) < 0) errx(1, "gcli: error: failed to fetch data: %s", diff --git a/src/curl.c b/src/curl.c index 59e670af..2baf235a 100644 --- a/src/curl.c +++ b/src/curl.c @@ -87,7 +87,7 @@ gcli_curl_ensure(struct gcli_ctx *ctx) * appropriate error message and exit */ static int gcli_curl_check_api_error(struct gcli_ctx *ctx, CURLcode code, char const *url, - gcli_fetch_buffer *const result) + struct gcli_fetch_buffer *const result) { long status_code = 0; @@ -108,7 +108,7 @@ gcli_curl_check_api_error(struct gcli_ctx *ctx, CURLcode code, char const *url, return 0; } -/* Callback for writing data into the gcli_fetch_buffer passed by +/* Callback for writing data into the struct gcli_fetch_buffer passed by * calling routines */ static size_t fetch_write_callback(char *in, size_t size, size_t nmemb, void *data) @@ -116,7 +116,7 @@ fetch_write_callback(char *in, size_t size, size_t nmemb, void *data) /* the user may have passed null indicating that we do not care * about the result body of the request. */ if (data) { - gcli_fetch_buffer *out = data; + struct gcli_fetch_buffer *out = data; out->data = realloc(out->data, out->length + size * nmemb); memcpy(&(out->data[out->length]), in, size * nmemb); @@ -129,10 +129,10 @@ fetch_write_callback(char *in, size_t size, size_t nmemb, void *data) /* Plain HTTP get request. * * pagination_next returns the next url to query for paged results. - * Results are placed into the gcli_fetch_buffer. */ + * Results are placed into the struct gcli_fetch_buffer. */ int gcli_fetch(struct gcli_ctx *ctx, char const *url, char **const pagination_next, - gcli_fetch_buffer *out) + struct gcli_fetch_buffer *out) { return gcli_fetch_with_method(ctx, "GET", url, NULL, pagination_next, out); } @@ -159,7 +159,7 @@ int gcli_curl_test_success(struct gcli_ctx *ctx, char const *url) { CURLcode ret; - gcli_fetch_buffer buffer = {0}; + struct gcli_fetch_buffer buffer = {0}; long status_code; bool is_success = true; int rc = 0; @@ -218,7 +218,7 @@ gcli_curl(struct gcli_ctx *ctx, FILE *stream, char const *url, { CURLcode ret; struct curl_slist *headers; - gcli_fetch_buffer buffer = {0}; + struct gcli_fetch_buffer buffer = {0}; char *auth_header = NULL; int rc = 0; @@ -353,16 +353,16 @@ parse_link_header(char *_header) int gcli_fetch_with_method( struct gcli_ctx *ctx, - char const *method, /* HTTP method. e.g. POST, GET, DELETE etc. */ - char const *url, /* Endpoint */ - char const *data, /* Form data */ - char **const pagination_next, /* Next URL for pagination */ - gcli_fetch_buffer *const out) /* output buffer */ + char const *method, /* HTTP method. e.g. POST, GET, DELETE etc. */ + char const *url, /* Endpoint */ + char const *data, /* Form data */ + char **const pagination_next, /* Next URL for pagination */ + struct gcli_fetch_buffer *const out) /* output buffer */ { CURLcode ret; struct curl_slist *headers; - gcli_fetch_buffer tmp = {0}; /* used for error codes when out is NULL */ - gcli_fetch_buffer *buf = NULL; + struct gcli_fetch_buffer tmp = {0}; /* used for error codes when out is NULL */ + struct gcli_fetch_buffer *buf = NULL; char *link_header = NULL; int rc = 0; @@ -388,7 +388,7 @@ gcli_fetch_with_method( * user is not interested in the result we use a temporary buffer * for proper error reporting. */ if (out) { - *out = (gcli_fetch_buffer) {0}; + *out = (struct gcli_fetch_buffer) {0}; buf = out; } else { buf = &tmp; @@ -457,7 +457,7 @@ gcli_fetch_with_method( int gcli_post_upload(struct gcli_ctx *ctx, char const *url, char const *content_type, void *buffer, size_t const buffer_size, - gcli_fetch_buffer *const out) + struct gcli_fetch_buffer *const out) { CURLcode ret; struct curl_slist *headers; @@ -525,7 +525,7 @@ gcli_post_upload(struct gcli_ctx *ctx, char const *url, char const *content_type int gcli_curl_gitea_upload_attachment(struct gcli_ctx *ctx, char const *url, char const *filename, - gcli_fetch_buffer *const out) + struct gcli_fetch_buffer *const out) { CURLcode ret; curl_mime *mime; @@ -664,7 +664,7 @@ gcli_fetch_list(struct gcli_ctx *ctx, char *url, gcli_fetch_list_ctx *fl) int rc; do { - gcli_fetch_buffer buffer = {0}; + struct gcli_fetch_buffer buffer = {0}; rc = gcli_fetch(ctx, url, &next_url, &buffer); if (rc == 0) { diff --git a/src/gitea/comments.c b/src/gitea/comments.c index b0043966..1b9b6653 100644 --- a/src/gitea/comments.c +++ b/src/gitea/comments.c @@ -39,7 +39,7 @@ gitea_get_comments(struct gcli_ctx *ctx, char const *owner, char const *repo, int gitea_perform_submit_comment(struct gcli_ctx *ctx, struct gcli_submit_comment_opts opts, - gcli_fetch_buffer *const out) + struct gcli_fetch_buffer *const out) { return github_perform_submit_comment(ctx, opts, out); } diff --git a/src/gitea/issues.c b/src/gitea/issues.c index 6399338c..9e88dd9c 100644 --- a/src/gitea/issues.c +++ b/src/gitea/issues.c @@ -56,7 +56,7 @@ gitea_get_issue_summary(struct gcli_ctx *ctx, char const *owner, int gitea_submit_issue(struct gcli_ctx *ctx, gcli_submit_issue_options opts, - gcli_fetch_buffer *const out) + struct gcli_fetch_buffer *const out) { return github_perform_submit_issue(ctx,opts, out); } diff --git a/src/gitea/milestones.c b/src/gitea/milestones.c index dd6a57a7..a4b533ee 100644 --- a/src/gitea/milestones.c +++ b/src/gitea/milestones.c @@ -71,7 +71,7 @@ gitea_get_milestone(struct gcli_ctx *ctx, char const *const owner, gcli_milestone *const out) { char *url, *e_owner, *e_repo; - gcli_fetch_buffer buffer = {0}; + struct gcli_fetch_buffer buffer = {0}; int rc = 0; e_owner = gcli_urlencode(owner); diff --git a/src/gitea/releases.c b/src/gitea/releases.c index 484e7a2f..f98a6e9a 100644 --- a/src/gitea/releases.c +++ b/src/gitea/releases.c @@ -44,7 +44,7 @@ gitea_get_releases(struct gcli_ctx *ctx, char const *owner, char const *repo, } static void -gitea_parse_release(struct gcli_ctx *ctx, gcli_fetch_buffer const *const buffer, +gitea_parse_release(struct gcli_ctx *ctx, struct gcli_fetch_buffer const *const buffer, struct gcli_release *const out) { json_stream stream = {0}; @@ -59,7 +59,7 @@ gitea_upload_release_asset(struct gcli_ctx *ctx, char *const url, { char *e_assetname = NULL; char *request = NULL; - gcli_fetch_buffer buffer = {0}; + struct gcli_fetch_buffer buffer = {0}; int rc = 0; e_assetname = gcli_urlencode(asset.name); @@ -78,7 +78,7 @@ int gitea_create_release(struct gcli_ctx *ctx, struct gcli_new_release const *release) { char *e_owner = NULL, *e_repo = NULL, *payload = NULL, *upload_url = NULL, *url = NULL; - gcli_fetch_buffer buffer = {0}; + struct gcli_fetch_buffer buffer = {0}; gcli_jsongen gen = {0}; struct gcli_release response = {0}; int rc = 0; diff --git a/src/github/api.c b/src/github/api.c index 7bc6d78d..689772c3 100644 --- a/src/github/api.c +++ b/src/github/api.c @@ -35,7 +35,7 @@ #include char const * -github_api_error_string(struct gcli_ctx *ctx, gcli_fetch_buffer *const buf) +github_api_error_string(struct gcli_ctx *ctx, struct gcli_fetch_buffer *const buf) { json_stream stream = {0}; int rc; diff --git a/src/github/checks.c b/src/github/checks.c index 8ac51350..c0694fa4 100644 --- a/src/github/checks.c +++ b/src/github/checks.c @@ -44,7 +44,7 @@ int github_get_checks(struct gcli_ctx *ctx, char const *owner, char const *repo, char const *ref, int const max, struct github_check_list *const out) { - gcli_fetch_buffer buffer = {0}; + struct gcli_fetch_buffer buffer = {0}; char *url = NULL, *next_url = NULL; int rc = 0; diff --git a/src/github/comments.c b/src/github/comments.c index 59797d89..e1b5ae34 100644 --- a/src/github/comments.c +++ b/src/github/comments.c @@ -39,7 +39,7 @@ int github_perform_submit_comment(struct gcli_ctx *ctx, struct gcli_submit_comment_opts opts, - gcli_fetch_buffer *out) + struct gcli_fetch_buffer *out) { int rc = 0; gcli_jsongen gen = {0}; diff --git a/src/github/gists.c b/src/github/gists.c index 4b74f1cf..feae9cdb 100644 --- a/src/github/gists.c +++ b/src/github/gists.c @@ -91,7 +91,7 @@ int gcli_get_gist(struct gcli_ctx *ctx, char const *gist_id, struct gcli_gist *out) { char *url = NULL; - gcli_fetch_buffer buffer = {0}; + struct gcli_fetch_buffer buffer = {0}; int rc = 0; url = sn_asprintf("%s/gists/%s", gcli_get_apibase(ctx), gist_id); @@ -138,7 +138,7 @@ gcli_create_gist(struct gcli_ctx *ctx, struct gcli_new_gist opts) { char *url = NULL; char *post_data = NULL; - gcli_fetch_buffer fetch_buffer = {0}; + struct gcli_fetch_buffer fetch_buffer = {0}; sn_sv read_buffer = {0}; sn_sv content = {0}; int rc = 0; @@ -187,7 +187,7 @@ int gcli_delete_gist(struct gcli_ctx *ctx, char const *gist_id) { char *url = NULL; - gcli_fetch_buffer buffer = {0}; + struct gcli_fetch_buffer buffer = {0}; int rc = 0; url = sn_asprintf("%s/gists/%s", gcli_get_apibase(ctx), gist_id); diff --git a/src/github/issues.c b/src/github/issues.c index ad573712..047f6b9f 100644 --- a/src/github/issues.c +++ b/src/github/issues.c @@ -187,7 +187,7 @@ github_get_issue_summary(struct gcli_ctx *ctx, char const *owner, char *url = NULL; char *e_owner = NULL; char *e_repo = NULL; - gcli_fetch_buffer buffer = {0}; + struct gcli_fetch_buffer buffer = {0}; json_stream parser = {0}; int rc = 0; @@ -256,7 +256,7 @@ github_issue_reopen(struct gcli_ctx *ctx, char const *owner, char const *repo, int github_perform_submit_issue(struct gcli_ctx *ctx, gcli_submit_issue_options opts, - gcli_fetch_buffer *out) + struct gcli_fetch_buffer *out) { char *e_owner = NULL, *e_repo = NULL, *payload = NULL, *url = NULL; gcli_jsongen gen = {0}; diff --git a/src/github/labels.c b/src/github/labels.c index 4a0643fd..05ee0140 100644 --- a/src/github/labels.c +++ b/src/github/labels.c @@ -62,7 +62,7 @@ github_create_label(struct gcli_ctx *ctx, char const *owner, char const *repo, { char *url = NULL, *payload = NULL, *e_owner = NULL, *e_repo = NULL, *colour = NULL; - gcli_fetch_buffer buffer = {0}; + struct gcli_fetch_buffer buffer = {0}; gcli_jsongen gen = {0}; int rc = 0; json_stream stream = {0}; diff --git a/src/github/milestones.c b/src/github/milestones.c index de46887e..1a1d01c4 100644 --- a/src/github/milestones.c +++ b/src/github/milestones.c @@ -74,7 +74,7 @@ github_get_milestone(struct gcli_ctx *ctx, char const *const owner, gcli_milestone *const out) { char *url, *e_owner, *e_repo; - gcli_fetch_buffer buffer = {0}; + struct gcli_fetch_buffer buffer = {0}; int rc = 0; e_owner = gcli_urlencode(owner); diff --git a/src/github/pulls.c b/src/github/pulls.c index 242c0131..45e5859c 100644 --- a/src/github/pulls.c +++ b/src/github/pulls.c @@ -302,7 +302,7 @@ int github_perform_submit_pull(struct gcli_ctx *ctx, gcli_submit_pull_options opts) { char *url = NULL, *payload = NULL, *e_owner = NULL, *e_repo = NULL; - gcli_fetch_buffer fetch_buffer = {0}; + struct gcli_fetch_buffer fetch_buffer = {0}; gcli_jsongen gen = {0}; int rc = 0; @@ -404,7 +404,7 @@ github_get_pull(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const pr, gcli_pull *const out) { int rc = 0; - gcli_fetch_buffer json_buffer = {0}; + struct gcli_fetch_buffer json_buffer = {0}; char *url = NULL, *e_owner = NULL, *e_repo = NULL; e_owner = gcli_urlencode(owner); diff --git a/src/github/releases.c b/src/github/releases.c index 70f14bb3..677d6253 100644 --- a/src/github/releases.c +++ b/src/github/releases.c @@ -70,7 +70,7 @@ github_get_releases(struct gcli_ctx *ctx, char const *owner, char const *repo, } static void -github_parse_single_release(struct gcli_ctx *ctx, gcli_fetch_buffer buffer, +github_parse_single_release(struct gcli_ctx *ctx, struct gcli_fetch_buffer buffer, struct gcli_release *const out) { struct json_stream stream = {0}; @@ -101,7 +101,7 @@ github_upload_release_asset(struct gcli_ctx *ctx, char const *url, { char *req = NULL; sn_sv file_content = {0}; - gcli_fetch_buffer buffer = {0}; + struct gcli_fetch_buffer buffer = {0}; int rc = 0; file_content.length = sn_mmap_file(asset.path, (void **)&file_content.data); @@ -130,7 +130,7 @@ github_create_release(struct gcli_ctx *ctx, struct gcli_new_release const *relea { char *url = NULL, *e_owner = NULL, *e_repo = NULL, *upload_url = NULL, *payload = NULL; - gcli_fetch_buffer buffer = {0}; + struct gcli_fetch_buffer buffer = {0}; gcli_jsongen gen = {0}; struct gcli_release response = {0}; int rc = 0; diff --git a/src/github/repos.c b/src/github/repos.c index d88511f1..e990e780 100644 --- a/src/github/repos.c +++ b/src/github/repos.c @@ -134,7 +134,7 @@ github_repo_create(struct gcli_ctx *ctx, gcli_repo_create_options const *options gcli_repo *const out) { char *url, *payload; - gcli_fetch_buffer buffer = {0}; + struct gcli_fetch_buffer buffer = {0}; gcli_jsongen gen = {0}; struct json_stream stream = {0}; int rc = 0; diff --git a/src/gitlab/api.c b/src/gitlab/api.c index 2cab03c6..9e709022 100644 --- a/src/gitlab/api.c +++ b/src/gitlab/api.c @@ -35,7 +35,7 @@ #include char const * -gitlab_api_error_string(struct gcli_ctx *ctx, gcli_fetch_buffer *const buf) +gitlab_api_error_string(struct gcli_ctx *ctx, struct gcli_fetch_buffer *const buf) { char *msg = NULL; int rc; @@ -62,7 +62,7 @@ gitlab_api_error_string(struct gcli_ctx *ctx, gcli_fetch_buffer *const buf) int gitlab_user_id(struct gcli_ctx *ctx, char const *user_name) { - gcli_fetch_buffer buffer = {0}; + struct gcli_fetch_buffer buffer = {0}; struct json_stream stream = {0}; char *url = NULL; char *e_username; diff --git a/src/gitlab/comments.c b/src/gitlab/comments.c index 89ccd3bc..0ce6e69a 100644 --- a/src/gitlab/comments.c +++ b/src/gitlab/comments.c @@ -36,7 +36,7 @@ int gitlab_perform_submit_comment(struct gcli_ctx *ctx, struct gcli_submit_comment_opts opts, - gcli_fetch_buffer *const out) + struct gcli_fetch_buffer *const out) { char *url = NULL, *payload = NULL, *e_owner = NULL, *e_repo = NULL; char const *type = NULL; diff --git a/src/gitlab/issues.c b/src/gitlab/issues.c index 712c775f..2413aca8 100644 --- a/src/gitlab/issues.c +++ b/src/gitlab/issues.c @@ -117,7 +117,7 @@ gitlab_get_issue_summary(struct gcli_ctx *ctx, char const *owner, char *url = NULL; char *e_owner = NULL; char *e_repo = NULL; - gcli_fetch_buffer buffer = {0}; + struct gcli_fetch_buffer buffer = {0}; json_stream parser = {0}; int rc = 0; @@ -198,7 +198,7 @@ gitlab_issue_reopen(struct gcli_ctx *ctx, char const *owner, char const *repo, int gitlab_perform_submit_issue(struct gcli_ctx *ctx, gcli_submit_issue_options opts, - gcli_fetch_buffer *const out) + struct gcli_fetch_buffer *const out) { char *e_owner = NULL, *e_repo = NULL, *url = NULL, *payload = NULL; gcli_jsongen gen = {0}; diff --git a/src/gitlab/labels.c b/src/gitlab/labels.c index f8a83bae..f9db4bd4 100644 --- a/src/gitlab/labels.c +++ b/src/gitlab/labels.c @@ -62,7 +62,7 @@ gitlab_create_label(struct gcli_ctx *ctx, char const *owner, char const *repo, { char *url = NULL, *payload = NULL, *colour_string = NULL, *e_owner = NULL, *e_repo = NULL; - gcli_fetch_buffer buffer = {0}; + struct gcli_fetch_buffer buffer = {0}; gcli_jsongen gen = {0}; int rc = 0; json_stream stream = {0}; diff --git a/src/gitlab/merge_requests.c b/src/gitlab/merge_requests.c index 1b5e7376..a9ddcc1b 100644 --- a/src/gitlab/merge_requests.c +++ b/src/gitlab/merge_requests.c @@ -277,7 +277,7 @@ int gitlab_mr_merge(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const mr_number, enum gcli_merge_flags const flags) { - gcli_fetch_buffer buffer = {0}; + struct gcli_fetch_buffer buffer = {0}; char *url = NULL; char *e_owner = NULL; char *e_repo = NULL; @@ -312,7 +312,7 @@ int gitlab_get_pull(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const pr_number, gcli_pull *const out) { - gcli_fetch_buffer json_buffer = {0}; + struct gcli_fetch_buffer json_buffer = {0}; char *url = NULL; char *e_owner = NULL; char *e_repo = NULL; @@ -623,7 +623,7 @@ gitlab_mr_get_reviewers(struct gcli_ctx *ctx, char const *e_owner, { char *url; int rc; - gcli_fetch_buffer json_buffer = {0}; + struct gcli_fetch_buffer json_buffer = {0}; url = sn_asprintf("%s/projects/%s%%2F%s/merge_requests/%"PRIid, gcli_get_apibase(ctx), e_owner, e_repo, mr); diff --git a/src/gitlab/milestones.c b/src/gitlab/milestones.c index a7b63d63..c6e84cb1 100644 --- a/src/gitlab/milestones.c +++ b/src/gitlab/milestones.c @@ -73,7 +73,7 @@ gitlab_get_milestone(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const milestone, gcli_milestone *const out) { char *url, *e_owner, *e_repo; - gcli_fetch_buffer buffer = {0}; + struct gcli_fetch_buffer buffer = {0}; json_stream stream = {0}; int rc = 0; diff --git a/src/gitlab/pipelines.c b/src/gitlab/pipelines.c index 894338fe..60528469 100644 --- a/src/gitlab/pipelines.c +++ b/src/gitlab/pipelines.c @@ -192,7 +192,7 @@ int gitlab_get_job(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const jid, gitlab_job *const out) { - gcli_fetch_buffer buffer = {0}; + struct gcli_fetch_buffer buffer = {0}; char *url = NULL, *e_owner = NULL, *e_repo = NULL; int rc = 0; diff --git a/src/gitlab/repos.c b/src/gitlab/repos.c index e6e7ee6b..974724f4 100644 --- a/src/gitlab/repos.c +++ b/src/gitlab/repos.c @@ -45,7 +45,7 @@ gitlab_get_repo(struct gcli_ctx *ctx, char const *owner, char const *repo, { /* GET /projects/:id */ char *url = NULL; - gcli_fetch_buffer buffer = {0}; + struct gcli_fetch_buffer buffer = {0}; json_stream stream = {0}; char *e_owner = {0}; char *e_repo = {0}; @@ -141,7 +141,7 @@ gitlab_repo_create(struct gcli_ctx *ctx, gcli_repo_create_options const *options gcli_repo *out) { char *url, *payload; - gcli_fetch_buffer buffer = {0}; + struct gcli_fetch_buffer buffer = {0}; gcli_jsongen gen = {0}; int rc; json_stream stream = {0}; diff --git a/src/gitlab/sshkeys.c b/src/gitlab/sshkeys.c index db727219..e2a289ca 100644 --- a/src/gitlab/sshkeys.c +++ b/src/gitlab/sshkeys.c @@ -63,7 +63,7 @@ gitlab_add_sshkey(struct gcli_ctx *ctx, char const *const title, { char *url, *payload; char *e_title, *e_key; - gcli_fetch_buffer buf = {0}; + struct gcli_fetch_buffer buf = {0}; int rc = 0; url = sn_asprintf("%s/user/keys", gcli_get_apibase(ctx)); From bb6f8b8d4a084e58a2c2e0b3d21c63f18317f25b Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 5 Jan 2024 20:57:48 +0100 Subject: [PATCH 108/158] Remove struct typedef for gcli_fetch_list_ctx --- include/gcli/curl.h | 9 +++++---- src/curl.c | 2 +- src/gitea/milestones.c | 2 +- src/gitea/status.c | 2 +- src/github/comments.c | 2 +- src/github/forks.c | 2 +- src/github/gists.c | 2 +- src/github/issues.c | 2 +- src/github/labels.c | 2 +- src/github/milestones.c | 2 +- src/github/pulls.c | 4 ++-- src/github/releases.c | 2 +- src/github/repos.c | 4 ++-- src/github/status.c | 2 +- src/gitlab/comments.c | 4 ++-- src/gitlab/forks.c | 2 +- src/gitlab/issues.c | 2 +- src/gitlab/labels.c | 2 +- src/gitlab/merge_requests.c | 6 +++--- src/gitlab/milestones.c | 2 +- src/gitlab/pipelines.c | 4 ++-- src/gitlab/releases.c | 2 +- src/gitlab/repos.c | 2 +- src/gitlab/snippets.c | 2 +- src/gitlab/sshkeys.c | 2 +- src/gitlab/status.c | 2 +- 26 files changed, 36 insertions(+), 35 deletions(-) diff --git a/include/gcli/curl.h b/include/gcli/curl.h index 27353c67..b2f13196 100644 --- a/include/gcli/curl.h +++ b/include/gcli/curl.h @@ -46,7 +46,6 @@ typedef int (*parsefn)(struct gcli_ctx *, json_stream *stream, void *list, size_t *listsize); typedef void (*filterfn)(void *list, size_t *listsize, void const *userdata); -typedef struct gcli_fetch_list_ctx gcli_fetch_list_ctx; struct gcli_fetch_buffer { char *data; @@ -69,9 +68,10 @@ int gcli_fetch(struct gcli_ctx *ctx, char const *url, char **pagination_next, int gcli_curl(struct gcli_ctx *ctx, FILE *stream, char const *url, char const *content_type); -int gcli_fetch_with_method(struct gcli_ctx *ctx, char const *method, +int gcli_fetch_with_method(struct gcli_ctx *ctx, char const *method, char const *url, char const *data, - char **pagination_next, struct gcli_fetch_buffer *out); + char **pagination_next, + struct gcli_fetch_buffer *out); int gcli_post_upload(struct gcli_ctx *ctx, char const *url, char const *content_type, void *buffer, size_t buffer_size, @@ -85,6 +85,7 @@ int gcli_curl_test_success(struct gcli_ctx *ctx, char const *url); char *gcli_urlencode(char const *); sn_sv gcli_urlencode_sv(sn_sv const); char *gcli_urldecode(struct gcli_ctx *ctx, char const *input); -int gcli_fetch_list(struct gcli_ctx *ctx, char *url, gcli_fetch_list_ctx *fctx); +int gcli_fetch_list(struct gcli_ctx *ctx, char *url, + struct gcli_fetch_list_ctx *fctx); #endif /* CURL_H */ diff --git a/src/curl.c b/src/curl.c index 2baf235a..bbcbd548 100644 --- a/src/curl.c +++ b/src/curl.c @@ -658,7 +658,7 @@ gcli_urldecode(struct gcli_ctx *ctx, char const *input) * * If max is -1 then everything will be fetched. */ int -gcli_fetch_list(struct gcli_ctx *ctx, char *url, gcli_fetch_list_ctx *fl) +gcli_fetch_list(struct gcli_ctx *ctx, char *url, struct gcli_fetch_list_ctx *fl) { char *next_url = NULL; int rc; diff --git a/src/gitea/milestones.c b/src/gitea/milestones.c index a4b533ee..a1511eb8 100644 --- a/src/gitea/milestones.c +++ b/src/gitea/milestones.c @@ -46,7 +46,7 @@ gitea_get_milestones(struct gcli_ctx *ctx, char const *const owner, char *url; char *e_owner, *e_repo; - gcli_fetch_list_ctx fl = { + struct gcli_fetch_list_ctx fl = { .listp = &out->milestones, .sizep = &out->milestones_size, .max = max, diff --git a/src/gitea/status.c b/src/gitea/status.c index 3f659e0f..b51129ed 100644 --- a/src/gitea/status.c +++ b/src/gitea/status.c @@ -41,7 +41,7 @@ gitea_get_notifications(struct gcli_ctx *ctx, int const max, { char *url = NULL; - gcli_fetch_list_ctx fl = { + struct gcli_fetch_list_ctx fl = { .listp = &out->notifications, .sizep = &out->notifications_size, .parse = (parsefn)(parse_gitea_notifications), diff --git a/src/github/comments.c b/src/github/comments.c index e1b5ae34..48195514 100644 --- a/src/github/comments.c +++ b/src/github/comments.c @@ -78,7 +78,7 @@ github_get_comments(struct gcli_ctx *ctx, char const *owner, char const *repo, char *e_owner = NULL; char *e_repo = NULL; char *url = NULL; - gcli_fetch_list_ctx fl = { + struct gcli_fetch_list_ctx fl = { .listp = &out->comments, .sizep = &out->comments_size, .parse = (parsefn)parse_github_comments, diff --git a/src/github/forks.c b/src/github/forks.c index 5ffe82f6..4e270c8b 100644 --- a/src/github/forks.c +++ b/src/github/forks.c @@ -44,7 +44,7 @@ github_get_forks(struct gcli_ctx *ctx, char const *owner, char const *repo, char *e_owner = NULL; char *e_repo = NULL; - gcli_fetch_list_ctx fl = { + struct gcli_fetch_list_ctx fl = { .listp = &list->forks, .sizep = &list->forks_size, .max = max, diff --git a/src/github/gists.c b/src/github/gists.c index feae9cdb..7f0fbcb8 100644 --- a/src/github/gists.c +++ b/src/github/gists.c @@ -72,7 +72,7 @@ gcli_get_gists(struct gcli_ctx *ctx, char const *user, int const max, struct gcli_gist_list *const list) { char *url = NULL; - gcli_fetch_list_ctx fl = { + struct gcli_fetch_list_ctx fl = { .listp = &list->gists, .sizep = &list->gists_size, .parse = (parsefn)(parse_github_gists), diff --git a/src/github/issues.c b/src/github/issues.c index 047f6b9f..a12d6ec2 100644 --- a/src/github/issues.c +++ b/src/github/issues.c @@ -70,7 +70,7 @@ int github_fetch_issues(struct gcli_ctx *ctx, char *url, int const max, gcli_issue_list *const out) { - gcli_fetch_list_ctx fl = { + struct gcli_fetch_list_ctx fl = { .listp = &out->issues, .sizep = &out->issues_size, .parse = (parsefn)(parse_github_issues), diff --git a/src/github/labels.c b/src/github/labels.c index 05ee0140..ce80a80d 100644 --- a/src/github/labels.c +++ b/src/github/labels.c @@ -40,7 +40,7 @@ github_get_labels(struct gcli_ctx *ctx, char const *owner, char const *reponame, int const max, gcli_label_list *const out) { char *url = NULL; - gcli_fetch_list_ctx fl = { + struct gcli_fetch_list_ctx fl = { .listp = &out->labels, .sizep= &out->labels_size, .parse = (parsefn)(parse_github_labels), diff --git a/src/github/milestones.c b/src/github/milestones.c index 1a1d01c4..17f985e5 100644 --- a/src/github/milestones.c +++ b/src/github/milestones.c @@ -48,7 +48,7 @@ github_get_milestones(struct gcli_ctx *ctx, char const *const owner, gcli_milestone_list *const out) { char *url, *e_owner, *e_repo; - gcli_fetch_list_ctx fl = { + struct gcli_fetch_list_ctx fl = { .listp = &out->milestones, .sizep = &out->milestones_size, .parse = (parsefn)parse_github_milestones, diff --git a/src/github/pulls.c b/src/github/pulls.c index 45e5859c..4ae49bf1 100644 --- a/src/github/pulls.c +++ b/src/github/pulls.c @@ -95,7 +95,7 @@ github_fetch_pulls(struct gcli_ctx *ctx, char *url, gcli_pull_fetch_details const *details, int max, gcli_pull_list *const list) { - gcli_fetch_list_ctx fl = { + struct gcli_fetch_list_ctx fl = { .listp = &list->pulls, .sizep = &list->pulls_size, .parse = (parsefn)(parse_github_pulls), @@ -379,7 +379,7 @@ github_get_pull_commits(struct gcli_ctx *ctx, char const *owner, char *e_owner = NULL; char *e_repo = NULL; - gcli_fetch_list_ctx fl = { + struct gcli_fetch_list_ctx fl = { .listp = &out->commits, .sizep = &out->commits_size, .max = -1, diff --git a/src/github/releases.c b/src/github/releases.c index 677d6253..fefc560a 100644 --- a/src/github/releases.c +++ b/src/github/releases.c @@ -46,7 +46,7 @@ github_get_releases(struct gcli_ctx *ctx, char const *owner, char const *repo, char *e_owner = NULL; char *e_repo = NULL; - gcli_fetch_list_ctx fl = { + struct gcli_fetch_list_ctx fl = { .listp = &list->releases, .sizep = &list->releases_size, .max = max, diff --git a/src/github/repos.c b/src/github/repos.c index e990e780..06b62ffd 100644 --- a/src/github/repos.c +++ b/src/github/repos.c @@ -47,7 +47,7 @@ github_get_repos(struct gcli_ctx *ctx, char const *owner, int const max, char *e_owner = NULL; int rc = 0; - gcli_fetch_list_ctx lf = { + struct gcli_fetch_list_ctx lf = { .listp = &list->repos, .sizep = &list->repos_size, .max = max, @@ -93,7 +93,7 @@ github_get_own_repos(struct gcli_ctx *ctx, int const max, gcli_repo_list *const list) { char *url = NULL; - gcli_fetch_list_ctx fl = { + struct gcli_fetch_list_ctx fl = { .listp = &list->repos, .sizep = &list->repos_size, .max = max, diff --git a/src/github/status.c b/src/github/status.c index b0b6f6f2..72263e7f 100644 --- a/src/github/status.c +++ b/src/github/status.c @@ -42,7 +42,7 @@ github_get_notifications(struct gcli_ctx *ctx, int const max, { char *url = NULL; - gcli_fetch_list_ctx fl = { + struct gcli_fetch_list_ctx fl = { .listp = &out->notifications, .sizep = &out->notifications_size, .parse = (parsefn)(parse_github_notifications), diff --git a/src/gitlab/comments.c b/src/gitlab/comments.c index 0ce6e69a..12a8f236 100644 --- a/src/gitlab/comments.c +++ b/src/gitlab/comments.c @@ -87,7 +87,7 @@ gitlab_get_mr_comments(struct gcli_ctx *ctx, char const *owner, char const *repo char *e_owner = gcli_urlencode(owner); char *e_repo = gcli_urlencode(repo); - gcli_fetch_list_ctx fl = { + struct gcli_fetch_list_ctx fl = { .listp = &out->comments, .sizep = &out->comments_size, .parse = (parsefn)parse_gitlab_comments, @@ -113,7 +113,7 @@ gitlab_get_issue_comments(struct gcli_ctx *ctx, char const *owner, char *e_owner = gcli_urlencode(owner); char *e_repo = gcli_urlencode(repo); - gcli_fetch_list_ctx fl = { + struct gcli_fetch_list_ctx fl = { .listp = &out->comments, .sizep = &out->comments_size, .parse = (parsefn)parse_gitlab_comments, diff --git a/src/gitlab/forks.c b/src/gitlab/forks.c index ffdacfb8..53477b9d 100644 --- a/src/gitlab/forks.c +++ b/src/gitlab/forks.c @@ -44,7 +44,7 @@ gitlab_get_forks(struct gcli_ctx *ctx, char const *owner, char const *repo, char *e_owner = NULL; char *e_repo = NULL; - gcli_fetch_list_ctx fl = { + struct gcli_fetch_list_ctx fl = { .listp = &list->forks, .sizep = &list->forks_size, .parse = (parsefn)parse_gitlab_forks, diff --git a/src/gitlab/issues.c b/src/gitlab/issues.c index 2413aca8..afd937e7 100644 --- a/src/gitlab/issues.c +++ b/src/gitlab/issues.c @@ -43,7 +43,7 @@ int gitlab_fetch_issues(struct gcli_ctx *ctx, char *url, int const max, gcli_issue_list *const out) { - gcli_fetch_list_ctx fl = { + struct gcli_fetch_list_ctx fl = { .listp = &out->issues, .sizep = &out->issues_size, .max = max, diff --git a/src/gitlab/labels.c b/src/gitlab/labels.c index f9db4bd4..42638452 100644 --- a/src/gitlab/labels.c +++ b/src/gitlab/labels.c @@ -41,7 +41,7 @@ gitlab_get_labels(struct gcli_ctx *ctx, char const *owner, char const *repo, int const max, gcli_label_list *const out) { char *url = NULL; - gcli_fetch_list_ctx fl = { + struct gcli_fetch_list_ctx fl = { .listp = &out->labels, .sizep = &out->labels_size, .max = max, diff --git a/src/gitlab/merge_requests.c b/src/gitlab/merge_requests.c index a9ddcc1b..f6c1b925 100644 --- a/src/gitlab/merge_requests.c +++ b/src/gitlab/merge_requests.c @@ -55,7 +55,7 @@ gitlab_fetch_mrs(struct gcli_ctx *ctx, char *url, int const max, { int rc = 0; - gcli_fetch_list_ctx fl = { + struct gcli_fetch_list_ctx fl = { .listp = &list->pulls, .sizep = &list->pulls_size, .max = max, @@ -181,7 +181,7 @@ gitlab_make_commit_patch(struct gcli_ctx *ctx, FILE *stream, int rc; gitlab_diff_list list = {0}; - gcli_fetch_list_ctx fl = { + struct gcli_fetch_list_ctx fl = { .listp = &list.diffs, .sizep = &list.diffs_size, .max = -1, @@ -350,7 +350,7 @@ gitlab_get_pull_commits(struct gcli_ctx *ctx, char const *owner, char const *rep char *e_owner = NULL; char *e_repo = NULL; - gcli_fetch_list_ctx fl = { + struct gcli_fetch_list_ctx fl = { .listp = &out->commits, .sizep = &out->commits_size, .max = -1, diff --git a/src/gitlab/milestones.c b/src/gitlab/milestones.c index c6e84cb1..5c726d5f 100644 --- a/src/gitlab/milestones.c +++ b/src/gitlab/milestones.c @@ -49,7 +49,7 @@ gitlab_get_milestones(struct gcli_ctx *ctx, char const *owner, char const *repo, char *url; char *e_owner, *e_repo; - gcli_fetch_list_ctx fl = { + struct gcli_fetch_list_ctx fl = { .listp = &out->milestones, .sizep = &out->milestones_size, .max = max, diff --git a/src/gitlab/pipelines.c b/src/gitlab/pipelines.c index 60528469..f8463b32 100644 --- a/src/gitlab/pipelines.c +++ b/src/gitlab/pipelines.c @@ -47,7 +47,7 @@ static int fetch_pipelines(struct gcli_ctx *ctx, char *url, int const max, gitlab_pipeline_list *const list) { - gcli_fetch_list_ctx fl = { + struct gcli_fetch_list_ctx fl = { .listp = &list->pipelines, .sizep = &list->pipelines_size, .max = max, @@ -120,7 +120,7 @@ gitlab_get_pipeline_jobs(struct gcli_ctx *ctx, char const *owner, int const max, gitlab_job_list *const out) { char *url = NULL, *e_owner = NULL, *e_repo = NULL; - gcli_fetch_list_ctx fl = { + struct gcli_fetch_list_ctx fl = { .listp = &out->jobs, .sizep = &out->jobs_size, .max = max, diff --git a/src/gitlab/releases.c b/src/gitlab/releases.c index 4d87c1fa..1db361ba 100644 --- a/src/gitlab/releases.c +++ b/src/gitlab/releases.c @@ -70,7 +70,7 @@ gitlab_get_releases(struct gcli_ctx *ctx, char const *owner, char const *repo, char *e_repo = NULL; int rc = 0; - gcli_fetch_list_ctx fl = { + struct gcli_fetch_list_ctx fl = { .listp = &list->releases, .sizep = &list->releases_size, .max = max, diff --git a/src/gitlab/repos.c b/src/gitlab/repos.c index 974724f4..f16b76f3 100644 --- a/src/gitlab/repos.c +++ b/src/gitlab/repos.c @@ -94,7 +94,7 @@ gitlab_get_repos(struct gcli_ctx *ctx, char const *owner, int const max, char *url = NULL; char *e_owner = NULL; int rc = 0; - gcli_fetch_list_ctx fl = { + struct gcli_fetch_list_ctx fl = { .listp = &list->repos, .sizep = &list->repos_size, .parse = (parsefn)(parse_gitlab_repos), diff --git a/src/gitlab/snippets.c b/src/gitlab/snippets.c index 397a37dd..78fb31eb 100644 --- a/src/gitlab/snippets.c +++ b/src/gitlab/snippets.c @@ -70,7 +70,7 @@ gcli_snippets_get(struct gcli_ctx *ctx, int const max, { char *url = NULL; - gcli_fetch_list_ctx fl = { + struct gcli_fetch_list_ctx fl = { .listp = &out->snippets, .sizep = &out->snippets_size, .max = max, diff --git a/src/gitlab/sshkeys.c b/src/gitlab/sshkeys.c index e2a289ca..0b14a88c 100644 --- a/src/gitlab/sshkeys.c +++ b/src/gitlab/sshkeys.c @@ -44,7 +44,7 @@ int gitlab_get_sshkeys(struct gcli_ctx *ctx, gcli_sshkey_list *list) { char *url; - gcli_fetch_list_ctx fl = { + struct gcli_fetch_list_ctx fl = { .listp = &list->keys, .sizep = &list->keys_size, .max = -1, diff --git a/src/gitlab/status.c b/src/gitlab/status.c index 309ef8c7..b2e78b4c 100644 --- a/src/gitlab/status.c +++ b/src/gitlab/status.c @@ -43,7 +43,7 @@ gitlab_get_notifications(struct gcli_ctx *ctx, int const max, { char *url = NULL; - gcli_fetch_list_ctx fl = { + struct gcli_fetch_list_ctx fl = { .listp = &out->notifications, .sizep = &out->notifications_size, .parse = (parsefn)(parse_gitlab_todos), From 3cffd08c350e6808871f18205e42b00e14376453 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 5 Jan 2024 20:58:57 +0100 Subject: [PATCH 109/158] Remove typedef for gitlab_reviewer_id_list --- include/gcli/gitlab/merge_requests.h | 1 - src/gitlab/merge_requests.c | 6 +++--- templates/gitlab/merge_requests.t | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/include/gcli/gitlab/merge_requests.h b/include/gcli/gitlab/merge_requests.h index 63f5e010..c998e07e 100644 --- a/include/gcli/gitlab/merge_requests.h +++ b/include/gcli/gitlab/merge_requests.h @@ -36,7 +36,6 @@ #include -typedef struct gitlab_reviewer_id_list gitlab_reviewer_id_list; struct gitlab_reviewer_id_list { gcli_id *reviewers; size_t reviewers_size; diff --git a/src/gitlab/merge_requests.c b/src/gitlab/merge_requests.c index f6c1b925..e4ed7c71 100644 --- a/src/gitlab/merge_requests.c +++ b/src/gitlab/merge_requests.c @@ -619,7 +619,7 @@ gitlab_mr_clear_milestone(struct gcli_ctx *ctx, char const *owner, static int gitlab_mr_get_reviewers(struct gcli_ctx *ctx, char const *e_owner, char const *e_repo, gcli_id const mr, - gitlab_reviewer_id_list *const out) + struct gitlab_reviewer_id_list *const out) { char *url; int rc; @@ -643,7 +643,7 @@ gitlab_mr_get_reviewers(struct gcli_ctx *ctx, char const *e_owner, } static void -gitlab_reviewer_list_free(gitlab_reviewer_id_list *const list) +gitlab_reviewer_list_free(struct gitlab_reviewer_id_list *const list) { free(list->reviewers); list->reviewers = NULL; @@ -656,7 +656,7 @@ gitlab_mr_add_reviewer(struct gcli_ctx *ctx, char const *owner, char const *repo { char *url, *e_owner, *e_repo, *payload; int uid, rc = 0; - gitlab_reviewer_id_list list = {0}; + struct gitlab_reviewer_id_list list = {0}; gcli_jsongen gen = {0}; e_owner = gcli_urlencode(owner); diff --git a/templates/gitlab/merge_requests.t b/templates/gitlab/merge_requests.t index 9d77c517..6ae25a50 100644 --- a/templates/gitlab/merge_requests.t +++ b/templates/gitlab/merge_requests.t @@ -52,7 +52,7 @@ parser gitlab_commits is array of gcli_commit use parse_gitlab_commit; parser gitlab_reviewer_id is object of gcli_id select "id" as id; parser gitlab_reviewer_ids is -object of gitlab_reviewer_id_list with +object of struct gitlab_reviewer_id_list with ("reviewers" => reviewers as array of gcli_id use parse_gitlab_reviewer_id); parser gitlab_diff is From b4e8e3d8262f446558da86217481fe44e8b7c79f Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 5 Jan 2024 21:01:08 +0100 Subject: [PATCH 110/158] Remove typedefs for gitlab_diff --- include/gcli/gitlab/merge_requests.h | 4 +--- src/gitlab/merge_requests.c | 8 ++++---- templates/gitlab/merge_requests.t | 4 ++-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/include/gcli/gitlab/merge_requests.h b/include/gcli/gitlab/merge_requests.h index c998e07e..9cde6f98 100644 --- a/include/gcli/gitlab/merge_requests.h +++ b/include/gcli/gitlab/merge_requests.h @@ -43,7 +43,6 @@ struct gitlab_reviewer_id_list { /* Structs used for internal patch generator. Gitlab does not provide * an endpoint for doing this properly. */ -typedef struct gitlab_diff gitlab_diff; struct gitlab_diff { char *diff; char *old_path; @@ -55,9 +54,8 @@ struct gitlab_diff { bool deleted_file; }; -typedef struct gitlab_diff_list gitlab_diff_list; struct gitlab_diff_list { - gitlab_diff *diffs; + struct gitlab_diff *diffs; size_t diffs_size; }; diff --git a/src/gitlab/merge_requests.c b/src/gitlab/merge_requests.c index e4ed7c71..ed67b841 100644 --- a/src/gitlab/merge_requests.c +++ b/src/gitlab/merge_requests.c @@ -125,7 +125,7 @@ gitlab_get_mrs(struct gcli_ctx *ctx, char const *owner, char const *repo, } static void -gitlab_free_diff(gitlab_diff *diff) +gitlab_free_diff(struct gitlab_diff *diff) { free(diff->diff); free(diff->old_path); @@ -137,7 +137,7 @@ gitlab_free_diff(gitlab_diff *diff) } static void -gitlab_free_diffs(gitlab_diff_list *list) +gitlab_free_diffs(struct gitlab_diff_list *list) { for (size_t i = 0; i < list->diffs_size; ++i) { gitlab_free_diff(&list->diffs[i]); @@ -150,7 +150,7 @@ gitlab_free_diffs(gitlab_diff_list *list) static void gitlab_make_commit_diff(gcli_commit const *const commit, - gitlab_diff const *const diff, + struct gitlab_diff const *const diff, char const *const prev_commit_sha, FILE *const out) { fprintf(out, "diff --git a/%s b/%s\n", diff->old_path, diff->new_path); @@ -179,7 +179,7 @@ gitlab_make_commit_patch(struct gcli_ctx *ctx, FILE *stream, { char *url; int rc; - gitlab_diff_list list = {0}; + struct gitlab_diff_list list = {0}; struct gcli_fetch_list_ctx fl = { .listp = &list.diffs, diff --git a/templates/gitlab/merge_requests.t b/templates/gitlab/merge_requests.t index 6ae25a50..277e99e8 100644 --- a/templates/gitlab/merge_requests.t +++ b/templates/gitlab/merge_requests.t @@ -56,7 +56,7 @@ object of struct gitlab_reviewer_id_list with ("reviewers" => reviewers as array of gcli_id use parse_gitlab_reviewer_id); parser gitlab_diff is -object of gitlab_diff with +object of struct gitlab_diff with ("diff" => diff as string, "new_path" => new_path as string, "old_path" => old_path as string, @@ -67,4 +67,4 @@ object of gitlab_diff with "deleted_file" => deleted_file as bool); parser gitlab_diffs is -array of gitlab_diff use parse_gitlab_diff; +array of struct gitlab_diff use parse_gitlab_diff; From 2453ef7f0f0ca1719ba29c5c0799dc19bb3cd67a Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 5 Jan 2024 21:03:58 +0100 Subject: [PATCH 111/158] Remove struct typedefs in gitlab pipelines --- include/gcli/cmd/pipelines.h | 6 +++--- include/gcli/gitlab/pipelines.h | 26 +++++++++++--------------- include/gcli/pulls.h | 2 +- src/cmd/pipelines.c | 14 +++++++------- src/cmd/pulls.c | 2 +- src/gitlab/pipelines.c | 18 +++++++++--------- src/pulls.c | 2 +- templates/gitlab/pipelines.t | 10 +++++----- tests/gitlab-parse-tests.c | 2 +- 9 files changed, 39 insertions(+), 43 deletions(-) diff --git a/include/gcli/cmd/pipelines.h b/include/gcli/cmd/pipelines.h index 4d7e2d65..cc613b43 100644 --- a/include/gcli/cmd/pipelines.h +++ b/include/gcli/cmd/pipelines.h @@ -34,16 +34,16 @@ #include -void gitlab_print_pipelines(gitlab_pipeline_list const *const list); +void gitlab_print_pipelines(struct gitlab_pipeline_list const *const list); int gitlab_pipelines(char const *owner, char const *repo, int const count); int gitlab_mr_pipelines(char const *owner, char const *repo, int const mr_id); int gitlab_pipeline_jobs(char const *owner, char const *repo, long pipeline, int count); -void gitlab_print_jobs(gitlab_job_list const *const list); +void gitlab_print_jobs(struct gitlab_job_list const *const list); -void gitlab_print_job_status(gitlab_job const *const job); +void gitlab_print_job_status(struct gitlab_job const *const job); int gitlab_job_status(char const *owner, char const *repo, long const jid); int subcommand_pipelines(int argc, char *argv[]); diff --git a/include/gcli/gitlab/pipelines.h b/include/gcli/gitlab/pipelines.h index aad9fbe4..e89e5373 100644 --- a/include/gcli/gitlab/pipelines.h +++ b/include/gcli/gitlab/pipelines.h @@ -36,11 +36,6 @@ #include -typedef struct gitlab_pipeline gitlab_pipeline; -typedef struct gitlab_pipeline_list gitlab_pipeline_list; -typedef struct gitlab_job gitlab_job; -typedef struct gitlab_job_list gitlab_job_list; - struct gitlab_pipeline { gcli_id id; char *status; @@ -52,7 +47,7 @@ struct gitlab_pipeline { }; struct gitlab_pipeline_list { - gitlab_pipeline *pipelines; + struct gitlab_pipeline *pipelines; size_t pipelines_size; }; @@ -72,22 +67,23 @@ struct gitlab_job { }; struct gitlab_job_list { - gitlab_job *jobs; + struct gitlab_job *jobs; size_t jobs_size; }; int gitlab_get_pipelines(struct gcli_ctx *ctx, char const *owner, - char const *repo, int max, gitlab_pipeline_list *out); + char const *repo, int max, + struct gitlab_pipeline_list *out); -void gitlab_pipeline_free(gitlab_pipeline *pipeline); -void gitlab_pipelines_free(gitlab_pipeline_list *list); +void gitlab_pipeline_free(struct gitlab_pipeline *pipeline); +void gitlab_pipelines_free(struct gitlab_pipeline_list *list); int gitlab_get_pipeline_jobs(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id pipeline, int count, - gitlab_job_list *out); + struct gitlab_job_list *out); -void gitlab_free_jobs(gitlab_job_list *jobs); -void gitlab_free_job(gitlab_job *job); +void gitlab_free_jobs(struct gitlab_job_list *jobs); +void gitlab_free_job(struct gitlab_job *job); int gitlab_job_get_log(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id job_id, FILE *stream); @@ -104,9 +100,9 @@ int gitlab_job_download_artifacts(struct gcli_ctx *ctx, char const *owner, int gitlab_get_mr_pipelines(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id mr_id, - gitlab_pipeline_list *list); + struct gitlab_pipeline_list *list); int gitlab_get_job(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const jid, gitlab_job *const out); + gcli_id const jid, struct gitlab_job *const out); #endif /* GITLAB_PIPELINES_H */ diff --git a/include/gcli/pulls.h b/include/gcli/pulls.h index 2f94595f..b5e79243 100644 --- a/include/gcli/pulls.h +++ b/include/gcli/pulls.h @@ -120,7 +120,7 @@ struct gcli_pull_fetch_details { * NOTE: KEEP THIS ORDER! WE DEPEND ON THE ABI HERE. * * For github the type of checks is gitlab_check* - * For gitlab the type of checks is gitlab_pipeline* + * For gitlab the type of checks is struct gitlab_pipeline* * * You can cast this type to the list type of either one of them. */ struct gcli_pull_checks_list { diff --git a/src/cmd/pipelines.c b/src/cmd/pipelines.c index 66015704..ccecaa1d 100644 --- a/src/cmd/pipelines.c +++ b/src/cmd/pipelines.c @@ -72,7 +72,7 @@ usage(void) int gitlab_mr_pipelines(char const *owner, char const *repo, int const mr_id) { - gitlab_pipeline_list list = {0}; + struct gitlab_pipeline_list list = {0}; int rc = 0; rc = gitlab_get_mr_pipelines(g_clictx, owner, repo, mr_id, &list); @@ -85,7 +85,7 @@ gitlab_mr_pipelines(char const *owner, char const *repo, int const mr_id) } void -gitlab_print_pipelines(gitlab_pipeline_list const *const list) +gitlab_print_pipelines(struct gitlab_pipeline_list const *const list) { gcli_tbl table; struct gcli_tblcoldef cols[] = { @@ -120,7 +120,7 @@ gitlab_print_pipelines(gitlab_pipeline_list const *const list) int gitlab_pipelines(char const *owner, char const *repo, int const count) { - gitlab_pipeline_list pipelines = {0}; + struct gitlab_pipeline_list pipelines = {0}; int rc = 0; rc = gitlab_get_pipelines(g_clictx, owner, repo, count, &pipelines); @@ -134,7 +134,7 @@ gitlab_pipelines(char const *owner, char const *repo, int const count) } void -gitlab_print_jobs(gitlab_job_list const *const list) +gitlab_print_jobs(struct gitlab_job_list const *const list) { gcli_tbl table; struct gcli_tblcoldef cols[] = { @@ -174,7 +174,7 @@ int gitlab_pipeline_jobs(char const *owner, char const *repo, long const id, int const count) { - gitlab_job_list jobs = {0}; + struct gitlab_job_list jobs = {0}; int rc = 0; rc = gitlab_get_pipeline_jobs(g_clictx, owner, repo, id, count, &jobs); @@ -188,7 +188,7 @@ gitlab_pipeline_jobs(char const *owner, char const *repo, } void -gitlab_print_job_status(gitlab_job const *const job) +gitlab_print_job_status(struct gitlab_job const *const job) { gcli_dict printer; @@ -213,7 +213,7 @@ gitlab_print_job_status(gitlab_job const *const job) int gitlab_job_status(char const *owner, char const *repo, long const jid) { - gitlab_job job = {0}; + struct gitlab_job job = {0}; int rc = 0; rc = gitlab_get_job(g_clictx, owner, repo, jid, &job); diff --git a/src/cmd/pulls.c b/src/cmd/pulls.c index 5d01beaa..754439f7 100644 --- a/src/cmd/pulls.c +++ b/src/cmd/pulls.c @@ -253,7 +253,7 @@ gcli_print_checks_list(gcli_pull_checks_list const *const list) github_print_checks((struct github_check_list const *)(list)); break; case GCLI_FORGE_GITLAB: - gitlab_print_pipelines((gitlab_pipeline_list const*)(list)); + gitlab_print_pipelines((struct gitlab_pipeline_list const*)(list)); break; default: assert(0 && "unreachable"); diff --git a/src/gitlab/pipelines.c b/src/gitlab/pipelines.c index f8463b32..cc050d3c 100644 --- a/src/gitlab/pipelines.c +++ b/src/gitlab/pipelines.c @@ -45,7 +45,7 @@ static int fetch_pipelines(struct gcli_ctx *ctx, char *url, int const max, - gitlab_pipeline_list *const list) + struct gitlab_pipeline_list *const list) { struct gcli_fetch_list_ctx fl = { .listp = &list->pipelines, @@ -59,7 +59,7 @@ fetch_pipelines(struct gcli_ctx *ctx, char *url, int const max, int gitlab_get_pipelines(struct gcli_ctx *ctx, char const *owner, char const *repo, - int const max, gitlab_pipeline_list *const list) + int const max, struct gitlab_pipeline_list *const list) { char *url = NULL; char *e_owner = gcli_urlencode(owner); @@ -75,7 +75,7 @@ gitlab_get_pipelines(struct gcli_ctx *ctx, char const *owner, char const *repo, int gitlab_get_mr_pipelines(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const mr_id, gitlab_pipeline_list *const list) + gcli_id const mr_id, struct gitlab_pipeline_list *const list) { char *url = NULL; char *e_owner = gcli_urlencode(owner); @@ -92,7 +92,7 @@ gitlab_get_mr_pipelines(struct gcli_ctx *ctx, char const *owner, char const *rep } void -gitlab_pipeline_free(gitlab_pipeline *pipeline) +gitlab_pipeline_free(struct gitlab_pipeline *pipeline) { free(pipeline->status); free(pipeline->created_at); @@ -103,7 +103,7 @@ gitlab_pipeline_free(gitlab_pipeline *pipeline) } void -gitlab_pipelines_free(gitlab_pipeline_list *const list) +gitlab_pipelines_free(struct gitlab_pipeline_list *const list) { for (size_t i = 0; i < list->pipelines_size; ++i) { gitlab_pipeline_free(&list->pipelines[i]); @@ -117,7 +117,7 @@ gitlab_pipelines_free(gitlab_pipeline_list *const list) int gitlab_get_pipeline_jobs(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const pipeline, - int const max, gitlab_job_list *const out) + int const max, struct gitlab_job_list *const out) { char *url = NULL, *e_owner = NULL, *e_repo = NULL; struct gcli_fetch_list_ctx fl = { @@ -140,7 +140,7 @@ gitlab_get_pipeline_jobs(struct gcli_ctx *ctx, char const *owner, } void -gitlab_free_job(gitlab_job *const job) +gitlab_free_job(struct gitlab_job *const job) { free(job->status); free(job->stage); @@ -154,7 +154,7 @@ gitlab_free_job(gitlab_job *const job) } void -gitlab_free_jobs(gitlab_job_list *list) +gitlab_free_jobs(struct gitlab_job_list *list) { for (size_t i = 0; i < list->jobs_size; ++i) gitlab_free_job(&list->jobs[i]); @@ -190,7 +190,7 @@ gitlab_job_get_log(struct gcli_ctx *ctx, char const *owner, char const *repo, int gitlab_get_job(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const jid, gitlab_job *const out) + gcli_id const jid, struct gitlab_job *const out) { struct gcli_fetch_buffer buffer = {0}; char *url = NULL, *e_owner = NULL, *e_repo = NULL; diff --git a/src/pulls.c b/src/pulls.c index 7bec4520..49c2e142 100644 --- a/src/pulls.c +++ b/src/pulls.c @@ -134,7 +134,7 @@ gcli_pull_checks_free(gcli_pull_checks_list *list) github_free_checks((struct github_check_list *)list); break; case GCLI_FORGE_GITLAB: - gitlab_pipelines_free((gitlab_pipeline_list *)list); + gitlab_pipelines_free((struct gitlab_pipeline_list *)list); break; default: assert(0 && "unreachable"); diff --git a/templates/gitlab/pipelines.t b/templates/gitlab/pipelines.t index 569796cb..2e18ffe4 100644 --- a/templates/gitlab/pipelines.t +++ b/templates/gitlab/pipelines.t @@ -1,7 +1,7 @@ include "gcli/gitlab/pipelines.h"; parser gitlab_pipeline is -object of gitlab_pipeline with +object of struct gitlab_pipeline with ("status" => status as string, "created_at" => created_at as string, "updated_at" => updated_at as string, @@ -11,15 +11,15 @@ object of gitlab_pipeline with "id" => id as id); parser gitlab_pipelines is -array of gitlab_pipeline use parse_gitlab_pipeline; +array of struct gitlab_pipeline use parse_gitlab_pipeline; parser gitlab_job_runner is -object of gitlab_job with +object of struct gitlab_job with ("name" => runner_name as string, "description" => runner_description as string); parser gitlab_job is -object of gitlab_job with +object of struct gitlab_job with ("status" => status as string, "stage" => stage as string, "name" => name as string, @@ -33,4 +33,4 @@ object of gitlab_job with "coverage" => coverage as double); parser gitlab_jobs is -array of gitlab_job use parse_gitlab_job; +array of struct gitlab_job use parse_gitlab_job; diff --git a/tests/gitlab-parse-tests.c b/tests/gitlab-parse-tests.c index 5068419b..8bb9c4f5 100644 --- a/tests/gitlab-parse-tests.c +++ b/tests/gitlab-parse-tests.c @@ -244,7 +244,7 @@ ATF_TC_BODY(gitlab_simple_pipeline, tc) json_stream stream = {0}; struct gcli_ctx *ctx = test_context(); FILE *f = open_sample("gitlab_simple_pipeline.json"); - gitlab_pipeline pipeline = {0}; + struct gitlab_pipeline pipeline = {0}; json_open_stream(&stream, f); ATF_REQUIRE(parse_gitlab_pipeline(ctx, &stream, &pipeline) == 0); From ffa95f4684812ba069ccc77d34e9b2d853112b58 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 5 Jan 2024 21:05:38 +0100 Subject: [PATCH 112/158] Remove struct typedefs in gitlab_snippets --- include/gcli/cmd/snippets.h | 2 +- include/gcli/gitlab/snippets.h | 13 ++++++------- src/cmd/snippets.c | 10 +++++----- src/gitlab/snippets.c | 8 ++++---- templates/gitlab/snippets.t | 4 ++-- tests/gitlab-parse-tests.c | 2 +- 6 files changed, 19 insertions(+), 20 deletions(-) diff --git a/include/gcli/cmd/snippets.h b/include/gcli/cmd/snippets.h index a790867b..b34e56d4 100644 --- a/include/gcli/cmd/snippets.h +++ b/include/gcli/cmd/snippets.h @@ -39,7 +39,7 @@ #include void gcli_snippets_print(enum gcli_output_flags const flags, - gcli_gitlab_snippet_list const *const list, + struct gcli_gitlab_snippet_list const *const list, int const max); int subcommand_snippets(int argc, char *argv[]); diff --git a/include/gcli/gitlab/snippets.h b/include/gcli/gitlab/snippets.h index ff36be29..cc5a058c 100644 --- a/include/gcli/gitlab/snippets.h +++ b/include/gcli/gitlab/snippets.h @@ -36,9 +36,6 @@ #include -typedef struct gcli_gitlab_snippet gcli_gitlab_snippet; -typedef struct gcli_gitlab_snippet_list gcli_gitlab_snippet_list; - struct gcli_gitlab_snippet { int id; char *title; @@ -50,17 +47,19 @@ struct gcli_gitlab_snippet { }; struct gcli_gitlab_snippet_list { - gcli_gitlab_snippet *snippets; + struct gcli_gitlab_snippet *snippets; size_t snippets_size; }; -void gcli_snippets_free(gcli_gitlab_snippet_list *list); +void gcli_snippets_free(struct gcli_gitlab_snippet_list *list); -int gcli_snippets_get(struct gcli_ctx *ctx, int max, gcli_gitlab_snippet_list *out); +int gcli_snippets_get(struct gcli_ctx *ctx, int max, + struct gcli_gitlab_snippet_list *out); int gcli_snippet_delete(struct gcli_ctx *ctx, char const *snippet_id); int gcli_snippet_get(struct gcli_ctx *ctx, char const *snippet_id, FILE *stream); -void gcli_gitlab_snippet_free(gcli_gitlab_snippet *snippet); +void gcli_gitlab_snippet_free(struct gcli_gitlab_snippet *snippet); + #endif /* GITLAB_SNIPPETS_H */ diff --git a/src/cmd/snippets.c b/src/cmd/snippets.c index a2a7c358..5ee8045d 100644 --- a/src/cmd/snippets.c +++ b/src/cmd/snippets.c @@ -58,7 +58,7 @@ usage(void) static void gcli_print_snippet(enum gcli_output_flags const flags, - gcli_gitlab_snippet const *const it) + struct gcli_gitlab_snippet const *const it) { gcli_dict dict; @@ -79,7 +79,7 @@ gcli_print_snippet(enum gcli_output_flags const flags, static void gcli_print_snippets_long(enum gcli_output_flags const flags, - gcli_gitlab_snippet_list const *const list, int const max) + struct gcli_gitlab_snippet_list const *const list, int const max) { int n; @@ -100,7 +100,7 @@ gcli_print_snippets_long(enum gcli_output_flags const flags, static void gcli_print_snippets_short(enum gcli_output_flags const flags, - gcli_gitlab_snippet_list const *const list, + struct gcli_gitlab_snippet_list const *const list, int const max) { int n; @@ -147,7 +147,7 @@ gcli_print_snippets_short(enum gcli_output_flags const flags, void gcli_snippets_print(enum gcli_output_flags const flags, - gcli_gitlab_snippet_list const *const list, int const max) + struct gcli_gitlab_snippet_list const *const list, int const max) { if (list->snippets_size == 0) { puts("No Snippets"); @@ -226,7 +226,7 @@ int subcommand_snippets(int argc, char *argv[]) { int ch; - gcli_gitlab_snippet_list list = {0}; + struct gcli_gitlab_snippet_list list = {0}; int count = 30; enum gcli_output_flags flags = 0; diff --git a/src/gitlab/snippets.c b/src/gitlab/snippets.c index 78fb31eb..0765a447 100644 --- a/src/gitlab/snippets.c +++ b/src/gitlab/snippets.c @@ -41,7 +41,7 @@ #include void -gcli_gitlab_snippet_free(gcli_gitlab_snippet *snippet) +gcli_gitlab_snippet_free(struct gcli_gitlab_snippet *snippet) { free(snippet->title); free(snippet->filename); @@ -52,7 +52,7 @@ gcli_gitlab_snippet_free(gcli_gitlab_snippet *snippet) } void -gcli_snippets_free(gcli_gitlab_snippet_list *const list) +gcli_snippets_free(struct gcli_gitlab_snippet_list *const list) { for (size_t i = 0; i < list->snippets_size; ++i) { gcli_gitlab_snippet_free(&list->snippets[i]); @@ -66,7 +66,7 @@ gcli_snippets_free(gcli_gitlab_snippet_list *const list) int gcli_snippets_get(struct gcli_ctx *ctx, int const max, - gcli_gitlab_snippet_list *const out) + struct gcli_gitlab_snippet_list *const out) { char *url = NULL; @@ -77,7 +77,7 @@ gcli_snippets_get(struct gcli_ctx *ctx, int const max, .parse = (parsefn)(parse_gitlab_snippets), }; - *out = (gcli_gitlab_snippet_list) {0}; + *out = (struct gcli_gitlab_snippet_list) {0}; url = sn_asprintf("%s/snippets", gcli_get_apibase(ctx)); return gcli_fetch_list(ctx, url, &fl); diff --git a/templates/gitlab/snippets.t b/templates/gitlab/snippets.t index ed250d2d..e9025195 100644 --- a/templates/gitlab/snippets.t +++ b/templates/gitlab/snippets.t @@ -2,7 +2,7 @@ include "gcli/json_util.h"; include "gcli/gitlab/snippets.h"; parser gitlab_snippet is -object of gcli_gitlab_snippet with +object of struct gcli_gitlab_snippet with ("title" => title as string, "id" => id as int, "raw_url" => raw_url as string, @@ -12,4 +12,4 @@ object of gcli_gitlab_snippet with "visibility" => visibility as string); parser gitlab_snippets is -array of gcli_gitlab_snippet use parse_gitlab_snippet; +array of struct gcli_gitlab_snippet use parse_gitlab_snippet; diff --git a/tests/gitlab-parse-tests.c b/tests/gitlab-parse-tests.c index 8bb9c4f5..07d2e8d4 100644 --- a/tests/gitlab-parse-tests.c +++ b/tests/gitlab-parse-tests.c @@ -292,7 +292,7 @@ ATF_TC_BODY(gitlab_simple_snippet, tc) json_stream stream = {0}; struct gcli_ctx *ctx = test_context(); FILE *f = open_sample("gitlab_simple_snippet.json"); - gcli_gitlab_snippet snippet = {0}; + struct gcli_gitlab_snippet snippet = {0}; json_open_stream(&stream, f); ATF_REQUIRE(parse_gitlab_snippet(ctx, &stream, &snippet) == 0); From f1282b99484cd6205a35e9ff148546dd391719e8 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 5 Jan 2024 21:09:14 +0100 Subject: [PATCH 113/158] Remove struct typedefs in gcli_issues --- include/gcli/bugzilla/bugs-parser.h | 2 +- include/gcli/bugzilla/bugs.h | 8 ++++---- include/gcli/cmd/issues.h | 6 +++--- include/gcli/forges.h | 10 +++++----- include/gcli/gitea/issues.h | 8 ++++---- include/gcli/gitea/milestones.h | 2 +- include/gcli/github/issues.h | 10 +++++----- include/gcli/github/milestones.h | 2 +- include/gcli/gitlab/issues.h | 10 +++++----- include/gcli/gitlab/milestones.h | 2 +- include/gcli/issues.h | 28 ++++++++++++---------------- include/gcli/milestones.h | 2 +- src/bugzilla/bugs-parser.c | 2 +- src/bugzilla/bugs.c | 10 +++++----- src/cmd/issues.c | 24 ++++++++++++------------ src/cmd/milestones.c | 4 ++-- src/gitea/issues.c | 8 ++++---- src/gitea/milestones.c | 2 +- src/github/issues.c | 14 +++++++------- src/github/milestones.c | 2 +- src/gitlab/issues.c | 10 +++++----- src/gitlab/milestones.c | 2 +- src/issues.c | 12 ++++++------ src/milestones.c | 2 +- templates/bugzilla/bugs.t | 8 ++++---- templates/github/issues.t | 6 +++--- templates/gitlab/issues.t | 6 +++--- tests/bugzilla-parse-tests.c | 4 ++-- tests/github-parse-tests.c | 2 +- tests/gitlab-parse-tests.c | 2 +- 30 files changed, 103 insertions(+), 107 deletions(-) diff --git a/include/gcli/bugzilla/bugs-parser.h b/include/gcli/bugzilla/bugs-parser.h index 7d4905cd..9b8de30e 100644 --- a/include/gcli/bugzilla/bugs-parser.h +++ b/include/gcli/bugzilla/bugs-parser.h @@ -55,7 +55,7 @@ int parse_bugzilla_comments_array_only_first(struct gcli_ctx *ctx, char **out); int parse_bugzilla_assignee(struct gcli_ctx *ctx, struct json_stream *stream, - gcli_issue *out); + struct gcli_issue *out); int parse_bugzilla_bug_attachments_dict(struct gcli_ctx *ctx, struct json_stream *stream, diff --git a/include/gcli/bugzilla/bugs.h b/include/gcli/bugzilla/bugs.h index 6ae08011..c11440ec 100644 --- a/include/gcli/bugzilla/bugs.h +++ b/include/gcli/bugzilla/bugs.h @@ -40,11 +40,11 @@ int bugzilla_get_bugs(struct gcli_ctx *ctx, char const *product, char const *component, - gcli_issue_fetch_details const *details, int const max, - gcli_issue_list *out); + struct gcli_issue_fetch_details const *details, int const max, + struct gcli_issue_list *out); int bugzilla_get_bug(struct gcli_ctx *ctx, char const *product, - char const *component, gcli_id bug_id, gcli_issue *out); + char const *component, gcli_id bug_id, struct gcli_issue *out); int bugzilla_bug_get_comments(struct gcli_ctx *const ctx, char const *const product, @@ -56,7 +56,7 @@ int bugzilla_bug_get_attachments(struct gcli_ctx *ctx, char const *const product gcli_id const bug_id, struct gcli_attachment_list *const out); -int bugzilla_bug_submit(struct gcli_ctx *ctx, gcli_submit_issue_options opts, +int bugzilla_bug_submit(struct gcli_ctx *ctx, struct gcli_submit_issue_options opts, struct gcli_fetch_buffer *out); #endif /* GCLI_BUGZILLA_BUGS_H */ diff --git a/include/gcli/cmd/issues.h b/include/gcli/cmd/issues.h index f45e9690..866dc8c9 100644 --- a/include/gcli/cmd/issues.h +++ b/include/gcli/cmd/issues.h @@ -37,11 +37,11 @@ #include void gcli_print_issues(enum gcli_output_flags const flags, - gcli_issue_list const *const list, int const max); + struct gcli_issue_list const *const list, int const max); -void gcli_issue_print_summary(gcli_issue const *const it); +void gcli_issue_print_summary(struct gcli_issue const *const it); -void gcli_issue_print_op(gcli_issue const *const it); +void gcli_issue_print_op(struct gcli_issue const *const it); int subcommand_issues(int argc, char *argv[]); diff --git a/include/gcli/forges.h b/include/gcli/forges.h index cc5a73d6..99fdf648 100644 --- a/include/gcli/forges.h +++ b/include/gcli/forges.h @@ -103,9 +103,9 @@ struct gcli_forge_descriptor { struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_issue_fetch_details const *details, + struct gcli_issue_fetch_details const *details, int max, - gcli_issue_list *out); + struct gcli_issue_list *out); /** * Get a summary of an issue */ @@ -114,7 +114,7 @@ struct gcli_forge_descriptor { char const *owner, char const *repo, gcli_id issue_number, - gcli_issue *out); + struct gcli_issue *out); /** * Close the given issue */ @@ -165,7 +165,7 @@ struct gcli_forge_descriptor { * Submit an issue */ int (*perform_submit_issue)( struct gcli_ctx *ctx, - gcli_submit_issue_options opts, + struct gcli_submit_issue_options opts, struct gcli_fetch_buffer *out); /** @@ -259,7 +259,7 @@ struct gcli_forge_descriptor { char const *owner, char const *repo, gcli_id milestone, - gcli_issue_list *out); + struct gcli_issue_list *out); /** Assign an issue to a milestone */ int (*issue_set_milestone)( diff --git a/include/gcli/gitea/issues.h b/include/gcli/gitea/issues.h index 397d682f..a003b292 100644 --- a/include/gcli/gitea/issues.h +++ b/include/gcli/gitea/issues.h @@ -37,14 +37,14 @@ #include int gitea_get_issues(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_issue_fetch_details const *details, int max, - gcli_issue_list *out); + struct gcli_issue_fetch_details const *details, int max, + struct gcli_issue_list *out); int gitea_get_issue_summary(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue_number, - gcli_issue *out); + struct gcli_issue *out); -int gitea_submit_issue(struct gcli_ctx *ctx, gcli_submit_issue_options opts, +int gitea_submit_issue(struct gcli_ctx *ctx, struct gcli_submit_issue_options opts, struct gcli_fetch_buffer *out); int gitea_issue_close(struct gcli_ctx *ctx, char const *owner, char const *repo, diff --git a/include/gcli/gitea/milestones.h b/include/gcli/gitea/milestones.h index 24dcca0b..8748345d 100644 --- a/include/gcli/gitea/milestones.h +++ b/include/gcli/gitea/milestones.h @@ -52,6 +52,6 @@ int gitea_milestone_set_duedate(struct gcli_ctx *ctx, char const *owner, int gitea_milestone_get_issues(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id milestone, - gcli_issue_list *out); + struct gcli_issue_list *out); #endif /* GCLI_GITEA_MILESTONES_H */ diff --git a/include/gcli/github/issues.h b/include/gcli/github/issues.h index 2db3ab62..9027f2df 100644 --- a/include/gcli/github/issues.h +++ b/include/gcli/github/issues.h @@ -38,15 +38,15 @@ #include int github_fetch_issues(struct gcli_ctx *ctx, char *url, int max, - gcli_issue_list *out); + struct gcli_issue_list *out); int github_get_issues(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_issue_fetch_details const *details, int max, - gcli_issue_list *out); + struct gcli_issue_fetch_details const *details, int max, + struct gcli_issue_list *out); int github_get_issue_summary(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue_number, - gcli_issue *out); + struct gcli_issue *out); int github_issue_close(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue_number); @@ -55,7 +55,7 @@ int github_issue_reopen(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue_number); int github_perform_submit_issue(struct gcli_ctx *ctx, - gcli_submit_issue_options opts, + struct gcli_submit_issue_options opts, struct gcli_fetch_buffer *out); int github_issue_assign(struct gcli_ctx *ctx, char const *owner, diff --git a/include/gcli/github/milestones.h b/include/gcli/github/milestones.h index 7d6a6e0d..e2cd90bd 100644 --- a/include/gcli/github/milestones.h +++ b/include/gcli/github/milestones.h @@ -47,7 +47,7 @@ int github_delete_milestone(struct gcli_ctx *ctx, char const *owner, int github_milestone_get_issues(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id milestone, - gcli_issue_list *out); + struct gcli_issue_list *out); int github_milestone_set_duedate(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id milestone, diff --git a/include/gcli/gitlab/issues.h b/include/gcli/gitlab/issues.h index 4fc95fa3..98ebc010 100644 --- a/include/gcli/gitlab/issues.h +++ b/include/gcli/gitlab/issues.h @@ -38,15 +38,15 @@ #include int gitlab_fetch_issues(struct gcli_ctx *ctx, char *url, int max, - gcli_issue_list *out); + struct gcli_issue_list *out); int gitlab_get_issues(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_issue_fetch_details const *details, int max, - gcli_issue_list *out); + struct gcli_issue_fetch_details const *details, int max, + struct gcli_issue_list *out); int gitlab_get_issue_summary(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue_number, - gcli_issue *out); + struct gcli_issue *out); int gitlab_issue_close(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue_number); @@ -59,7 +59,7 @@ int gitlab_issue_assign(struct gcli_ctx *ctx, char const *owner, char const *assignee); int gitlab_perform_submit_issue(struct gcli_ctx *ctx, - gcli_submit_issue_options opts, + struct gcli_submit_issue_options opts, struct gcli_fetch_buffer *out); int gitlab_issue_add_labels(struct gcli_ctx *ctx, char const *owner, diff --git a/include/gcli/gitlab/milestones.h b/include/gcli/gitlab/milestones.h index 62af9eec..ac3c9fe5 100644 --- a/include/gcli/gitlab/milestones.h +++ b/include/gcli/gitlab/milestones.h @@ -52,7 +52,7 @@ int gitlab_get_milestone(struct gcli_ctx *ctx, char const *owner, int gitlab_milestone_get_issues(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id milestone, - gcli_issue_list *out); + struct gcli_issue_list *out); int gitlab_milestone_set_duedate(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id milestone, diff --git a/include/gcli/issues.h b/include/gcli/issues.h index 1b0dfcd7..40719ef2 100644 --- a/include/gcli/issues.h +++ b/include/gcli/issues.h @@ -43,11 +43,6 @@ #include -typedef struct gcli_issue gcli_issue; -typedef struct gcli_submit_issue_options gcli_submit_issue_options; -typedef struct gcli_issue_list gcli_issue_list; -typedef struct gcli_issue_fetch_details gcli_issue_fetch_details; - struct gcli_issue { gcli_id number; char *title; @@ -79,7 +74,7 @@ struct gcli_submit_issue_options { }; struct gcli_issue_list { - gcli_issue *issues; + struct gcli_issue *issues; size_t issues_size; }; @@ -90,16 +85,16 @@ struct gcli_issue_fetch_details { char const *milestone; /* filter by the given milestone */ }; -int gcli_get_issues(struct gcli_ctx *ctx, char const *owner, char const *reponame, - gcli_issue_fetch_details const *details, int max, - gcli_issue_list *out); +int gcli_get_issues(struct gcli_ctx *ctx, char const *owner, char const *repo, + struct gcli_issue_fetch_details const *details, int max, + struct gcli_issue_list *out); -void gcli_issues_free(gcli_issue_list *); +void gcli_issues_free(struct gcli_issue_list *); -int gcli_get_issue(struct gcli_ctx *ctx, char const *owner, char const *reponame, - gcli_id issue_number, gcli_issue *out); +int gcli_get_issue(struct gcli_ctx *ctx, char const *owner, char const *repo, + gcli_id issue_number, struct gcli_issue *out); -void gcli_issue_free(gcli_issue *it); +void gcli_issue_free(struct gcli_issue *it); int gcli_issue_close(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue_number); @@ -107,7 +102,7 @@ int gcli_issue_close(struct gcli_ctx *ctx, char const *owner, char const *repo, int gcli_issue_reopen(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue_number); -int gcli_issue_submit(struct gcli_ctx *ctx, gcli_submit_issue_options); +int gcli_issue_submit(struct gcli_ctx *ctx, struct gcli_submit_issue_options); int gcli_issue_assign(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue_number, char const *assignee); @@ -126,8 +121,9 @@ int gcli_issue_set_milestone(struct gcli_ctx *ctx, char const *owner, int gcli_issue_clear_milestone(struct gcli_ctx *cxt, char const *owner, char const *repo, gcli_id issue); -int gcli_issue_set_title(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id issue, char const *new_title); +int gcli_issue_set_title(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id issue, + char const *new_title); int gcli_issue_get_attachments(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue, diff --git a/include/gcli/milestones.h b/include/gcli/milestones.h index d459ed2e..48146f8f 100644 --- a/include/gcli/milestones.h +++ b/include/gcli/milestones.h @@ -92,7 +92,7 @@ void gcli_free_milestones(gcli_milestone_list *it); int gcli_milestone_get_issues(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id milestone, - gcli_issue_list *out); + struct gcli_issue_list *out); int gcli_milestone_set_duedate(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id milestone, diff --git a/src/bugzilla/bugs-parser.c b/src/bugzilla/bugs-parser.c index 451597f9..ac778b94 100644 --- a/src/bugzilla/bugs-parser.c +++ b/src/bugzilla/bugs-parser.c @@ -133,7 +133,7 @@ parse_bugzilla_bug_comments_dictionary_only_first(struct gcli_ctx *const ctx, int parse_bugzilla_assignee(struct gcli_ctx *ctx, struct json_stream *stream, - gcli_issue *out) + struct gcli_issue *out) { out->assignees = calloc(1, sizeof (*out->assignees)); out->assignees_size = 1; diff --git a/src/bugzilla/bugs.c b/src/bugzilla/bugs.c index 28d2d7cf..7329c676 100644 --- a/src/bugzilla/bugs.c +++ b/src/bugzilla/bugs.c @@ -43,8 +43,8 @@ int bugzilla_get_bugs(struct gcli_ctx *ctx, char const *product, char const *component, - gcli_issue_fetch_details const *details, int const max, - gcli_issue_list *out) + struct gcli_issue_fetch_details const *details, int const max, + struct gcli_issue_list *out) { char *url, *e_product = NULL, *e_component = NULL, *e_author = NULL; struct gcli_fetch_buffer buffer = {0}; @@ -160,12 +160,12 @@ bugzilla_bug_get_op(struct gcli_ctx *ctx, gcli_id const bug_id, char **out) int bugzilla_get_bug(struct gcli_ctx *ctx, char const *product, - char const *component, gcli_id bug_id, gcli_issue *out) + char const *component, gcli_id bug_id, struct gcli_issue *out) { int rc = 0; char *url; struct gcli_fetch_buffer buffer = {0}; - gcli_issue_list list = {0}; + struct gcli_issue_list list = {0}; json_stream stream = {0}; /* XXX should we warn if product or component is set? */ @@ -275,7 +275,7 @@ add_extra_options(gcli_nvlist const *list, gcli_jsongen *gen) } int -bugzilla_bug_submit(struct gcli_ctx *ctx, gcli_submit_issue_options opts, +bugzilla_bug_submit(struct gcli_ctx *ctx, struct gcli_submit_issue_options opts, struct gcli_fetch_buffer *out) { char *payload = NULL, *url = NULL; diff --git a/src/cmd/issues.c b/src/cmd/issues.c index f1b4592e..9f1588f8 100644 --- a/src/cmd/issues.c +++ b/src/cmd/issues.c @@ -86,7 +86,7 @@ usage(void) void gcli_print_issues(enum gcli_output_flags const flags, - gcli_issue_list const *const list, int const max) + struct gcli_issue_list const *const list, int const max) { int n, pruned = 0; gcli_tbl table; @@ -148,7 +148,7 @@ gcli_print_issues(enum gcli_output_flags const flags, } void -gcli_issue_print_summary(gcli_issue const *const it) +gcli_issue_print_summary(struct gcli_issue const *const it) { gcli_dict dict; uint32_t const quirks = gcli_forge(g_clictx)->issue_quirks; @@ -204,7 +204,7 @@ gcli_issue_print_summary(gcli_issue const *const it) } void -gcli_issue_print_op(gcli_issue const *const it) +gcli_issue_print_op(struct gcli_issue const *const it) { if (it->body) pretty_print(it->body, 4, 80, stdout); @@ -214,7 +214,7 @@ static void issue_init_user_file(struct gcli_ctx *ctx, FILE *stream, void *_opts) { (void) ctx; - gcli_submit_issue_options *opts = _opts; + struct gcli_submit_issue_options *opts = _opts; fprintf( stream, "! ISSUE TITLE : %s\n" @@ -224,13 +224,13 @@ issue_init_user_file(struct gcli_ctx *ctx, FILE *stream, void *_opts) } static char * -gcli_issue_get_user_message(gcli_submit_issue_options *opts) +gcli_issue_get_user_message(struct gcli_submit_issue_options *opts) { return gcli_editor_get_user_message(g_clictx, issue_init_user_file, opts); } static int -create_issue(gcli_submit_issue_options opts, int always_yes) +create_issue(struct gcli_submit_issue_options opts, int always_yes) { int rc; @@ -260,7 +260,7 @@ create_issue(gcli_submit_issue_options opts, int always_yes) } static int -parse_submit_issue_option(gcli_submit_issue_options *opts) +parse_submit_issue_option(struct gcli_submit_issue_options *opts) { char *hd = strdup(optarg); char *key = hd; @@ -284,7 +284,7 @@ static int subcommand_issue_create(int argc, char *argv[]) { int ch; - gcli_submit_issue_options opts = {0}; + struct gcli_submit_issue_options opts = {0}; int always_yes = 0; if (gcli_nvlist_init(&opts.extra) < 0) { @@ -361,12 +361,12 @@ static inline int handle_issues_actions(int argc, char *argv[], int subcommand_issues(int argc, char *argv[]) { - gcli_issue_list list = {0}; + struct gcli_issue_list list = {0}; char const *owner = NULL; char const *repo = NULL; char *endptr = NULL; int ch = 0, issue_id = -1, n = 30; - gcli_issue_fetch_details details = {0}; + struct gcli_issue_fetch_details details = {0}; enum gcli_output_flags flags = 0; /* detect whether we wanna create an issue */ @@ -499,7 +499,7 @@ subcommand_issues(int argc, char *argv[]) static inline void ensure_issue(char const *const owner, char const *const repo, int const issue_id, - int *const have_fetched_issue, gcli_issue *const issue) + int *const have_fetched_issue, struct gcli_issue *const issue) { if (*have_fetched_issue) return; @@ -637,7 +637,7 @@ handle_issues_actions(int argc, char *argv[], int const issue_id) { int have_fetched_issue = 0; - gcli_issue issue = {0}; + struct gcli_issue issue = {0}; /* Check if the user missed out on supplying actions */ if (argc == 0) { diff --git a/src/cmd/milestones.c b/src/cmd/milestones.c index a6bb3412..7bb1f3f3 100644 --- a/src/cmd/milestones.c +++ b/src/cmd/milestones.c @@ -339,7 +339,7 @@ handle_milestone_actions(int argc, char *argv[], if (strcmp(action, "all") == 0) { int rc = 0; - gcli_issue_list issues = {0}; + struct gcli_issue_list issues = {0}; ensure_milestone(owner, repo, milestone_id, &fetched_milestone, &milestone); @@ -359,7 +359,7 @@ handle_milestone_actions(int argc, char *argv[], } else if (strcmp(action, "issues") == 0) { int rc = 0; - gcli_issue_list issues = {0}; + struct gcli_issue_list issues = {0}; /* Fetch list of issues associated with milestone */ rc = gcli_milestone_get_issues(g_clictx, owner, repo, milestone_id, diff --git a/src/gitea/issues.c b/src/gitea/issues.c index 9e88dd9c..db3b3fbe 100644 --- a/src/gitea/issues.c +++ b/src/gitea/issues.c @@ -40,8 +40,8 @@ int gitea_get_issues(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_issue_fetch_details const *details, int const max, - gcli_issue_list *const out) + struct gcli_issue_fetch_details const *details, int const max, + struct gcli_issue_list *const out) { return github_get_issues(ctx, owner, repo, details, max, out); } @@ -49,13 +49,13 @@ gitea_get_issues(struct gcli_ctx *ctx, char const *owner, char const *repo, int gitea_get_issue_summary(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const issue_number, - gcli_issue *const out) + struct gcli_issue *const out) { return github_get_issue_summary(ctx, owner, repo, issue_number, out); } int -gitea_submit_issue(struct gcli_ctx *ctx, gcli_submit_issue_options opts, +gitea_submit_issue(struct gcli_ctx *ctx, struct gcli_submit_issue_options opts, struct gcli_fetch_buffer *const out) { return github_perform_submit_issue(ctx,opts, out); diff --git a/src/gitea/milestones.c b/src/gitea/milestones.c index a1511eb8..12130b81 100644 --- a/src/gitea/milestones.c +++ b/src/gitea/milestones.c @@ -109,7 +109,7 @@ gitea_create_milestone(struct gcli_ctx *ctx, int gitea_milestone_get_issues(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const milestone, - gcli_issue_list *const out) + struct gcli_issue_list *const out) { char *url, *e_owner, *e_repo; diff --git a/src/github/issues.c b/src/github/issues.c index a12d6ec2..ab12eeac 100644 --- a/src/github/issues.c +++ b/src/github/issues.c @@ -47,14 +47,14 @@ * request issues. This function nukes them from the list, readjusts * the allocation size and fixes the reported list size. */ static void -github_hack_fixup_issues_that_are_actually_pulls(gcli_issue **list, size_t *size, +github_hack_fixup_issues_that_are_actually_pulls(struct gcli_issue **list, size_t *size, void *_data) { (void) _data; for (size_t i = *size; i > 0; --i) { if ((*list)[i-1].is_pr) { - gcli_issue *l = *list; + struct gcli_issue *l = *list; /* len = 7, i = 5, to move = 7 - 5 = 2 * 0 1 2 3 4 5 6 * | x | x | x | x | X | x | x | */ @@ -68,7 +68,7 @@ github_hack_fixup_issues_that_are_actually_pulls(gcli_issue **list, size_t *size int github_fetch_issues(struct gcli_ctx *ctx, char *url, int const max, - gcli_issue_list *const out) + struct gcli_issue_list *const out) { struct gcli_fetch_list_ctx fl = { .listp = &out->issues, @@ -125,8 +125,8 @@ parse_github_milestone(struct gcli_ctx *ctx, char const *owner, int github_get_issues(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_issue_fetch_details const *details, int const max, - gcli_issue_list *const out) + struct gcli_issue_fetch_details const *details, int const max, + struct gcli_issue_list *const out) { char *url = NULL; char *e_owner = NULL; @@ -182,7 +182,7 @@ github_get_issues(struct gcli_ctx *ctx, char const *owner, char const *repo, int github_get_issue_summary(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const issue_number, - gcli_issue *const out) + struct gcli_issue *const out) { char *url = NULL; char *e_owner = NULL; @@ -255,7 +255,7 @@ github_issue_reopen(struct gcli_ctx *ctx, char const *owner, char const *repo, } int -github_perform_submit_issue(struct gcli_ctx *ctx, gcli_submit_issue_options opts, +github_perform_submit_issue(struct gcli_ctx *ctx, struct gcli_submit_issue_options opts, struct gcli_fetch_buffer *out) { char *e_owner = NULL, *e_repo = NULL, *payload = NULL, *url = NULL; diff --git a/src/github/milestones.c b/src/github/milestones.c index 17f985e5..ee9b9ada 100644 --- a/src/github/milestones.c +++ b/src/github/milestones.c @@ -104,7 +104,7 @@ github_get_milestone(struct gcli_ctx *ctx, char const *const owner, int github_milestone_get_issues(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const milestone, - gcli_issue_list *const out) + struct gcli_issue_list *const out) { char *url, *e_owner, *e_repo; diff --git a/src/gitlab/issues.c b/src/gitlab/issues.c index afd937e7..f1194a2e 100644 --- a/src/gitlab/issues.c +++ b/src/gitlab/issues.c @@ -41,7 +41,7 @@ /** Given the url fetch issues */ int gitlab_fetch_issues(struct gcli_ctx *ctx, char *url, int const max, - gcli_issue_list *const out) + struct gcli_issue_list *const out) { struct gcli_fetch_list_ctx fl = { .listp = &out->issues, @@ -55,8 +55,8 @@ gitlab_fetch_issues(struct gcli_ctx *ctx, char *url, int const max, int gitlab_get_issues(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_issue_fetch_details const *details, int const max, - gcli_issue_list *const out) + struct gcli_issue_fetch_details const *details, int const max, + struct gcli_issue_list *const out) { char *url = NULL; char *e_owner = NULL; @@ -112,7 +112,7 @@ gitlab_get_issues(struct gcli_ctx *ctx, char const *owner, char const *repo, int gitlab_get_issue_summary(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const issue_number, - gcli_issue *const out) + struct gcli_issue *const out) { char *url = NULL; char *e_owner = NULL; @@ -197,7 +197,7 @@ gitlab_issue_reopen(struct gcli_ctx *ctx, char const *owner, char const *repo, } int -gitlab_perform_submit_issue(struct gcli_ctx *ctx, gcli_submit_issue_options opts, +gitlab_perform_submit_issue(struct gcli_ctx *ctx, struct gcli_submit_issue_options opts, struct gcli_fetch_buffer *const out) { char *e_owner = NULL, *e_repo = NULL, *url = NULL, *payload = NULL; diff --git a/src/gitlab/milestones.c b/src/gitlab/milestones.c index 5c726d5f..0b722bb6 100644 --- a/src/gitlab/milestones.c +++ b/src/gitlab/milestones.c @@ -101,7 +101,7 @@ gitlab_get_milestone(struct gcli_ctx *ctx, char const *owner, char const *repo, int gitlab_milestone_get_issues(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const milestone, - gcli_issue_list *const out) + struct gcli_issue_list *const out) { char *url, *e_owner, *e_repo; diff --git a/src/issues.c b/src/issues.c index 5ad88cde..e76dc47d 100644 --- a/src/issues.c +++ b/src/issues.c @@ -34,7 +34,7 @@ #include void -gcli_issue_free(gcli_issue *const it) +gcli_issue_free(struct gcli_issue *const it) { free(it->product); free(it->component); @@ -60,7 +60,7 @@ gcli_issue_free(gcli_issue *const it) } void -gcli_issues_free(gcli_issue_list *const list) +gcli_issues_free(struct gcli_issue_list *const list) { for (size_t i = 0; i < list->issues_size; ++i) gcli_issue_free(&list->issues[i]); @@ -73,15 +73,15 @@ gcli_issues_free(gcli_issue_list *const list) int gcli_get_issues(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_issue_fetch_details const *details, int const max, - gcli_issue_list *const out) + struct gcli_issue_fetch_details const *details, int const max, + struct gcli_issue_list *const out) { gcli_null_check_call(get_issues, ctx, owner, repo, details, max, out); } int gcli_get_issue(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const issue_number, gcli_issue *const out) + gcli_id const issue_number, struct gcli_issue *const out) { gcli_null_check_call(get_issue_summary, ctx, owner, repo, issue_number, out); @@ -102,7 +102,7 @@ gcli_issue_reopen(struct gcli_ctx *ctx, char const *owner, char const *repo, } int -gcli_issue_submit(struct gcli_ctx *ctx, gcli_submit_issue_options opts) +gcli_issue_submit(struct gcli_ctx *ctx, struct gcli_submit_issue_options opts) { gcli_null_check_call(perform_submit_issue, ctx, opts, NULL); } diff --git a/src/milestones.c b/src/milestones.c index 0bcb5b24..730e3cb5 100644 --- a/src/milestones.c +++ b/src/milestones.c @@ -91,7 +91,7 @@ gcli_free_milestones(gcli_milestone_list *const it) int gcli_milestone_get_issues(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const milestone, - gcli_issue_list *const out) + struct gcli_issue_list *const out) { gcli_null_check_call(get_milestone_issues, ctx, owner, repo, milestone, out); diff --git a/templates/bugzilla/bugs.t b/templates/bugzilla/bugs.t index d0936d3d..02790287 100644 --- a/templates/bugzilla/bugs.t +++ b/templates/bugzilla/bugs.t @@ -4,15 +4,15 @@ include "gcli/bugzilla/bugs.h"; include "gcli/bugzilla/bugs-parser.h"; parser bugzilla_bug_creator is -object of gcli_issue with +object of struct gcli_issue with ("real_name" => author as string); parser bugzilla_assigned_to_detail is -object of gcli_issue with +object of struct gcli_issue with ("name" => use parse_bugzilla_assignee); parser bugzilla_bug_item is -object of gcli_issue with +object of struct gcli_issue with ("id" => number as id, "summary" => title as string, "creation_time" => created_at as string, @@ -27,7 +27,7 @@ object of gcli_issue with "url" => url as string); parser bugzilla_bugs is -object of gcli_issue_list with +object of struct gcli_issue_list with ("bugs" => issues as array of gcli_issue use parse_bugzilla_bug_item); parser bugzilla_comment is diff --git a/templates/github/issues.t b/templates/github/issues.t index 90b9df7d..863e7b28 100644 --- a/templates/github/issues.t +++ b/templates/github/issues.t @@ -4,11 +4,11 @@ include "gcli/labels.h"; include "templates/github/labels.h"; parser github_issue_milestone is -object of gcli_issue with +object of struct gcli_issue with ("title" => milestone as string); parser github_issue is -object of gcli_issue with +object of struct gcli_issue with ("title" => title as string, "state" => state as string, "body" => body as string, @@ -23,4 +23,4 @@ object of gcli_issue with "pull_request" => is_pr as github_is_pr, "milestone" => use parse_github_issue_milestone); -parser github_issues is array of gcli_issue use parse_github_issue; +parser github_issues is array of struct gcli_issue use parse_github_issue; diff --git a/templates/gitlab/issues.t b/templates/gitlab/issues.t index 9247c885..46a90eac 100644 --- a/templates/gitlab/issues.t +++ b/templates/gitlab/issues.t @@ -3,11 +3,11 @@ include "gcli/gitlab/issues.h"; parser gitlab_user is object of char* select "username" as string; parser gitlab_issue_milestone is -object of gcli_issue with +object of struct gcli_issue with ("title" => milestone as string); parser gitlab_issue is -object of gcli_issue with +object of struct gcli_issue with ("title" => title as string, "state" => state as string, "description" => body as string, @@ -21,4 +21,4 @@ object of gcli_issue with use parse_gitlab_user, "milestone" => use parse_gitlab_issue_milestone); -parser gitlab_issues is array of gcli_issue use parse_gitlab_issue; +parser gitlab_issues is array of struct gcli_issue use parse_gitlab_issue; diff --git a/tests/bugzilla-parse-tests.c b/tests/bugzilla-parse-tests.c index 20178854..a28fe0b5 100644 --- a/tests/bugzilla-parse-tests.c +++ b/tests/bugzilla-parse-tests.c @@ -70,8 +70,8 @@ open_sample(char const *const name) ATF_TC_WITHOUT_HEAD(simple_bugzilla_issue); ATF_TC_BODY(simple_bugzilla_issue, tc) { - gcli_issue_list list = {0}; - gcli_issue const *issue; + struct gcli_issue_list list = {0}; + struct gcli_issue const *issue; FILE *f; json_stream stream; struct gcli_ctx *ctx = test_context(); diff --git a/tests/github-parse-tests.c b/tests/github-parse-tests.c index 6f9e0080..abda1dbf 100644 --- a/tests/github-parse-tests.c +++ b/tests/github-parse-tests.c @@ -74,7 +74,7 @@ open_sample(char const *const name) ATF_TC_WITHOUT_HEAD(simple_github_issue); ATF_TC_BODY(simple_github_issue, tc) { - gcli_issue issue = {0}; + struct gcli_issue issue = {0}; FILE *f; json_stream stream; struct gcli_ctx *ctx = test_context(); diff --git a/tests/gitlab-parse-tests.c b/tests/gitlab-parse-tests.c index 07d2e8d4..9701956e 100644 --- a/tests/gitlab-parse-tests.c +++ b/tests/gitlab-parse-tests.c @@ -89,7 +89,7 @@ ATF_TC_BODY(gitlab_simple_issue, tc) json_stream stream = {0}; struct gcli_ctx *ctx = test_context(); FILE *f = open_sample("gitlab_simple_issue.json"); - gcli_issue issue = {0}; + struct gcli_issue issue = {0}; json_open_stream(&stream, f); ATF_REQUIRE(parse_gitlab_issue(ctx, &stream, &issue) == 0); From 49598464e289b5dc2ea7826283827ae0875d1df2 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 5 Jan 2024 21:10:31 +0100 Subject: [PATCH 114/158] Remove typedef for gcli_jsongen --- include/gcli/json_gen.h | 27 +++++++++++----------- src/bugzilla/bugs.c | 4 ++-- src/gitea/issues.c | 6 ++--- src/gitea/pulls.c | 2 +- src/gitea/releases.c | 2 +- src/github/comments.c | 2 +- src/github/issues.c | 6 ++--- src/github/labels.c | 2 +- src/github/pulls.c | 8 +++---- src/github/releases.c | 2 +- src/github/repos.c | 2 +- src/gitlab/comments.c | 2 +- src/gitlab/issues.c | 10 ++++---- src/gitlab/labels.c | 2 +- src/gitlab/merge_requests.c | 12 +++++----- src/gitlab/releases.c | 2 +- src/gitlab/repos.c | 2 +- src/json_gen.c | 46 ++++++++++++++++++------------------- tests/test-jsongen.c | 16 ++++++------- 19 files changed, 77 insertions(+), 78 deletions(-) diff --git a/include/gcli/json_gen.h b/include/gcli/json_gen.h index 55de9a35..c6166dfd 100644 --- a/include/gcli/json_gen.h +++ b/include/gcli/json_gen.h @@ -44,7 +44,6 @@ enum { GCLI_JSONGEN_OBJECT = 2, }; -typedef struct gcli_jsongen gcli_jsongen; struct gcli_jsongen { char *buffer; size_t buffer_size; @@ -58,19 +57,19 @@ struct gcli_jsongen { bool first_elem; /* first element in object/array */ }; -int gcli_jsongen_init(gcli_jsongen *gen); -void gcli_jsongen_free(gcli_jsongen *gen); -char *gcli_jsongen_to_string(gcli_jsongen *gen); +int gcli_jsongen_init(struct gcli_jsongen *gen); +void gcli_jsongen_free(struct gcli_jsongen *gen); +char *gcli_jsongen_to_string(struct gcli_jsongen *gen); -int gcli_jsongen_begin_object(gcli_jsongen *gen); -int gcli_jsongen_end_object(gcli_jsongen *gen); -int gcli_jsongen_begin_array(gcli_jsongen *gen); -int gcli_jsongen_end_array(gcli_jsongen *gen); -int gcli_jsongen_objmember(gcli_jsongen *gen, char const *key); -int gcli_jsongen_number(gcli_jsongen *gen, long long num); -int gcli_jsongen_id(gcli_jsongen *gen, gcli_id const id); -int gcli_jsongen_string(gcli_jsongen *gen, char const *value); -int gcli_jsongen_bool(gcli_jsongen *gen, bool value); -int gcli_jsongen_null(gcli_jsongen *gen); +int gcli_jsongen_begin_object(struct gcli_jsongen *gen); +int gcli_jsongen_end_object(struct gcli_jsongen *gen); +int gcli_jsongen_begin_array(struct gcli_jsongen *gen); +int gcli_jsongen_end_array(struct gcli_jsongen *gen); +int gcli_jsongen_objmember(struct gcli_jsongen *gen, char const *key); +int gcli_jsongen_number(struct gcli_jsongen *gen, long long num); +int gcli_jsongen_id(struct gcli_jsongen *gen, gcli_id const id); +int gcli_jsongen_string(struct gcli_jsongen *gen, char const *value); +int gcli_jsongen_bool(struct gcli_jsongen *gen, bool value); +int gcli_jsongen_null(struct gcli_jsongen *gen); #endif /* GCLI_JSON_GEN_H */ diff --git a/src/bugzilla/bugs.c b/src/bugzilla/bugs.c index 7329c676..ee7ea12b 100644 --- a/src/bugzilla/bugs.c +++ b/src/bugzilla/bugs.c @@ -245,7 +245,7 @@ bugzilla_bug_get_attachments(struct gcli_ctx *ctx, char const *const product, } static void -add_extra_options(gcli_nvlist const *list, gcli_jsongen *gen) +add_extra_options(gcli_nvlist const *list, struct gcli_jsongen *gen) { static struct extra_opt { char const *json_name; @@ -282,7 +282,7 @@ bugzilla_bug_submit(struct gcli_ctx *ctx, struct gcli_submit_issue_options opts, char *token; /* bugzilla wants the api token as a parameter in the url or the json payload */ char const *product = opts.owner, *component = opts.repo, *summary = opts.title, *description = opts.body; - gcli_jsongen gen = {0}; + struct gcli_jsongen gen = {0}; int rc = 0; /* prepare data for payload generation */ diff --git a/src/gitea/issues.c b/src/gitea/issues.c index db3b3fbe..55ed1e07 100644 --- a/src/gitea/issues.c +++ b/src/gitea/issues.c @@ -67,7 +67,7 @@ gitea_issue_patch_state(struct gcli_ctx *ctx, char const *owner, char const *rep int const issue_number, char const *const state) { char *url = NULL, *payload = NULL, *e_owner = NULL, *e_repo = NULL; - gcli_jsongen gen = {0}; + struct gcli_jsongen gen = {0}; int rc = 0; gcli_jsongen_init(&gen); @@ -117,7 +117,7 @@ gitea_issue_assign(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const issue_number, char const *const assignee) { char *url = NULL, *e_owner = NULL, *e_repo = NULL, *payload = NULL; - gcli_jsongen gen = {0}; + struct gcli_jsongen gen = {0}; int rc = 0; /* Generate payload */ @@ -208,7 +208,7 @@ gitea_issue_add_labels(struct gcli_ctx *ctx, char const *owner, char const *repo size_t const labels_size) { char *payload = NULL, *url = NULL, *e_owner = NULL, *e_repo = NULL; - gcli_jsongen gen = {0}; + struct gcli_jsongen gen = {0}; int rc = 0; /* First, convert to ids */ diff --git a/src/gitea/pulls.c b/src/gitea/pulls.c index c3dd7631..d61b13a8 100644 --- a/src/gitea/pulls.c +++ b/src/gitea/pulls.c @@ -71,7 +71,7 @@ gitea_pull_merge(struct gcli_ctx *ctx, char const *owner, char const *repo, bool const delete_branch = flags & GCLI_PULL_MERGE_DELETEHEAD; bool const squash = flags & GCLI_PULL_MERGE_SQUASH; char *url = NULL, *e_owner = NULL, *e_repo = NULL, *payload = NULL; - gcli_jsongen gen = {0}; + struct gcli_jsongen gen = {0}; int rc = 0; /* Generate payload */ diff --git a/src/gitea/releases.c b/src/gitea/releases.c index f98a6e9a..bfdc739a 100644 --- a/src/gitea/releases.c +++ b/src/gitea/releases.c @@ -79,7 +79,7 @@ gitea_create_release(struct gcli_ctx *ctx, struct gcli_new_release const *releas { char *e_owner = NULL, *e_repo = NULL, *payload = NULL, *upload_url = NULL, *url = NULL; struct gcli_fetch_buffer buffer = {0}; - gcli_jsongen gen = {0}; + struct gcli_jsongen gen = {0}; struct gcli_release response = {0}; int rc = 0; diff --git a/src/github/comments.c b/src/github/comments.c index 48195514..27acb460 100644 --- a/src/github/comments.c +++ b/src/github/comments.c @@ -42,7 +42,7 @@ github_perform_submit_comment(struct gcli_ctx *ctx, struct gcli_fetch_buffer *out) { int rc = 0; - gcli_jsongen gen = {0}; + struct gcli_jsongen gen = {0}; char *e_owner = gcli_urlencode(opts.owner); char *e_repo = gcli_urlencode(opts.repo); char *payload = NULL, *url = NULL; diff --git a/src/github/issues.c b/src/github/issues.c index ab12eeac..83e7bc84 100644 --- a/src/github/issues.c +++ b/src/github/issues.c @@ -259,7 +259,7 @@ github_perform_submit_issue(struct gcli_ctx *ctx, struct gcli_submit_issue_optio struct gcli_fetch_buffer *out) { char *e_owner = NULL, *e_repo = NULL, *payload = NULL, *url = NULL; - gcli_jsongen gen = {0}; + struct gcli_jsongen gen = {0}; int rc = 0; /* Generate Payload */ @@ -299,7 +299,7 @@ int github_issue_assign(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const issue_number, char const *assignee) { - gcli_jsongen gen = {0}; + struct gcli_jsongen gen = {0}; char *url = NULL, *payload = NULL, *e_owner = NULL, *e_repo = NULL; int rc = 0; @@ -448,7 +448,7 @@ github_issue_set_title(struct gcli_ctx *ctx, char const *const owner, char const *const new_title) { char *url, *e_owner, *e_repo, *payload; - gcli_jsongen gen = {0}; + struct gcli_jsongen gen = {0}; int rc; /* Generate url */ diff --git a/src/github/labels.c b/src/github/labels.c index ce80a80d..af8086b3 100644 --- a/src/github/labels.c +++ b/src/github/labels.c @@ -63,7 +63,7 @@ github_create_label(struct gcli_ctx *ctx, char const *owner, char const *repo, char *url = NULL, *payload = NULL, *e_owner = NULL, *e_repo = NULL, *colour = NULL; struct gcli_fetch_buffer buffer = {0}; - gcli_jsongen gen = {0}; + struct gcli_jsongen gen = {0}; int rc = 0; json_stream stream = {0}; diff --git a/src/github/pulls.c b/src/github/pulls.c index 4ae49bf1..20f6d410 100644 --- a/src/github/pulls.c +++ b/src/github/pulls.c @@ -251,7 +251,7 @@ github_pull_patch_state(struct gcli_ctx *const ctx, char const *const owner, char const *const new_state) { char *url = NULL, *e_owner = NULL, *e_repo = NULL, *payload = NULL; - gcli_jsongen gen = {0}; + struct gcli_jsongen gen = {0}; int rc = 0; /* Generate payload */ @@ -303,7 +303,7 @@ github_perform_submit_pull(struct gcli_ctx *ctx, gcli_submit_pull_options opts) { char *url = NULL, *payload = NULL, *e_owner = NULL, *e_repo = NULL; struct gcli_fetch_buffer fetch_buffer = {0}; - gcli_jsongen gen = {0}; + struct gcli_jsongen gen = {0}; int rc = 0; gcli_jsongen_init(&gen); @@ -452,7 +452,7 @@ github_pull_add_reviewer(struct gcli_ctx *ctx, char const *owner, { int rc = 0; char *url, *payload, *e_owner, *e_repo; - gcli_jsongen gen = {0}; + struct gcli_jsongen gen = {0}; /* URL-encode repo and owner */ e_owner = gcli_urlencode(owner); @@ -494,7 +494,7 @@ github_pull_set_title(struct gcli_ctx *ctx, char const *owner, char const *repo, { char *url, *e_owner, *e_repo, *payload; int rc; - gcli_jsongen gen = {0}; + struct gcli_jsongen gen = {0}; /* Generate the url */ e_owner = gcli_urlencode(owner); diff --git a/src/github/releases.c b/src/github/releases.c index fefc560a..ae6fb1b2 100644 --- a/src/github/releases.c +++ b/src/github/releases.c @@ -131,7 +131,7 @@ github_create_release(struct gcli_ctx *ctx, struct gcli_new_release const *relea char *url = NULL, *e_owner = NULL, *e_repo = NULL, *upload_url = NULL, *payload = NULL; struct gcli_fetch_buffer buffer = {0}; - gcli_jsongen gen = {0}; + struct gcli_jsongen gen = {0}; struct gcli_release response = {0}; int rc = 0; diff --git a/src/github/repos.c b/src/github/repos.c index 06b62ffd..72a36546 100644 --- a/src/github/repos.c +++ b/src/github/repos.c @@ -135,7 +135,7 @@ github_repo_create(struct gcli_ctx *ctx, gcli_repo_create_options const *options { char *url, *payload; struct gcli_fetch_buffer buffer = {0}; - gcli_jsongen gen = {0}; + struct gcli_jsongen gen = {0}; struct json_stream stream = {0}; int rc = 0; diff --git a/src/gitlab/comments.c b/src/gitlab/comments.c index 12a8f236..009b684b 100644 --- a/src/gitlab/comments.c +++ b/src/gitlab/comments.c @@ -40,7 +40,7 @@ gitlab_perform_submit_comment(struct gcli_ctx *ctx, struct gcli_submit_comment_o { char *url = NULL, *payload = NULL, *e_owner = NULL, *e_repo = NULL; char const *type = NULL; - gcli_jsongen gen = {0}; + struct gcli_jsongen gen = {0}; int rc = 0; e_owner = gcli_urlencode(opts.owner); diff --git a/src/gitlab/issues.c b/src/gitlab/issues.c index f1194a2e..5c45982c 100644 --- a/src/gitlab/issues.c +++ b/src/gitlab/issues.c @@ -149,7 +149,7 @@ gitlab_issue_patch_state(struct gcli_ctx *const ctx, char const *const owner, char const *const new_state) { char *url = NULL, *payload = NULL, *e_owner = NULL, *e_repo = NULL; - gcli_jsongen gen = {0}; + struct gcli_jsongen gen = {0}; int rc = 0; /* Generate payload */ @@ -201,7 +201,7 @@ gitlab_perform_submit_issue(struct gcli_ctx *ctx, struct gcli_submit_issue_optio struct gcli_fetch_buffer *const out) { char *e_owner = NULL, *e_repo = NULL, *url = NULL, *payload = NULL; - gcli_jsongen gen = {0}; + struct gcli_jsongen gen = {0}; int rc = 0; e_owner = gcli_urlencode(opts.owner); @@ -240,7 +240,7 @@ gitlab_issue_assign(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const issue_number, char const *assignee) { char *url = NULL, *payload = NULL, *e_owner = NULL, *e_repo = NULL; - gcli_jsongen gen = {0}; + struct gcli_jsongen gen = {0}; int assignee_uid = -1; int rc = 0; @@ -287,7 +287,7 @@ gitlab_issues_update_labels(struct gcli_ctx *const ctx, char const *const owner, { char *url = NULL, *payload = NULL, *label_list = NULL, *e_owner = NULL, *e_repo = NULL; - gcli_jsongen gen = {0}; + struct gcli_jsongen gen = {0}; int rc = 0; /* Generate payload. For some reason Gitlab expects us to put a @@ -406,7 +406,7 @@ gitlab_issue_set_title(struct gcli_ctx *ctx, char const *owner, char const *const new_title) { char *url, *e_owner, *e_repo, *payload; - gcli_jsongen gen = {0}; + struct gcli_jsongen gen = {0}; int rc; /* Generate url */ diff --git a/src/gitlab/labels.c b/src/gitlab/labels.c index 42638452..00feb179 100644 --- a/src/gitlab/labels.c +++ b/src/gitlab/labels.c @@ -63,7 +63,7 @@ gitlab_create_label(struct gcli_ctx *ctx, char const *owner, char const *repo, char *url = NULL, *payload = NULL, *colour_string = NULL, *e_owner = NULL, *e_repo = NULL; struct gcli_fetch_buffer buffer = {0}; - gcli_jsongen gen = {0}; + struct gcli_jsongen gen = {0}; int rc = 0; json_stream stream = {0}; diff --git a/src/gitlab/merge_requests.c b/src/gitlab/merge_requests.c index ed67b841..d03bfb68 100644 --- a/src/gitlab/merge_requests.c +++ b/src/gitlab/merge_requests.c @@ -376,7 +376,7 @@ gitlab_mr_patch_state(struct gcli_ctx *const ctx, char const *const owner, char const *const new_state) { char *url = NULL, *payload = NULL, *e_owner = NULL, *e_repo = NULL; - gcli_jsongen gen = {0}; + struct gcli_jsongen gen = {0}; int rc = 0; /* Generate payload */ @@ -432,7 +432,7 @@ gitlab_perform_submit_mr(struct gcli_ctx *ctx, gcli_submit_pull_options opts) char *source_branch = NULL, *source_owner = NULL, *payload = NULL, *e_owner = NULL, *e_repo = NULL, *url = NULL; char const *target_branch = NULL; - gcli_jsongen gen = {0}; + struct gcli_jsongen gen = {0}; gcli_repo target = {0}; int rc = 0; @@ -511,7 +511,7 @@ gitlab_mr_update_labels(struct gcli_ctx *ctx, char const *owner, { char *url = NULL, *payload = NULL, *list = NULL, *e_owner = NULL, *e_repo = NULL; - gcli_jsongen gen = {0}; + struct gcli_jsongen gen = {0}; int rc = 0; /* Generate payload */ @@ -569,7 +569,7 @@ gitlab_mr_set_milestone(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id mr, gcli_id milestone_id) { char *url = NULL, *payload = NULL, *e_owner = NULL, *e_repo = NULL; - gcli_jsongen gen = {0}; + struct gcli_jsongen gen = {0}; int rc = 0; /* Generate Payload */ @@ -657,7 +657,7 @@ gitlab_mr_add_reviewer(struct gcli_ctx *ctx, char const *owner, char const *repo char *url, *e_owner, *e_repo, *payload; int uid, rc = 0; struct gitlab_reviewer_id_list list = {0}; - gcli_jsongen gen = {0}; + struct gcli_jsongen gen = {0}; e_owner = gcli_urlencode(owner); e_repo = gcli_urlencode(repo); @@ -719,7 +719,7 @@ gitlab_mr_set_title(struct gcli_ctx *ctx, char const *const owner, char const *const new_title) { char *url, *e_owner, *e_repo, *payload; - gcli_jsongen gen = {0}; + struct gcli_jsongen gen = {0}; int rc = 0; /* Generate url diff --git a/src/gitlab/releases.c b/src/gitlab/releases.c index 1db361ba..ffb11c06 100644 --- a/src/gitlab/releases.c +++ b/src/gitlab/releases.c @@ -100,7 +100,7 @@ int gitlab_create_release(struct gcli_ctx *ctx, struct gcli_new_release const *release) { char *e_owner = NULL, *e_repo = NULL, *url = NULL, *payload = NULL; - gcli_jsongen gen = {0}; + struct gcli_jsongen gen = {0}; int rc = 0; /* Warnings because unsupported on gitlab */ diff --git a/src/gitlab/repos.c b/src/gitlab/repos.c index f16b76f3..19f5f934 100644 --- a/src/gitlab/repos.c +++ b/src/gitlab/repos.c @@ -142,7 +142,7 @@ gitlab_repo_create(struct gcli_ctx *ctx, gcli_repo_create_options const *options { char *url, *payload; struct gcli_fetch_buffer buffer = {0}; - gcli_jsongen gen = {0}; + struct gcli_jsongen gen = {0}; int rc; json_stream stream = {0}; diff --git a/src/json_gen.c b/src/json_gen.c index 091d13bd..51ee1ae2 100644 --- a/src/json_gen.c +++ b/src/json_gen.c @@ -39,14 +39,14 @@ #include static void -grow_buffer(gcli_jsongen *gen) +grow_buffer(struct gcli_jsongen *gen) { gen->buffer_capacity *= 2; gen->buffer = realloc(gen->buffer, gen->buffer_capacity); } int -gcli_jsongen_init(gcli_jsongen *gen) +gcli_jsongen_init(struct gcli_jsongen *gen) { /* This will allocate a 32 byte buffer. We can optimise * this for better allocation speed by analysing some statistics @@ -63,7 +63,7 @@ gcli_jsongen_init(gcli_jsongen *gen) } void -gcli_jsongen_free(gcli_jsongen *gen) +gcli_jsongen_free(struct gcli_jsongen *gen) { free(gen->buffer); gen->buffer = NULL; @@ -74,7 +74,7 @@ gcli_jsongen_free(gcli_jsongen *gen) } char * -gcli_jsongen_to_string(gcli_jsongen *gen) +gcli_jsongen_to_string(struct gcli_jsongen *gen) { char *buf = calloc(gen->buffer_size + 1, 1); @@ -82,14 +82,14 @@ gcli_jsongen_to_string(gcli_jsongen *gen) } static void -fit(gcli_jsongen *gen, size_t const n_chars) +fit(struct gcli_jsongen *gen, size_t const n_chars) { while (gen->buffer_capacity - gen->buffer_size < n_chars) grow_buffer(gen); } static int -push_scope(gcli_jsongen *gen, int const scope) +push_scope(struct gcli_jsongen *gen, int const scope) { if (gen->scopes_size >= (sizeof(gen->scopes) / sizeof(*gen->scopes))) return -1; @@ -100,7 +100,7 @@ push_scope(gcli_jsongen *gen, int const scope) } static int -pop_scope(gcli_jsongen *gen) +pop_scope(struct gcli_jsongen *gen) { if (gen->scopes_size == 0) return -1; @@ -109,13 +109,13 @@ pop_scope(gcli_jsongen *gen) } static bool -is_array_or_object_scope(gcli_jsongen *gen) +is_array_or_object_scope(struct gcli_jsongen *gen) { return !!gen->scopes_size; } static void -append_str(gcli_jsongen *gen, char const *str) +append_str(struct gcli_jsongen *gen, char const *str) { size_t const len = strlen(str); fit(gen, len); @@ -124,7 +124,7 @@ append_str(gcli_jsongen *gen, char const *str) } static void -put_comma_if_needed(gcli_jsongen *gen) +put_comma_if_needed(struct gcli_jsongen *gen) { if (!gen->await_object_value && !gen->first_elem && is_array_or_object_scope(gen)) append_str(gen, ", "); @@ -133,7 +133,7 @@ put_comma_if_needed(gcli_jsongen *gen) } static bool -is_object_scope(gcli_jsongen *gen) +is_object_scope(struct gcli_jsongen *gen) { if (gen->scopes_size == 0) return false; @@ -142,7 +142,7 @@ is_object_scope(gcli_jsongen *gen) } int -gcli_jsongen_begin_object(gcli_jsongen *gen) +gcli_jsongen_begin_object(struct gcli_jsongen *gen) { /* Cannot put a json object into a json object key */ if (is_object_scope(gen) && !gen->await_object_value) @@ -161,7 +161,7 @@ gcli_jsongen_begin_object(gcli_jsongen *gen) } int -gcli_jsongen_end_object(gcli_jsongen *gen) +gcli_jsongen_end_object(struct gcli_jsongen *gen) { if (pop_scope(gen) != GCLI_JSONGEN_OBJECT) return -1; @@ -175,7 +175,7 @@ gcli_jsongen_end_object(gcli_jsongen *gen) } int -gcli_jsongen_begin_array(gcli_jsongen *gen) +gcli_jsongen_begin_array(struct gcli_jsongen *gen) { /* Cannot put a json array into a json object key */ if (is_object_scope(gen) && !gen->await_object_value) @@ -194,7 +194,7 @@ gcli_jsongen_begin_array(gcli_jsongen *gen) } int -gcli_jsongen_end_array(gcli_jsongen *gen) +gcli_jsongen_end_array(struct gcli_jsongen *gen) { if (pop_scope(gen) != GCLI_JSONGEN_ARRAY) return -1; @@ -208,7 +208,7 @@ gcli_jsongen_end_array(gcli_jsongen *gen) } static void -append_vstrf(gcli_jsongen *gen, char const *const fmt, va_list vp) +append_vstrf(struct gcli_jsongen *gen, char const *const fmt, va_list vp) { va_list vp_copy; size_t len; @@ -223,7 +223,7 @@ append_vstrf(gcli_jsongen *gen, char const *const fmt, va_list vp) } static void -append_strf(gcli_jsongen *gen, char const *const fmt, ...) +append_strf(struct gcli_jsongen *gen, char const *const fmt, ...) { va_list ap; @@ -233,7 +233,7 @@ append_strf(gcli_jsongen *gen, char const *const fmt, ...) } int -gcli_jsongen_objmember(gcli_jsongen *gen, char const *const key) +gcli_jsongen_objmember(struct gcli_jsongen *gen, char const *const key) { if (!is_object_scope(gen)) return -1; @@ -252,7 +252,7 @@ gcli_jsongen_objmember(gcli_jsongen *gen, char const *const key) } int -gcli_jsongen_number(gcli_jsongen *gen, long long const number) +gcli_jsongen_number(struct gcli_jsongen *gen, long long const number) { put_comma_if_needed(gen); append_strf(gen, "%lld", number); @@ -264,7 +264,7 @@ gcli_jsongen_number(gcli_jsongen *gen, long long const number) } int -gcli_jsongen_id(gcli_jsongen *gen, gcli_id const id) +gcli_jsongen_id(struct gcli_jsongen *gen, gcli_id const id) { put_comma_if_needed(gen); append_strf(gen, "%"PRIid, id); @@ -276,7 +276,7 @@ gcli_jsongen_id(gcli_jsongen *gen, gcli_id const id) } int -gcli_jsongen_bool(gcli_jsongen *gen, bool const value) +gcli_jsongen_bool(struct gcli_jsongen *gen, bool const value) { put_comma_if_needed(gen); @@ -289,7 +289,7 @@ gcli_jsongen_bool(gcli_jsongen *gen, bool const value) } int -gcli_jsongen_string(gcli_jsongen *gen, char const *value) +gcli_jsongen_string(struct gcli_jsongen *gen, char const *value) { put_comma_if_needed(gen); char *const e_value = gcli_json_escape_cstr(value); @@ -305,7 +305,7 @@ gcli_jsongen_string(gcli_jsongen *gen, char const *value) } int -gcli_jsongen_null(gcli_jsongen *gen) +gcli_jsongen_null(struct gcli_jsongen *gen) { put_comma_if_needed(gen); append_str(gen, "null"); diff --git a/tests/test-jsongen.c b/tests/test-jsongen.c index fca41a1e..4526f17d 100644 --- a/tests/test-jsongen.c +++ b/tests/test-jsongen.c @@ -36,7 +36,7 @@ ATF_TC_WITHOUT_HEAD(empty_object); ATF_TC_BODY(empty_object, tc) { - gcli_jsongen gen = {0}; + struct gcli_jsongen gen = {0}; ATF_REQUIRE(gcli_jsongen_init(&gen) == 0); ATF_REQUIRE(gcli_jsongen_begin_object(&gen) == 0); @@ -52,7 +52,7 @@ ATF_TC_BODY(empty_object, tc) ATF_TC_WITHOUT_HEAD(array_with_two_empty_objects); ATF_TC_BODY(array_with_two_empty_objects, tc) { - gcli_jsongen gen = {0}; + struct gcli_jsongen gen = {0}; ATF_REQUIRE(gcli_jsongen_init(&gen) == 0); ATF_REQUIRE(gcli_jsongen_begin_array(&gen) == 0); @@ -72,7 +72,7 @@ ATF_TC_BODY(array_with_two_empty_objects, tc) ATF_TC_WITHOUT_HEAD(empty_array); ATF_TC_BODY(empty_array, tc) { - gcli_jsongen gen = {0}; + struct gcli_jsongen gen = {0}; ATF_REQUIRE(gcli_jsongen_init(&gen) == 0); ATF_REQUIRE(gcli_jsongen_begin_array(&gen) == 0); @@ -88,7 +88,7 @@ ATF_TC_BODY(empty_array, tc) ATF_TC_WITHOUT_HEAD(object_with_number); ATF_TC_BODY(object_with_number, tc) { - gcli_jsongen gen = {0}; + struct gcli_jsongen gen = {0}; ATF_REQUIRE(gcli_jsongen_init(&gen) == 0); ATF_REQUIRE(gcli_jsongen_begin_object(&gen) == 0); @@ -106,7 +106,7 @@ ATF_TC_BODY(object_with_number, tc) ATF_TC_WITHOUT_HEAD(object_nested); ATF_TC_BODY(object_nested, tc) { - gcli_jsongen gen = {0}; + struct gcli_jsongen gen = {0}; ATF_REQUIRE(gcli_jsongen_init(&gen) == 0); ATF_REQUIRE(gcli_jsongen_begin_object(&gen) == 0); @@ -131,7 +131,7 @@ ATF_TC_BODY(object_nested, tc) ATF_TC_WITHOUT_HEAD(object_with_strings); ATF_TC_BODY(object_with_strings, tc) { - gcli_jsongen gen = {0}; + struct gcli_jsongen gen = {0}; ATF_REQUIRE(gcli_jsongen_init(&gen) == 0); ATF_REQUIRE(gcli_jsongen_begin_object(&gen) == 0); @@ -149,7 +149,7 @@ ATF_TC_BODY(object_with_strings, tc) ATF_TC_WITHOUT_HEAD(object_with_mixed_values); ATF_TC_BODY(object_with_mixed_values, tc) { - gcli_jsongen gen = {0}; + struct gcli_jsongen gen = {0}; ATF_REQUIRE(gcli_jsongen_init(&gen) == 0); ATF_REQUIRE(gcli_jsongen_begin_object(&gen) == 0); @@ -174,7 +174,7 @@ ATF_TC_BODY(object_with_mixed_values, tc) ATF_TC_WITHOUT_HEAD(object_with_two_keys_and_values_that_are_string); ATF_TC_BODY(object_with_two_keys_and_values_that_are_string, tc) { - gcli_jsongen gen = {0}; + struct gcli_jsongen gen = {0}; ATF_REQUIRE(gcli_jsongen_init(&gen) == 0); ATF_REQUIRE(gcli_jsongen_begin_object(&gen) == 0); From 32f8c0e1ee1608b02ad6c0e2bb45330ea85f81f0 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 5 Jan 2024 21:12:27 +0100 Subject: [PATCH 115/158] Remove struct typedefs for gcli_label --- include/gcli/cmd/labels.h | 2 +- include/gcli/forges.h | 4 ++-- include/gcli/gitea/labels.h | 4 ++-- include/gcli/github/labels.h | 4 ++-- include/gcli/gitlab/labels.h | 4 ++-- include/gcli/labels.h | 13 +++++-------- src/cmd/labels.c | 8 ++++---- src/gitea/issues.c | 4 ++-- src/gitea/labels.c | 6 +++--- src/github/labels.c | 6 +++--- src/gitlab/labels.c | 6 +++--- src/labels.c | 8 ++++---- templates/github/labels.t | 4 ++-- templates/gitlab/labels.t | 4 ++-- tests/github-parse-tests.c | 2 +- tests/gitlab-parse-tests.c | 2 +- 16 files changed, 39 insertions(+), 42 deletions(-) diff --git a/include/gcli/cmd/labels.h b/include/gcli/cmd/labels.h index 83217fac..eca84f76 100644 --- a/include/gcli/cmd/labels.h +++ b/include/gcli/cmd/labels.h @@ -36,7 +36,7 @@ #include -void gcli_labels_print(gcli_label_list const *list, int max); +void gcli_labels_print(struct gcli_label_list const *list, int max); int subcommand_labels(int argc, char *argv[]); diff --git a/include/gcli/forges.h b/include/gcli/forges.h index 99fdf648..ed2e746b 100644 --- a/include/gcli/forges.h +++ b/include/gcli/forges.h @@ -457,7 +457,7 @@ struct gcli_forge_descriptor { char const *owner, char const *repo, int max, - gcli_label_list *out); + struct gcli_label_list *out); /** * Create the given label @@ -467,7 +467,7 @@ struct gcli_forge_descriptor { struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_label *label); + struct gcli_label *label); /** * Delete the given label */ diff --git a/include/gcli/gitea/labels.h b/include/gcli/gitea/labels.h index a2555c8a..abb7f130 100644 --- a/include/gcli/gitea/labels.h +++ b/include/gcli/gitea/labels.h @@ -37,10 +37,10 @@ #include int gitea_get_labels(struct gcli_ctx *ctx, char const *owner, char const *repo, - int max, gcli_label_list *out); + int max, struct gcli_label_list *out); int gitea_create_label(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_label *label); + struct gcli_label *label); int gitea_delete_label(struct gcli_ctx *ctx, char const *owner, char const *repo, char const *label); diff --git a/include/gcli/github/labels.h b/include/gcli/github/labels.h index 42cfc281..6ab47d37 100644 --- a/include/gcli/github/labels.h +++ b/include/gcli/github/labels.h @@ -37,10 +37,10 @@ #include int github_get_labels(struct gcli_ctx *ctx, char const *owner, char const *repo, - int max, gcli_label_list *out); + int max, struct gcli_label_list *out); int github_create_label(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_label *label); + struct gcli_label *label); int github_delete_label(struct gcli_ctx *ctx, char const *owner, char const *repo, char const *label); diff --git a/include/gcli/gitlab/labels.h b/include/gcli/gitlab/labels.h index 82502f8b..34bbde8d 100644 --- a/include/gcli/gitlab/labels.h +++ b/include/gcli/gitlab/labels.h @@ -37,10 +37,10 @@ #include int gitlab_get_labels(struct gcli_ctx *ctx, char const *owner, char const *repo, - int max, gcli_label_list *out); + int max, struct gcli_label_list *out); int gitlab_create_label(struct gcli_ctx *ctx, char const *owner, - char const *repo, gcli_label *label); + char const *repo, struct gcli_label *label); int gitlab_delete_label(struct gcli_ctx *ctx, char const *owner, char const *repo, char const *label); diff --git a/include/gcli/labels.h b/include/gcli/labels.h index c8c15812..39c7161b 100644 --- a/include/gcli/labels.h +++ b/include/gcli/labels.h @@ -40,9 +40,6 @@ #include -typedef struct gcli_label gcli_label; -typedef struct gcli_label_list gcli_label_list; - struct gcli_label { gcli_id id; char *name; @@ -51,19 +48,19 @@ struct gcli_label { }; struct gcli_label_list { - gcli_label *labels; + struct gcli_label *labels; size_t labels_size; }; int gcli_get_labels(struct gcli_ctx *ctx, char const *owner, char const *repo, - int max, gcli_label_list *out); + int max, struct gcli_label_list *out); -void gcli_free_label(gcli_label *label); +void gcli_free_label(struct gcli_label *label); -void gcli_free_labels(gcli_label_list *labels); +void gcli_free_labels(struct gcli_label_list *labels); int gcli_create_label(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_label *label); + struct gcli_label *label); int gcli_delete_label(struct gcli_ctx *ctx, char const *owner, char const *repo, char const *label); diff --git a/src/cmd/labels.c b/src/cmd/labels.c index 1282cabf..d9c83783 100644 --- a/src/cmd/labels.c +++ b/src/cmd/labels.c @@ -62,7 +62,7 @@ usage(void) } void -gcli_labels_print(gcli_label_list const *const list, int const max) +gcli_labels_print(struct gcli_label_list const *const list, int const max) { size_t n; gcli_tbl table; @@ -145,8 +145,8 @@ subcommand_labels_delete(int argc, char *argv[]) static int subcommand_labels_create(int argc, char *argv[]) { - gcli_label label = {0}; - gcli_label_list labels = { .labels = &label, .labels_size = 1 }; + struct gcli_label label = {0}; + struct gcli_label_list labels = { .labels = &label, .labels_size = 1 }; char const *owner = NULL, *repo = NULL; int ch; @@ -231,7 +231,7 @@ subcommand_labels(int argc, char *argv[]) int count = 30; int ch; char const *owner = NULL, *repo = NULL; - gcli_label_list labels = {0}; + struct gcli_label_list labels = {0}; const struct option options[] = { {.name = "repo", .has_arg = required_argument, .flag = NULL, .val = 'r'}, diff --git a/src/gitea/issues.c b/src/gitea/issues.c index 55ed1e07..92be53dd 100644 --- a/src/gitea/issues.c +++ b/src/gitea/issues.c @@ -155,7 +155,7 @@ gitea_issue_assign(struct gcli_ctx *ctx, char const *owner, char const *repo, /* Return the stringified id of the given label */ static char * get_id_of_label(char const *label_name, - gcli_label_list const *const list) + struct gcli_label_list const *const list) { for (size_t i = 0; i < list->labels_size; ++i) if (strcmp(list->labels[i].name, label_name) == 0) @@ -176,7 +176,7 @@ static char ** label_names_to_ids(struct gcli_ctx *ctx, char const *owner, char const *repo, char const *const names[], size_t const names_size) { - gcli_label_list list = {0}; + struct gcli_label_list list = {0}; char **ids = NULL; size_t ids_size = 0; diff --git a/src/gitea/labels.c b/src/gitea/labels.c index 77160e35..09f40e5e 100644 --- a/src/gitea/labels.c +++ b/src/gitea/labels.c @@ -37,14 +37,14 @@ int gitea_get_labels(struct gcli_ctx *ctx, char const *owner, char const *reponame, - int max, gcli_label_list *const list) + int max, struct gcli_label_list *const list) { return github_get_labels(ctx, owner, reponame, max, list); } int gitea_create_label(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_label *const label) + struct gcli_label *const label) { return github_create_label(ctx, owner, repo, label); } @@ -54,7 +54,7 @@ gitea_delete_label(struct gcli_ctx *ctx, char const *owner, char const *repo, char const *label) { char *url = NULL; - gcli_label_list list = {0}; + struct gcli_label_list list = {0}; int id = -1; int rc = 0; diff --git a/src/github/labels.c b/src/github/labels.c index af8086b3..bf0b6b99 100644 --- a/src/github/labels.c +++ b/src/github/labels.c @@ -37,7 +37,7 @@ int github_get_labels(struct gcli_ctx *ctx, char const *owner, char const *reponame, - int const max, gcli_label_list *const out) + int const max, struct gcli_label_list *const out) { char *url = NULL; struct gcli_fetch_list_ctx fl = { @@ -47,7 +47,7 @@ github_get_labels(struct gcli_ctx *ctx, char const *owner, char const *reponame, .max = max, }; - *out = (gcli_label_list) {0}; + *out = (struct gcli_label_list) {0}; url = sn_asprintf( "%s/repos/%s/%s/labels", @@ -58,7 +58,7 @@ github_get_labels(struct gcli_ctx *ctx, char const *owner, char const *reponame, int github_create_label(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_label *const label) + struct gcli_label *const label) { char *url = NULL, *payload = NULL, *e_owner = NULL, *e_repo = NULL, *colour = NULL; diff --git a/src/gitlab/labels.c b/src/gitlab/labels.c index 00feb179..adeb0ac7 100644 --- a/src/gitlab/labels.c +++ b/src/gitlab/labels.c @@ -38,7 +38,7 @@ int gitlab_get_labels(struct gcli_ctx *ctx, char const *owner, char const *repo, - int const max, gcli_label_list *const out) + int const max, struct gcli_label_list *const out) { char *url = NULL; struct gcli_fetch_list_ctx fl = { @@ -48,7 +48,7 @@ gitlab_get_labels(struct gcli_ctx *ctx, char const *owner, char const *repo, .parse = (parsefn)(parse_gitlab_labels), }; - *out = (gcli_label_list) {0}; + *out = (struct gcli_label_list) {0}; url = sn_asprintf("%s/projects/%s%%2F%s/labels", gcli_get_apibase(ctx), owner, repo); @@ -58,7 +58,7 @@ gitlab_get_labels(struct gcli_ctx *ctx, char const *owner, char const *repo, int gitlab_create_label(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_label *const label) + struct gcli_label *const label) { char *url = NULL, *payload = NULL, *colour_string = NULL, *e_owner = NULL, *e_repo = NULL; diff --git a/src/labels.c b/src/labels.c index 0028aff1..6f7b27aa 100644 --- a/src/labels.c +++ b/src/labels.c @@ -32,20 +32,20 @@ int gcli_get_labels(struct gcli_ctx *ctx, char const *owner, char const *reponame, - int const max, gcli_label_list *const out) + int const max, struct gcli_label_list *const out) { gcli_null_check_call(get_labels, ctx, owner, reponame, max, out); } void -gcli_free_label(gcli_label *const label) +gcli_free_label(struct gcli_label *const label) { free(label->name); free(label->description); } void -gcli_free_labels(gcli_label_list *const list) +gcli_free_labels(struct gcli_label_list *const list) { for (size_t i = 0; i < list->labels_size; ++i) gcli_free_label(&list->labels[i]); @@ -57,7 +57,7 @@ gcli_free_labels(gcli_label_list *const list) int gcli_create_label(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_label *const label) + struct gcli_label *const label) { gcli_null_check_call(create_label, ctx, owner, repo, label); } diff --git a/templates/github/labels.t b/templates/github/labels.t index 3de580e0..20fd63ae 100644 --- a/templates/github/labels.t +++ b/templates/github/labels.t @@ -3,11 +3,11 @@ include "gcli/github/labels.h"; parser github_label_text is object of char* select "name" as string; parser github_label is -object of gcli_label with +object of struct gcli_label with ("id" => id as id, "name" => name as string, "description" => description as string, "color" => colour as github_style_colour); -parser github_labels is array of gcli_label +parser github_labels is array of struct gcli_label use parse_github_label; diff --git a/templates/gitlab/labels.t b/templates/gitlab/labels.t index c2a3ed84..40bf7b7b 100644 --- a/templates/gitlab/labels.t +++ b/templates/gitlab/labels.t @@ -1,10 +1,10 @@ include "gcli/gitlab/labels.h"; parser gitlab_label is -object of gcli_label with +object of struct gcli_label with ("name" => name as string, "description" => description as string, "color" => colour as gitlab_style_colour, "id" => id as id); -parser gitlab_labels is array of gcli_label use parse_gitlab_label; +parser gitlab_labels is array of struct gcli_label use parse_gitlab_label; diff --git a/tests/github-parse-tests.c b/tests/github-parse-tests.c index abda1dbf..33d6994e 100644 --- a/tests/github-parse-tests.c +++ b/tests/github-parse-tests.c @@ -155,7 +155,7 @@ ATF_TC_BODY(simple_github_pull, tc) ATF_TC_WITHOUT_HEAD(simple_github_label); ATF_TC_BODY(simple_github_label, tc) { - gcli_label label = {0}; + struct gcli_label label = {0}; FILE *f; json_stream stream; struct gcli_ctx *ctx = test_context(); diff --git a/tests/gitlab-parse-tests.c b/tests/gitlab-parse-tests.c index 9701956e..cc4e8213 100644 --- a/tests/gitlab-parse-tests.c +++ b/tests/gitlab-parse-tests.c @@ -120,7 +120,7 @@ ATF_TC_BODY(gitlab_simple_label, tc) json_stream stream = {0}; struct gcli_ctx *ctx = test_context(); FILE *f = open_sample("gitlab_simple_label.json"); - gcli_label label = {0}; + struct gcli_label label = {0}; json_open_stream(&stream, f); ATF_REQUIRE(parse_gitlab_label(ctx, &stream, &label) == 0); From e9b1edafde0bb32c2c0b0093b9c5b3476b092605 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 5 Jan 2024 21:15:37 +0100 Subject: [PATCH 116/158] Remove struct typedefs for gcli_milestones --- include/gcli/cmd/milestones.h | 4 ++-- include/gcli/forges.h | 4 ++-- include/gcli/gitea/milestones.h | 4 ++-- include/gcli/github/milestones.h | 5 +++-- include/gcli/gitlab/milestones.h | 4 ++-- include/gcli/milestones.h | 15 +++++++-------- src/cmd/milestones.c | 10 +++++----- src/gitea/milestones.c | 4 ++-- src/github/issues.c | 2 +- src/github/milestones.c | 4 ++-- src/gitlab/milestones.c | 4 ++-- src/milestones.c | 8 ++++---- templates/gitea/milestones.t | 4 ++-- templates/github/milestones.t | 4 ++-- templates/gitlab/milestones.t | 4 ++-- tests/github-parse-tests.c | 2 +- tests/gitlab-parse-tests.c | 2 +- 17 files changed, 42 insertions(+), 42 deletions(-) diff --git a/include/gcli/cmd/milestones.h b/include/gcli/cmd/milestones.h index b79eb1b0..75a65428 100644 --- a/include/gcli/cmd/milestones.h +++ b/include/gcli/cmd/milestones.h @@ -36,10 +36,10 @@ #include -void gcli_print_milestones(struct gcli_ctx *ctx, gcli_milestone_list const *it, +void gcli_print_milestones(struct gcli_ctx *ctx, struct gcli_milestone_list const *it, int max); -void gcli_print_milestone(struct gcli_ctx *ctx, gcli_milestone const *it); +void gcli_print_milestone(struct gcli_ctx *ctx, struct gcli_milestone const *it); int subcommand_milestones(int argc, char *argv[]); diff --git a/include/gcli/forges.h b/include/gcli/forges.h index ed2e746b..b532d316 100644 --- a/include/gcli/forges.h +++ b/include/gcli/forges.h @@ -218,7 +218,7 @@ struct gcli_forge_descriptor { char const *owner, char const *repo, int max, - gcli_milestone_list *out); + struct gcli_milestone_list *out); /** * Get a single milestone */ @@ -227,7 +227,7 @@ struct gcli_forge_descriptor { char const *owner, char const *repo, gcli_id milestone, - gcli_milestone *out); + struct gcli_milestone *out); /** * create a milestone */ diff --git a/include/gcli/gitea/milestones.h b/include/gcli/gitea/milestones.h index 8748345d..54531036 100644 --- a/include/gcli/gitea/milestones.h +++ b/include/gcli/gitea/milestones.h @@ -34,11 +34,11 @@ int gitea_get_milestones(struct gcli_ctx *ctx, char const *const owner, char const *const repo, int max, - gcli_milestone_list *out); + struct gcli_milestone_list *out); int gitea_get_milestone(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id milestone, - gcli_milestone *out); + struct gcli_milestone *out); int gitea_create_milestone(struct gcli_ctx *ctx, struct gcli_milestone_create_args const *args); diff --git a/include/gcli/github/milestones.h b/include/gcli/github/milestones.h index e2cd90bd..dc2964b5 100644 --- a/include/gcli/github/milestones.h +++ b/include/gcli/github/milestones.h @@ -33,11 +33,12 @@ #include int github_get_milestones(struct gcli_ctx *ctx, char const *owner, - char const *repo, int max, gcli_milestone_list *out); + char const *repo, int max, + struct gcli_milestone_list *out); int github_get_milestone(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id milestone, - gcli_milestone *out); + struct gcli_milestone *out); int github_create_milestone(struct gcli_ctx *ctx, struct gcli_milestone_create_args const *args); diff --git a/include/gcli/gitlab/milestones.h b/include/gcli/gitlab/milestones.h index ac3c9fe5..44225e14 100644 --- a/include/gcli/gitlab/milestones.h +++ b/include/gcli/gitlab/milestones.h @@ -38,7 +38,7 @@ int gitlab_get_milestones(struct gcli_ctx *ctx, char const *owner, char const *repo, int max, - gcli_milestone_list *const out); + struct gcli_milestone_list *const out); int gitlab_create_milestone(struct gcli_ctx *ctx, struct gcli_milestone_create_args const *args); @@ -48,7 +48,7 @@ int gitlab_delete_milestone(struct gcli_ctx *ctx, char const *owner, int gitlab_get_milestone(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id milestone, - gcli_milestone *out); + struct gcli_milestone *out); int gitlab_milestone_get_issues(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id milestone, diff --git a/include/gcli/milestones.h b/include/gcli/milestones.h index 48146f8f..1da0fb4f 100644 --- a/include/gcli/milestones.h +++ b/include/gcli/milestones.h @@ -40,9 +40,6 @@ #include #include -typedef struct gcli_milestone gcli_milestone; -typedef struct gcli_milestone_list gcli_milestone_list; - struct gcli_milestone { gcli_id id; char *title; @@ -61,7 +58,7 @@ struct gcli_milestone { }; struct gcli_milestone_list { - gcli_milestone *milestones; + struct gcli_milestone *milestones; size_t milestones_size; }; @@ -76,10 +73,12 @@ struct gcli_milestone_create_args { }; int gcli_get_milestones(struct gcli_ctx *ctx, char const *owner, - char const *repo, int max, gcli_milestone_list *out); + char const *repo, int max, + struct gcli_milestone_list *out); int gcli_get_milestone(struct gcli_ctx *ctx, char const *owner, - char const *repo, gcli_id milestone, gcli_milestone *out); + char const *repo, gcli_id milestone, + struct gcli_milestone *out); int gcli_create_milestone(struct gcli_ctx *ctx, struct gcli_milestone_create_args const *args); @@ -87,8 +86,8 @@ int gcli_create_milestone(struct gcli_ctx *ctx, int gcli_delete_milestone(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id milestone); -void gcli_free_milestone(gcli_milestone *it); -void gcli_free_milestones(gcli_milestone_list *it); +void gcli_free_milestone(struct gcli_milestone *it); +void gcli_free_milestones(struct gcli_milestone_list *it); int gcli_milestone_get_issues(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id milestone, diff --git a/src/cmd/milestones.c b/src/cmd/milestones.c index 7bb1f3f3..43d2a167 100644 --- a/src/cmd/milestones.c +++ b/src/cmd/milestones.c @@ -64,7 +64,7 @@ usage(void) } void -gcli_print_milestones(gcli_milestone_list const *const list, int max) +gcli_print_milestones(struct gcli_milestone_list const *const list, int max) { size_t n; gcli_tbl tbl; @@ -101,7 +101,7 @@ gcli_print_milestones(gcli_milestone_list const *const list, int max) } void -gcli_print_milestone(gcli_milestone const *const milestone) +gcli_print_milestone(struct gcli_milestone const *const milestone) { gcli_dict dict; uint32_t const quirks = gcli_forge(g_clictx)->milestone_quirks; @@ -275,7 +275,7 @@ subcommand_milestones(int argc, char *argv[]) check_owner_and_repo(&owner, &repo); if (milestone_id < 0) { - gcli_milestone_list list = {0}; + struct gcli_milestone_list list = {0}; rc = gcli_get_milestones(g_clictx, owner, repo, max, &list); if (rc < 0) { @@ -298,7 +298,7 @@ ensure_milestone(char const *const owner, char const *const repo, int const milestone_id, int *const fetched_milestone, - gcli_milestone *const milestone) + struct gcli_milestone *const milestone) { int rc; @@ -319,7 +319,7 @@ handle_milestone_actions(int argc, char *argv[], char const *const repo, int const milestone_id) { - gcli_milestone milestone = {0}; + struct gcli_milestone milestone = {0}; int fetched_milestone = 0; /* Check if the user missed out on supplying actions */ diff --git a/src/gitea/milestones.c b/src/gitea/milestones.c index 12130b81..169e0594 100644 --- a/src/gitea/milestones.c +++ b/src/gitea/milestones.c @@ -41,7 +41,7 @@ int gitea_get_milestones(struct gcli_ctx *ctx, char const *const owner, char const *const repo, int const max, - gcli_milestone_list *const out) + struct gcli_milestone_list *const out) { char *url; char *e_owner, *e_repo; @@ -68,7 +68,7 @@ gitea_get_milestones(struct gcli_ctx *ctx, char const *const owner, int gitea_get_milestone(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const milestone, - gcli_milestone *const out) + struct gcli_milestone *const out) { char *url, *e_owner, *e_repo; struct gcli_fetch_buffer buffer = {0}; diff --git a/src/github/issues.c b/src/github/issues.c index 83e7bc84..40338e2c 100644 --- a/src/github/issues.c +++ b/src/github/issues.c @@ -86,7 +86,7 @@ get_milestone_id(struct gcli_ctx *ctx, char const *owner, char const *repo, char const *milestone_name, gcli_id *out) { int rc = 0; - gcli_milestone_list list = {0}; + struct gcli_milestone_list list = {0}; rc = github_get_milestones(ctx, owner, repo, -1, &list); if (rc < 0) diff --git a/src/github/milestones.c b/src/github/milestones.c index ee9b9ada..e41d2851 100644 --- a/src/github/milestones.c +++ b/src/github/milestones.c @@ -45,7 +45,7 @@ int github_get_milestones(struct gcli_ctx *ctx, char const *const owner, char const *const repo, int const max, - gcli_milestone_list *const out) + struct gcli_milestone_list *const out) { char *url, *e_owner, *e_repo; struct gcli_fetch_list_ctx fl = { @@ -71,7 +71,7 @@ github_get_milestones(struct gcli_ctx *ctx, char const *const owner, int github_get_milestone(struct gcli_ctx *ctx, char const *const owner, char const *const repo, gcli_id const milestone, - gcli_milestone *const out) + struct gcli_milestone *const out) { char *url, *e_owner, *e_repo; struct gcli_fetch_buffer buffer = {0}; diff --git a/src/gitlab/milestones.c b/src/gitlab/milestones.c index 0b722bb6..cf84ad5f 100644 --- a/src/gitlab/milestones.c +++ b/src/gitlab/milestones.c @@ -44,7 +44,7 @@ int gitlab_get_milestones(struct gcli_ctx *ctx, char const *owner, char const *repo, - int max, gcli_milestone_list *const out) + int max, struct gcli_milestone_list *const out) { char *url; char *e_owner, *e_repo; @@ -70,7 +70,7 @@ gitlab_get_milestones(struct gcli_ctx *ctx, char const *owner, char const *repo, int gitlab_get_milestone(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const milestone, gcli_milestone *const out) + gcli_id const milestone, struct gcli_milestone *const out) { char *url, *e_owner, *e_repo; struct gcli_fetch_buffer buffer = {0}; diff --git a/src/milestones.c b/src/milestones.c index 730e3cb5..fbac6126 100644 --- a/src/milestones.c +++ b/src/milestones.c @@ -33,14 +33,14 @@ int gcli_get_milestones(struct gcli_ctx *ctx, char const *const owner, char const *const repo, int const max, - gcli_milestone_list *const out) + struct gcli_milestone_list *const out) { gcli_null_check_call(get_milestones, ctx, owner, repo, max, out); } int gcli_get_milestone(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const milestone, gcli_milestone *const out) + gcli_id const milestone, struct gcli_milestone *const out) { gcli_null_check_call(get_milestone, ctx, owner, repo, milestone, out); } @@ -60,7 +60,7 @@ gcli_delete_milestone(struct gcli_ctx *ctx, char const *const owner, } void -gcli_free_milestone(gcli_milestone *const it) +gcli_free_milestone(struct gcli_milestone *const it) { free(it->title); it->title = NULL; @@ -78,7 +78,7 @@ gcli_free_milestone(gcli_milestone *const it) } void -gcli_free_milestones(gcli_milestone_list *const it) +gcli_free_milestones(struct gcli_milestone_list *const it) { for (size_t i = 0; i < it->milestones_size; ++i) gcli_free_milestone(&it->milestones[i]); diff --git a/templates/gitea/milestones.t b/templates/gitea/milestones.t index 85b70c5e..d363ca99 100644 --- a/templates/gitea/milestones.t +++ b/templates/gitea/milestones.t @@ -1,7 +1,7 @@ include "gcli/milestones.h"; parser gitea_milestone is -object of gcli_milestone with +object of struct gcli_milestone with ("id" => id as id, "title" => title as string, "created_at" => created_at as string, @@ -13,4 +13,4 @@ object of gcli_milestone with "closed_issues" => closed_issues as int); parser gitea_milestones is -array of gcli_milestone use parse_gitea_milestone; +array of struct gcli_milestone use parse_gitea_milestone; diff --git a/templates/github/milestones.t b/templates/github/milestones.t index e6cca23a..6aea61f1 100644 --- a/templates/github/milestones.t +++ b/templates/github/milestones.t @@ -1,7 +1,7 @@ include "gcli/milestones.h"; parser github_milestone is -object of gcli_milestone with +object of struct gcli_milestone with ("number" => id as id, "title" => title as string, "created_at" => created_at as string, @@ -12,4 +12,4 @@ object of gcli_milestone with "closed_issues" => closed_issues as int); parser github_milestones is -array of gcli_milestone use parse_github_milestone; +array of struct gcli_milestone use parse_github_milestone; diff --git a/templates/gitlab/milestones.t b/templates/gitlab/milestones.t index dd9f8b26..108a4eef 100644 --- a/templates/gitlab/milestones.t +++ b/templates/gitlab/milestones.t @@ -1,7 +1,7 @@ include "gcli/milestones.h"; parser gitlab_milestone is -object of gcli_milestone with +object of struct gcli_milestone with ("title" => title as string, "id" => id as id, "state" => state as string, @@ -11,4 +11,4 @@ object of gcli_milestone with "due_date" => due_date as string, "expired" => expired as bool); -parser gitlab_milestones is array of gcli_milestone use parse_gitlab_milestone; +parser gitlab_milestones is array of struct gcli_milestone use parse_gitlab_milestone; diff --git a/tests/github-parse-tests.c b/tests/github-parse-tests.c index 33d6994e..cd107f1d 100644 --- a/tests/github-parse-tests.c +++ b/tests/github-parse-tests.c @@ -178,7 +178,7 @@ ATF_TC_BODY(simple_github_label, tc) ATF_TC_WITHOUT_HEAD(simple_github_milestone); ATF_TC_BODY(simple_github_milestone, tc) { - gcli_milestone milestone = {0}; + struct gcli_milestone milestone = {0}; FILE *f; json_stream stream; struct gcli_ctx *ctx = test_context(); diff --git a/tests/gitlab-parse-tests.c b/tests/gitlab-parse-tests.c index cc4e8213..c708e381 100644 --- a/tests/gitlab-parse-tests.c +++ b/tests/gitlab-parse-tests.c @@ -215,7 +215,7 @@ ATF_TC_BODY(gitlab_simple_milestone, tc) json_stream stream = {0}; struct gcli_ctx *ctx = test_context(); FILE *f = open_sample("gitlab_simple_milestone.json"); - gcli_milestone milestone = {0}; + struct gcli_milestone milestone = {0}; json_open_stream(&stream, f); ATF_REQUIRE(parse_gitlab_milestone(ctx, &stream, &milestone) == 0); From 7358ce80dd216d3ea465d579c01c68c54afbb046 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 5 Jan 2024 21:17:41 +0100 Subject: [PATCH 117/158] Remove typedefs in gcli_nvlist --- include/gcli/issues.h | 2 +- include/gcli/nvlist.h | 15 ++++++--------- src/bugzilla/bugs.c | 2 +- src/nvlist.c | 16 ++++++++-------- 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/include/gcli/issues.h b/include/gcli/issues.h index 40719ef2..5a5a16be 100644 --- a/include/gcli/issues.h +++ b/include/gcli/issues.h @@ -70,7 +70,7 @@ struct gcli_submit_issue_options { char *title; char *body; - gcli_nvlist extra; + struct gcli_nvlist extra; }; struct gcli_issue_list { diff --git a/include/gcli/nvlist.h b/include/gcli/nvlist.h index 27f464d6..ea2a59b1 100644 --- a/include/gcli/nvlist.h +++ b/include/gcli/nvlist.h @@ -36,9 +36,6 @@ #include -typedef struct gcli_nvpair gcli_nvpair; -typedef struct gcli_nvlist gcli_nvlist; - struct gcli_nvpair { TAILQ_ENTRY(gcli_nvpair) next; @@ -48,11 +45,11 @@ struct gcli_nvpair { TAILQ_HEAD(gcli_nvlist, gcli_nvpair); -int gcli_nvlist_init(gcli_nvlist *list); -int gcli_nvlist_free(gcli_nvlist *list); -int gcli_nvlist_append(gcli_nvlist *list, char *key, char *value); -char const *gcli_nvlist_find(gcli_nvlist const *list, char const *key); -char const *gcli_nvlist_find_or(gcli_nvlist const *list, char const *key, - char const *alternative); +int gcli_nvlist_init(struct gcli_nvlist *list); +int gcli_nvlist_free(struct gcli_nvlist *list); +int gcli_nvlist_append(struct gcli_nvlist *list, char *key, char *value); +char const *gcli_nvlist_find(struct gcli_nvlist const *list, char const *key); +char const *gcli_nvlist_find_or(struct gcli_nvlist const *list, + char const *key, char const *alternative); #endif /* GCLI_NVLIST_H */ diff --git a/src/bugzilla/bugs.c b/src/bugzilla/bugs.c index ee7ea12b..12546a71 100644 --- a/src/bugzilla/bugs.c +++ b/src/bugzilla/bugs.c @@ -245,7 +245,7 @@ bugzilla_bug_get_attachments(struct gcli_ctx *ctx, char const *const product, } static void -add_extra_options(gcli_nvlist const *list, struct gcli_jsongen *gen) +add_extra_options(struct gcli_nvlist const *list, struct gcli_jsongen *gen) { static struct extra_opt { char const *json_name; diff --git a/src/nvlist.c b/src/nvlist.c index 7ed36750..dc573004 100644 --- a/src/nvlist.c +++ b/src/nvlist.c @@ -35,7 +35,7 @@ #include int -gcli_nvlist_init(gcli_nvlist *list) +gcli_nvlist_init(struct gcli_nvlist *list) { TAILQ_INIT(list); @@ -43,9 +43,9 @@ gcli_nvlist_init(gcli_nvlist *list) } int -gcli_nvlist_free(gcli_nvlist *list) +gcli_nvlist_free(struct gcli_nvlist *list) { - gcli_nvpair *p1, *p2; + struct gcli_nvpair *p1, *p2; p1 = TAILQ_FIRST(list); while (p1 != NULL) { @@ -64,12 +64,12 @@ gcli_nvlist_free(gcli_nvlist *list) } int -gcli_nvlist_append(gcli_nvlist *list, char *key, char *value) +gcli_nvlist_append(struct gcli_nvlist *list, char *key, char *value) { /* TODO: handle the case where a pair with an already existing * key is inserted. */ - gcli_nvpair *pair = calloc(1, sizeof(*pair)); + struct gcli_nvpair *pair = calloc(1, sizeof(*pair)); if (pair == NULL) return -1; @@ -82,9 +82,9 @@ gcli_nvlist_append(gcli_nvlist *list, char *key, char *value) } char const * -gcli_nvlist_find(gcli_nvlist const *list, char const *key) +gcli_nvlist_find(struct gcli_nvlist const *list, char const *key) { - gcli_nvpair const *pair; + struct gcli_nvpair const *pair; TAILQ_FOREACH(pair, list,next) { if (strcmp(pair->key, key) == 0) @@ -94,7 +94,7 @@ gcli_nvlist_find(gcli_nvlist const *list, char const *key) } char const * -gcli_nvlist_find_or(gcli_nvlist const *list, char const *const key, +gcli_nvlist_find_or(struct gcli_nvlist const *list, char const *const key, char const *const alternative) { char const *const result = gcli_nvlist_find(list, key); From 1fe1a25f556a9a70f960f194250ae095a041404c Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 5 Jan 2024 21:21:02 +0100 Subject: [PATCH 118/158] Remove struct typedefs in gcli_pulls --- include/gcli/cmd/pulls.h | 8 +++--- include/gcli/forges.h | 14 +++++----- include/gcli/gitea/pulls.h | 12 ++++---- include/gcli/github/pulls.h | 12 ++++---- include/gcli/gitlab/merge_requests.h | 12 ++++---- include/gcli/pulls.h | 41 ++++++++++++---------------- src/cmd/pulls.c | 28 +++++++++---------- src/gitea/pulls.c | 12 ++++---- src/github/pulls.c | 32 +++++++++++----------- src/gitlab/merge_requests.c | 22 +++++++-------- src/pulls.c | 20 +++++++------- templates/github/pulls.t | 18 ++++++------ templates/gitlab/merge_requests.t | 14 +++++----- tests/github-parse-tests.c | 2 +- tests/gitlab-parse-tests.c | 2 +- 15 files changed, 122 insertions(+), 127 deletions(-) diff --git a/include/gcli/cmd/pulls.h b/include/gcli/cmd/pulls.h index 0099ca33..6fdd469a 100644 --- a/include/gcli/cmd/pulls.h +++ b/include/gcli/cmd/pulls.h @@ -36,19 +36,19 @@ #include -void gcli_print_pulls(enum gcli_output_flags flags, gcli_pull_list const *list, +void gcli_print_pulls(enum gcli_output_flags flags, struct gcli_pull_list const *list, int max); int gcli_print_pull_diff(FILE *stream, char const *owner, char const *reponame, int pr_number); -void gcli_print_pull(gcli_pull const *pull); +void gcli_print_pull(struct gcli_pull const *pull); -void gcli_pull_print_op(gcli_pull const *pull); +void gcli_pull_print_op(struct gcli_pull const *pull); int gcli_pull_checks(char const *owner, char const *repo, int pr_number); -void gcli_print_commits(gcli_commit_list const *const list); +void gcli_print_commits(struct gcli_commit_list const *const list); int subcommand_pulls(int argc, char *argv[]); diff --git a/include/gcli/forges.h b/include/gcli/forges.h index b532d316..d7caf477 100644 --- a/include/gcli/forges.h +++ b/include/gcli/forges.h @@ -49,7 +49,7 @@ /* Hopefully temporary hack */ typedef int (*gcli_get_pull_checks_cb)( struct gcli_ctx *, char const *, char const *, gcli_id, - gcli_pull_checks_list *); + struct gcli_pull_checks_list *); /** * Struct of function pointers to perform actions in the given @@ -283,9 +283,9 @@ struct gcli_forge_descriptor { struct gcli_ctx *ctx, char const *owner, char const *reponame, - gcli_pull_fetch_details const *details, + struct gcli_pull_fetch_details const *details, int max, - gcli_pull_list *out); + struct gcli_pull_list *out); /** * Fetch the PR diff into the file */ @@ -309,7 +309,7 @@ struct gcli_forge_descriptor { * Return a list of checks associated with the given pull. * * The type of the returned list depends on the forge type. See - * the definition of gcli_pull_checks_list. */ + * the definition of struct gcli_pull_checks_list. */ gcli_get_pull_checks_cb get_pull_checks; /** @@ -341,7 +341,7 @@ struct gcli_forge_descriptor { * Submit PR/MR */ int (*perform_submit_pull)( struct gcli_ctx *ctx, - gcli_submit_pull_options opts); + struct gcli_submit_pull_options opts); /** * Get a list of commits in the given PR/MR */ @@ -350,7 +350,7 @@ struct gcli_forge_descriptor { char const *owner, char const *repo, gcli_id pr_number, - gcli_commit_list *out); + struct gcli_commit_list *out); /** Bitmask of unsupported fields in the pull summary for this * forge */ @@ -370,7 +370,7 @@ struct gcli_forge_descriptor { char const *owner, char const *repo, gcli_id pr_number, - gcli_pull *out); + struct gcli_pull *out); /** * Add labels to Pull Requests */ diff --git a/include/gcli/gitea/pulls.h b/include/gcli/gitea/pulls.h index 2b83b370..401575b5 100644 --- a/include/gcli/gitea/pulls.h +++ b/include/gcli/gitea/pulls.h @@ -38,17 +38,17 @@ #include int gitea_get_pulls(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_pull_fetch_details const *details, int max, - gcli_pull_list *out); + struct gcli_pull_fetch_details const *details, int max, + struct gcli_pull_list *out); int gitea_get_pull(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id pr_number, gcli_pull *out); + gcli_id pr_number, struct gcli_pull *out); int gitea_get_pull_commits(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id pr_number, - gcli_commit_list *out); + struct gcli_commit_list *out); -int gitea_pull_submit(struct gcli_ctx *ctx, gcli_submit_pull_options opts); +int gitea_pull_submit(struct gcli_ctx *ctx, struct gcli_submit_pull_options opts); int gitea_pull_merge(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id pr_number, enum gcli_merge_flags flags); @@ -67,7 +67,7 @@ int gitea_pull_get_patch(struct gcli_ctx *ctx, FILE *stream, char const *owner, int gitea_pull_get_checks(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id pr_number, - gcli_pull_checks_list *out); + struct gcli_pull_checks_list *out); int gitea_pull_set_milestone(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id pr_number, diff --git a/include/gcli/github/pulls.h b/include/gcli/github/pulls.h index 86f1dde2..30f07abc 100644 --- a/include/gcli/github/pulls.h +++ b/include/gcli/github/pulls.h @@ -38,8 +38,8 @@ #include int github_get_pulls(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_pull_fetch_details const *details, int max, - gcli_pull_list *out); + struct gcli_pull_fetch_details const *details, int max, + struct gcli_pull_list *out); int github_pull_get_diff(struct gcli_ctx *ctx, FILE *stream, char const *owner, char const *reponame, gcli_id pr_number); @@ -49,7 +49,7 @@ int github_pull_get_patch(struct gcli_ctx *ctx, FILE *stream, char const *owner, int github_pull_get_checks(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id pr_number, - gcli_pull_checks_list *out); + struct gcli_pull_checks_list *out); int github_pull_merge(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id pr_number, @@ -61,14 +61,14 @@ int github_pull_reopen(struct gcli_ctx *ctx, char const *owner, int github_pull_close(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id pr_number); -int github_perform_submit_pull(struct gcli_ctx *ctx, gcli_submit_pull_options opts); +int github_perform_submit_pull(struct gcli_ctx *ctx, struct gcli_submit_pull_options opts); int github_get_pull_commits(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id pr_number, - gcli_commit_list *out); + struct gcli_commit_list *out); int github_get_pull(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id pr_number, gcli_pull *out); + gcli_id pr_number, struct gcli_pull *out); sn_sv github_pull_try_derive_head(void); diff --git a/include/gcli/gitlab/merge_requests.h b/include/gcli/gitlab/merge_requests.h index 9cde6f98..889f3ac7 100644 --- a/include/gcli/gitlab/merge_requests.h +++ b/include/gcli/gitlab/merge_requests.h @@ -60,13 +60,13 @@ struct gitlab_diff_list { }; int gitlab_fetch_mrs(struct gcli_ctx *ctx, char *url, int max, - gcli_pull_list *list); + struct gcli_pull_list *list); int gitlab_get_mrs(struct gcli_ctx *ctx, char const *owner, char const *reponame, - gcli_pull_fetch_details const *details, + struct gcli_pull_fetch_details const *details, int max, - gcli_pull_list *out); + struct gcli_pull_list *out); int gitlab_mr_get_diff(struct gcli_ctx *ctx, FILE *stream, char const *owner, char const *reponame, gcli_id mr_number); @@ -84,13 +84,13 @@ int gitlab_mr_reopen(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id mr_number); int gitlab_get_pull(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id mr_number, gcli_pull *out); + gcli_id mr_number, struct gcli_pull *out); int gitlab_get_pull_commits(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id mr_number, - gcli_commit_list *out); + struct gcli_commit_list *out); -int gitlab_perform_submit_mr(struct gcli_ctx *ctx, gcli_submit_pull_options opts); +int gitlab_perform_submit_mr(struct gcli_ctx *ctx, struct gcli_submit_pull_options opts); int gitlab_mr_add_labels(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id mr_number, diff --git a/include/gcli/pulls.h b/include/gcli/pulls.h index b5e79243..28230ade 100644 --- a/include/gcli/pulls.h +++ b/include/gcli/pulls.h @@ -40,16 +40,8 @@ #include #include -typedef struct gcli_pull gcli_pull; -typedef struct gcli_pull_fetch_details gcli_pull_fetch_details; -typedef struct gcli_submit_pull_options gcli_submit_pull_options; -typedef struct gcli_commit gcli_commit; -typedef struct gcli_commit_list gcli_commit_list; -typedef struct gcli_pull_list gcli_pull_list; -typedef struct gcli_pull_checks_list gcli_pull_checks_list; - struct gcli_pull_list { - gcli_pull *pulls; + struct gcli_pull *pulls; size_t pulls_size; }; @@ -91,7 +83,7 @@ struct gcli_commit { }; struct gcli_commit_list { - gcli_commit *commits; + struct gcli_commit *commits; size_t commits_size; }; @@ -130,30 +122,32 @@ struct gcli_pull_checks_list { }; int gcli_get_pulls(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_pull_fetch_details const *details, int max, - gcli_pull_list *out); + struct gcli_pull_fetch_details const *details, int max, + struct gcli_pull_list *out); -void gcli_pull_free(gcli_pull *it); +void gcli_pull_free(struct gcli_pull *it); -void gcli_pulls_free(gcli_pull_list *list); +void gcli_pulls_free(struct gcli_pull_list *list); int gcli_pull_get_diff(struct gcli_ctx *ctx, FILE *fout, char const *owner, char const *repo, gcli_id pr_number); -int gcli_pull_get_checks(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id pr_number, gcli_pull_checks_list *out); +int gcli_pull_get_checks(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id pr_number, + struct gcli_pull_checks_list *out); -void gcli_pull_checks_free(gcli_pull_checks_list *list); +void gcli_pull_checks_free(struct gcli_pull_checks_list *list); -int gcli_pull_get_commits(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id pr_number, gcli_commit_list *out); +int gcli_pull_get_commits(struct gcli_ctx *ctx, char const *owner, + char const *repo, gcli_id pr_number, + struct gcli_commit_list *out); -void gcli_commits_free(gcli_commit_list *list); +void gcli_commits_free(struct gcli_commit_list *list); int gcli_get_pull(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id pr_number, gcli_pull *out); + gcli_id pr_number, struct gcli_pull *out); -int gcli_pull_submit(struct gcli_ctx *ctx, gcli_submit_pull_options); +int gcli_pull_submit(struct gcli_ctx *ctx, struct gcli_submit_pull_options); enum gcli_merge_flags { GCLI_PULL_MERGE_SQUASH = 0x1, /* squash commits when merging */ @@ -178,7 +172,8 @@ int gcli_pull_remove_labels(struct gcli_ctx *ctx, char const *owner, char const *const labels[], size_t labels_size); int gcli_pull_set_milestone(struct gcli_ctx *ctx, char const *owner, - char const *repo, gcli_id pr_number, int milestone_id); + char const *repo, gcli_id pr_number, + int milestone_id); int gcli_pull_clear_milestone(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id pr_number); diff --git a/src/cmd/pulls.c b/src/cmd/pulls.c index 754439f7..76955abb 100644 --- a/src/cmd/pulls.c +++ b/src/cmd/pulls.c @@ -103,7 +103,7 @@ usage(void) void gcli_print_pulls(enum gcli_output_flags const flags, - gcli_pull_list const *const list, int const max) + struct gcli_pull_list const *const list, int const max) { int n; gcli_tbl table; @@ -172,7 +172,7 @@ gcli_pull_print_patch(FILE *stream, char const *owner, char const *reponame, } void -gcli_pull_print(gcli_pull const *const it) +gcli_pull_print(struct gcli_pull const *const it) { gcli_dict dict; struct gcli_forge_descriptor const *const forge = gcli_forge(g_clictx); @@ -239,14 +239,14 @@ gcli_pull_print(gcli_pull const *const it) } void -gcli_pull_print_op(gcli_pull const *const pull) +gcli_pull_print_op(struct gcli_pull const *const pull) { if (pull->body) pretty_print(pull->body, 4, 80, stdout); } static void -gcli_print_checks_list(gcli_pull_checks_list const *const list) +gcli_print_checks_list(struct gcli_pull_checks_list const *const list) { switch (list->forge_type) { case GCLI_FORGE_GITHUB: @@ -263,7 +263,7 @@ gcli_print_checks_list(gcli_pull_checks_list const *const list) int gcli_pull_checks(char const *owner, char const *repo, int pr_number) { - gcli_pull_checks_list list = {0}; + struct gcli_pull_checks_list list = {0}; gcli_forge_type t = gcli_config_get_forge_type(g_clictx); list.forge_type = t; @@ -306,7 +306,7 @@ cut_newline(char const *const _it) } void -gcli_print_commits(gcli_commit_list const *const list) +gcli_print_commits(struct gcli_commit_list const *const list) { gcli_tbl table; struct gcli_tblcoldef cols[] = { @@ -343,7 +343,7 @@ int gcli_pull_commits(char const *owner, char const *repo, int const pr_number) { - gcli_commit_list commits = {0}; + struct gcli_commit_list commits = {0}; int rc = 0; rc = gcli_pull_get_commits(g_clictx, owner, repo, pr_number, &commits); @@ -359,7 +359,7 @@ gcli_pull_commits(char const *owner, char const *repo, static void pull_init_user_file(struct gcli_ctx *ctx, FILE *stream, void *_opts) { - gcli_submit_pull_options *opts = _opts; + struct gcli_submit_pull_options *opts = _opts; (void) ctx; fprintf( @@ -371,13 +371,13 @@ pull_init_user_file(struct gcli_ctx *ctx, FILE *stream, void *_opts) } static char * -gcli_pull_get_user_message(gcli_submit_pull_options *opts) +gcli_pull_get_user_message(struct gcli_submit_pull_options *opts) { return gcli_editor_get_user_message(g_clictx, pull_init_user_file, opts); } static int -create_pull(gcli_submit_pull_options opts, int always_yes) +create_pull(struct gcli_submit_pull_options opts, int always_yes) { opts.body = gcli_pull_get_user_message(&opts); @@ -430,7 +430,7 @@ subcommand_pull_create(int argc, char *argv[]) { /* we'll use getopt_long here to parse the arguments */ int ch; - gcli_submit_pull_options opts = {0}; + struct gcli_submit_pull_options opts = {0}; int always_yes = 0; const struct option options[] = { @@ -539,11 +539,11 @@ subcommand_pulls(int argc, char *argv[]) char *endptr = NULL; char const *owner = NULL; char const *repo = NULL; - gcli_pull_list pulls = {0}; + struct gcli_pull_list pulls = {0}; int ch = 0; int pr = -1; int n = 30; /* how many prs to fetch at least */ - gcli_pull_fetch_details details = {0}; + struct gcli_pull_fetch_details details = {0}; enum gcli_output_flags flags = 0; /* detect whether we wanna create a PR */ @@ -681,7 +681,7 @@ struct action_ctx { * we'll fetch the summary only if a command requires it. Then * we'll proceed to actually handling it. */ int fetched_pull; - gcli_pull pull; + struct gcli_pull pull; }; /** Helper routine for fetching a PR if required */ diff --git a/src/gitea/pulls.c b/src/gitea/pulls.c index d61b13a8..66db5932 100644 --- a/src/gitea/pulls.c +++ b/src/gitea/pulls.c @@ -35,15 +35,15 @@ int gitea_get_pulls(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_pull_fetch_details const *const details, int const max, - gcli_pull_list *const out) + struct gcli_pull_fetch_details const *const details, int const max, + struct gcli_pull_list *const out) { return github_get_pulls(ctx, owner, repo, details, max, out); } int gitea_get_pull(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const pr_number, gcli_pull *const out) + gcli_id const pr_number, struct gcli_pull *const out) { return github_get_pull(ctx, owner, repo, pr_number, out); } @@ -51,13 +51,13 @@ gitea_get_pull(struct gcli_ctx *ctx, char const *owner, char const *repo, int gitea_get_pull_commits(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const pr_number, - gcli_commit_list *const out) + struct gcli_commit_list *const out) { return github_get_pull_commits(ctx, owner, repo, pr_number, out); } int -gitea_pull_submit(struct gcli_ctx *ctx, gcli_submit_pull_options opts) +gitea_pull_submit(struct gcli_ctx *ctx, struct gcli_submit_pull_options opts) { warnx("In case the following process errors out, see: " "https://github.com/go-gitea/gitea/issues/20175"); @@ -205,7 +205,7 @@ gitea_pull_get_diff(struct gcli_ctx *ctx, FILE *const stream, char const *owner, int gitea_pull_get_checks(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const pr_number, gcli_pull_checks_list *out) + gcli_id const pr_number, struct gcli_pull_checks_list *out) { (void) ctx; (void) owner; diff --git a/src/github/pulls.c b/src/github/pulls.c index 20f6d410..e67fbabc 100644 --- a/src/github/pulls.c +++ b/src/github/pulls.c @@ -53,7 +53,7 @@ * allocation. */ static bool -pull_has_label(gcli_pull const *p, char const *const label) +pull_has_label(struct gcli_pull const *p, char const *const label) { for (size_t i = 0; i < p->labels_size; ++i) { if (strcmp(p->labels[i], label) == 0) @@ -63,12 +63,12 @@ pull_has_label(gcli_pull const *p, char const *const label) } static void -github_pulls_filter(gcli_pull **listp, size_t *sizep, - gcli_pull_fetch_details const *details) +github_pulls_filter(struct gcli_pull **listp, size_t *sizep, + struct gcli_pull_fetch_details const *details) { for (size_t i = *sizep; i > 0; --i) { - gcli_pull *pulls = *listp; - gcli_pull *pull = &pulls[i-1]; + struct gcli_pull *pulls = *listp; + struct gcli_pull *pull = &pulls[i-1]; bool should_remove = false; if (details->author && strcmp(details->author, pull->author)) @@ -92,8 +92,8 @@ github_pulls_filter(gcli_pull **listp, size_t *sizep, static int github_fetch_pulls(struct gcli_ctx *ctx, char *url, - gcli_pull_fetch_details const *details, int max, - gcli_pull_list *const list) + struct gcli_pull_fetch_details const *details, int max, + struct gcli_pull_list *const list) { struct gcli_fetch_list_ctx fl = { .listp = &list->pulls, @@ -109,8 +109,8 @@ github_fetch_pulls(struct gcli_ctx *ctx, char *url, int github_get_pulls(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_pull_fetch_details const *const details, - int const max, gcli_pull_list *const list) + struct gcli_pull_fetch_details const *const details, + int const max, struct gcli_pull_list *const list) { char *url = NULL; char *e_owner = NULL; @@ -186,7 +186,7 @@ static int github_pull_delete_head_branch(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const pr_number) { - gcli_pull pull = {0}; + struct gcli_pull pull = {0}; char *url, *e_owner, *e_repo; char const *head_branch; int rc = 0; @@ -299,7 +299,7 @@ github_pull_reopen(struct gcli_ctx *ctx, char const *owner, char const *repo, } int -github_perform_submit_pull(struct gcli_ctx *ctx, gcli_submit_pull_options opts) +github_perform_submit_pull(struct gcli_ctx *ctx, struct gcli_submit_pull_options opts) { char *url = NULL, *payload = NULL, *e_owner = NULL, *e_repo = NULL; struct gcli_fetch_buffer fetch_buffer = {0}; @@ -340,7 +340,7 @@ github_perform_submit_pull(struct gcli_ctx *ctx, gcli_submit_pull_options opts) * with one request. */ if (rc == 0 && opts.labels_size) { json_stream json = {0}; - gcli_pull pull = {0}; + struct gcli_pull pull = {0}; json_open_buffer(&json, fetch_buffer.data, fetch_buffer.length); parse_github_pull(ctx, &json, &pull); @@ -362,7 +362,7 @@ github_perform_submit_pull(struct gcli_ctx *ctx, gcli_submit_pull_options opts) } static void -filter_commit_short_sha(gcli_commit **listp, size_t *sizep, void *_data) +filter_commit_short_sha(struct gcli_commit **listp, size_t *sizep, void *_data) { (void) _data; @@ -373,7 +373,7 @@ filter_commit_short_sha(gcli_commit **listp, size_t *sizep, void *_data) int github_get_pull_commits(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const pr, - gcli_commit_list *const out) + struct gcli_commit_list *const out) { char *url = NULL; char *e_owner = NULL; @@ -401,7 +401,7 @@ github_get_pull_commits(struct gcli_ctx *ctx, char const *owner, int github_get_pull(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const pr, gcli_pull *const out) + gcli_id const pr, struct gcli_pull *const out) { int rc = 0; struct gcli_fetch_buffer json_buffer = {0}; @@ -433,7 +433,7 @@ github_get_pull(struct gcli_ctx *ctx, char const *owner, char const *repo, int github_pull_get_checks(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const pr_number, gcli_pull_checks_list *out) + gcli_id const pr_number, struct gcli_pull_checks_list *out) { char refname[64] = {0}; diff --git a/src/gitlab/merge_requests.c b/src/gitlab/merge_requests.c index d03bfb68..af6be7e0 100644 --- a/src/gitlab/merge_requests.c +++ b/src/gitlab/merge_requests.c @@ -42,7 +42,7 @@ /* Workaround because gitlab doesn't give us an explicit field for * this. */ static void -gitlab_mrs_fixup(gcli_pull_list *const list) +gitlab_mrs_fixup(struct gcli_pull_list *const list) { for (size_t i = 0; i < list->pulls_size; ++i) { list->pulls[i].merged = !strcmp(list->pulls[i].state, "merged"); @@ -51,7 +51,7 @@ gitlab_mrs_fixup(gcli_pull_list *const list) int gitlab_fetch_mrs(struct gcli_ctx *ctx, char *url, int const max, - gcli_pull_list *const list) + struct gcli_pull_list *const list) { int rc = 0; @@ -73,8 +73,8 @@ gitlab_fetch_mrs(struct gcli_ctx *ctx, char *url, int const max, int gitlab_get_mrs(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_pull_fetch_details const *const details, int const max, - gcli_pull_list *const list) + struct gcli_pull_fetch_details const *const details, int const max, + struct gcli_pull_list *const list) { char *url = NULL; char *e_owner = NULL; @@ -149,7 +149,7 @@ gitlab_free_diffs(struct gitlab_diff_list *list) } static void -gitlab_make_commit_diff(gcli_commit const *const commit, +gitlab_make_commit_diff(struct gcli_commit const *const commit, struct gitlab_diff const *const diff, char const *const prev_commit_sha, FILE *const out) { @@ -175,7 +175,7 @@ static int gitlab_make_commit_patch(struct gcli_ctx *ctx, FILE *stream, char const *const e_owner, char const *const e_repo, char const *const prev_commit_sha, - gcli_commit const *const commit) + struct gcli_commit const *const commit) { char *url; int rc; @@ -221,8 +221,8 @@ gitlab_mr_get_patch(struct gcli_ctx *ctx, FILE *stream, char const *owner, { int rc = 0; char *e_owner, *e_repo; - gcli_pull pull = {0}; - gcli_commit_list commits = {0}; + struct gcli_pull pull = {0}; + struct gcli_commit_list commits = {0}; char const *prev_commit_sha; char *base_sha_short; @@ -310,7 +310,7 @@ gitlab_mr_merge(struct gcli_ctx *ctx, char const *owner, char const *repo, int gitlab_get_pull(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const pr_number, gcli_pull *const out) + gcli_id const pr_number, struct gcli_pull *const out) { struct gcli_fetch_buffer json_buffer = {0}; char *url = NULL; @@ -344,7 +344,7 @@ gitlab_get_pull(struct gcli_ctx *ctx, char const *owner, char const *repo, int gitlab_get_pull_commits(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const pr_number, gcli_commit_list *const out) + gcli_id const pr_number, struct gcli_commit_list *const out) { char *url = NULL; char *e_owner = NULL; @@ -424,7 +424,7 @@ gitlab_mr_reopen(struct gcli_ctx *ctx, char const *owner, char const *repo, } int -gitlab_perform_submit_mr(struct gcli_ctx *ctx, gcli_submit_pull_options opts) +gitlab_perform_submit_mr(struct gcli_ctx *ctx, struct gcli_submit_pull_options opts) { /* Note: this doesn't really allow merging into repos with * different names. We need to figure out a way to make this diff --git a/src/pulls.c b/src/pulls.c index 49c2e142..5c17a4f6 100644 --- a/src/pulls.c +++ b/src/pulls.c @@ -38,7 +38,7 @@ #include void -gcli_pulls_free(gcli_pull_list *const it) +gcli_pulls_free(struct gcli_pull_list *const it) { for (size_t i = 0; i < it->pulls_size; ++i) gcli_pull_free(&it->pulls[i]); @@ -51,8 +51,8 @@ gcli_pulls_free(gcli_pull_list *const it) int gcli_get_pulls(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_pull_fetch_details const *const details, int const max, - gcli_pull_list *const out) + struct gcli_pull_fetch_details const *const details, int const max, + struct gcli_pull_list *const out) { gcli_null_check_call(get_pulls, ctx, owner, repo, details, max, out); } @@ -67,13 +67,13 @@ gcli_pull_get_diff(struct gcli_ctx *ctx, FILE *stream, char const *owner, int gcli_pull_get_commits(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const pr_number, gcli_commit_list *const out) + gcli_id const pr_number, struct gcli_commit_list *const out) { gcli_null_check_call(get_pull_commits, ctx, owner, repo, pr_number, out); } void -gcli_commits_free(gcli_commit_list *list) +gcli_commits_free(struct gcli_commit_list *list) { for (size_t i = 0; i < list->commits_size; ++i) { free(list->commits[i].sha); @@ -91,7 +91,7 @@ gcli_commits_free(gcli_commit_list *list) } void -gcli_pull_free(gcli_pull *const it) +gcli_pull_free(struct gcli_pull *const it) { free(it->author); free(it->state); @@ -114,20 +114,20 @@ gcli_pull_free(gcli_pull *const it) int gcli_get_pull(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const pr_number, gcli_pull *const out) + gcli_id const pr_number, struct gcli_pull *const out) { gcli_null_check_call(get_pull, ctx, owner, repo, pr_number, out); } int gcli_pull_get_checks(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_id const pr_number, gcli_pull_checks_list *out) + gcli_id const pr_number, struct gcli_pull_checks_list *out) { gcli_null_check_call(get_pull_checks, ctx, owner, repo, pr_number, out); } void -gcli_pull_checks_free(gcli_pull_checks_list *list) +gcli_pull_checks_free(struct gcli_pull_checks_list *list) { switch (list->forge_type) { case GCLI_FORGE_GITHUB: @@ -142,7 +142,7 @@ gcli_pull_checks_free(gcli_pull_checks_list *list) } int -gcli_pull_submit(struct gcli_ctx *ctx, gcli_submit_pull_options opts) +gcli_pull_submit(struct gcli_ctx *ctx, struct gcli_submit_pull_options opts) { gcli_null_check_call(perform_submit_pull, ctx, opts); } diff --git a/templates/github/pulls.t b/templates/github/pulls.t index a8437b5a..f0bbad53 100644 --- a/templates/github/pulls.t +++ b/templates/github/pulls.t @@ -2,42 +2,42 @@ include "gcli/pulls.h"; include "templates/github/labels.h"; parser github_commit_author_field is -object of gcli_commit with +object of struct gcli_commit with ("name" => author as string, "email" => email as string, "date" => date as string); parser github_commit_commit_field is -object of gcli_commit with +object of struct gcli_commit with ("message" => message as string, "author" => use parse_github_commit_author_field); parser github_commit is -object of gcli_commit with +object of struct gcli_commit with ("sha" => long_sha as string, "commit" => use parse_github_commit_commit_field); -parser github_commits is array of gcli_commit +parser github_commits is array of struct gcli_commit use parse_github_commit; parser github_pull_head is -object of gcli_pull with +object of struct gcli_pull with ("sha" => head_sha as string, "label" => head_label as string); parser github_branch_label is -object of gcli_pull with +object of struct gcli_pull with ("label" => base_label as string); parser github_pull_milestone is -object of gcli_pull with +object of struct gcli_pull with ("title" => milestone as string); parser github_reviewer is object of char* select "login" as string; parser github_pull is -object of gcli_pull with +object of struct gcli_pull with ("title" => title as string, "state" => state as string, "body" => body as string, @@ -62,5 +62,5 @@ object of gcli_pull with parser github_pr_merge_message is object of char* select "message" as string; -parser github_pulls is array of gcli_pull +parser github_pulls is array of struct gcli_pull use parse_github_pull; diff --git a/templates/gitlab/merge_requests.t b/templates/gitlab/merge_requests.t index 277e99e8..d220521e 100644 --- a/templates/gitlab/merge_requests.t +++ b/templates/gitlab/merge_requests.t @@ -1,23 +1,23 @@ include "gcli/gitlab/merge_requests.h"; parser gitlab_mr_milestone is -object of gcli_pull with +object of struct gcli_pull with ("title" => milestone as string); parser gitlab_mr_head_pipeline is -object of gcli_pull with +object of struct gcli_pull with ("id" => head_pipeline_id as int, "coverage" => coverage as string); parser gitlab_reviewer is object of char* select "username" as string; parser gitlab_diff_refs is -object of gcli_pull with +object of struct gcli_pull with ("base_sha" => base_sha as string, "head_sha" => head_sha as string); parser gitlab_mr is -object of gcli_pull with +object of struct gcli_pull with ("title" => title as string, "state" => state as string, "description" => body as string, @@ -36,10 +36,10 @@ object of gcli_pull with "reviewers" => reviewers as array of char* use parse_gitlab_reviewer, "diff_refs" => use parse_gitlab_diff_refs); -parser gitlab_mrs is array of gcli_pull use parse_gitlab_mr; +parser gitlab_mrs is array of struct gcli_pull use parse_gitlab_mr; parser gitlab_commit is -object of gcli_commit with +object of struct gcli_commit with ("short_id" => sha as string, "id" => long_sha as string, "title" => message as string, @@ -47,7 +47,7 @@ object of gcli_commit with "author_name" => author as string, "author_email" => email as string); -parser gitlab_commits is array of gcli_commit use parse_gitlab_commit; +parser gitlab_commits is array of struct gcli_commit use parse_gitlab_commit; parser gitlab_reviewer_id is object of gcli_id select "id" as id; diff --git a/tests/github-parse-tests.c b/tests/github-parse-tests.c index cd107f1d..dde53fe0 100644 --- a/tests/github-parse-tests.c +++ b/tests/github-parse-tests.c @@ -115,7 +115,7 @@ ATF_TC_BODY(simple_github_issue, tc) ATF_TC_WITHOUT_HEAD(simple_github_pull); ATF_TC_BODY(simple_github_pull, tc) { - gcli_pull pull = {0}; + struct gcli_pull pull = {0}; FILE *f; json_stream stream; struct gcli_ctx *ctx = test_context(); diff --git a/tests/gitlab-parse-tests.c b/tests/gitlab-parse-tests.c index c708e381..90e63cc7 100644 --- a/tests/gitlab-parse-tests.c +++ b/tests/gitlab-parse-tests.c @@ -49,7 +49,7 @@ ATF_TC_BODY(gitlab_simple_merge_request, tc) json_stream stream = {0}; struct gcli_ctx *ctx = test_context(); FILE *f = open_sample("gitlab_simple_merge_request.json"); - gcli_pull pull = {0}; + struct gcli_pull pull = {0}; json_open_stream(&stream, f); ATF_REQUIRE(parse_gitlab_mr(ctx, &stream, &pull) == 0); From a9ddb80d2818654bea922bd12847b268fb4c7404 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 5 Jan 2024 21:27:52 +0100 Subject: [PATCH 119/158] Remove struct typedefs in gcli_repos --- include/gcli/cmd/repos.h | 4 ++-- include/gcli/forges.h | 6 +++--- include/gcli/gitea/repos.h | 11 +++++++---- include/gcli/github/repos.h | 13 ++++++++----- include/gcli/gitlab/repos.h | 13 ++++++++----- include/gcli/repos.h | 17 +++++++---------- src/cmd/repos.c | 10 +++++----- src/gitea/repos.c | 8 ++++---- src/github/repos.c | 8 ++++---- src/gitlab/merge_requests.c | 2 +- src/gitlab/repos.c | 10 +++++----- src/repos.c | 10 +++++----- templates/github/repos.t | 4 ++-- templates/gitlab/repos.t | 4 ++-- tests/github-parse-tests.c | 2 +- tests/gitlab-parse-tests.c | 2 +- 16 files changed, 65 insertions(+), 59 deletions(-) diff --git a/include/gcli/cmd/repos.h b/include/gcli/cmd/repos.h index c7ab4653..26d8893a 100644 --- a/include/gcli/cmd/repos.h +++ b/include/gcli/cmd/repos.h @@ -37,10 +37,10 @@ #include #include -void gcli_print_repos(enum gcli_output_flags flags, gcli_repo_list const *repos, +void gcli_print_repos(enum gcli_output_flags flags, struct gcli_repo_list const *repos, int max); -void gcli_repo_print(gcli_repo const *it); +void gcli_repo_print(struct gcli_repo const *it); int subcommand_repos(int argc, char *argv[]); diff --git a/include/gcli/forges.h b/include/gcli/forges.h index d7caf477..f1d97c0c 100644 --- a/include/gcli/forges.h +++ b/include/gcli/forges.h @@ -483,14 +483,14 @@ struct gcli_forge_descriptor { struct gcli_ctx *ctx, char const *owner, int max, - gcli_repo_list *out); + struct gcli_repo_list *out); /** * Create the given repo */ int (*repo_create)( struct gcli_ctx *ctx, - gcli_repo_create_options const *options, - gcli_repo *out); + struct gcli_repo_create_options const *options, + struct gcli_repo *out); /** * Delete the given repo */ diff --git a/include/gcli/gitea/repos.h b/include/gcli/gitea/repos.h index d45194bb..281b6508 100644 --- a/include/gcli/gitea/repos.h +++ b/include/gcli/gitea/repos.h @@ -37,16 +37,19 @@ #include int gitea_get_repos(struct gcli_ctx *ctx, char const *owner, int max, - gcli_repo_list *out); + struct gcli_repo_list *out); -int gitea_get_own_repos(struct gcli_ctx *ctx, int max, gcli_repo_list *out); +int gitea_get_own_repos(struct gcli_ctx *ctx, int max, + struct gcli_repo_list *out); int gitea_repo_create(struct gcli_ctx *ctx, - gcli_repo_create_options const *options, gcli_repo *out); + struct gcli_repo_create_options const *options, + struct gcli_repo *out); int gitea_repo_delete(struct gcli_ctx *ctx, char const *owner, char const *repo); int gitea_repo_set_visibility(struct gcli_ctx *ctx, char const *const owner, - char const *const repo, gcli_repo_visibility vis); + char const *const repo, + gcli_repo_visibility vis); #endif /* GITEA_REPOS_H */ diff --git a/include/gcli/github/repos.h b/include/gcli/github/repos.h index 832de760..77ca147b 100644 --- a/include/gcli/github/repos.h +++ b/include/gcli/github/repos.h @@ -37,14 +37,17 @@ #include int github_get_repos(struct gcli_ctx *ctx, char const *owner, int max, - gcli_repo_list *out); + struct gcli_repo_list *out); -int github_get_own_repos(struct gcli_ctx *ctx, int max, gcli_repo_list *out); +int github_get_own_repos(struct gcli_ctx *ctx, int max, + struct gcli_repo_list *out); -int github_repo_delete(struct gcli_ctx *ctx, char const *owner, char const *repo); +int github_repo_delete(struct gcli_ctx *ctx, char const *owner, + char const *repo); -int github_repo_create(struct gcli_ctx *ctx, gcli_repo_create_options const *options, - gcli_repo *out); +int github_repo_create(struct gcli_ctx *ctx, + struct gcli_repo_create_options const *options, + struct gcli_repo *out); int github_repo_set_visibility(struct gcli_ctx *ctx, char const *const owner, char const *const repo, diff --git a/include/gcli/gitlab/repos.h b/include/gcli/gitlab/repos.h index 4c1fb1f8..785193ae 100644 --- a/include/gcli/gitlab/repos.h +++ b/include/gcli/gitlab/repos.h @@ -37,17 +37,20 @@ #include int gitlab_get_repo(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_repo *out); + struct gcli_repo *out); int gitlab_get_repos(struct gcli_ctx *ctx, char const *owner, int max, - gcli_repo_list *out); + struct gcli_repo_list *out); -int gitlab_get_own_repos(struct gcli_ctx *ctx, int max, gcli_repo_list *out); +int gitlab_get_own_repos(struct gcli_ctx *ctx, int max, + struct gcli_repo_list *out); -int gitlab_repo_delete(struct gcli_ctx *ctx, char const *owner, char const *repo); +int gitlab_repo_delete(struct gcli_ctx *ctx, char const *owner, + char const *repo); int gitlab_repo_create(struct gcli_ctx *ctx, - gcli_repo_create_options const *options, gcli_repo *out); + struct gcli_repo_create_options const *options, + struct gcli_repo *out); int gitlab_repo_set_visibility(struct gcli_ctx *ctx, char const *const owner, char const *const repo, diff --git a/include/gcli/repos.h b/include/gcli/repos.h index 29769ce9..1cefe1e6 100644 --- a/include/gcli/repos.h +++ b/include/gcli/repos.h @@ -37,10 +37,6 @@ #include #include -typedef struct gcli_repo gcli_repo; -typedef struct gcli_repo_list gcli_repo_list; -typedef struct gcli_repo_create_options gcli_repo_create_options; - struct gcli_repo { gcli_id id; char *full_name; @@ -52,7 +48,7 @@ struct gcli_repo { }; struct gcli_repo_list { - gcli_repo *repos; + struct gcli_repo *repos; size_t repos_size; }; @@ -68,15 +64,16 @@ typedef enum { } gcli_repo_visibility; int gcli_get_repos(struct gcli_ctx *ctx, char const *owner, int max, - gcli_repo_list *list); + struct gcli_repo_list *list); -void gcli_repos_free(gcli_repo_list *list); -void gcli_repo_free(gcli_repo *it); +void gcli_repos_free(struct gcli_repo_list *list); +void gcli_repo_free(struct gcli_repo *it); int gcli_repo_delete(struct gcli_ctx *ctx, char const *owner, char const *repo); -int gcli_repo_create(struct gcli_ctx *ctx, gcli_repo_create_options const *, - gcli_repo *out); +int gcli_repo_create(struct gcli_ctx *ctx, + struct gcli_repo_create_options const *, + struct gcli_repo *out); int gcli_repo_set_visibility(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_repo_visibility visibility); diff --git a/src/cmd/repos.c b/src/cmd/repos.c index e35e411c..c2b47106 100644 --- a/src/cmd/repos.c +++ b/src/cmd/repos.c @@ -67,7 +67,7 @@ usage(void) void gcli_print_repos(enum gcli_output_flags const flags, - gcli_repo_list const *const list, int const max) + struct gcli_repo_list const *const list, int const max) { size_t n; gcli_tbl table; @@ -116,7 +116,7 @@ gcli_print_repos(enum gcli_output_flags const flags, } void -gcli_repo_print(gcli_repo const *it) +gcli_repo_print(struct gcli_repo const *it) { gcli_dict dict; @@ -136,8 +136,8 @@ static int subcommand_repos_create(int argc, char *argv[]) { int ch; - gcli_repo_create_options create_options = {0}; - gcli_repo repo = {0}; + struct gcli_repo_create_options create_options = {0}; + struct gcli_repo repo = {0}; const struct option options[] = { { .name = "repo", @@ -301,7 +301,7 @@ subcommand_repos(int argc, char *argv[]) int ch, n = 30; char const *owner = NULL; char const *repo = NULL; - gcli_repo_list repos = {0}; + struct gcli_repo_list repos = {0}; enum gcli_output_flags flags = 0; /* detect whether we wanna create a repo */ diff --git a/src/gitea/repos.c b/src/gitea/repos.c index aab44c06..8b8f6548 100644 --- a/src/gitea/repos.c +++ b/src/gitea/repos.c @@ -36,21 +36,21 @@ int gitea_get_repos(struct gcli_ctx *ctx, char const *owner, int const max, - gcli_repo_list *const list) + struct gcli_repo_list *const list) { return github_get_repos(ctx, owner, max, list); } int gitea_get_own_repos(struct gcli_ctx *ctx, int const max, - gcli_repo_list *const list) + struct gcli_repo_list *const list) { return github_get_own_repos(ctx, max, list); } int -gitea_repo_create(struct gcli_ctx *ctx, gcli_repo_create_options const *options, - gcli_repo *const out) +gitea_repo_create(struct gcli_ctx *ctx, struct gcli_repo_create_options const *options, + struct gcli_repo *const out) { return github_repo_create(ctx, options, out); } diff --git a/src/github/repos.c b/src/github/repos.c index 72a36546..32d5de3e 100644 --- a/src/github/repos.c +++ b/src/github/repos.c @@ -41,7 +41,7 @@ int github_get_repos(struct gcli_ctx *ctx, char const *owner, int const max, - gcli_repo_list *const list) + struct gcli_repo_list *const list) { char *url = NULL; char *e_owner = NULL; @@ -90,7 +90,7 @@ github_get_repos(struct gcli_ctx *ctx, char const *owner, int const max, int github_get_own_repos(struct gcli_ctx *ctx, int const max, - gcli_repo_list *const list) + struct gcli_repo_list *const list) { char *url = NULL; struct gcli_fetch_list_ctx fl = { @@ -130,8 +130,8 @@ github_repo_delete(struct gcli_ctx *ctx, char const *owner, char const *repo) } int -github_repo_create(struct gcli_ctx *ctx, gcli_repo_create_options const *options, - gcli_repo *const out) +github_repo_create(struct gcli_ctx *ctx, struct gcli_repo_create_options const *options, + struct gcli_repo *const out) { char *url, *payload; struct gcli_fetch_buffer buffer = {0}; diff --git a/src/gitlab/merge_requests.c b/src/gitlab/merge_requests.c index af6be7e0..8479a4b2 100644 --- a/src/gitlab/merge_requests.c +++ b/src/gitlab/merge_requests.c @@ -433,7 +433,7 @@ gitlab_perform_submit_mr(struct gcli_ctx *ctx, struct gcli_submit_pull_options o *e_owner = NULL, *e_repo = NULL, *url = NULL; char const *target_branch = NULL; struct gcli_jsongen gen = {0}; - gcli_repo target = {0}; + struct gcli_repo target = {0}; int rc = 0; target_branch = opts.to; diff --git a/src/gitlab/repos.c b/src/gitlab/repos.c index 19f5f934..c6f405d0 100644 --- a/src/gitlab/repos.c +++ b/src/gitlab/repos.c @@ -41,7 +41,7 @@ int gitlab_get_repo(struct gcli_ctx *ctx, char const *owner, char const *repo, - gcli_repo *const out) + struct gcli_repo *const out) { /* GET /projects/:id */ char *url = NULL; @@ -74,7 +74,7 @@ gitlab_get_repo(struct gcli_ctx *ctx, char const *owner, char const *repo, } static void -gitlab_repos_fixup_missing_visibility(gcli_repo_list *const list) +gitlab_repos_fixup_missing_visibility(struct gcli_repo_list *const list) { static char const *const public = "public"; @@ -89,7 +89,7 @@ gitlab_repos_fixup_missing_visibility(gcli_repo_list *const list) int gitlab_get_repos(struct gcli_ctx *ctx, char const *owner, int const max, - gcli_repo_list *const list) + struct gcli_repo_list *const list) { char *url = NULL; char *e_owner = NULL; @@ -137,8 +137,8 @@ gitlab_repo_delete(struct gcli_ctx *ctx, char const *owner, char const *repo) } int -gitlab_repo_create(struct gcli_ctx *ctx, gcli_repo_create_options const *options, - gcli_repo *out) +gitlab_repo_create(struct gcli_ctx *ctx, struct gcli_repo_create_options const *options, + struct gcli_repo *out) { char *url, *payload; struct gcli_fetch_buffer buffer = {0}; diff --git a/src/repos.c b/src/repos.c index 8bd22699..14a5c501 100644 --- a/src/repos.c +++ b/src/repos.c @@ -36,13 +36,13 @@ int gcli_get_repos(struct gcli_ctx *ctx, char const *owner, int const max, - gcli_repo_list *const out) + struct gcli_repo_list *const out) { gcli_null_check_call(get_repos, ctx, owner, max, out); } void -gcli_repo_free(gcli_repo *it) +gcli_repo_free(struct gcli_repo *it) { free(it->full_name); free(it->name); @@ -53,7 +53,7 @@ gcli_repo_free(gcli_repo *it) } void -gcli_repos_free(gcli_repo_list *const list) +gcli_repos_free(struct gcli_repo_list *const list) { for (size_t i = 0; i < list->repos_size; ++i) { gcli_repo_free(&list->repos[i]); @@ -72,8 +72,8 @@ gcli_repo_delete(struct gcli_ctx *ctx, char const *owner, char const *repo) } int -gcli_repo_create(struct gcli_ctx *ctx, gcli_repo_create_options const *options, - gcli_repo *out) +gcli_repo_create(struct gcli_ctx *ctx, struct gcli_repo_create_options const *options, + struct gcli_repo *out) { gcli_null_check_call(repo_create, ctx, options, out); } diff --git a/templates/github/repos.t b/templates/github/repos.t index 90a77c04..533bd43d 100644 --- a/templates/github/repos.t +++ b/templates/github/repos.t @@ -2,7 +2,7 @@ include "gcli/github/repos.h"; include "gcli/gitea/repos.h"; parser github_repo is -object of gcli_repo with +object of struct gcli_repo with ("id" => id as id, "full_name" => full_name as string, "name" => name as string, @@ -12,5 +12,5 @@ object of gcli_repo with "private" => visibility as gitea_visibility, "fork" => is_fork as bool); -parser github_repos is array of gcli_repo +parser github_repos is array of struct gcli_repo use parse_github_repo; diff --git a/templates/gitlab/repos.t b/templates/gitlab/repos.t index 8ee7b75e..01429ee8 100644 --- a/templates/gitlab/repos.t +++ b/templates/gitlab/repos.t @@ -1,7 +1,7 @@ include "gcli/gitlab/repos.h"; parser gitlab_repo is -object of gcli_repo with +object of struct gcli_repo with ("path_with_namespace" => full_name as string, "name" => name as string, "owner" => owner as user, @@ -11,4 +11,4 @@ object of gcli_repo with "id" => id as id); parser gitlab_repos is -array of gcli_repo use parse_gitlab_repo; +array of struct gcli_repo use parse_gitlab_repo; diff --git a/tests/github-parse-tests.c b/tests/github-parse-tests.c index dde53fe0..5e4389cb 100644 --- a/tests/github-parse-tests.c +++ b/tests/github-parse-tests.c @@ -236,7 +236,7 @@ ATF_TC_BODY(simple_github_release, tc) ATF_TC_WITHOUT_HEAD(simple_github_repo); ATF_TC_BODY(simple_github_repo, tc) { - gcli_repo repo = {0}; + struct gcli_repo repo = {0}; FILE *f; json_stream stream; struct gcli_ctx *ctx = test_context(); diff --git a/tests/gitlab-parse-tests.c b/tests/gitlab-parse-tests.c index 90e63cc7..235f3485 100644 --- a/tests/gitlab-parse-tests.c +++ b/tests/gitlab-parse-tests.c @@ -268,7 +268,7 @@ ATF_TC_BODY(gitlab_simple_repo, tc) json_stream stream = {0}; struct gcli_ctx *ctx = test_context(); FILE *f = open_sample("gitlab_simple_repo.json"); - gcli_repo repo = {0}; + struct gcli_repo repo = {0}; json_open_stream(&stream, f); ATF_REQUIRE(parse_gitlab_repo(ctx, &stream, &repo) == 0); From 411252eb6047d084c8cbe0d9a4700750771eac1d Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 5 Jan 2024 21:31:55 +0100 Subject: [PATCH 120/158] Remove struct typedefs for sshkeys --- include/gcli/cmd/config.h | 2 +- include/gcli/forges.h | 4 ++-- include/gcli/gitea/sshkeys.h | 4 ++-- include/gcli/github/sshkeys.h | 4 ++-- include/gcli/gitlab/sshkeys.h | 4 ++-- include/gcli/sshkeys.h | 9 +++------ src/cmd/config.c | 4 ++-- src/gitea/sshkeys.c | 4 ++-- src/github/sshkeys.c | 4 ++-- src/gitlab/sshkeys.c | 6 +++--- src/sshkeys.c | 6 +++--- templates/gitlab/sshkeys.t | 4 ++-- 12 files changed, 26 insertions(+), 29 deletions(-) diff --git a/include/gcli/cmd/config.h b/include/gcli/cmd/config.h index 7e0ce117..2dcedbcf 100644 --- a/include/gcli/cmd/config.h +++ b/include/gcli/cmd/config.h @@ -37,7 +37,7 @@ #include #include -void gcli_sshkeys_print_keys(gcli_sshkey_list const *list); +void gcli_sshkeys_print_keys(struct gcli_sshkey_list const *list); int subcommand_config(int argc, char *argv[]); diff --git a/include/gcli/forges.h b/include/gcli/forges.h index f1d97c0c..bc69a505 100644 --- a/include/gcli/forges.h +++ b/include/gcli/forges.h @@ -528,7 +528,7 @@ struct gcli_forge_descriptor { /** * Get list of SSH keys */ - int (*get_sshkeys)(struct gcli_ctx *ctx, gcli_sshkey_list *); + int (*get_sshkeys)(struct gcli_ctx *ctx, struct gcli_sshkey_list *); /** * Add an SSH public key */ @@ -536,7 +536,7 @@ struct gcli_forge_descriptor { struct gcli_ctx *ctx, char const *title, char const *public_key_path, - gcli_sshkey *out); + struct gcli_sshkey *out); /** * Delete an SSH public key by its ID */ diff --git a/include/gcli/gitea/sshkeys.h b/include/gcli/gitea/sshkeys.h index 3dbff012..7afabd66 100644 --- a/include/gcli/gitea/sshkeys.h +++ b/include/gcli/gitea/sshkeys.h @@ -32,10 +32,10 @@ #include -int gitea_get_sshkeys(struct gcli_ctx *ctx, gcli_sshkey_list *out); +int gitea_get_sshkeys(struct gcli_ctx *ctx, struct gcli_sshkey_list *out); int gitea_add_sshkey(struct gcli_ctx *ctx, char const *title, - char const *public_key_data, gcli_sshkey *out); + char const *public_key_data, struct gcli_sshkey *out); int gitea_delete_sshkey(struct gcli_ctx *ctx, gcli_id id); diff --git a/include/gcli/github/sshkeys.h b/include/gcli/github/sshkeys.h index 579c7015..0cae5fdf 100644 --- a/include/gcli/github/sshkeys.h +++ b/include/gcli/github/sshkeys.h @@ -32,10 +32,10 @@ #include -int github_get_sshkeys(struct gcli_ctx *ctx, gcli_sshkey_list *out); +int github_get_sshkeys(struct gcli_ctx *ctx, struct gcli_sshkey_list *out); int github_add_sshkey(struct gcli_ctx *ctx, char const *const title, - char const *const pubkey, gcli_sshkey *out); + char const *const pubkey, struct gcli_sshkey *out); int github_delete_sshkey(struct gcli_ctx *ctx, gcli_id id); diff --git a/include/gcli/gitlab/sshkeys.h b/include/gcli/gitlab/sshkeys.h index 2e3c29b0..61ac3639 100644 --- a/include/gcli/gitlab/sshkeys.h +++ b/include/gcli/gitlab/sshkeys.h @@ -36,10 +36,10 @@ #include -int gitlab_get_sshkeys(struct gcli_ctx *ctx, gcli_sshkey_list *list); +int gitlab_get_sshkeys(struct gcli_ctx *ctx, struct gcli_sshkey_list *list); int gitlab_add_sshkey(struct gcli_ctx *ctx, char const *const title, - char const *const pubkey, gcli_sshkey *const out); + char const *const pubkey, struct gcli_sshkey *const out); int gitlab_delete_sshkey(struct gcli_ctx *ctx, gcli_id id); diff --git a/include/gcli/sshkeys.h b/include/gcli/sshkeys.h index 326611d8..911b3524 100644 --- a/include/gcli/sshkeys.h +++ b/include/gcli/sshkeys.h @@ -50,13 +50,10 @@ struct gcli_sshkey_list { size_t keys_size; }; -typedef struct gcli_sshkey gcli_sshkey; -typedef struct gcli_sshkey_list gcli_sshkey_list; - -int gcli_sshkeys_get_keys(struct gcli_ctx *ctx, gcli_sshkey_list *out); +int gcli_sshkeys_get_keys(struct gcli_ctx *ctx, struct gcli_sshkey_list *out); int gcli_sshkeys_add_key(struct gcli_ctx *ctx, char const *title, - char const *public_key_path, gcli_sshkey *out); + char const *public_key_path, struct gcli_sshkey *out); int gcli_sshkeys_delete_key(struct gcli_ctx *ctx, gcli_id id); -void gcli_sshkeys_free_keys(gcli_sshkey_list *list); +void gcli_sshkeys_free_keys(struct gcli_sshkey_list *list); #endif /* GCLI_SSHKEYS_H */ diff --git a/src/cmd/config.c b/src/cmd/config.c index 7d5aa269..cd2d49c2 100644 --- a/src/cmd/config.c +++ b/src/cmd/config.c @@ -59,7 +59,7 @@ usage(void) } void -gcli_sshkeys_print_keys(gcli_sshkey_list const *list) +gcli_sshkeys_print_keys(struct gcli_sshkey_list const *list) { gcli_tbl *tbl; struct gcli_tblcoldef cols[] = { @@ -86,7 +86,7 @@ gcli_sshkeys_print_keys(gcli_sshkey_list const *list) static int list_sshkeys(void) { - gcli_sshkey_list list = {0}; + struct gcli_sshkey_list list = {0}; if (gcli_sshkeys_get_keys(g_clictx, &list) < 0) { fprintf(stderr, "gcli: error: could not get list of SSH keys\n"); diff --git a/src/gitea/sshkeys.c b/src/gitea/sshkeys.c index 25a87c77..9430ea79 100644 --- a/src/gitea/sshkeys.c +++ b/src/gitea/sshkeys.c @@ -37,14 +37,14 @@ #include int -gitea_get_sshkeys(struct gcli_ctx *ctx, gcli_sshkey_list *list) +gitea_get_sshkeys(struct gcli_ctx *ctx, struct gcli_sshkey_list *list) { return gitlab_get_sshkeys(ctx, list); } int gitea_add_sshkey(struct gcli_ctx *ctx, char const *const title, - char const *const pubkey, gcli_sshkey *const out) + char const *const pubkey, struct gcli_sshkey *const out) { return gitlab_add_sshkey(ctx, title, pubkey, out); } diff --git a/src/github/sshkeys.c b/src/github/sshkeys.c index de347b0c..212ca1e1 100644 --- a/src/github/sshkeys.c +++ b/src/github/sshkeys.c @@ -34,14 +34,14 @@ #include int -github_get_sshkeys(struct gcli_ctx *ctx, gcli_sshkey_list *out) +github_get_sshkeys(struct gcli_ctx *ctx, struct gcli_sshkey_list *out) { return gitlab_get_sshkeys(ctx, out); } int github_add_sshkey(struct gcli_ctx *ctx, char const *const title, - char const *const pubkey, gcli_sshkey *out) + char const *const pubkey, struct gcli_sshkey *out) { return gitlab_add_sshkey(ctx, title, pubkey, out); } diff --git a/src/gitlab/sshkeys.c b/src/gitlab/sshkeys.c index 0b14a88c..a8be9b37 100644 --- a/src/gitlab/sshkeys.c +++ b/src/gitlab/sshkeys.c @@ -41,7 +41,7 @@ #include int -gitlab_get_sshkeys(struct gcli_ctx *ctx, gcli_sshkey_list *list) +gitlab_get_sshkeys(struct gcli_ctx *ctx, struct gcli_sshkey_list *list) { char *url; struct gcli_fetch_list_ctx fl = { @@ -51,7 +51,7 @@ gitlab_get_sshkeys(struct gcli_ctx *ctx, gcli_sshkey_list *list) .parse = (parsefn)(parse_gitlab_sshkeys), }; - *list = (gcli_sshkey_list) {0}; + *list = (struct gcli_sshkey_list) {0}; url = sn_asprintf("%s/user/keys", gcli_get_apibase(ctx)); return gcli_fetch_list(ctx, url, &fl); @@ -59,7 +59,7 @@ gitlab_get_sshkeys(struct gcli_ctx *ctx, gcli_sshkey_list *list) int gitlab_add_sshkey(struct gcli_ctx *ctx, char const *const title, - char const *const pubkey, gcli_sshkey *const out) + char const *const pubkey, struct gcli_sshkey *const out) { char *url, *payload; char *e_title, *e_key; diff --git a/src/sshkeys.c b/src/sshkeys.c index 392124ee..5f079d47 100644 --- a/src/sshkeys.c +++ b/src/sshkeys.c @@ -36,13 +36,13 @@ #include int -gcli_sshkeys_get_keys(struct gcli_ctx *ctx, gcli_sshkey_list *out) +gcli_sshkeys_get_keys(struct gcli_ctx *ctx, struct gcli_sshkey_list *out) { gcli_null_check_call(get_sshkeys, ctx, out); } void -gcli_sshkeys_free_keys(gcli_sshkey_list *list) +gcli_sshkeys_free_keys(struct gcli_sshkey_list *list) { for (size_t i = 0; i < list->keys_size; ++i) { free(list->keys[i].title); @@ -58,7 +58,7 @@ gcli_sshkeys_free_keys(gcli_sshkey_list *list) int gcli_sshkeys_add_key(struct gcli_ctx *ctx, char const *title, - char const *public_key_path, gcli_sshkey *out) + char const *public_key_path, struct gcli_sshkey *out) { int rc; char *buffer; diff --git a/templates/gitlab/sshkeys.t b/templates/gitlab/sshkeys.t index d9c5d8a0..b0be2074 100644 --- a/templates/gitlab/sshkeys.t +++ b/templates/gitlab/sshkeys.t @@ -1,10 +1,10 @@ include "gcli/sshkeys.h"; parser gitlab_sshkey is -object of gcli_sshkey with +object of struct gcli_sshkey with ("title" => title as string, "id" => id as id, "key" => key as string, "created_at" => created_at as string); -parser gitlab_sshkeys is array of gcli_sshkey use parse_gitlab_sshkey; +parser gitlab_sshkeys is array of struct gcli_sshkey use parse_gitlab_sshkey; From e76c49ad929a8b77726ec43b301644482d7c0f80 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 5 Jan 2024 21:34:53 +0100 Subject: [PATCH 121/158] Remove struct typedefs for gcli_status --- include/gcli/cmd/status.h | 2 +- include/gcli/forges.h | 2 +- include/gcli/gitea/status.h | 2 +- include/gcli/github/status.h | 3 ++- include/gcli/gitlab/status.h | 4 ++-- include/gcli/status.h | 11 ++++------- src/cmd/status.c | 4 ++-- src/gitea/status.c | 2 +- src/github/status.c | 2 +- src/gitlab/status.c | 2 +- src/status.c | 6 +++--- templates/gitea/status.t | 8 ++++---- templates/github/status.t | 8 ++++---- templates/gitlab/status.t | 6 +++--- tests/gitea-parse-tests.c | 2 +- 15 files changed, 31 insertions(+), 33 deletions(-) diff --git a/include/gcli/cmd/status.h b/include/gcli/cmd/status.h index 73654d9a..96b97268 100644 --- a/include/gcli/cmd/status.h +++ b/include/gcli/cmd/status.h @@ -38,7 +38,7 @@ #include int gcli_status(int count); -void gcli_print_notifications(gcli_notification_list const *); +void gcli_print_notifications(struct gcli_notification_list const *); int subcommand_status(int argc, char *argv[]); #endif /* GCLI_CMD_STATUS_H */ diff --git a/include/gcli/forges.h b/include/gcli/forges.h index bc69a505..2302fd2e 100644 --- a/include/gcli/forges.h +++ b/include/gcli/forges.h @@ -512,7 +512,7 @@ struct gcli_forge_descriptor { int (*get_notifications)( struct gcli_ctx *ctx, int max, - gcli_notification_list *notifications); + struct gcli_notification_list *notifications); /** * Mark notification with the given id as read diff --git a/include/gcli/gitea/status.h b/include/gcli/gitea/status.h index 349b610b..6e1ddc4c 100644 --- a/include/gcli/gitea/status.h +++ b/include/gcli/gitea/status.h @@ -33,7 +33,7 @@ #include int gitea_get_notifications(struct gcli_ctx *ctx, int max, - gcli_notification_list *out); + struct gcli_notification_list *out); int gitea_notification_mark_as_read(struct gcli_ctx *ctx, char const *id); diff --git a/include/gcli/github/status.h b/include/gcli/github/status.h index 1f5afdb5..ec60dc9b 100644 --- a/include/gcli/github/status.h +++ b/include/gcli/github/status.h @@ -36,7 +36,8 @@ #include -int github_get_notifications(struct gcli_ctx *ctx, int max, gcli_notification_list *out); +int github_get_notifications(struct gcli_ctx *ctx, int max, + struct gcli_notification_list *out); int github_notification_mark_as_read(struct gcli_ctx *ctx, char const *id); #endif /* GITHUB_STATUS_H */ diff --git a/include/gcli/gitlab/status.h b/include/gcli/gitlab/status.h index cc95c776..af350951 100644 --- a/include/gcli/gitlab/status.h +++ b/include/gcli/gitlab/status.h @@ -37,7 +37,7 @@ #include int gitlab_get_notifications(struct gcli_ctx *ctx, int max, - gcli_notification_list *out); -int gitlab_notification_mark_as_read(struct gcli_ctx *ctx, char const *id); + struct gcli_notification_list *out); +int gitlab_notification_mark_as_read(struct gcli_ctx *ctx, char const *id); #endif /* GITLAB_STATUS_H */ diff --git a/include/gcli/status.h b/include/gcli/status.h index 9ffcea46..68ec2575 100644 --- a/include/gcli/status.h +++ b/include/gcli/status.h @@ -38,9 +38,6 @@ #include -typedef struct gcli_notification gcli_notification; -typedef struct gcli_notification_list gcli_notification_list; - struct gcli_notification { char *id; char *title; @@ -51,14 +48,14 @@ struct gcli_notification { }; struct gcli_notification_list { - gcli_notification *notifications; + struct gcli_notification *notifications; size_t notifications_size; }; int gcli_get_notifications(struct gcli_ctx *ctx, int count, - gcli_notification_list *out); + struct gcli_notification_list *out); int gcli_notification_mark_as_read(struct gcli_ctx *ctx, char const *id); -void gcli_free_notification(gcli_notification *); -void gcli_free_notifications(gcli_notification_list *); +void gcli_free_notification(struct gcli_notification *); +void gcli_free_notifications(struct gcli_notification_list *); #endif /* STATUS_H */ diff --git a/src/cmd/status.c b/src/cmd/status.c index 343dd378..ea787121 100644 --- a/src/cmd/status.c +++ b/src/cmd/status.c @@ -54,7 +54,7 @@ usage(void) int gcli_status(int const count) { - gcli_notification_list list = {0}; + struct gcli_notification_list list = {0}; int rc = 0; rc = gcli_get_notifications(g_clictx, count, &list); @@ -68,7 +68,7 @@ gcli_status(int const count) } void -gcli_print_notifications(gcli_notification_list const *const list) +gcli_print_notifications(struct gcli_notification_list const *const list) { for (size_t i = 0; i < list->notifications_size; ++i) { printf("%s - %s - %s - %s", diff --git a/src/gitea/status.c b/src/gitea/status.c index b51129ed..fc5b878e 100644 --- a/src/gitea/status.c +++ b/src/gitea/status.c @@ -37,7 +37,7 @@ int gitea_get_notifications(struct gcli_ctx *ctx, int const max, - gcli_notification_list *const out) + struct gcli_notification_list *const out) { char *url = NULL; diff --git a/src/github/status.c b/src/github/status.c index 72263e7f..14ea8814 100644 --- a/src/github/status.c +++ b/src/github/status.c @@ -38,7 +38,7 @@ int github_get_notifications(struct gcli_ctx *ctx, int const max, - gcli_notification_list *const out) + struct gcli_notification_list *const out) { char *url = NULL; diff --git a/src/gitlab/status.c b/src/gitlab/status.c index b2e78b4c..004fc114 100644 --- a/src/gitlab/status.c +++ b/src/gitlab/status.c @@ -39,7 +39,7 @@ int gitlab_get_notifications(struct gcli_ctx *ctx, int const max, - gcli_notification_list *const out) + struct gcli_notification_list *const out) { char *url = NULL; diff --git a/src/status.c b/src/status.c index c24d6a12..5a3ed392 100644 --- a/src/status.c +++ b/src/status.c @@ -32,13 +32,13 @@ int gcli_get_notifications(struct gcli_ctx *ctx, int const max, - gcli_notification_list *const out) + struct gcli_notification_list *const out) { gcli_null_check_call(get_notifications, ctx, max, out); } void -gcli_free_notification(gcli_notification *const notification) +gcli_free_notification(struct gcli_notification *const notification) { free(notification->id); free(notification->title); @@ -49,7 +49,7 @@ gcli_free_notification(gcli_notification *const notification) } void -gcli_free_notifications(gcli_notification_list *list) +gcli_free_notifications(struct gcli_notification_list *list) { for (size_t i = 0; i < list->notifications_size; ++i) { gcli_free_notification(&list->notifications[i]); diff --git a/templates/gitea/status.t b/templates/gitea/status.t index 9196d240..50236b3b 100644 --- a/templates/gitea/status.t +++ b/templates/gitea/status.t @@ -1,20 +1,20 @@ include "gcli/status.h"; parser gitea_notification_repository is -object of gcli_notification with +object of struct gcli_notification with ("full_name" => repository as string); parser gitea_notification_status is -object of gcli_notification with +object of struct gcli_notification with ("title" => title as string, "type" => type as string); parser gitea_notification is -object of gcli_notification with +object of struct gcli_notification with ("id" => id as int_to_string, "repository" => use parse_gitea_notification_repository, "subject" => use parse_gitea_notification_status, "updated_at" => date as string); parser gitea_notifications is -array of gcli_notification use parse_gitea_notification; +array of struct gcli_notification use parse_gitea_notification; diff --git a/templates/github/status.t b/templates/github/status.t index f576fa24..2d176b37 100644 --- a/templates/github/status.t +++ b/templates/github/status.t @@ -1,21 +1,21 @@ include "gcli/github/status.h"; parser github_notification_subject is -object of gcli_notification with +object of struct gcli_notification with ("title" => title as string, "type" => type as string); parser github_notification_repository is -object of gcli_notification with +object of struct gcli_notification with ("full_name" => repository as string); parser github_notification is -object of gcli_notification with +object of struct gcli_notification with ("updated_at" => date as string, "id" => id as string, "reason" => reason as string, "subject" => use parse_github_notification_subject, "repository" => use parse_github_notification_repository); -parser github_notifications is array of gcli_notification +parser github_notifications is array of struct gcli_notification use parse_github_notification; diff --git a/templates/gitlab/status.t b/templates/gitlab/status.t index 932396d0..3a27bbe4 100644 --- a/templates/gitlab/status.t +++ b/templates/gitlab/status.t @@ -1,11 +1,11 @@ include "gcli/gitlab/status.h"; parser gitlab_project is -object of gcli_notification with +object of struct gcli_notification with ("path_with_namespace" => repository as string); parser gitlab_todo is -object of gcli_notification with +object of struct gcli_notification with ("updated_at" => date as string, "action_name" => reason as string, "id" => id as int_to_string, @@ -14,4 +14,4 @@ object of gcli_notification with "project" => use parse_gitlab_project); parser gitlab_todos is -array of gcli_notification use parse_gitlab_todo; +array of struct gcli_notification use parse_gitlab_todo; diff --git a/tests/gitea-parse-tests.c b/tests/gitea-parse-tests.c index f4e84f39..b0dcec27 100644 --- a/tests/gitea-parse-tests.c +++ b/tests/gitea-parse-tests.c @@ -42,7 +42,7 @@ open_sample(char const *const name) ATF_TC_WITHOUT_HEAD(gitea_simple_notification); ATF_TC_BODY(gitea_simple_notification, tc) { - gcli_notification notification = {0}; + struct gcli_notification notification = {0}; FILE *sample; json_stream stream = {0}; struct gcli_ctx *ctx; From 31618f6802dd45fd76885137a825bf5a7258cda6 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 5 Jan 2024 21:38:25 +0100 Subject: [PATCH 122/158] Update documentation for removal of typedefs for structs --- HACKING.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/HACKING.md b/HACKING.md index db0e1d79..114c4f91 100644 --- a/HACKING.md +++ b/HACKING.md @@ -134,15 +134,18 @@ Please use the BSD Style conventions for formatting your code. This means: This allows to search for the implementation of a function through a simple `grep -rn '^foo' .`. -- typedef structs separately from their definitions - - typedef struct foo foo; +- Use struct tags for structs, do not typedef them struct foo { int bar; char const *baz; }; + static void + foodoo(struct foo const *const bar) + { + } + - Indent with tabs, align with spaces `»` denotes a TAB character, `.` indicates a whitespace: From bc1d7fa56b723fb86f5006011823baaacd195d10 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 5 Jan 2024 21:50:26 +0100 Subject: [PATCH 123/158] Add struct tags for json_stream everywhere --- include/gcli/bugzilla/bugs-parser.h | 6 +++--- include/gcli/curl.h | 4 ++-- src/bugzilla/api.c | 2 +- src/bugzilla/attachments.c | 2 +- src/bugzilla/bugs-parser.c | 4 ++-- src/bugzilla/bugs.c | 10 +++++----- src/gitea/milestones.c | 2 +- src/gitea/releases.c | 2 +- src/github/api.c | 2 +- src/github/issues.c | 2 +- src/github/labels.c | 2 +- src/github/milestones.c | 2 +- src/github/pulls.c | 4 ++-- src/gitlab/api.c | 2 +- src/gitlab/issues.c | 2 +- src/gitlab/labels.c | 2 +- src/gitlab/merge_requests.c | 4 ++-- src/gitlab/milestones.c | 2 +- src/gitlab/repos.c | 4 ++-- src/gitlab/sshkeys.c | 8 ++++---- tests/bugzilla-parse-tests.c | 6 +++--- tests/gitea-parse-tests.c | 2 +- tests/github-parse-tests.c | 18 +++++++++--------- tests/gitlab-parse-tests.c | 18 +++++++++--------- 24 files changed, 56 insertions(+), 56 deletions(-) diff --git a/include/gcli/bugzilla/bugs-parser.h b/include/gcli/bugzilla/bugs-parser.h index 9b8de30e..1da4bbef 100644 --- a/include/gcli/bugzilla/bugs-parser.h +++ b/include/gcli/bugzilla/bugs-parser.h @@ -39,7 +39,7 @@ #include int parse_bugzilla_bug_comments_dictionary_skip_first(struct gcli_ctx *const ctx, - json_stream *stream, + struct json_stream *stream, struct gcli_comment_list *out); int parse_bugzilla_comments_array_skip_first(struct gcli_ctx *ctx, @@ -47,7 +47,7 @@ int parse_bugzilla_comments_array_skip_first(struct gcli_ctx *ctx, struct gcli_comment_list *out); int parse_bugzilla_bug_comments_dictionary_only_first(struct gcli_ctx *const ctx, - json_stream *stream, + struct json_stream *stream, char **out); int parse_bugzilla_comments_array_only_first(struct gcli_ctx *ctx, @@ -62,7 +62,7 @@ int parse_bugzilla_bug_attachments_dict(struct gcli_ctx *ctx, struct gcli_attachment_list *out); int parse_bugzilla_attachment_content_only_first(struct gcli_ctx *ctx, - json_stream *stream, + struct json_stream *stream, struct gcli_attachment *out); #endif /* GCLI_BUGZILLA_BUGS_PARSER_H */ diff --git a/include/gcli/curl.h b/include/gcli/curl.h index b2f13196..08ceab52 100644 --- a/include/gcli/curl.h +++ b/include/gcli/curl.h @@ -43,8 +43,8 @@ #include #include -typedef int (*parsefn)(struct gcli_ctx *, json_stream *stream, void *list, - size_t *listsize); +typedef int (*parsefn)(struct gcli_ctx *, struct json_stream *stream, + void *list, size_t *listsize); typedef void (*filterfn)(void *list, size_t *listsize, void const *userdata); struct gcli_fetch_buffer { diff --git a/src/bugzilla/api.c b/src/bugzilla/api.c index 6faa919b..c1593e57 100644 --- a/src/bugzilla/api.c +++ b/src/bugzilla/api.c @@ -37,7 +37,7 @@ char const * bugzilla_api_error_string(struct gcli_ctx *ctx, struct gcli_fetch_buffer *const buf) { - json_stream stream = {0}; + struct json_stream stream = {0}; int rc; char *msg; diff --git a/src/bugzilla/attachments.c b/src/bugzilla/attachments.c index f9a6146a..b1227dc4 100644 --- a/src/bugzilla/attachments.c +++ b/src/bugzilla/attachments.c @@ -41,7 +41,7 @@ bugzilla_attachment_get_content(struct gcli_ctx *ctx, gcli_id attachment_id, int rc = 0; char *url; struct gcli_fetch_buffer buffer = {0}; - json_stream stream = {0}; + struct json_stream stream = {0}; struct gcli_attachment attachment = {0}; url = sn_asprintf("%s/rest/bug/attachment/%"PRIid, diff --git a/src/bugzilla/bugs-parser.c b/src/bugzilla/bugs-parser.c index ac778b94..4391202e 100644 --- a/src/bugzilla/bugs-parser.c +++ b/src/bugzilla/bugs-parser.c @@ -87,7 +87,7 @@ parse_bugzilla_comments_array_only_first(struct gcli_ctx *ctx, int parse_bugzilla_bug_comments_dictionary_skip_first(struct gcli_ctx *const ctx, - json_stream *stream, + struct json_stream *stream, struct gcli_comment_list *out) { enum json_type next = JSON_NULL; @@ -110,7 +110,7 @@ parse_bugzilla_bug_comments_dictionary_skip_first(struct gcli_ctx *const ctx, int parse_bugzilla_bug_comments_dictionary_only_first(struct gcli_ctx *const ctx, - json_stream *stream, + struct json_stream *stream, char **out) { enum json_type next = JSON_NULL; diff --git a/src/bugzilla/bugs.c b/src/bugzilla/bugs.c index 12546a71..eaefed3c 100644 --- a/src/bugzilla/bugs.c +++ b/src/bugzilla/bugs.c @@ -85,7 +85,7 @@ bugzilla_get_bugs(struct gcli_ctx *ctx, char const *product, char const *compone rc = gcli_fetch(ctx, url, NULL, &buffer); if (rc == 0) { - json_stream stream = {0}; + struct json_stream stream = {0}; json_open_buffer(&stream, buffer.data, buffer.length); rc = parse_bugzilla_bugs(ctx, &stream, out); @@ -106,7 +106,7 @@ bugzilla_bug_get_comments(struct gcli_ctx *const ctx, char const *const product, { int rc = 0; struct gcli_fetch_buffer buffer = {0}; - json_stream stream = {0}; + struct json_stream stream = {0}; char *url = NULL; (void) product; @@ -136,7 +136,7 @@ bugzilla_bug_get_op(struct gcli_ctx *ctx, gcli_id const bug_id, char **out) { int rc = 0; struct gcli_fetch_buffer buffer = {0}; - json_stream stream = {0}; + struct json_stream stream = {0}; char *url = NULL; url = sn_asprintf("%s/rest/bug/%"PRIid"/comment?include_fields=_all", @@ -166,7 +166,7 @@ bugzilla_get_bug(struct gcli_ctx *ctx, char const *product, char *url; struct gcli_fetch_buffer buffer = {0}; struct gcli_issue_list list = {0}; - json_stream stream = {0}; + struct json_stream stream = {0}; /* XXX should we warn if product or component is set? */ (void) product; @@ -220,7 +220,7 @@ bugzilla_bug_get_attachments(struct gcli_ctx *ctx, char const *const product, int rc = 0; char *url = NULL; struct gcli_fetch_buffer buffer = {0}; - json_stream stream = {0}; + struct json_stream stream = {0}; (void) product; (void) component; diff --git a/src/gitea/milestones.c b/src/gitea/milestones.c index 169e0594..9adda519 100644 --- a/src/gitea/milestones.c +++ b/src/gitea/milestones.c @@ -86,7 +86,7 @@ gitea_get_milestone(struct gcli_ctx *ctx, char const *const owner, rc = gcli_fetch(ctx, url, NULL, &buffer); if (rc == 0) { - json_stream stream = {0}; + struct json_stream stream = {0}; json_open_buffer(&stream, buffer.data, buffer.length); parse_gitea_milestone(ctx, &stream, out); diff --git a/src/gitea/releases.c b/src/gitea/releases.c index bfdc739a..a25698f7 100644 --- a/src/gitea/releases.c +++ b/src/gitea/releases.c @@ -47,7 +47,7 @@ static void gitea_parse_release(struct gcli_ctx *ctx, struct gcli_fetch_buffer const *const buffer, struct gcli_release *const out) { - json_stream stream = {0}; + struct json_stream stream = {0}; json_open_buffer(&stream, buffer->data, buffer->length); parse_github_release(ctx, &stream, out); json_close(&stream); diff --git a/src/github/api.c b/src/github/api.c index 689772c3..74b8ab9d 100644 --- a/src/github/api.c +++ b/src/github/api.c @@ -37,7 +37,7 @@ char const * github_api_error_string(struct gcli_ctx *ctx, struct gcli_fetch_buffer *const buf) { - json_stream stream = {0}; + struct json_stream stream = {0}; int rc; char *msg; diff --git a/src/github/issues.c b/src/github/issues.c index 40338e2c..82e89b1c 100644 --- a/src/github/issues.c +++ b/src/github/issues.c @@ -188,7 +188,7 @@ github_get_issue_summary(struct gcli_ctx *ctx, char const *owner, char *e_owner = NULL; char *e_repo = NULL; struct gcli_fetch_buffer buffer = {0}; - json_stream parser = {0}; + struct json_stream parser = {0}; int rc = 0; e_owner = gcli_urlencode(owner); diff --git a/src/github/labels.c b/src/github/labels.c index bf0b6b99..47a97369 100644 --- a/src/github/labels.c +++ b/src/github/labels.c @@ -65,7 +65,7 @@ github_create_label(struct gcli_ctx *ctx, char const *owner, char const *repo, struct gcli_fetch_buffer buffer = {0}; struct gcli_jsongen gen = {0}; int rc = 0; - json_stream stream = {0}; + struct json_stream stream = {0}; /* Generate payload */ colour = sn_asprintf("%06X", label->colour >> 8); diff --git a/src/github/milestones.c b/src/github/milestones.c index e41d2851..c10ad097 100644 --- a/src/github/milestones.c +++ b/src/github/milestones.c @@ -88,7 +88,7 @@ github_get_milestone(struct gcli_ctx *ctx, char const *const owner, rc = gcli_fetch(ctx, url, NULL, &buffer); if (rc == 0) { - json_stream stream = {0}; + struct json_stream stream = {0}; json_open_buffer(&stream, buffer.data, buffer.length); parse_github_milestone(ctx, &stream, out); diff --git a/src/github/pulls.c b/src/github/pulls.c index e67fbabc..a11816b0 100644 --- a/src/github/pulls.c +++ b/src/github/pulls.c @@ -339,7 +339,7 @@ github_perform_submit_pull(struct gcli_ctx *ctx, struct gcli_submit_pull_options /* Add labels if requested. GitHub doesn't allow us to do this all * with one request. */ if (rc == 0 && opts.labels_size) { - json_stream json = {0}; + struct json_stream json = {0}; struct gcli_pull pull = {0}; json_open_buffer(&json, fetch_buffer.data, fetch_buffer.length); @@ -418,7 +418,7 @@ github_get_pull(struct gcli_ctx *ctx, char const *owner, char const *repo, rc = gcli_fetch(ctx, url, NULL, &json_buffer); if (rc == 0) { - json_stream stream = {0}; + struct json_stream stream = {0}; json_open_buffer(&stream, json_buffer.data, json_buffer.length); parse_github_pull(ctx, &stream, out); diff --git a/src/gitlab/api.c b/src/gitlab/api.c index 9e709022..ea87a745 100644 --- a/src/gitlab/api.c +++ b/src/gitlab/api.c @@ -39,7 +39,7 @@ gitlab_api_error_string(struct gcli_ctx *ctx, struct gcli_fetch_buffer *const bu { char *msg = NULL; int rc; - json_stream stream = {0}; + struct json_stream stream = {0}; json_open_buffer(&stream, buf->data, buf->length); rc = parse_gitlab_get_error(ctx, &stream, &msg); diff --git a/src/gitlab/issues.c b/src/gitlab/issues.c index 5c45982c..b2dc70e5 100644 --- a/src/gitlab/issues.c +++ b/src/gitlab/issues.c @@ -118,7 +118,7 @@ gitlab_get_issue_summary(struct gcli_ctx *ctx, char const *owner, char *e_owner = NULL; char *e_repo = NULL; struct gcli_fetch_buffer buffer = {0}; - json_stream parser = {0}; + struct json_stream parser = {0}; int rc = 0; e_owner = gcli_urlencode(owner); diff --git a/src/gitlab/labels.c b/src/gitlab/labels.c index adeb0ac7..d7c2b9b5 100644 --- a/src/gitlab/labels.c +++ b/src/gitlab/labels.c @@ -65,7 +65,7 @@ gitlab_create_label(struct gcli_ctx *ctx, char const *owner, char const *repo, struct gcli_fetch_buffer buffer = {0}; struct gcli_jsongen gen = {0}; int rc = 0; - json_stream stream = {0}; + struct json_stream stream = {0}; /* Generate payload */ colour_string = sn_asprintf("#%06X", (label->colour>>8)&0xFFFFFF); diff --git a/src/gitlab/merge_requests.c b/src/gitlab/merge_requests.c index 8479a4b2..88f435db 100644 --- a/src/gitlab/merge_requests.c +++ b/src/gitlab/merge_requests.c @@ -330,7 +330,7 @@ gitlab_get_pull(struct gcli_ctx *ctx, char const *owner, char const *repo, rc = gcli_fetch(ctx, url, NULL, &json_buffer); if (rc == 0) { - json_stream stream = {0}; + struct json_stream stream = {0}; json_open_buffer(&stream, json_buffer.data, json_buffer.length); parse_gitlab_mr(ctx, &stream, out); json_close(&stream); @@ -630,7 +630,7 @@ gitlab_mr_get_reviewers(struct gcli_ctx *ctx, char const *e_owner, rc = gcli_fetch(ctx, url, NULL, &json_buffer); if (rc == 0) { - json_stream stream = {0}; + struct json_stream stream = {0}; json_open_buffer(&stream, json_buffer.data, json_buffer.length); parse_gitlab_reviewer_ids(ctx, &stream, out); json_close(&stream); diff --git a/src/gitlab/milestones.c b/src/gitlab/milestones.c index cf84ad5f..b9f1a461 100644 --- a/src/gitlab/milestones.c +++ b/src/gitlab/milestones.c @@ -74,7 +74,7 @@ gitlab_get_milestone(struct gcli_ctx *ctx, char const *owner, char const *repo, { char *url, *e_owner, *e_repo; struct gcli_fetch_buffer buffer = {0}; - json_stream stream = {0}; + struct json_stream stream = {0}; int rc = 0; e_owner = gcli_urlencode(owner); diff --git a/src/gitlab/repos.c b/src/gitlab/repos.c index c6f405d0..2e13dba0 100644 --- a/src/gitlab/repos.c +++ b/src/gitlab/repos.c @@ -46,7 +46,7 @@ gitlab_get_repo(struct gcli_ctx *ctx, char const *owner, char const *repo, /* GET /projects/:id */ char *url = NULL; struct gcli_fetch_buffer buffer = {0}; - json_stream stream = {0}; + struct json_stream stream = {0}; char *e_owner = {0}; char *e_repo = {0}; int rc; @@ -144,7 +144,7 @@ gitlab_repo_create(struct gcli_ctx *ctx, struct gcli_repo_create_options const * struct gcli_fetch_buffer buffer = {0}; struct gcli_jsongen gen = {0}; int rc; - json_stream stream = {0}; + struct json_stream stream = {0}; /* Request preparation */ url = sn_asprintf("%s/projects", gcli_get_apibase(ctx)); diff --git a/src/gitlab/sshkeys.c b/src/gitlab/sshkeys.c index a8be9b37..b323f07c 100644 --- a/src/gitlab/sshkeys.c +++ b/src/gitlab/sshkeys.c @@ -79,11 +79,11 @@ gitlab_add_sshkey(struct gcli_ctx *ctx, char const *const title, rc = gcli_fetch_with_method(ctx, "POST", url, payload, NULL, &buf); if (rc == 0 && out) { - json_stream str; + struct json_stream stream = {0}; - json_open_buffer(&str, buf.data, buf.length); - parse_gitlab_sshkey(ctx, &str, out); - json_close(&str); + json_open_buffer(&stream, buf.data, buf.length); + parse_gitlab_sshkey(ctx, &stream, out); + json_close(&stream); } free(buf.data); diff --git a/tests/bugzilla-parse-tests.c b/tests/bugzilla-parse-tests.c index a28fe0b5..96e3115a 100644 --- a/tests/bugzilla-parse-tests.c +++ b/tests/bugzilla-parse-tests.c @@ -73,7 +73,7 @@ ATF_TC_BODY(simple_bugzilla_issue, tc) struct gcli_issue_list list = {0}; struct gcli_issue const *issue; FILE *f; - json_stream stream; + struct json_stream stream; struct gcli_ctx *ctx = test_context(); ATF_REQUIRE(f = open_sample("bugzilla_simple_bug.json")); @@ -104,7 +104,7 @@ ATF_TC_BODY(bugzilla_comments, tc) struct gcli_comment const *cmt = NULL; struct gcli_comment_list list = {0}; struct gcli_ctx *ctx = test_context(); - json_stream stream; + struct json_stream stream; ATF_REQUIRE(f = open_sample("bugzilla_comments.json")); json_open_stream(&stream, f); @@ -133,7 +133,7 @@ ATF_TC_BODY(bugzilla_attachments, tc) struct gcli_attachment const *it; struct gcli_attachment_list list = {0}; struct gcli_ctx *ctx = test_context(); - json_stream stream = {0}; + struct json_stream stream = {0}; ATF_REQUIRE(f = open_sample("bugzilla_attachments.json")); json_open_stream(&stream, f); diff --git a/tests/gitea-parse-tests.c b/tests/gitea-parse-tests.c index b0dcec27..a68497fd 100644 --- a/tests/gitea-parse-tests.c +++ b/tests/gitea-parse-tests.c @@ -44,7 +44,7 @@ ATF_TC_BODY(gitea_simple_notification, tc) { struct gcli_notification notification = {0}; FILE *sample; - json_stream stream = {0}; + struct json_stream stream = {0}; struct gcli_ctx *ctx; ctx = test_context(); diff --git a/tests/github-parse-tests.c b/tests/github-parse-tests.c index 5e4389cb..a39756b2 100644 --- a/tests/github-parse-tests.c +++ b/tests/github-parse-tests.c @@ -76,7 +76,7 @@ ATF_TC_BODY(simple_github_issue, tc) { struct gcli_issue issue = {0}; FILE *f; - json_stream stream; + struct json_stream stream; struct gcli_ctx *ctx = test_context(); ATF_REQUIRE(f = open_sample("github_simple_issue.json")); @@ -117,7 +117,7 @@ ATF_TC_BODY(simple_github_pull, tc) { struct gcli_pull pull = {0}; FILE *f; - json_stream stream; + struct json_stream stream; struct gcli_ctx *ctx = test_context(); ATF_REQUIRE(f = open_sample("github_simple_pull.json")); @@ -157,7 +157,7 @@ ATF_TC_BODY(simple_github_label, tc) { struct gcli_label label = {0}; FILE *f; - json_stream stream; + struct json_stream stream; struct gcli_ctx *ctx = test_context(); ATF_REQUIRE(f = open_sample("github_simple_label.json")); @@ -180,7 +180,7 @@ ATF_TC_BODY(simple_github_milestone, tc) { struct gcli_milestone milestone = {0}; FILE *f; - json_stream stream; + struct json_stream stream; struct gcli_ctx *ctx = test_context(); ATF_REQUIRE(f = open_sample("github_simple_milestone.json")); @@ -209,7 +209,7 @@ ATF_TC_BODY(simple_github_release, tc) { struct gcli_release release = {0}; FILE *f; - json_stream stream; + struct json_stream stream; struct gcli_ctx *ctx = test_context(); ATF_REQUIRE(f = open_sample("github_simple_release.json")); @@ -238,7 +238,7 @@ ATF_TC_BODY(simple_github_repo, tc) { struct gcli_repo repo = {0}; FILE *f; - json_stream stream; + struct json_stream stream; struct gcli_ctx *ctx = test_context(); ATF_REQUIRE(f = open_sample("github_simple_repo.json")); @@ -264,7 +264,7 @@ ATF_TC_BODY(simple_github_fork, tc) { struct gcli_fork fork = {0}; FILE *f; - json_stream stream; + struct json_stream stream; struct gcli_ctx *ctx = test_context(); ATF_REQUIRE(f = open_sample("github_simple_fork.json")); @@ -287,7 +287,7 @@ ATF_TC_BODY(simple_github_comment, tc) { struct gcli_comment comment = {0}; FILE *f; - json_stream stream; + struct json_stream stream; struct gcli_ctx *ctx = test_context(); ATF_REQUIRE(f = open_sample("github_simple_comment.json")); @@ -310,7 +310,7 @@ ATF_TC_BODY(simple_github_check, tc) { struct gcli_github_check check = {0}; FILE *f; - json_stream stream; + struct json_stream stream; struct gcli_ctx *ctx = test_context(); ATF_REQUIRE(f = open_sample("github_simple_check.json")); diff --git a/tests/gitlab-parse-tests.c b/tests/gitlab-parse-tests.c index 235f3485..a8153482 100644 --- a/tests/gitlab-parse-tests.c +++ b/tests/gitlab-parse-tests.c @@ -46,7 +46,7 @@ open_sample(char const *const name) ATF_TC_WITHOUT_HEAD(gitlab_simple_merge_request); ATF_TC_BODY(gitlab_simple_merge_request, tc) { - json_stream stream = {0}; + struct json_stream stream = {0}; struct gcli_ctx *ctx = test_context(); FILE *f = open_sample("gitlab_simple_merge_request.json"); struct gcli_pull pull = {0}; @@ -86,7 +86,7 @@ ATF_TC_BODY(gitlab_simple_merge_request, tc) ATF_TC_WITHOUT_HEAD(gitlab_simple_issue); ATF_TC_BODY(gitlab_simple_issue, tc) { - json_stream stream = {0}; + struct json_stream stream = {0}; struct gcli_ctx *ctx = test_context(); FILE *f = open_sample("gitlab_simple_issue.json"); struct gcli_issue issue = {0}; @@ -117,7 +117,7 @@ ATF_TC_BODY(gitlab_simple_issue, tc) ATF_TC_WITHOUT_HEAD(gitlab_simple_label); ATF_TC_BODY(gitlab_simple_label, tc) { - json_stream stream = {0}; + struct json_stream stream = {0}; struct gcli_ctx *ctx = test_context(); FILE *f = open_sample("gitlab_simple_label.json"); struct gcli_label label = {0}; @@ -138,7 +138,7 @@ ATF_TC_BODY(gitlab_simple_label, tc) ATF_TC_WITHOUT_HEAD(gitlab_simple_release); ATF_TC_BODY(gitlab_simple_release, tc) { - json_stream stream = {0}; + struct json_stream stream = {0}; struct gcli_ctx *ctx = test_context(); FILE *f = open_sample("gitlab_simple_release.json"); struct gcli_release release = {0}; @@ -191,7 +191,7 @@ ATF_TC_BODY(gitlab_simple_release, tc) ATF_TC_WITHOUT_HEAD(gitlab_simple_fork); ATF_TC_BODY(gitlab_simple_fork, tc) { - json_stream stream = {0}; + struct json_stream stream = {0}; struct gcli_ctx *ctx = test_context(); FILE *f = open_sample("gitlab_simple_fork.json"); struct gcli_fork fork = {0}; @@ -212,7 +212,7 @@ ATF_TC_BODY(gitlab_simple_fork, tc) ATF_TC_WITHOUT_HEAD(gitlab_simple_milestone); ATF_TC_BODY(gitlab_simple_milestone, tc) { - json_stream stream = {0}; + struct json_stream stream = {0}; struct gcli_ctx *ctx = test_context(); FILE *f = open_sample("gitlab_simple_milestone.json"); struct gcli_milestone milestone = {0}; @@ -241,7 +241,7 @@ ATF_TC_BODY(gitlab_simple_milestone, tc) ATF_TC_WITHOUT_HEAD(gitlab_simple_pipeline); ATF_TC_BODY(gitlab_simple_pipeline, tc) { - json_stream stream = {0}; + struct json_stream stream = {0}; struct gcli_ctx *ctx = test_context(); FILE *f = open_sample("gitlab_simple_pipeline.json"); struct gitlab_pipeline pipeline = {0}; @@ -265,7 +265,7 @@ ATF_TC_BODY(gitlab_simple_pipeline, tc) ATF_TC_WITHOUT_HEAD(gitlab_simple_repo); ATF_TC_BODY(gitlab_simple_repo, tc) { - json_stream stream = {0}; + struct json_stream stream = {0}; struct gcli_ctx *ctx = test_context(); FILE *f = open_sample("gitlab_simple_repo.json"); struct gcli_repo repo = {0}; @@ -289,7 +289,7 @@ ATF_TC_BODY(gitlab_simple_repo, tc) ATF_TC_WITHOUT_HEAD(gitlab_simple_snippet); ATF_TC_BODY(gitlab_simple_snippet, tc) { - json_stream stream = {0}; + struct json_stream stream = {0}; struct gcli_ctx *ctx = test_context(); FILE *f = open_sample("gitlab_simple_snippet.json"); struct gcli_gitlab_snippet snippet = {0}; From 9a711473de530d36c94e131422289b1d17b6a09b Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Mon, 29 Jan 2024 10:26:54 +0100 Subject: [PATCH 124/158] Avoid segmentation fault in editor when input message is empty Because a user can input an empty message when the editor is opened we may get a NULL pointer as a result. Do not dereference it. Issue-tracker: https://gitlab.com/herrhotzenplotz/gcli/-/issues/219 --- src/cmd/editor.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cmd/editor.c b/src/cmd/editor.c index fa9dbd34..34771169 100644 --- a/src/cmd/editor.c +++ b/src/cmd/editor.c @@ -121,7 +121,10 @@ gcli_editor_get_user_message( munmap(file_content, len); unlink(filename); - result.data[result.length] = '\0'; + /* When the input is empty, the data pointer is going to be NULL. + * Do not access it in this case. */ + if (result.length) + result.data[result.length] = '\0'; return result.data; } From 3d521e395bf4e9ed70cec363e095d1c664de5386 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Mon, 29 Jan 2024 10:33:40 +0100 Subject: [PATCH 125/158] Prevent null pointer dereference/undefined behaviour when user provided no message to gcli_editor_get_user_message This is a follow up on the segfault. Issue-tracker: https://gitlab.com/herrhotzenplotz/gcli/-/issues/219 --- src/cmd/comment.c | 3 +++ src/cmd/issues.c | 3 ++- src/cmd/pulls.c | 2 +- src/cmd/releases.c | 2 ++ 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/cmd/comment.c b/src/cmd/comment.c index 08005f9c..be72e765 100644 --- a/src/cmd/comment.c +++ b/src/cmd/comment.c @@ -108,6 +108,9 @@ comment_submit(struct gcli_submit_comment_opts opts, int always_yes) message = gcli_comment_get_message(&opts); opts.message = message; + if (message == NULL) + errx(1, "gcli: empty message. aborting."); + fprintf( stdout, "You will be commenting the following in %s/%s #%"PRIid":\n%s\n", diff --git a/src/cmd/issues.c b/src/cmd/issues.c index 9f1588f8..e650b30b 100644 --- a/src/cmd/issues.c +++ b/src/cmd/issues.c @@ -242,7 +242,8 @@ create_issue(struct gcli_submit_issue_options opts, int always_yes) "OWNER : %s\n" "REPO : %s\n" "MESSAGE :\n%s\n", - opts.title, opts.owner, opts.repo, opts.body); + opts.title, opts.owner, opts.repo, + opts.body ? opts.body : "No message"); putchar('\n'); diff --git a/src/cmd/pulls.c b/src/cmd/pulls.c index 76955abb..0db2dfd1 100644 --- a/src/cmd/pulls.c +++ b/src/cmd/pulls.c @@ -390,7 +390,7 @@ create_pull(struct gcli_submit_pull_options opts, int always_yes) "IN : %s/%s\n" "MESSAGE :\n%s\n", opts.title, opts.to, opts.from, - opts.owner, opts.repo, opts.body); + opts.owner, opts.repo, opts.body ? opts.body : "No message."); fputc('\n', stdout); diff --git a/src/cmd/releases.c b/src/cmd/releases.c index c7e456cf..6572c1ab 100644 --- a/src/cmd/releases.c +++ b/src/cmd/releases.c @@ -314,6 +314,8 @@ subcommand_releases_create(int argc, char *argv[]) } release.body = get_release_message(&release); + if (release.body == NULL) + errx(1, "gcli: empty message. aborting."); if (!always_yes) if (!sn_yesno("Do you want to create this release?")) From edd2c85236a27a917d6bbbb1f88487ffd0f647af Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Mon, 29 Jan 2024 10:40:17 +0100 Subject: [PATCH 126/158] Update Changelog for fix of GL/#219 Issue-tracker: https://gitlab.com/herrhotzenplotz/gcli/-/issues/219 --- Changelog.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Changelog.md b/Changelog.md index b02202c1..dc38cbf4 100644 --- a/Changelog.md +++ b/Changelog.md @@ -31,6 +31,10 @@ This changelog does not follow semantic versioning. Previously the patches were invalid when new files were created or deleted. +- Fixed Segmentation fault when the editor was opened and closed + without changing the file. Several subcommands have been updated + to also account for empty user messages. + ### Changed - Internally a lot of code was using string views. Maintaining this From 3e58dc193c399d2351583e0d61d61282b9ed241c Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Mon, 29 Jan 2024 18:29:57 +0100 Subject: [PATCH 127/158] Add missing Bugzilla Sample files for distcheck This also removes required_files from the Kyuafile to ensure that we run all tests and they are not skipped in case we miss adding the files to the Automakefile. Signed-off-by: Nico Sonack --- Makefile.am | 5 ++++- tests/Kyuafile.in | 4 ---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Makefile.am b/Makefile.am index 842682d3..9af5865f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -316,6 +316,9 @@ EXTRA_DIST += tests/samples/github_simple_comment.json \ tests/samples/gitlab_simple_repo.json \ tests/samples/gitlab_simple_snippet.json \ tests/samples/github_simple_check.json \ - tests/samples/gitea_simple_notification.json + tests/samples/gitea_simple_notification.json \ + tests/samples/bugzilla_attachments.json \ + tests/samples/bugzilla_comments.json \ + tests/samples/bugzilla_simple_bug.json endif diff --git a/tests/Kyuafile.in b/tests/Kyuafile.in index 22a7b553..94ab5e05 100644 --- a/tests/Kyuafile.in +++ b/tests/Kyuafile.in @@ -8,22 +8,18 @@ atf_test_program{ atf_test_program{ name = 'github-parse-tests', - required_files = '@TESTSRCDIR@/samples/github_simple_issue.json @TESTSRCDIR@/samples/github_simple_pull.json @TESTSRCDIR@/samples/github_simple_label.json' } atf_test_program{ name = 'gitlab-parse-tests', - required_files = '@TESTSRCDIR@/samples/gitlab_simple_merge_request.json' } atf_test_program{ name = 'gitea-parse-tests', - required_files = '@TESTSRCDIR@/samples/gitea_simple_notification.json' } atf_test_program{ name = 'bugzilla-parse-tests', - required_files = '@TESTSRCDIR@/samples/bugzilla_simple_bug.json' } atf_test_program{ From 09860fa0e73f0f5c296a378c75817427bbdae898 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Wed, 31 Jan 2024 19:00:54 +0100 Subject: [PATCH 128/158] GL/#218: Make it an error when the user didn't provide a 6-digit hexadecimal colour code This is part of https://gitlab.com/herrhotzenplotz/gcli/-/issues/218. Essentially I want to ensure that the user doesn't provide invalid colour codes. Signed-off-by: Nico Sonack --- src/cmd/labels.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cmd/labels.c b/src/cmd/labels.c index d9c83783..ab7d7e1b 100644 --- a/src/cmd/labels.c +++ b/src/cmd/labels.c @@ -169,6 +169,9 @@ subcommand_labels_create(int argc, char *argv[]) break; case 'c': { char *endptr = NULL; + if (strlen(optarg) != 6) + err(1, "gcli: error: colour must be a six-digit hexadecimal colour code"); + label.colour = strtol(optarg, &endptr, 16); if (endptr != (optarg + strlen(optarg))) err(1, "labels: cannot parse colour"); From 85d2d05f46d88c96d47c6eb4c1b4498f35dc6fa3 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Thu, 1 Feb 2024 11:34:37 +0100 Subject: [PATCH 129/158] GL/#218: Fix bad colour when creating labels on Gitlab I have no idea why the shift was there. This caused the bytes to be shifted into the BGA components and producing green instead of red. Signed-off-by: Nico Sonack --- src/gitlab/labels.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gitlab/labels.c b/src/gitlab/labels.c index d7c2b9b5..f1c8351f 100644 --- a/src/gitlab/labels.c +++ b/src/gitlab/labels.c @@ -68,7 +68,7 @@ gitlab_create_label(struct gcli_ctx *ctx, char const *owner, char const *repo, struct json_stream stream = {0}; /* Generate payload */ - colour_string = sn_asprintf("#%06X", (label->colour>>8)&0xFFFFFF); + colour_string = sn_asprintf("#%06X", label->colour & 0xFFFFFF); gcli_jsongen_init(&gen); gcli_jsongen_begin_object(&gen); From b554db3dc8d9d699dca9a3763670ca6ea373029a Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Thu, 1 Feb 2024 11:36:03 +0100 Subject: [PATCH 130/158] GL/#218: Fix incorrect colours when creating labels on Github The same bug as with Gitlab applied to Github. See Previous commit. Signed-off-by: Nico Sonack --- src/github/labels.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/github/labels.c b/src/github/labels.c index 47a97369..d467c495 100644 --- a/src/github/labels.c +++ b/src/github/labels.c @@ -68,7 +68,7 @@ github_create_label(struct gcli_ctx *ctx, char const *owner, char const *repo, struct json_stream stream = {0}; /* Generate payload */ - colour = sn_asprintf("%06X", label->colour >> 8); + colour = sn_asprintf("%06X", label->colour & 0xFFFFFF); gcli_jsongen_init(&gen); gcli_jsongen_begin_object(&gen); From 621897d69a24ff08a93bcc5444410ea74f7c4ec8 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Thu, 1 Feb 2024 11:47:56 +0100 Subject: [PATCH 131/158] GL/#218: Update changelog for fix of label colours Signed-off-by: Nico Sonack --- Changelog.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Changelog.md b/Changelog.md index dc38cbf4..d185d414 100644 --- a/Changelog.md +++ b/Changelog.md @@ -35,6 +35,10 @@ This changelog does not follow semantic versioning. without changing the file. Several subcommands have been updated to also account for empty user messages. +- Fixed incorrect colour when creating labels. In any forge the + provided colour code was converted incorrectly and always producing + the wrong colour. + ### Changed - Internally a lot of code was using string views. Maintaining this From c03e4c4f44f331fc449aaba83747a3d336943b76 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Thu, 1 Feb 2024 20:02:45 +0100 Subject: [PATCH 132/158] Update README We're not that simple anymore... :-) Signed-off-by: Nico Sonack --- README.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4c010eaa..bb8773a5 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # GCLI -Simple and portable CLI tool for interacting with GitHub, GitLab and -Gitea from the command line. +Portable CLI tool for interacting with Git(Hub|Lab|Tea) from the command line. ![](docs/screenshot.png) @@ -12,9 +11,8 @@ unified tool for various git forges such as GitHub and GitLab because every forge does things differently yet all build on Git and purposefully break with its philosophy. -Also, the official tool from Github is written in Go, which does -manual [DNS -resolution](https://github.com/golang/go/blob/master/src/net/dnsclient_unix.go#L49) +Also, the official tool from Github is written in Go, which does manual +[DNS resolution](https://github.com/golang/go/blob/master/src/net/dnsclient_unix.go#L49) which is a massive security vulnerability for people using Tor as it leaks your IP to the DNS server. This program builds upon libcurl, which obeys the operating system's DNS resolution mechanisms and thus From 5938fb14ca768f89803cc269b7af94a37ed06bbc Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Thu, 1 Feb 2024 23:24:24 +0100 Subject: [PATCH 133/158] Fix more segmentation faults if messages entered by user through editor are empty I previously attempted fixing these segfaults but apparently I wasn't thorough enough. This now also fixes more NULL derefs in the JSON generation code in the various backends. Signed-off-by: Nico Sonack --- src/bugzilla/bugs.c | 6 ++++-- src/gitea/releases.c | 6 ++++-- src/github/issues.c | 7 +++++-- src/github/pulls.c | 7 +++++-- src/github/releases.c | 7 ++++--- src/gitlab/issues.c | 8 ++++++-- src/gitlab/merge_requests.c | 7 +++++-- src/gitlab/releases.c | 6 ++++-- 8 files changed, 37 insertions(+), 17 deletions(-) diff --git a/src/bugzilla/bugs.c b/src/bugzilla/bugs.c index eaefed3c..7bd5636d 100644 --- a/src/bugzilla/bugs.c +++ b/src/bugzilla/bugs.c @@ -321,8 +321,10 @@ bugzilla_bug_submit(struct gcli_ctx *ctx, struct gcli_submit_issue_options opts, gcli_jsongen_objmember(&gen, "summary"); gcli_jsongen_string(&gen, summary); - gcli_jsongen_objmember(&gen, "description"); - gcli_jsongen_string(&gen, description); + if (description) { + gcli_jsongen_objmember(&gen, "description"); + gcli_jsongen_string(&gen, description); + } gcli_jsongen_objmember(&gen, "api_key"); gcli_jsongen_string(&gen, token); diff --git a/src/gitea/releases.c b/src/gitea/releases.c index a25698f7..7d3c337a 100644 --- a/src/gitea/releases.c +++ b/src/gitea/releases.c @@ -96,8 +96,10 @@ gitea_create_release(struct gcli_ctx *ctx, struct gcli_new_release const *releas gcli_jsongen_objmember(&gen, "prerelease"); gcli_jsongen_bool(&gen, release->prerelease); - gcli_jsongen_objmember(&gen, "body"); - gcli_jsongen_string(&gen, release->body); + if (release->body) { + gcli_jsongen_objmember(&gen, "body"); + gcli_jsongen_string(&gen, release->body); + } if (release->commitish) { gcli_jsongen_objmember(&gen, "target_commitish"); diff --git a/src/github/issues.c b/src/github/issues.c index 82e89b1c..ffce17f5 100644 --- a/src/github/issues.c +++ b/src/github/issues.c @@ -269,8 +269,11 @@ github_perform_submit_issue(struct gcli_ctx *ctx, struct gcli_submit_issue_optio gcli_jsongen_objmember(&gen, "title"); gcli_jsongen_string(&gen, opts.title); - gcli_jsongen_objmember(&gen, "body"); - gcli_jsongen_string(&gen, opts.body); + /* Body can be omitted and is NULL in that case */ + if (opts.body) { + gcli_jsongen_objmember(&gen, "body"); + gcli_jsongen_string(&gen, opts.body); + } } gcli_jsongen_begin_object(&gen); diff --git a/src/github/pulls.c b/src/github/pulls.c index a11816b0..5bcab6ce 100644 --- a/src/github/pulls.c +++ b/src/github/pulls.c @@ -318,8 +318,11 @@ github_perform_submit_pull(struct gcli_ctx *ctx, struct gcli_submit_pull_options gcli_jsongen_objmember(&gen, "title"); gcli_jsongen_string(&gen, opts.title); - gcli_jsongen_objmember(&gen, "body"); - gcli_jsongen_string(&gen, opts.body); + /* Body is optional and will be NULL if unset */ + if (opts.body) { + gcli_jsongen_objmember(&gen, "body"); + gcli_jsongen_string(&gen, opts.body); + } } gcli_jsongen_end_object(&gen); payload = gcli_jsongen_to_string(&gen); diff --git a/src/github/releases.c b/src/github/releases.c index ae6fb1b2..12d2695b 100644 --- a/src/github/releases.c +++ b/src/github/releases.c @@ -148,9 +148,10 @@ github_create_release(struct gcli_ctx *ctx, struct gcli_new_release const *relea gcli_jsongen_objmember(&gen, "prerelease"); gcli_jsongen_bool(&gen, release->prerelease); - gcli_jsongen_objmember(&gen, "body"); - gcli_jsongen_string(&gen, release->body); - + if (release->body) { + gcli_jsongen_objmember(&gen, "body"); + gcli_jsongen_string(&gen, release->body); + } if (release->commitish) { gcli_jsongen_objmember(&gen, "target_commitish"); diff --git a/src/gitlab/issues.c b/src/gitlab/issues.c index b2dc70e5..3304e355 100644 --- a/src/gitlab/issues.c +++ b/src/gitlab/issues.c @@ -213,8 +213,12 @@ gitlab_perform_submit_issue(struct gcli_ctx *ctx, struct gcli_submit_issue_optio gcli_jsongen_objmember(&gen, "title"); gcli_jsongen_string(&gen, opts.title); - gcli_jsongen_objmember(&gen, "description"); - gcli_jsongen_string(&gen, opts.body); + /* The body may be NULL if empty. In this case we can omit the + * body / description as it is not required by the API */ + if (opts.body) { + gcli_jsongen_objmember(&gen, "description"); + gcli_jsongen_string(&gen, opts.body); + } } gcli_jsongen_end_object(&gen); diff --git a/src/gitlab/merge_requests.c b/src/gitlab/merge_requests.c index 88f435db..273d0d42 100644 --- a/src/gitlab/merge_requests.c +++ b/src/gitlab/merge_requests.c @@ -462,8 +462,11 @@ gitlab_perform_submit_mr(struct gcli_ctx *ctx, struct gcli_submit_pull_options o gcli_jsongen_objmember(&gen, "title"); gcli_jsongen_string(&gen, opts.title); - gcli_jsongen_objmember(&gen, "description"); - gcli_jsongen_string(&gen, opts.body); + /* description is optional and will be NULL if unset */ + if (opts.body) { + gcli_jsongen_objmember(&gen, "description"); + gcli_jsongen_string(&gen, opts.body); + } gcli_jsongen_objmember(&gen, "target_project_id"); gcli_jsongen_number(&gen, target.id); diff --git a/src/gitlab/releases.c b/src/gitlab/releases.c index ffb11c06..993e33cc 100644 --- a/src/gitlab/releases.c +++ b/src/gitlab/releases.c @@ -120,8 +120,10 @@ gitlab_create_release(struct gcli_ctx *ctx, struct gcli_new_release const *relea gcli_jsongen_objmember(&gen, "tag_name"); gcli_jsongen_string(&gen, release->tag); - gcli_jsongen_objmember(&gen, "description"); - gcli_jsongen_string(&gen, release->body); + if (release->body) { + gcli_jsongen_objmember(&gen, "description"); + gcli_jsongen_string(&gen, release->body); + } if (release->commitish) { gcli_jsongen_objmember(&gen, "ref"); From e6da76453b8bc98c31cec6c41425a8e89584d4d4 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Thu, 1 Feb 2024 23:44:07 +0100 Subject: [PATCH 134/158] cleanup: prefix error messages with 'gcli:' on stderr Whenever we are in a pipeline and print an error message to stderr we need to prefix it with the program name because if multiple programs in the pipeline print errors one cannot directly distinguish from which program the error message was emitted. Signed-off-by: Nico Sonack --- src/cmd/cmdconfig.c | 42 +++++++++++++++++++++--------------------- src/cmd/gitconfig.c | 36 ++++++++++++++++++------------------ src/cmd/issues.c | 6 +++--- src/cmd/labels.c | 4 ++-- src/cmd/pipelines.c | 6 +++--- 5 files changed, 47 insertions(+), 47 deletions(-) diff --git a/src/cmd/cmdconfig.c b/src/cmd/cmdconfig.c index fdf99051..e412755e 100644 --- a/src/cmd/cmdconfig.c +++ b/src/cmd/cmdconfig.c @@ -115,7 +115,7 @@ find_dotgcli(void) curr_dir_path = getcwd(NULL, 128); if (!curr_dir_path) - err(1, "getcwd"); + err(1, "gcli: getcwd"); /* Here we are trying to traverse upwards through the directory * tree, searching for a directory called .git. @@ -123,7 +123,7 @@ find_dotgcli(void) do { curr_dir = opendir(curr_dir_path); if (!curr_dir) - err(1, "opendir"); + err(1, "gcli: opendir"); while ((ent = readdir(curr_dir))) { if (strcmp(".", ent->d_name) == 0 || strcmp("..", ent->d_name) == 0) @@ -154,7 +154,7 @@ find_dotgcli(void) curr_dir_path = realpath(tmp, NULL); if (!curr_dir_path) - err(1, "realpath at %s", tmp); + err(1, "gcli: realpath at %s", tmp); free(tmp); @@ -198,7 +198,7 @@ init_local_config(struct gcli_ctx *ctx) int len = sn_mmap_file(path, &dgcli->mmap_pointer); if (len < 0) - err(1, "Unable to open config file"); + err(1, "gcli: unable to open config file"); dgcli->buffer = sn_sv_from_parts(dgcli->mmap_pointer, len); dgcli->buffer = sn_sv_trim_front(dgcli->buffer); @@ -210,7 +210,7 @@ init_local_config(struct gcli_ctx *ctx) line = sn_sv_trim(line); if (line.length == 0) - errx(1, "%s:%d: Unexpected end of line", + errx(1, "gcli: %s:%d: Unexpected end of line", path, curr_line); // Comments @@ -225,7 +225,7 @@ init_local_config(struct gcli_ctx *ctx) key = sn_sv_trim(key); if (key.length == 0) - errx(1, "%s:%d: empty key", path, curr_line); + errx(1, "gcli: %s:%d: empty key", path, curr_line); line.data += 1; line.length -= 1; @@ -291,7 +291,7 @@ parse_section_entry(struct config_parser *input, sn_sv key = sn_sv_chop_until(&input->buffer, '='); if (key.length == 0) - errx(1, "%s:%d: empty key", input->filename, input->line); + errx(1, "gcli: %s:%d: empty key", input->filename, input->line); input->buffer.data += 1; input->buffer.length -= 1; @@ -307,7 +307,7 @@ parse_section_title(struct config_parser *input) { size_t len = 0; if (input->buffer.length == 0) - errx(1, "%s:%d: unexpected end of input in section title", + errx(1, "gcli: %s:%d: unexpected end of input in section title", input->filename, input->line); @@ -321,10 +321,10 @@ parse_section_title(struct config_parser *input) skip_ws_and_comments(input); if (input->buffer.length == 0) - errx(1, "%s:%d: unexpected end of input", input->filename, input->line); + errx(1, "gcli: %s:%d: unexpected end of input", input->filename, input->line); if (input->buffer.data[0] != '{') - errx(1, "%s:%d: expected '{'", input->filename, input->line); + errx(1, "gcli: %s:%d: expected '{'", input->filename, input->line); input->buffer.length -= 1; input->buffer.data += 1; @@ -354,7 +354,7 @@ parse_config_section(struct gcli_config *cfg, } if (input->buffer.length == 0) - errx(1, "%s:%d: missing '}' before end of file", + errx(1, "gcli: %s:%d: missing '}' before end of file", input->filename, input->line); input->buffer.length -= 1; @@ -405,13 +405,13 @@ ensure_config(struct gcli_ctx *ctx) } if (access(file_path, R_OK) < 0) { - warn("Cannot access config file at %s", file_path); + warn("gcli: cannot access config file at %s", file_path); return cfg; } int len = sn_mmap_file(file_path, &cfg->mmap_pointer); if (len < 0) - err(1, "Unable to open config file"); + err(1, "gcli: unable to open config file"); cfg->buffer = sn_sv_from_parts(cfg->mmap_pointer, len); cfg->buffer = sn_sv_trim_front(cfg->buffer); @@ -565,7 +565,7 @@ gcli_config_parse_args(struct gcli_ctx *ctx, int *argc, char ***argv) } else if (strcmp(optarg, "bugzilla") == 0) { cfg->override_forgetype = GCLI_FORGE_BUGZILLA; } else { - fprintf(stderr, "error: unknown forge type '%s'. " + fprintf(stderr, "gcli: error: unknown forge type '%s'. " "Have either github, gitlab or gitea.\n", optarg); return EXIT_FAILURE; } @@ -631,7 +631,7 @@ gcli_config_find_by_key(struct gcli_ctx *ctx, char const *section_name, find_section(cfg, section_name); if (!section) { - warnx("no config section with name '%s'", section_name); + warnx("gcli: no config section with name '%s'", section_name); return SV_NULL; } @@ -796,7 +796,7 @@ gcli_config_get_upstream_parts(struct gcli_ctx *ctx, sn_sv *const owner, /* Sanity check: did we actually reach the '/'? */ if (*upstream.data != '/') - errx(1, ".gcli has invalid upstream format. expected owner/repo"); + errx(1, "gcli: .gcli has invalid upstream format. expected owner/repo"); upstream.data += 1; upstream.length -= 1; @@ -844,7 +844,7 @@ gcli_config_get_forge_type_internal(struct gcli_ctx *ctx) entry = gcli_config_find_by_key(ctx, section, "forge-type"); if (sn_sv_null(entry)) errx(1, - "error: given default override account not found or " + "gcli: error: given default override account not found or " "missing forge-type"); } else { entry = gcli_local_config_find_by_key(ctx, "forge-type"); @@ -860,13 +860,13 @@ gcli_config_get_forge_type_internal(struct gcli_ctx *ctx) else if (sn_sv_eq_to(entry, "bugzilla")) return GCLI_FORGE_BUGZILLA; else - errx(1, "Unknown forge type "SV_FMT, SV_ARGS(entry)); + errx(1, "gcli: unknown forge type "SV_FMT, SV_ARGS(entry)); } /* As a last resort, try to infer from the git remote */ int const type = gcli_gitconfig_get_forgetype(ctx, cfg->override_remote); if (type < 0) - errx(1, "error: cannot infer forge type. " + errx(1, "gcli: error: cannot infer forge type. " "use -t to overrride manually."); return type; @@ -889,7 +889,7 @@ gcli_config_get_forge_type(struct gcli_ctx *ctx) if (!have_printed_forge_type) { have_printed_forge_type = 1; - fprintf(stderr, "info: forge type is %s\n", ftype_name[result]); + fprintf(stderr, "gcli: info: forge type is %s\n", ftype_name[result]); } } @@ -911,7 +911,7 @@ gcli_config_get_repo(struct gcli_ctx *ctx, char const **const owner, if (forge >= 0) { if ((int)(gcli_config_get_forge_type(ctx)) != forge) - errx(1, "error: forge types are inconsistent"); + errx(1, "gcli: error: forge types are inconsistent"); } return; diff --git a/src/cmd/gitconfig.c b/src/cmd/gitconfig.c index 1f2813d7..f851f0f4 100644 --- a/src/cmd/gitconfig.c +++ b/src/cmd/gitconfig.c @@ -56,7 +56,7 @@ resolve_worktree_gitdir_if_needed(char *dotgit) char *newdir = NULL; if (stat(dotgit, &sb) < 0) - err(1, "stat"); + err(1, "gcli: stat"); /* Real .git directory */ if (S_ISDIR(sb.st_mode)) @@ -64,7 +64,7 @@ resolve_worktree_gitdir_if_needed(char *dotgit) f = fopen(dotgit, "r"); if (!f) - err(1, "fopen"); + err(1, "gcli: fopen"); while (!ferror(f) && !feof(f)) { char *key, *value; @@ -95,7 +95,7 @@ resolve_worktree_gitdir_if_needed(char *dotgit) } if (newdir == NULL) - errx(1, "error: .git is a file but does not contain a gitdir pointer"); + errx(1, "gcli: error: .git is a file but does not contain a gitdir pointer"); fclose(f); @@ -118,7 +118,7 @@ find_file_in_dotgit(char const *fname) curr_dir_path = getcwd(NULL, 128); if (!curr_dir_path) - err(1, "getcwd"); + err(1, "gcli: getcwd"); /* Here we are trying to traverse upwards through the directory * tree, searching for a directory called .git. @@ -126,7 +126,7 @@ find_file_in_dotgit(char const *fname) do { curr_dir = opendir(curr_dir_path); if (!curr_dir) - err(1, "opendir"); + err(1, "gcli: opendir"); /* Read entries of the directory */ while ((ent = readdir(curr_dir))) { @@ -162,7 +162,7 @@ find_file_in_dotgit(char const *fname) curr_dir_path = realpath(tmp, NULL); if (!curr_dir_path) - err(1, "error: realpath at %s", tmp); + err(1, "gcli: error: realpath at %s", tmp); free(tmp); @@ -189,7 +189,7 @@ find_file_in_dotgit(char const *fname) /* Now search for the file in the found .git directory */ curr_dir = opendir(dotgit); if (!curr_dir) - err(1, "opendir"); + err(1, "gcli: opendir"); while ((ent = readdir(curr_dir))) { /* skip over . and .. directory entries */ @@ -215,7 +215,7 @@ find_file_in_dotgit(char const *fname) } } - errx(1, "error: .git without a config file"); + errx(1, "gcli: error: .git without a config file"); return NULL; } @@ -240,7 +240,7 @@ gcli_gitconfig_get_current_branch(void) int len = sn_mmap_file(HEAD, &mmap_pointer); if (len < 0) - err(1, "mmap"); + err(1, "gcli: mmap"); buffer = sn_sv_from_parts(mmap_pointer, len); @@ -350,7 +350,7 @@ gitconfig_parse_remote(sn_sv section_title, sn_sv entry) while ((entry = sn_sv_trim_front(entry)).length > 0) { if (sn_sv_has_prefix(entry, "url")) { if (remotes_size == MAX_REMOTES) - errx(1, "error: too many remotes"); + errx(1, "gcli: error: too many remotes"); struct gcli_gitremote *const remote = &remotes[remotes_size++]; @@ -406,7 +406,7 @@ gcli_gitconfig_read_gitconfig(void) /* TODO: Git Config files support comments */ if (*buffer.data != '[') - errx(1, "error: invalid git config"); + errx(1, "gcli: error: invalid git config"); sn_sv section_title = sn_sv_chop_until(&buffer, ']'); section_title.length -= 1; @@ -432,7 +432,7 @@ gcli_gitconfig_add_fork_remote(char const *org, char const *repo) FILE *remote_list = popen("git remote", "r"); if (!remote_list) - err(1, "popen"); + err(1, "gcli: popen"); /* TODO: Output informational messages */ /* Rename possibly existing origin remote to point at the @@ -450,9 +450,9 @@ gcli_gitconfig_add_fork_remote(char const *org, char const *repo) waitpid(pid, &status, 0); if (!(WIFEXITED(status) && (WEXITSTATUS(status) == 0))) - errx(1, "git child process failed"); + errx(1, "gcli: git child process failed"); } else { - err(1, "fork"); + err(1, "gcli: fork"); } break; @@ -475,9 +475,9 @@ gcli_gitconfig_add_fork_remote(char const *org, char const *repo) waitpid(pid, &status, 0); if (!(WIFEXITED(status) && (WEXITSTATUS(status) == 0))) - errx(1, "git child process failed"); + errx(1, "gcli: git child process failed"); } else { - err(1, "fork"); + err(1, "gcli: fork"); } } } @@ -523,11 +523,11 @@ gcli_gitconfig_repo_by_remote( } } - errx(1, "error: no such remote: %s", remote_name); + errx(1, "gcli: error: no such remote: %s", remote_name); } if (!remotes_size) - errx(1, "error: no remotes to auto-detect forge"); + errx(1, "gcli: error: no remotes to auto-detect forge"); *owner = sn_sv_to_cstr(remotes[0].owner); *repo = sn_sv_to_cstr(remotes[0].repo); diff --git a/src/cmd/issues.c b/src/cmd/issues.c index e650b30b..363545b9 100644 --- a/src/cmd/issues.c +++ b/src/cmd/issues.c @@ -104,7 +104,7 @@ gcli_print_issues(enum gcli_output_flags const flags, table = gcli_tbl_begin(cols, ARRAY_SIZE(cols)); if (!table) - errx(1, "could not init table printer"); + errx(1, "gcli: could not init table printer"); /* Determine the correct number of items to print */ if (max < 0 || (size_t)(max) > list->issues_size) @@ -249,7 +249,7 @@ create_issue(struct gcli_submit_issue_options opts, int always_yes) if (!always_yes) { if (!sn_yesno("Do you want to continue?")) - errx(1, "Submission aborted."); + errx(1, "gcli: Submission aborted."); } rc = gcli_issue_submit(g_clictx, opts); @@ -725,7 +725,7 @@ handle_issues_actions(int argc, char *argv[], int rc = gcli_issue_get_attachments(g_clictx, owner, repo, issue_id, &list); if (rc < 0) { - errx(1, "error: failed to fetch attachments: %s", + errx(1, "gcli: error: failed to fetch attachments: %s", gcli_get_error(g_clictx)); } diff --git a/src/cmd/labels.c b/src/cmd/labels.c index ab7d7e1b..0827715f 100644 --- a/src/cmd/labels.c +++ b/src/cmd/labels.c @@ -174,7 +174,7 @@ subcommand_labels_create(int argc, char *argv[]) label.colour = strtol(optarg, &endptr, 16); if (endptr != (optarg + strlen(optarg))) - err(1, "labels: cannot parse colour"); + err(1, "gcli: error: cannot parse colour"); } break; case 'd': { label.description = optarg; @@ -264,7 +264,7 @@ subcommand_labels(int argc, char *argv[]) count = strtol(optarg, &endptr, 10); if (endptr != (optarg + strlen(optarg))) - errx(1, "labels: cannot parse label count"); + errx(1, "gcli: error: cannot parse label count"); if (count == 0) errx(1, "gcli: error: number of labels must not be zero"); diff --git a/src/cmd/pipelines.c b/src/cmd/pipelines.c index ccecaa1d..ca6473f1 100644 --- a/src/cmd/pipelines.c +++ b/src/cmd/pipelines.c @@ -276,13 +276,13 @@ subcommand_pipelines(int argc, char *argv[]) char *endptr = NULL; count = strtol(optarg, &endptr, 10); if (endptr != (optarg + strlen(optarg))) - err(1, "ci: cannot parse argument to -n"); + err(1, "gcli: error: cannot parse argument to -n"); } break; case 'p': { char *endptr = NULL; pid = strtol(optarg, &endptr, 10); if (endptr != (optarg + strlen(optarg))) - err(1, "ci: cannot parse argument to -p"); + err(1, "gcli: error: cannot parse argument to -p"); if (pid < 0) { errx(1, "gcli: error: pipeline id must be a positive number"); } @@ -291,7 +291,7 @@ subcommand_pipelines(int argc, char *argv[]) char *endptr = NULL; jid = strtol(optarg, &endptr, 10); if (endptr != (optarg + strlen(optarg))) - err(1, "ci: cannot parse argument to -j"); + err(1, "gcli: error: cannot parse argument to -j"); if (jid < 0) { errx(1, "gcli: error: job id must be a positive number"); } From 193d1fde34fa183eb2ff77d99a3d410d69714ad3 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 2 Feb 2024 00:49:45 +0100 Subject: [PATCH 135/158] Add missing free for issue titles Signed-off-by: Nico Sonack --- src/issues.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/issues.c b/src/issues.c index e76dc47d..e678267d 100644 --- a/src/issues.c +++ b/src/issues.c @@ -43,6 +43,7 @@ gcli_issue_free(struct gcli_issue *const it) free(it->state); free(it->body); free(it->url); + free(it->title); for (size_t i = 0; i < it->labels_size; ++i) free(it->labels[i]); From 4df5c03f9ae566456103bd0c29a98ac597769d82 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 2 Feb 2024 00:25:16 +0100 Subject: [PATCH 136/158] Realign macro Signed-off-by: Nico Sonack --- include/gcli/forges.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/include/gcli/forges.h b/include/gcli/forges.h index 2302fd2e..7b59eacb 100644 --- a/include/gcli/forges.h +++ b/include/gcli/forges.h @@ -561,15 +561,15 @@ struct gcli_forge_descriptor const *gcli_forge(struct gcli_ctx *ctx); * It check whether the given function pointer is null. If it is it will return * an error message otherwise the function is called with the specified * arguments. */ -#define gcli_null_check_call(routine, ctx, ...) \ - do { \ - struct gcli_forge_descriptor const *const forge = gcli_forge(ctx); \ - \ - if (forge->routine) { \ +#define gcli_null_check_call(routine, ctx, ...) \ + do { \ + struct gcli_forge_descriptor const *const forge = gcli_forge(ctx); \ + \ + if (forge->routine) { \ return forge->routine(ctx, __VA_ARGS__); \ - } else { \ + } else { \ return gcli_error(ctx, #routine " is not available on this forge"); \ - } \ + } \ } while (0) From d9146a82356d8ad276edd5ad8953e35704ef0efc Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Sat, 30 Dec 2023 23:30:12 +0100 Subject: [PATCH 137/158] gitlab merge requests: add a "automerge" field This boolean flag indicates whether a merge request can be automagically merged once the CI succeeds. Ideally we also want to show this flag in the list of PRs however, this requires a bit more work. Requested-by: Simon Richter --- include/gcli/forges.h | 1 + include/gcli/pulls.h | 1 + src/cmd/pulls.c | 3 +++ src/forges.c | 4 +++- templates/gitlab/merge_requests.t | 35 ++++++++++++++++--------------- 5 files changed, 26 insertions(+), 18 deletions(-) diff --git a/include/gcli/forges.h b/include/gcli/forges.h index 7b59eacb..0ff532d3 100644 --- a/include/gcli/forges.h +++ b/include/gcli/forges.h @@ -361,6 +361,7 @@ struct gcli_forge_descriptor { GCLI_PRS_QUIRK_MERGED = 0x08, GCLI_PRS_QUIRK_DRAFT = 0x10, GCLI_PRS_QUIRK_COVERAGE = 0x20, + GCLI_PRS_QUIRK_AUTOMERGE = 0x40, } pull_summary_quirks; /** diff --git a/include/gcli/pulls.h b/include/gcli/pulls.h index 28230ade..dfc9ad2b 100644 --- a/include/gcli/pulls.h +++ b/include/gcli/pulls.h @@ -76,6 +76,7 @@ struct gcli_pull { bool merged; bool mergeable; bool draft; + bool automerge; }; struct gcli_commit { diff --git a/src/cmd/pulls.c b/src/cmd/pulls.c index 0db2dfd1..0d37ccdc 100644 --- a/src/cmd/pulls.c +++ b/src/cmd/pulls.c @@ -208,6 +208,9 @@ gcli_pull_print(struct gcli_pull const *const it) if ((quirks & GCLI_PRS_QUIRK_CHANGES) == 0) gcli_dict_add(dict, "CHANGED", 0, 0, "%d", it->changed_files); + if ((quirks & GCLI_PRS_QUIRK_AUTOMERGE) == 0) + gcli_dict_add_string(dict, "AUTOMERGE", 0, 0, sn_bool_yesno(it->automerge)); + if ((quirks & GCLI_PRS_QUIRK_MERGED) == 0) gcli_dict_add_string(dict, "MERGED", 0, 0, sn_bool_yesno(it->merged)); diff --git a/src/forges.c b/src/forges.c index f13d0b84..7b17d96d 100644 --- a/src/forges.c +++ b/src/forges.c @@ -167,7 +167,8 @@ github_forge_descriptor = .milestone_quirks = GCLI_MILESTONE_QUIRKS_EXPIRED | GCLI_MILESTONE_QUIRKS_DUEDATE | GCLI_MILESTONE_QUIRKS_PULLS, - .pull_summary_quirks = GCLI_PRS_QUIRK_COVERAGE, + .pull_summary_quirks = GCLI_PRS_QUIRK_COVERAGE + | GCLI_PRS_QUIRK_AUTOMERGE, }; static struct gcli_forge_descriptor const @@ -351,6 +352,7 @@ gitea_forge_descriptor = | GCLI_MILESTONE_QUIRKS_PULLS, .pull_summary_quirks = GCLI_PRS_QUIRK_COMMITS | GCLI_PRS_QUIRK_ADDDEL + | GCLI_PRS_QUIRK_AUTOMERGE | GCLI_PRS_QUIRK_DRAFT | GCLI_PRS_QUIRK_CHANGES | GCLI_PRS_QUIRK_COVERAGE, diff --git a/templates/gitlab/merge_requests.t b/templates/gitlab/merge_requests.t index d220521e..3b5eeb6c 100644 --- a/templates/gitlab/merge_requests.t +++ b/templates/gitlab/merge_requests.t @@ -18,23 +18,24 @@ object of struct gcli_pull with parser gitlab_mr is object of struct gcli_pull with - ("title" => title as string, - "state" => state as string, - "description" => body as string, - "created_at" => created_at as string, - "iid" => number as id, - "id" => id as id, - "labels" => labels as array of char* use get_string, - "user_notes_count" => comments as int, - "merge_status" => mergeable as gitlab_can_be_merged, - "draft" => draft as bool, - "author" => author as user, - "source_branch" => head_label as string, - "target_branch" => base_label as string, - "milestone" => use parse_gitlab_mr_milestone, - "head_pipeline" => use parse_gitlab_mr_head_pipeline, - "reviewers" => reviewers as array of char* use parse_gitlab_reviewer, - "diff_refs" => use parse_gitlab_diff_refs); + ("title" => title as string, + "state" => state as string, + "description" => body as string, + "created_at" => created_at as string, + "iid" => number as id, + "id" => id as id, + "labels" => labels as array of char* use get_string, + "user_notes_count" => comments as int, + "merge_status" => mergeable as gitlab_can_be_merged, + "draft" => draft as bool, + "author" => author as user, + "source_branch" => head_label as string, + "target_branch" => base_label as string, + "milestone" => use parse_gitlab_mr_milestone, + "head_pipeline" => use parse_gitlab_mr_head_pipeline, + "reviewers" => reviewers as array of char* use parse_gitlab_reviewer, + "diff_refs" => use parse_gitlab_diff_refs, + "merge_when_pipeline_succeeds" => automerge as bool); parser gitlab_mrs is array of struct gcli_pull use parse_gitlab_mr; From 8b2dc9e5f7b47eb02fa6bbfca23c15a44d928670 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Thu, 18 Jan 2024 18:35:16 +0100 Subject: [PATCH 138/158] automerge: Add a new flag for the create subcommand and update documentation for the new flag --- docs/gcli-pulls.1.in | 8 +++++++- include/gcli/pulls.h | 1 + src/cmd/pulls.c | 14 +++++++++++--- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/docs/gcli-pulls.1.in b/docs/gcli-pulls.1.in index 7129c503..7b6c44bb 100644 --- a/docs/gcli-pulls.1.in +++ b/docs/gcli-pulls.1.in @@ -67,7 +67,11 @@ option above - the same reasoning applies to this option. List all PRs, including closed and merged ones. Cannot be combined with actions. This does not affect the .Fl n -option. +option. Note that this flag has a different meaning in the +.Cm create +subcommand. See +.Sx SUBCOMMANDS +for more information. .It Fl n , -count Ar n Fetch at least .Ar n @@ -105,6 +109,8 @@ the commits that are to be merged into the target repository. You may omit this flag and gcli will try to infer this information. .It Fl y , -yes Do not ask for confirmation before creating the PR. Assume yes. +.It Fl a , -automerge +Enable the automerge feature when creating the PR. .It Ar "PR Title..." The title of the Pull Request or Merge Request. .El diff --git a/include/gcli/pulls.h b/include/gcli/pulls.h index dfc9ad2b..a9b02971 100644 --- a/include/gcli/pulls.h +++ b/include/gcli/pulls.h @@ -99,6 +99,7 @@ struct gcli_submit_pull_options { char **labels; size_t labels_size; int draft; + bool automerge; /** Automatically merge the PR when a pipeline passes */ }; struct gcli_pull_fetch_details { diff --git a/src/cmd/pulls.c b/src/cmd/pulls.c index 0d37ccdc..7344f479 100644 --- a/src/cmd/pulls.c +++ b/src/cmd/pulls.c @@ -56,14 +56,15 @@ static void usage(void) { fprintf(stderr, "usage: gcli pulls create [-o owner -r repo] [-f from]\n"); - fprintf(stderr, " [-t to] [-d] [-l label] pull-request-title\n"); + fprintf(stderr, " [-t to] [-d] [-a] [-l label] pull-request-title\n"); fprintf(stderr, " gcli pulls [-o owner -r repo] [-a] [-A author] [-n number]\n"); fprintf(stderr, " [-L label] [-M milestone] [-s]\n"); fprintf(stderr, " gcli pulls [-o owner -r repo] -i pull-id actions...\n"); fprintf(stderr, "OPTIONS:\n"); fprintf(stderr, " -o owner The repository owner\n"); fprintf(stderr, " -r repo The repository name\n"); - fprintf(stderr, " -a Fetch everything including closed and merged PRs\n"); + fprintf(stderr, " -a When listing PRs, show everything including closed and merged PRs.\n"); + fprintf(stderr, " When creating a PR enable automerge.\n"); fprintf(stderr, " -A author Filter pull requests by the given author\n"); fprintf(stderr, " -L label Filter pull requests by the given label\n"); fprintf(stderr, " -M milestone Filter pull requests by the given milestone\n"); @@ -461,10 +462,14 @@ subcommand_pull_create(int argc, char *argv[]) .has_arg = required_argument, .flag = NULL, .val = 'l' }, + { .name = "automerge", + .has_arg = required_argument, + .flag = NULL, + .val = 'a' }, {0}, }; - while ((ch = getopt_long(argc, argv, "yf:t:do:r:l:", options, NULL)) != -1) { + while ((ch = getopt_long(argc, argv, "ayf:t:do:r:l:", options, NULL)) != -1) { switch (ch) { case 'f': opts.from = optarg; @@ -489,6 +494,9 @@ subcommand_pull_create(int argc, char *argv[]) case 'y': always_yes = 1; break; + case 'a': + opts.automerge = true; + break; default: usage(); return EXIT_FAILURE; From 1531cdfd618c2f48c291d302521ad532466c79a9 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Mon, 22 Jan 2024 18:09:59 +0100 Subject: [PATCH 139/158] Gitlab: Implement automerge for Merge Requests There's a bug in Gitlab (referenced in the change). If used incorrectly (atm) gcli might hang indefinitely. However in most cases people will not encounter this bug. --- src/gitlab/merge_requests.c | 115 ++++++++++++++++++++++++++++++++++-- 1 file changed, 109 insertions(+), 6 deletions(-) diff --git a/src/gitlab/merge_requests.c b/src/gitlab/merge_requests.c index 273d0d42..d95928be 100644 --- a/src/gitlab/merge_requests.c +++ b/src/gitlab/merge_requests.c @@ -39,6 +39,8 @@ #include +#include /* for nanosleep */ + /* Workaround because gitlab doesn't give us an explicit field for * this. */ static void @@ -273,11 +275,35 @@ gitlab_mr_get_diff(struct gcli_ctx *ctx, FILE *stream, char const *owner, return gcli_error(ctx, "not yet implemented"); } +int +gitlab_mr_set_automerge(struct gcli_ctx *const ctx, char const *const owner, + char const *const repo, gcli_id const mr_number) +{ + char *url, *e_owner, *e_repo; + int rc; + + e_owner = gcli_urlencode(owner); + e_repo = gcli_urlencode(repo); + + url = sn_asprintf("%s/projects/%s%%2F%s/merge_requests/%"PRIid"/merge" + "?merge_when_pipeline_succeeds=true", + gcli_get_apibase(ctx), e_owner, e_repo, mr_number); + + free(e_owner); + free(e_repo); + + rc = gcli_fetch_with_method(ctx, "PUT", url, NULL, NULL, NULL); + + free(url); + + return rc; +} + int gitlab_mr_merge(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const mr_number, enum gcli_merge_flags const flags) { - struct gcli_fetch_buffer buffer = {0}; + struct gcli_fetch_buffer buffer = {0}; char *url = NULL; char *e_owner = NULL; char *e_repo = NULL; @@ -423,6 +449,59 @@ gitlab_mr_reopen(struct gcli_ctx *ctx, char const *owner, char const *repo, return gitlab_mr_patch_state(ctx, owner, repo, mr, "reopen"); } +/* This routine is a workaround for a Gitlab bug: + * + * https://gitlab.com/gitlab-org/gitlab/-/issues/353984 + * + * This is a race condition because something in the creation of a merge request + * is being handled asynchronously. See the above link for more details. + * + * TL;DR: We need to wait until the »merge_status« field of the MR is set to + * »can_be_merged«. This is indicated by the mergable field becoming true. */ +static int +gitlab_mr_wait_until_mergeable(struct gcli_ctx *ctx, char const *const e_owner, + char const *const e_repo, gcli_id const mr_id) +{ + char *url; + int rc = 0; + struct timespec const ts = { .tv_sec = 1, .tv_nsec = 0 }; + + url = sn_asprintf("%s/projects/%s%%2F%s/merge_requests/%"PRIid, + gcli_get_apibase(ctx), e_owner, e_repo, mr_id); + + for (;;) { + bool is_mergeable; + struct gcli_fetch_buffer buffer = {0}; + struct json_stream stream = {0}; + struct gcli_pull pull = {0}; + + rc = gcli_fetch(ctx, url, NULL, &buffer); + if (rc < 0) + break; + + json_open_buffer(&stream, buffer.data, buffer.length); + rc = parse_gitlab_mr(ctx, &stream, &pull); + json_close(&stream); + + /* FIXME: this doesn't quite cut it when the PR has no commits in it. + * In that case this will turn into an infinite loop. */ + is_mergeable = pull.mergeable; + + gcli_pull_free(&pull); + free(buffer.data); + + if (is_mergeable) + break; + + /* sort of a hack: wait for a second until the next request goes out */ + nanosleep(&ts, NULL); + } + + free(url); + + return rc; +} + int gitlab_perform_submit_mr(struct gcli_ctx *ctx, struct gcli_submit_pull_options opts) { @@ -432,9 +511,10 @@ gitlab_perform_submit_mr(struct gcli_ctx *ctx, struct gcli_submit_pull_options o char *source_branch = NULL, *source_owner = NULL, *payload = NULL, *e_owner = NULL, *e_repo = NULL, *url = NULL; char const *target_branch = NULL; + int rc = 0; + struct gcli_fetch_buffer buffer = {0}; struct gcli_jsongen gen = {0}; struct gcli_repo target = {0}; - int rc = 0; target_branch = opts.to; source_owner = strdup(opts.from); @@ -492,13 +572,36 @@ gitlab_perform_submit_mr(struct gcli_ctx *ctx, struct gcli_submit_pull_options o url = sn_asprintf("%s/projects/%s%%2F%s/merge_requests", gcli_get_apibase(ctx), e_owner, e_repo); - free(e_owner); - free(e_repo); - /* perform request */ - rc = gcli_fetch_with_method(ctx, "POST", url, payload, NULL, NULL); + rc = gcli_fetch_with_method(ctx, "POST", url, payload, NULL, &buffer); + + /* if that succeeded and the user wants automerge, parse the result and + * set the automerge flag */ + if (rc == 0 && opts.automerge) { + struct json_stream stream = {0}; + struct gcli_pull pull = {0}; + + json_open_buffer(&stream, buffer.data, buffer.length); + rc = parse_gitlab_mr(ctx, &stream, &pull); + json_close(&stream); + + if (rc < 0) + goto out; + + rc = gitlab_mr_wait_until_mergeable(ctx, e_owner, e_repo, pull.number); + if (rc < 0) + goto out; + + rc = gitlab_mr_set_automerge(ctx, opts.owner, opts.repo, pull.number); + + out: + gcli_pull_free(&pull); + } /* cleanup */ + free(e_owner); + free(e_repo); + free(buffer.data); free(source_owner); free(payload); free(url); From 2db9a910992fd8ce2403697ce6e4edf09321b79b Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Mon, 22 Jan 2024 17:10:57 +0100 Subject: [PATCH 140/158] Github: Parse the global node_id for pull requests This field is needed in the GraphQL queries in order to set the automerge flag on a pull request. --- include/gcli/pulls.h | 1 + src/pulls.c | 1 + templates/github/pulls.t | 1 + 3 files changed, 3 insertions(+) diff --git a/include/gcli/pulls.h b/include/gcli/pulls.h index a9b02971..d9724561 100644 --- a/include/gcli/pulls.h +++ b/include/gcli/pulls.h @@ -59,6 +59,7 @@ struct gcli_pull { char *milestone; gcli_id id; gcli_id number; + char *node_id; /* Github: GraphQL compat */ int comments; int additions; int deletions; diff --git a/src/pulls.c b/src/pulls.c index 5c17a4f6..71d1f755 100644 --- a/src/pulls.c +++ b/src/pulls.c @@ -105,6 +105,7 @@ gcli_pull_free(struct gcli_pull *const it) free(it->base_sha); free(it->milestone); free(it->coverage); + free(it->node_id); for (size_t i = 0; i < it->labels_size; ++i) free(it->labels[i]); diff --git a/templates/github/pulls.t b/templates/github/pulls.t index f0bbad53..8f2e467b 100644 --- a/templates/github/pulls.t +++ b/templates/github/pulls.t @@ -44,6 +44,7 @@ object of struct gcli_pull with "created_at" => created_at as string, "number" => number as id, "id" => id as id, + "node_id" => node_id as string, "commits" => commits as int, "labels" => labels as array of github_label use parse_github_label_text, From aeef5d8fef2e689dff2e162d5a1fc4550c3b230c Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Mon, 22 Jan 2024 17:11:17 +0100 Subject: [PATCH 141/158] Github: Implement Automerge for Pull Requests --- src/github/pulls.c | 56 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/src/github/pulls.c b/src/github/pulls.c index 5bcab6ce..61ae2342 100644 --- a/src/github/pulls.c +++ b/src/github/pulls.c @@ -298,6 +298,47 @@ github_pull_reopen(struct gcli_ctx *ctx, char const *owner, char const *repo, return github_pull_patch_state(ctx, owner, repo, pr, "open"); } +static int +github_pull_set_automerge(struct gcli_ctx *const ctx, char const *const node_id) +{ + char *url, *query, *payload; + int rc; + char const *const fmt = + "mutation updateAutomergeState {\n" + " enablePullRequestAutoMerge(input: {\n" + " pullRequestId: \"%s\",\n" + " mergeMethod: MERGE\n" + " }) {\n" + " clientMutationId\n" + " }\n" + "}\n"; + + struct gcli_jsongen gen = {0}; + + query = sn_asprintf(fmt, node_id); + + gcli_jsongen_init(&gen); + gcli_jsongen_begin_object(&gen); + { + gcli_jsongen_objmember(&gen, "query"); + gcli_jsongen_string(&gen, query); + } + gcli_jsongen_end_object(&gen); + + payload = gcli_jsongen_to_string(&gen); + gcli_jsongen_free(&gen); + free(query); + + url = sn_asprintf("%s/graphql", gcli_get_apibase(ctx)); + + rc = gcli_fetch_with_method(ctx, "POST", url, payload, NULL, NULL); + + free(payload); + free(url); + + return rc; +} + int github_perform_submit_pull(struct gcli_ctx *ctx, struct gcli_submit_pull_options opts) { @@ -341,16 +382,23 @@ github_perform_submit_pull(struct gcli_ctx *ctx, struct gcli_submit_pull_options /* Add labels if requested. GitHub doesn't allow us to do this all * with one request. */ - if (rc == 0 && opts.labels_size) { + if (rc == 0 && (opts.labels_size || opts.automerge)) { struct json_stream json = {0}; struct gcli_pull pull = {0}; json_open_buffer(&json, fetch_buffer.data, fetch_buffer.length); parse_github_pull(ctx, &json, &pull); - github_issue_add_labels(ctx, opts.owner, opts.repo, pull.id, - (char const *const *)opts.labels, - opts.labels_size); + if (opts.labels_size) { + rc = github_issue_add_labels(ctx, opts.owner, opts.repo, pull.id, + (char const *const *)opts.labels, + opts.labels_size); + } + + if (rc == 0 && opts.automerge) { + /* pull.id is the global pull request ID */ + rc = github_pull_set_automerge(ctx, pull.node_id); + } gcli_pull_free(&pull); json_close(&json); From a3b57f85a0d55ae5b6c40068aa8b598e1a9c0a90 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 2 Feb 2024 19:54:22 +0100 Subject: [PATCH 142/158] Do not allow submission of automerge pull requests on forges that do not support automerge This is currently specific to Gitea, however in the future we may add more forges. Signed-off-by: Nico Sonack --- src/pulls.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/pulls.c b/src/pulls.c index 71d1f755..373c2e3d 100644 --- a/src/pulls.c +++ b/src/pulls.c @@ -145,6 +145,12 @@ gcli_pull_checks_free(struct gcli_pull_checks_list *list) int gcli_pull_submit(struct gcli_ctx *ctx, struct gcli_submit_pull_options opts) { + if (opts.automerge) { + int const q = gcli_forge(ctx)->pull_summary_quirks; + if (q & GCLI_PRS_QUIRK_AUTOMERGE) + return gcli_error(ctx, "forge does not support auto-merge"); + } + gcli_null_check_call(perform_submit_pull, ctx, opts); } From 42f9a5af90d15e7974e8863e9e3f88412b706a96 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Mon, 5 Feb 2024 12:41:11 +0100 Subject: [PATCH 143/158] Fix bad documentation in gcli-issues.1 - Missing documentation for milestone filter - Incorrect order of arguments in examples Signed-off-by: Nico Sonack --- docs/gcli-issues.1.in | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/gcli-issues.1.in b/docs/gcli-issues.1.in index 98119098..ebf992bb 100644 --- a/docs/gcli-issues.1.in +++ b/docs/gcli-issues.1.in @@ -11,6 +11,7 @@ .Op Fl s .Op Fl A Ar author .Op Fl L Ar label +.Op Fl M Ar milestone .Op Fl o Ar owner Fl r Ar repo .Nm .Fl i Ar issue @@ -49,6 +50,8 @@ option. Only list issues authored by the given user. .It Fl L , Fl -label Ar label Filter issues by the given label. This option may only be specfied once. +.It Fl M , Fl -milestone Ar milestone +Filter issues by the given milestone. This option may only be specfied once. .It Fl n , -count Ar n Fetch at least .Ar n @@ -130,7 +133,7 @@ $ gcli issues .Pp Report a new issue in the current project: .Bd -literal -offset indent -$ gcli create issues "summary here" +$ gcli issues create "summary here" .Ed .Pp Print both a summary and comments of issue 1 in herrhotzenplotz/gcli: From 4d4140ff3c7ef936ef674b5d22bb4609460e3bbb Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 2 Feb 2024 00:06:52 +0100 Subject: [PATCH 144/158] GL/#220: Add command stubs for search feature Issue-tracker: https://gitlab.com/herrhotzenplotz/gcli/-/issues/220 Signed-off-by: Nico Sonack --- include/gcli/forges.h | 2 +- include/gcli/gitea/issues.h | 6 +++--- include/gcli/github/issues.h | 6 +++--- include/gcli/gitlab/issues.h | 6 +++--- include/gcli/issues.h | 7 ++++--- src/cmd/issues.c | 9 ++++++--- src/forges.c | 8 ++++---- src/gitea/issues.c | 8 ++++---- src/github/issues.c | 6 +++--- src/gitlab/issues.c | 6 +++--- src/issues.c | 8 ++++---- 11 files changed, 38 insertions(+), 34 deletions(-) diff --git a/include/gcli/forges.h b/include/gcli/forges.h index 7b59eacb..70e311cc 100644 --- a/include/gcli/forges.h +++ b/include/gcli/forges.h @@ -99,7 +99,7 @@ struct gcli_forge_descriptor { /** * Get a list of issues on the given repo */ - int (*get_issues)( + int (*search_issues)( struct gcli_ctx *ctx, char const *owner, char const *repo, diff --git a/include/gcli/gitea/issues.h b/include/gcli/gitea/issues.h index a003b292..12742c49 100644 --- a/include/gcli/gitea/issues.h +++ b/include/gcli/gitea/issues.h @@ -36,9 +36,9 @@ #include -int gitea_get_issues(struct gcli_ctx *ctx, char const *owner, char const *repo, - struct gcli_issue_fetch_details const *details, int max, - struct gcli_issue_list *out); +int gitea_issues_search(struct gcli_ctx *ctx, char const *owner, char const *repo, + struct gcli_issue_fetch_details const *details, int max, + struct gcli_issue_list *out); int gitea_get_issue_summary(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue_number, diff --git a/include/gcli/github/issues.h b/include/gcli/github/issues.h index 9027f2df..54e5e456 100644 --- a/include/gcli/github/issues.h +++ b/include/gcli/github/issues.h @@ -40,9 +40,9 @@ int github_fetch_issues(struct gcli_ctx *ctx, char *url, int max, struct gcli_issue_list *out); -int github_get_issues(struct gcli_ctx *ctx, char const *owner, char const *repo, - struct gcli_issue_fetch_details const *details, int max, - struct gcli_issue_list *out); +int github_issues_search(struct gcli_ctx *ctx, char const *owner, char const *repo, + struct gcli_issue_fetch_details const *details, int max, + struct gcli_issue_list *out); int github_get_issue_summary(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue_number, diff --git a/include/gcli/gitlab/issues.h b/include/gcli/gitlab/issues.h index 98ebc010..bdb1dade 100644 --- a/include/gcli/gitlab/issues.h +++ b/include/gcli/gitlab/issues.h @@ -40,9 +40,9 @@ int gitlab_fetch_issues(struct gcli_ctx *ctx, char *url, int max, struct gcli_issue_list *out); -int gitlab_get_issues(struct gcli_ctx *ctx, char const *owner, char const *repo, - struct gcli_issue_fetch_details const *details, int max, - struct gcli_issue_list *out); +int gitlab_issues_search(struct gcli_ctx *ctx, char const *owner, char const *repo, + struct gcli_issue_fetch_details const *details, + int max, struct gcli_issue_list *out); int gitlab_get_issue_summary(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id issue_number, diff --git a/include/gcli/issues.h b/include/gcli/issues.h index 5a5a16be..b223279e 100644 --- a/include/gcli/issues.h +++ b/include/gcli/issues.h @@ -83,11 +83,12 @@ struct gcli_issue_fetch_details { char const *author; /* filter issues by this author*/ char const *label; /* filter by the given label */ char const *milestone; /* filter by the given milestone */ + char const *search_term; /* a search term or NULL if unspecified */ }; -int gcli_get_issues(struct gcli_ctx *ctx, char const *owner, char const *repo, - struct gcli_issue_fetch_details const *details, int max, - struct gcli_issue_list *out); +int gcli_issues_search(struct gcli_ctx *ctx, char const *owner, char const *repo, + struct gcli_issue_fetch_details const *details, int max, + struct gcli_issue_list *out); void gcli_issues_free(struct gcli_issue_list *); diff --git a/src/cmd/issues.c b/src/cmd/issues.c index 363545b9..83203bfc 100644 --- a/src/cmd/issues.c +++ b/src/cmd/issues.c @@ -51,7 +51,7 @@ usage(void) { fprintf(stderr, "usage: gcli issues create [-o owner -r repo] [-y] title...\n"); fprintf(stderr, " gcli issues [-o owner -r repo] [-a] [-n number] [-A author] [-L label]\n"); - fprintf(stderr, " [-M milestone] [-s]\n"); + fprintf(stderr, " [-M milestone] [-s] [search query...]\n"); fprintf(stderr, " gcli issues [-o owner -r repo] -i issue actions...\n"); fprintf(stderr, "OPTIONS:\n"); fprintf(stderr, " -o owner The repository owner\n"); @@ -471,12 +471,15 @@ subcommand_issues(int argc, char *argv[]) argc -= optind; argv += optind; - check_owner_and_repo(&owner, &repo); /* No issue number was given, so list all open issues */ if (issue_id < 0) { - if (gcli_get_issues(g_clictx, owner, repo, &details, n, &list) < 0) + /* Prepare search term if specified */ + if (argc) + details.search_term = sn_join_with((char const *const *)argv, argc, " "); + + if (gcli_issues_search(g_clictx, owner, repo, &details, n, &list) < 0) errx(1, "gcli: error: could not get issues: %s", gcli_get_error(g_clictx)); gcli_print_issues(flags, &list, n); diff --git a/src/forges.c b/src/forges.c index f13d0b84..cbdea3af 100644 --- a/src/forges.c +++ b/src/forges.c @@ -89,7 +89,7 @@ github_forge_descriptor = /* Issues */ .get_issue_summary = github_get_issue_summary, - .get_issues = github_get_issues, + .search_issues = github_issues_search, .issue_add_labels = github_issue_add_labels, .issue_assign = github_issue_assign, .issue_clear_milestone = github_issue_clear_milestone, @@ -184,7 +184,7 @@ gitlab_forge_descriptor = /* Issues */ .get_issue_summary = gitlab_get_issue_summary, - .get_issues = gitlab_get_issues, + .search_issues = gitlab_issues_search, .issue_add_labels = gitlab_issue_add_labels, .issue_assign = gitlab_issue_assign, .issue_clear_milestone = gitlab_issue_clear_milestone, @@ -276,7 +276,7 @@ gitea_forge_descriptor = /* Issues */ .get_issue_summary = gitea_get_issue_summary, - .get_issues = gitea_get_issues, + .search_issues = gitea_issues_search, .issue_add_labels = gitea_issue_add_labels, .issue_assign = gitea_issue_assign, .issue_clear_milestone = gitea_issue_clear_milestone, @@ -360,7 +360,7 @@ static struct gcli_forge_descriptor const bugzilla_forge_descriptor = { /* Issues */ - .get_issues = bugzilla_get_bugs, + .search_issues = bugzilla_get_bugs, .get_issue_summary = bugzilla_get_bug, .get_issue_comments = bugzilla_bug_get_comments, .get_issue_attachments = bugzilla_bug_get_attachments, diff --git a/src/gitea/issues.c b/src/gitea/issues.c index 92be53dd..21bbc489 100644 --- a/src/gitea/issues.c +++ b/src/gitea/issues.c @@ -39,11 +39,11 @@ #include int -gitea_get_issues(struct gcli_ctx *ctx, char const *owner, char const *repo, - struct gcli_issue_fetch_details const *details, int const max, - struct gcli_issue_list *const out) +gitea_issues_search(struct gcli_ctx *ctx, char const *owner, char const *repo, + struct gcli_issue_fetch_details const *details, int const max, + struct gcli_issue_list *const out) { - return github_get_issues(ctx, owner, repo, details, max, out); + return github_issues_search(ctx, owner, repo, details, max, out); } int diff --git a/src/github/issues.c b/src/github/issues.c index ffce17f5..e3d36687 100644 --- a/src/github/issues.c +++ b/src/github/issues.c @@ -124,9 +124,9 @@ parse_github_milestone(struct gcli_ctx *ctx, char const *owner, } int -github_get_issues(struct gcli_ctx *ctx, char const *owner, char const *repo, - struct gcli_issue_fetch_details const *details, int const max, - struct gcli_issue_list *const out) +github_issues_search(struct gcli_ctx *ctx, char const *owner, char const *repo, + struct gcli_issue_fetch_details const *details, int const max, + struct gcli_issue_list *const out) { char *url = NULL; char *e_owner = NULL; diff --git a/src/gitlab/issues.c b/src/gitlab/issues.c index 3304e355..5ee0ff72 100644 --- a/src/gitlab/issues.c +++ b/src/gitlab/issues.c @@ -54,9 +54,9 @@ gitlab_fetch_issues(struct gcli_ctx *ctx, char *url, int const max, } int -gitlab_get_issues(struct gcli_ctx *ctx, char const *owner, char const *repo, - struct gcli_issue_fetch_details const *details, int const max, - struct gcli_issue_list *const out) +gitlab_issues_search(struct gcli_ctx *ctx, char const *owner, char const *repo, + struct gcli_issue_fetch_details const *details, int const max, + struct gcli_issue_list *const out) { char *url = NULL; char *e_owner = NULL; diff --git a/src/issues.c b/src/issues.c index e678267d..d367fb00 100644 --- a/src/issues.c +++ b/src/issues.c @@ -73,11 +73,11 @@ gcli_issues_free(struct gcli_issue_list *const list) } int -gcli_get_issues(struct gcli_ctx *ctx, char const *owner, char const *repo, - struct gcli_issue_fetch_details const *details, int const max, - struct gcli_issue_list *const out) +gcli_issues_search(struct gcli_ctx *ctx, char const *owner, char const *repo, + struct gcli_issue_fetch_details const *details, int const max, + struct gcli_issue_list *const out) { - gcli_null_check_call(get_issues, ctx, owner, repo, details, max, out); + gcli_null_check_call(search_issues, ctx, owner, repo, details, max, out); } int From 5cd5dd65a07e21f8c45170143828667204e60538 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 2 Feb 2024 16:28:17 +0100 Subject: [PATCH 145/158] GL/#220: Implement issue search for Github Issue-tracker: https://gitlab.com/herrhotzenplotz/gcli/-/issues/220 Signed-off-by: Nico Sonack --- src/github/issues.c | 75 ++++++++++++++++++++++++++++++++++++--- templates/github/issues.t | 4 +++ 2 files changed, 75 insertions(+), 4 deletions(-) diff --git a/src/github/issues.c b/src/github/issues.c index e3d36687..f1185aa4 100644 --- a/src/github/issues.c +++ b/src/github/issues.c @@ -123,10 +123,65 @@ parse_github_milestone(struct gcli_ctx *ctx, char const *owner, return get_milestone_id(ctx, owner, repo, milestone, out); } -int -github_issues_search(struct gcli_ctx *ctx, char const *owner, char const *repo, - struct gcli_issue_fetch_details const *details, int const max, - struct gcli_issue_list *const out) +/* Search issues with a search term */ +static int +search_issues(struct gcli_ctx *ctx, char const *owner, char const *repo, + struct gcli_issue_fetch_details const *details, int const max, + struct gcli_issue_list *const out) +{ + char *url = NULL, *query_string = NULL, *e_query_string = NULL, + *milestone = NULL, *author = NULL, *label = NULL; + int rc = 0; + struct gcli_fetch_buffer buffer = {0}; + struct json_stream stream = {0}; + + (void) max; + + if (details->milestone) + milestone = sn_asprintf("milestone:%s", details->milestone); + + if (details->author) + author = sn_asprintf("author:%s", details->author); + + if (details->label) + label = sn_asprintf("label:%s", details->label); + + query_string = sn_asprintf("repo:%s/%s is:issue%s %s %s %s %s", owner, repo, + details->all ? "" : " is:open", + milestone ? milestone : "", author ? author : "", + label ? label : "", details->search_term); + e_query_string = gcli_urlencode(query_string); + + url = sn_asprintf("%s/search/issues?q=%s", gcli_get_apibase(ctx), + e_query_string); + + free(milestone); + free(author); + free(label); + free(query_string); + free(e_query_string); + + rc = gcli_fetch(ctx, url, NULL, &buffer); + if (rc < 0) + goto error_fetch; + + json_open_buffer(&stream, buffer.data, buffer.length); + rc = parse_github_issue_search_result(ctx, &stream, out); + + json_close(&stream); + free(buffer.data); + +error_fetch: + free(url); + + return rc; +} + +/* Optimised routine for issues without a search term */ +static int +get_issues(struct gcli_ctx *ctx, char const *owner, char const *repo, + struct gcli_issue_fetch_details const *details, int const max, + struct gcli_issue_list *const out) { char *url = NULL; char *e_owner = NULL; @@ -179,6 +234,18 @@ github_issues_search(struct gcli_ctx *ctx, char const *owner, char const *repo, return github_fetch_issues(ctx, url, max, out); } +int +github_issues_search(struct gcli_ctx *ctx, char const *owner, char const *repo, + struct gcli_issue_fetch_details const *details, + int const max, struct gcli_issue_list *const out) +{ + + if (details->search_term) + return search_issues(ctx, owner, repo, details, max, out); + else + return get_issues(ctx, owner, repo, details, max, out); +} + int github_get_issue_summary(struct gcli_ctx *ctx, char const *owner, char const *repo, gcli_id const issue_number, diff --git a/templates/github/issues.t b/templates/github/issues.t index 863e7b28..05de5321 100644 --- a/templates/github/issues.t +++ b/templates/github/issues.t @@ -24,3 +24,7 @@ object of struct gcli_issue with "milestone" => use parse_github_issue_milestone); parser github_issues is array of struct gcli_issue use parse_github_issue; + +parser github_issue_search_result is +object of struct gcli_issue_list with + ("items" => issues as array of gcli_issue use parse_github_issue); From b5e460c34fa998ea076e63f54780359e1d77a0ac Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 2 Feb 2024 16:30:09 +0100 Subject: [PATCH 146/158] GL/#220: Implement issue search for Gitlab Issue-tracker: https://gitlab.com/herrhotzenplotz/gcli/-/issues/220 Signed-off-by: Nico Sonack --- src/gitlab/issues.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/gitlab/issues.c b/src/gitlab/issues.c index 5ee0ff72..fe6ea433 100644 --- a/src/gitlab/issues.c +++ b/src/gitlab/issues.c @@ -55,8 +55,8 @@ gitlab_fetch_issues(struct gcli_ctx *ctx, char *url, int const max, int gitlab_issues_search(struct gcli_ctx *ctx, char const *owner, char const *repo, - struct gcli_issue_fetch_details const *details, int const max, - struct gcli_issue_list *const out) + struct gcli_issue_fetch_details const *details, + int const max, struct gcli_issue_list *const out) { char *url = NULL; char *e_owner = NULL; @@ -64,6 +64,7 @@ gitlab_issues_search(struct gcli_ctx *ctx, char const *owner, char const *repo, char *e_author = NULL; char *e_labels = NULL; char *e_milestone = NULL; + char *e_search = NULL; e_owner = gcli_urlencode(owner); e_repo = gcli_urlencode(repo); @@ -94,11 +95,20 @@ gitlab_issues_search(struct gcli_ctx *ctx, char const *owner, char const *repo, free(tmp); } - url = sn_asprintf("%s/projects/%s%%2F%s/issues%s%s%s%s", + if (details->search_term) { + char *tmp = gcli_urlencode(details->search_term); + int const should_do_qmark = details->all && !details->author && + !details->label && !details->milestone; + e_search = sn_asprintf("%csearch=%s", should_do_qmark ? '?': '&', tmp); + free(tmp); + } + + url = sn_asprintf("%s/projects/%s%%2F%s/issues%s%s%s%s%s", gcli_get_apibase(ctx), e_owner, e_repo, details->all ? "" : "?state=opened", e_author ? e_author : "", e_labels ? e_labels : "", - e_milestone ? e_milestone : ""); + e_milestone ? e_milestone : "", + e_search ? e_search : ""); free(e_milestone); free(e_author); From 265e806de16e51b345f8707ca797368be3c072ac Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 2 Feb 2024 16:59:06 +0100 Subject: [PATCH 147/158] GL/#220: Implement issue search for Gitea Issue-tracker: https://gitlab.com/herrhotzenplotz/gcli/-/issues/220 Signed-off-by: Nico Sonack --- src/gitea/issues.c | 52 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/src/gitea/issues.c b/src/gitea/issues.c index 21bbc489..a73c08e4 100644 --- a/src/gitea/issues.c +++ b/src/gitea/issues.c @@ -40,10 +40,56 @@ int gitea_issues_search(struct gcli_ctx *ctx, char const *owner, char const *repo, - struct gcli_issue_fetch_details const *details, int const max, - struct gcli_issue_list *const out) + struct gcli_issue_fetch_details const *details, + int const max, struct gcli_issue_list *const out) { - return github_issues_search(ctx, owner, repo, details, max, out); + char *url = NULL, *e_owner = NULL, *e_repo = NULL, *e_author = NULL, + *e_label = NULL, *e_milestone = NULL, *e_query = NULL; + + if (details->milestone) { + char *tmp = gcli_urlencode(details->milestone); + e_milestone = sn_asprintf("&milestones=%s", tmp); + free(tmp); + } + + if (details->author) { + char *tmp = gcli_urlencode(details->author); + e_author = sn_asprintf("&created_by=%s", tmp); + free(tmp); + } + + if (details->label) { + char *tmp = gcli_urlencode(details->label); + e_label = sn_asprintf("&labels=%s", tmp); + free(tmp); + } + + if (details->search_term) { + char *tmp = gcli_urlencode(details->search_term); + e_query = sn_asprintf("&q=%s", tmp); + free(tmp); + } + + e_owner = gcli_urlencode(owner); + e_repo = gcli_urlencode(repo); + + url = sn_asprintf("%s/repos/%s/%s/issues?state=%s%s%s%s%s", + gcli_get_apibase(ctx), + e_owner, e_repo, + details->all ? "all" : "open", + e_author ? e_author : "", + e_label ? e_label : "", + e_milestone ? e_milestone : "", + e_query ? e_query : ""); + + free(e_query); + free(e_milestone); + free(e_author); + free(e_label); + free(e_owner); + free(e_repo); + + return github_fetch_issues(ctx, url, max, out); } int From 1898b54ceeb716d25c3ae31ce999893755f99094 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 2 Feb 2024 17:07:15 +0100 Subject: [PATCH 148/158] GL/#220: Implement bug search for Bugzilla Issue-tracker: https://gitlab.com/herrhotzenplotz/gcli/-/issues/220 Signed-off-by: Nico Sonack --- src/bugzilla/bugs.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/bugzilla/bugs.c b/src/bugzilla/bugs.c index 7bd5636d..3820727a 100644 --- a/src/bugzilla/bugs.c +++ b/src/bugzilla/bugs.c @@ -46,7 +46,8 @@ bugzilla_get_bugs(struct gcli_ctx *ctx, char const *product, char const *compone struct gcli_issue_fetch_details const *details, int const max, struct gcli_issue_list *out) { - char *url, *e_product = NULL, *e_component = NULL, *e_author = NULL; + char *url, *e_product = NULL, *e_component = NULL, *e_author = NULL, + *e_query = NULL; struct gcli_fetch_buffer buffer = {0}; int rc = 0; @@ -68,17 +69,25 @@ bugzilla_get_bugs(struct gcli_ctx *ctx, char const *product, char const *compone free(tmp); } + if (details->search_term) { + char *tmp = gcli_urlencode(details->search_term); + e_query = sn_asprintf("&quicksearch=%s", tmp); + free(tmp); + } + /* TODO: handle the max = -1 case */ /* Note(Nico): Most of the options here are not very well * documented. Specifically the order= parameter I have figured out by * reading the code and trying things until it worked. */ - url = sn_asprintf("%s/rest/bug?order=bug_id%%20DESC%%2C&limit=%d%s%s%s%s", + url = sn_asprintf("%s/rest/bug?order=bug_id%%20DESC%%2C&limit=%d%s%s%s%s%s", gcli_get_apibase(ctx), max, details->all ? "&status=All" : "&status=Open&status=New", e_product ? e_product : "", e_component ? e_component : "", - e_author ? e_author : ""); + e_author ? e_author : "", + e_query ? e_query : ""); + free(e_query); free(e_product); free(e_component); free(e_author); From ca2fc73a0112952eab477698bd469478b5227a55 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 2 Feb 2024 17:19:08 +0100 Subject: [PATCH 149/158] GL/#220: Update gcli-issues.1 for new issue search feature Issue-tracker: https://gitlab.com/herrhotzenplotz/gcli/-/issues/220 Signed-off-by: Nico Sonack --- docs/gcli-issues.1.in | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/gcli-issues.1.in b/docs/gcli-issues.1.in index ebf992bb..d28658ab 100644 --- a/docs/gcli-issues.1.in +++ b/docs/gcli-issues.1.in @@ -13,6 +13,7 @@ .Op Fl L Ar label .Op Fl M Ar milestone .Op Fl o Ar owner Fl r Ar repo +.Op Ar "search-query" .Nm .Fl i Ar issue .Op Fl o Ar owner Fl r Ar repo @@ -24,7 +25,7 @@ .Sh DESCRIPTION Use .Nm -to list, create, edit or delete issues in repositories in various +to search, list, create, edit or delete issues in repositories in various .Xr git 1 forges such as GitHub, GitLab and Gitea. Without any action specified, .Nm @@ -131,6 +132,13 @@ Print a list of issues in the current project: $ gcli issues .Ed .Pp +Search for issues containing +.Dq crash +in contour-terminal/contour on GitHub including closed issues: +.Bd -literal -offset indent +$ gcli -t github issues -o contour-terminal -r contour -a crash +.Ed +.Pp Report a new issue in the current project: .Bd -literal -offset indent $ gcli issues create "summary here" From a20475f70ed687b62684672d6c1f261af21e00ae Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Fri, 2 Feb 2024 19:29:45 +0100 Subject: [PATCH 150/158] GL/#220: Update changelog for issue search feature Issue-tracker: https://gitlab.com/herrhotzenplotz/gcli/-/issues/220 Signed-off-by: Nico Sonack --- Changelog.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Changelog.md b/Changelog.md index d185d414..048ce09b 100644 --- a/Changelog.md +++ b/Changelog.md @@ -13,6 +13,17 @@ This changelog does not follow semantic versioning. Currently if now account has been specified it will default to the FreeBSD Bugzilla - this may however change in the future. +- A search feature has been added to the issues subcommand. You can + now optionally provide trailing text to the issues subcommand + which will be used as a search term: + + ```console + $ gcli issues -A herrhotzenplotz Segfault + ``` + + This will search for tickets authored by herrhotzenplotz containing + "Segfault". + ### Fixed - Fixed a segmentation fault when getting a 404 on Gitlab. This bug From 7e2bf3aa87d9e2a264760c99d2a6395712a63441 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Mon, 5 Feb 2024 14:40:08 +0100 Subject: [PATCH 151/158] Correct spelling in README Signed-off-by: Nico Sonack --- Changelog.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Changelog.md b/Changelog.md index ed8fee99..b350c46b 100644 --- a/Changelog.md +++ b/Changelog.md @@ -10,8 +10,8 @@ This changelog does not follow semantic versioning. - Preliminary (and thus experimental) support for Bugzilla has been added. For this a new yet undocumented `attachments` subcommand has been introduced. - Currently if now account has been specified it will default to - the FreeBSD Bugzilla - this may however change in the future. + Currently if no account has been specified it will default to the + FreeBSD Bugzilla - this may however change in the future. - A search feature has been added to the issues subcommand. You can now optionally provide trailing text to the issues subcommand From 4751d1d6619e5a348e68f6470c2fc32c93d926d9 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Mon, 5 Feb 2024 14:56:52 +0100 Subject: [PATCH 152/158] GL/#221: Fix listing Github Gists A segmentation fault occured due to the changes regarding string views. Issue-tracker: https://gitlab.com/herrhotzenplotz/gcli/-/issues/221 Signed-off-by: Nico Sonack --- Changelog.md | 2 ++ src/cmd/gists.c | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Changelog.md b/Changelog.md index b350c46b..74ac83c2 100644 --- a/Changelog.md +++ b/Changelog.md @@ -59,6 +59,8 @@ This changelog does not follow semantic versioning. provided colour code was converted incorrectly and always producing the wrong colour. +- Fixed a segmentation fault when listing Github gists + ### Changed - Internally a lot of code was using string views. Maintaining this diff --git a/src/cmd/gists.c b/src/cmd/gists.c index e3b6e84e..c3b53404 100644 --- a/src/cmd/gists.c +++ b/src/cmd/gists.c @@ -150,11 +150,11 @@ gcli_print_gists_short(enum gcli_output_flags const flags, size_t n; gcli_tbl table; struct gcli_tblcoldef cols[] = { - { .name = "ID", .type = GCLI_TBLCOLTYPE_SV, .flags = GCLI_TBLCOL_COLOUREXPL }, - { .name = "OWNER", .type = GCLI_TBLCOLTYPE_SV, .flags = GCLI_TBLCOL_BOLD }, - { .name = "DATE", .type = GCLI_TBLCOLTYPE_SV, .flags = 0 }, - { .name = "FILES", .type = GCLI_TBLCOLTYPE_INT, .flags = GCLI_TBLCOL_JUSTIFYR }, - { .name = "DESCRIPTION", .type = GCLI_TBLCOLTYPE_SV, .flags = 0 }, + { .name = "ID", .type = GCLI_TBLCOLTYPE_STRING, .flags = GCLI_TBLCOL_COLOUREXPL }, + { .name = "OWNER", .type = GCLI_TBLCOLTYPE_STRING, .flags = GCLI_TBLCOL_BOLD }, + { .name = "DATE", .type = GCLI_TBLCOLTYPE_STRING, .flags = 0 }, + { .name = "FILES", .type = GCLI_TBLCOLTYPE_INT, .flags = GCLI_TBLCOL_JUSTIFYR }, + { .name = "DESCRIPTION", .type = GCLI_TBLCOLTYPE_STRING, .flags = 0 }, }; if (max < 0 || (size_t)(max) > list->gists_size) From 543e33c611e474e5a8308ffec488d3bc71dc437c Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Mon, 5 Feb 2024 16:25:50 +0100 Subject: [PATCH 153/158] GL/#221: Refactor gist creation to use gcli_jsongen This fixes the escaping of strings during payload generation. Issue-tracker: https://gitlab.com/herrhotzenplotz/gcli/-/issues/221 Signed-off-by: Nico Sonack --- src/github/gists.c | 77 +++++++++++++++++++++++++++++++++------------- 1 file changed, 56 insertions(+), 21 deletions(-) diff --git a/src/github/gists.c b/src/github/gists.c index 7f0fbcb8..b44ada99 100644 --- a/src/github/gists.c +++ b/src/github/gists.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -115,36 +116,49 @@ gcli_get_gist(struct gcli_ctx *ctx, char const *gist_id, struct gcli_gist *out) } #define READ_SZ 4096 -static size_t -read_file(FILE *f, char **out) +static char * +read_file(FILE *f) { size_t size = 0; - - *out = NULL; + char *out = NULL; while (!feof(f) && !ferror(f)) { - *out = realloc(*out, size + READ_SZ); - size_t bytes_read = fread(*out + size, 1, READ_SZ, f); + out = realloc(out, size + READ_SZ); + size_t bytes_read = fread(out + size, 1, READ_SZ, f); if (bytes_read == 0) break; + size += bytes_read; } - return size; + if (out) { + out = realloc(out, size + 1); + out[size] = '\0'; + } + + if (ferror(f)) { + free(out); + out = NULL; + } + + return out; } int gcli_create_gist(struct gcli_ctx *ctx, struct gcli_new_gist opts) { - char *url = NULL; + char *content = NULL; char *post_data = NULL; - struct gcli_fetch_buffer fetch_buffer = {0}; - sn_sv read_buffer = {0}; - sn_sv content = {0}; + char *url = NULL; int rc = 0; + struct gcli_fetch_buffer fetch_buffer = {0}; + struct gcli_jsongen gen = {0}; - read_buffer.length = read_file(opts.file, &read_buffer.data); - content = gcli_json_escape(read_buffer); + /* Read in the file content. this may come from stdin this we don't know + * the size in advance. */ + content = read_file(opts.file); + if (content == NULL) + return gcli_error(ctx, "failed to read from input file"); /* This API is documented very badly. In fact, I dug up how you're * supposed to do this from @@ -163,19 +177,40 @@ gcli_create_gist(struct gcli_ctx *ctx, struct gcli_new_gist opts) * } * } */ + gcli_jsongen_init(&gen); + gcli_jsongen_begin_object(&gen); + { + gcli_jsongen_objmember(&gen, "description"); + gcli_jsongen_string(&gen, opts.gist_description); + + gcli_jsongen_objmember(&gen, "public"); + gcli_jsongen_bool(&gen, true); + + gcli_jsongen_objmember(&gen, "files"); + gcli_jsongen_begin_object(&gen); + { + gcli_jsongen_objmember(&gen, opts.file_name); + gcli_jsongen_begin_object(&gen); + { + gcli_jsongen_objmember(&gen, "content"); + gcli_jsongen_string(&gen, content); + } + gcli_jsongen_end_object(&gen); + } + gcli_jsongen_end_object(&gen); + } + gcli_jsongen_end_object(&gen); + + post_data = gcli_jsongen_to_string(&gen); + gcli_jsongen_free(&gen); - /* TODO: Escape gist_description and file_name */ + /* Generate URL */ url = sn_asprintf("%s/gists", gcli_get_apibase(ctx)); - post_data = sn_asprintf( - "{\"description\":\"%s\",\"public\":true,\"files\":" - "{\"%s\": {\"content\":\""SV_FMT"\"}}}", - opts.gist_description, - opts.file_name, - SV_ARGS(content)); + /* Perferm fetch */ rc = gcli_fetch_with_method(ctx, "POST", url, post_data, NULL, &fetch_buffer); - free(read_buffer.data); + free(content); free(fetch_buffer.data); free(url); free(post_data); From 7acf9bcd82848e068b0eaa97ea376b4f30c33ed0 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Mon, 5 Feb 2024 16:44:29 +0100 Subject: [PATCH 154/158] Reindent and clean up code style in gists.c Signed-off-by: Nico Sonack --- src/cmd/gists.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/cmd/gists.c b/src/cmd/gists.c index c3b53404..f5dfe33a 100644 --- a/src/cmd/gists.c +++ b/src/cmd/gists.c @@ -242,9 +242,9 @@ subcommand_gist_get(int argc, char *argv[]) static int subcommand_gist_create(int argc, char *argv[]) { - int ch; - struct gcli_new_gist opts = {0}; - char const *file = NULL; + char const *file = NULL; + int ch; + struct gcli_new_gist opts = {0}; struct option const options[] = { { .name = "file", @@ -303,9 +303,9 @@ subcommand_gist_create(int argc, char *argv[]) static int subcommand_gist_delete(int argc, char *argv[]) { - int ch; - bool always_yes = false; - char const *gist_id = NULL; + bool always_yes = false; + char const *gist_id = NULL; + int ch; struct option const options[] = { { .name = "yes", @@ -352,11 +352,11 @@ static struct { int subcommand_gists(int argc, char *argv[]) { - int ch; - char const *user = NULL; - struct gcli_gist_list gists = {0}; - int count = 30; - enum gcli_output_flags flags = 0; + char const *user = NULL; + enum gcli_output_flags flags = 0; + int ch; + int count = 30; + struct gcli_gist_list gists = {0}; /* Make sure we are looking at a GitHub forge */ if (gcli_config_get_forge_type(g_clictx) != GCLI_FORGE_GITHUB) { From e4d4930a9f8cce9fe9e18f52d0b127fe6e0c6d3d Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Mon, 5 Feb 2024 16:37:06 +0100 Subject: [PATCH 155/158] Report correct libcurl version in User-Agent header Previously we had incorrectly hardcoded user agents in the gcli_fetch routines reporting wrong libcurl versions. Fix the user agent by querying the libcurl version we are linked against and report its version. Signed-off-by: Nico Sonack --- include/gcli/ctx.h | 1 + src/curl.c | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/include/gcli/ctx.h b/include/gcli/ctx.h index f5310b75..4388c293 100644 --- a/include/gcli/ctx.h +++ b/include/gcli/ctx.h @@ -38,6 +38,7 @@ * data */ struct gcli_ctx { CURL *curl; + char *curl_useragent; void *usrdata; char *last_error; diff --git a/src/curl.c b/src/curl.c index bbcbd548..9a19ac70 100644 --- a/src/curl.c +++ b/src/curl.c @@ -64,7 +64,11 @@ gcli_curl_ctx_destroy(struct gcli_ctx *ctx) { if (ctx->curl) curl_easy_cleanup(ctx->curl); + ctx->curl = NULL; + + free(ctx->curl_useragent); + ctx->curl_useragent = NULL; } /* Ensures a clean cURL handle. Call this whenever you wanna use the @@ -72,6 +76,7 @@ gcli_curl_ctx_destroy(struct gcli_ctx *ctx) static int gcli_curl_ensure(struct gcli_ctx *ctx) { + if (ctx->curl) { curl_easy_reset(ctx->curl); } else { @@ -80,6 +85,13 @@ gcli_curl_ensure(struct gcli_ctx *ctx) return gcli_error(ctx, "failed to initialise curl context"); } + if (!ctx->curl_useragent) { + curl_version_info_data const *ver; + + ver = curl_version_info(CURLVERSION_NOW); + ctx->curl_useragent = sn_asprintf("curl/%s", ver->version); + } + return 0; } @@ -171,7 +183,7 @@ gcli_curl_test_success(struct gcli_ctx *ctx, char const *url) curl_easy_setopt(ctx->curl, CURLOPT_BUFFERSIZE, 102400L); curl_easy_setopt(ctx->curl, CURLOPT_NOPROGRESS, 1L); curl_easy_setopt(ctx->curl, CURLOPT_MAXREDIRS, 50L); - curl_easy_setopt(ctx->curl, CURLOPT_USERAGENT, "curl/7.78.0"); + curl_easy_setopt(ctx->curl, CURLOPT_USERAGENT, ctx->curl_useragent); #if defined(CURL_HTTP_VERSION_2TLS) curl_easy_setopt( ctx->curl, CURLOPT_HTTP_VERSION, (long)CURL_HTTP_VERSION_2TLS); @@ -240,7 +252,7 @@ gcli_curl(struct gcli_ctx *ctx, FILE *stream, char const *url, curl_easy_setopt(ctx->curl, CURLOPT_MAXREDIRS, 50L); curl_easy_setopt(ctx->curl, CURLOPT_FTP_SKIP_PASV_IP, 1L); curl_easy_setopt(ctx->curl, CURLOPT_HTTPHEADER, headers); - curl_easy_setopt(ctx->curl, CURLOPT_USERAGENT, "curl/7.78.0"); + curl_easy_setopt(ctx->curl, CURLOPT_USERAGENT, ctx->curl_useragent); #if defined(CURL_HTTP_VERSION_2TLS) curl_easy_setopt( ctx->curl, CURLOPT_HTTP_VERSION, (long)CURL_HTTP_VERSION_2TLS); @@ -400,7 +412,7 @@ gcli_fetch_with_method( curl_easy_setopt(ctx->curl, CURLOPT_POSTFIELDS, data); curl_easy_setopt(ctx->curl, CURLOPT_HTTPHEADER, headers); - curl_easy_setopt(ctx->curl, CURLOPT_USERAGENT, "curl/7.79.1"); + curl_easy_setopt(ctx->curl, CURLOPT_USERAGENT, ctx->curl_useragent); curl_easy_setopt(ctx->curl, CURLOPT_CUSTOMREQUEST, method); curl_easy_setopt(ctx->curl, CURLOPT_TCP_KEEPALIVE, 1L); curl_easy_setopt(ctx->curl, CURLOPT_WRITEDATA, buf); @@ -490,7 +502,7 @@ gcli_post_upload(struct gcli_ctx *ctx, char const *url, char const *content_type curl_easy_setopt(ctx->curl, CURLOPT_POSTFIELDSIZE, (long)buffer_size); curl_easy_setopt(ctx->curl, CURLOPT_HTTPHEADER, headers); - curl_easy_setopt(ctx->curl, CURLOPT_USERAGENT, "curl/7.79.1"); + curl_easy_setopt(ctx->curl, CURLOPT_USERAGENT, ctx->curl_useragent); curl_easy_setopt(ctx->curl, CURLOPT_WRITEDATA, out); curl_easy_setopt(ctx->curl, CURLOPT_WRITEFUNCTION, fetch_write_callback); From e5caea0eb7407b143ed26b888535357c7498edfa Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Mon, 5 Feb 2024 16:50:27 +0100 Subject: [PATCH 156/158] GL/#205: Fix segmentation fault when no authheader is available Some of the gcli_curl_routines do not check the generated authheader for a null pointer. Passing a null pointer to curl_slist_append causes a segmentation fault. Fix by wrapping curl_slist_append in a null check. Issue-tracker: https://gitlab.com/herrhotzenplotz/gcli/-/issues/205 Signed-off-by: Nico Sonack --- src/curl.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/curl.c b/src/curl.c index bbcbd548..76fd7b9d 100644 --- a/src/curl.c +++ b/src/curl.c @@ -480,7 +480,10 @@ gcli_post_upload(struct gcli_ctx *ctx, char const *url, char const *content_type headers = curl_slist_append( headers, "Accept: application/vnd.github.v3+json"); - headers = curl_slist_append(headers, auth_header); + + if (auth_header) + headers = curl_slist_append(headers, auth_header); + headers = curl_slist_append(headers, contenttype_header); headers = curl_slist_append(headers, contentsize_header); @@ -546,7 +549,9 @@ gcli_curl_gitea_upload_attachment(struct gcli_ctx *ctx, char const *url, headers = curl_slist_append( headers, "Accept: application/json"); - headers = curl_slist_append(headers, auth_header); + + if (auth_header) + headers = curl_slist_append(headers, auth_header); /* The docs say we should be using this mime thing. */ mime = curl_mime_init(ctx->curl); From 5b07a383972746c8e6807cbcbf810c7ba15bb7b6 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Mon, 5 Feb 2024 17:52:59 +0100 Subject: [PATCH 157/158] Update changelog Signed-off-by: Nico Sonack --- Changelog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Changelog.md b/Changelog.md index ccc91f0a..e9bea1a6 100644 --- a/Changelog.md +++ b/Changelog.md @@ -66,6 +66,9 @@ This changelog does not follow semantic versioning. - Fixed gcli reporting incorrect libcurl version in the User-Agent header when performing HTTP requests. +- Fixed possible segmentation fault when no token was configured in + gcli configuration file. + ### Changed - Internally a lot of code was using string views. Maintaining this From 7bb4743c4667694afc6859a991fbd5b51a8a5dcf Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Mon, 5 Feb 2024 17:57:34 +0100 Subject: [PATCH 158/158] Bump version Signed-off-by: Nico Sonack --- Changelog.md | 3 +-- configure.ac | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Changelog.md b/Changelog.md index e9bea1a6..1f1cb8f2 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,8 +2,7 @@ This changelog does not follow semantic versioning. - -## UNRELEASED +## 2.2.0 (2024-Feb-05) ### Added diff --git a/configure.ac b/configure.ac index 82539d70..c683c784 100644 --- a/configure.ac +++ b/configure.ac @@ -3,14 +3,14 @@ AC_PREREQ([2.69]) AC_INIT([gcli], - [2.2.0-devel], + [2.2.0], [~herrhotzenplotz/gcli-discuss@lists.sr.ht], [gcli], [https://herrhotzenplotz.de/gcli]) AM_INIT_AUTOMAKE([1.0 foreign subdir-objects dist-bzip2 dist-xz -Wall]) dnl Release Date. -PACKAGE_DATE="UNRELEASED" +PACKAGE_DATE="2024-Feb-05" AC_SUBST([PACKAGE_DATE]) dnl Silent by default.