aboutsummaryrefslogtreecommitdiff
path: root/ui-ci.c
diff options
from:
to:
context:
space:
mode:
authorGravatar Saya Andy <saya.andy@posteo.com> 2026-07-30 12:27:31 +0700
committerGravatar Saya Andy <saya.andy@posteo.com> 2026-07-30 12:27:31 +0700
commit7162aef3344a4f4f2d7edd2f214d805bd744c20c (patch)
tree53f1f504b83b3d8d36270431206aea7c6f6d969b /ui-ci.c
parentb4b4f2325db71041f38902143b28bae94762b111 (diff)
downloadcgitext-7162aef3344a4f4f2d7edd2f214d805bd744c20c.tar.gz
cgitext-7162aef3344a4f4f2d7edd2f214d805bd744c20c.zip
ui-ci: let a ci-filter decide whether the tab is shown
cgit cannot know whether the ref being viewed actually has a pipeline, so the "ci" tab is offered for every ref and only reveals a missing one once followed. Probing the ci system from cgit is not an option: the tab is part of the page header, so it would mean a blocking request for every page of every repository, cgit links no http client, and job pages are usually not readable anonymously. Add a ci filter instead, which receives the ref, whether it is a branch or a tag, and the expanded url, and answers with its exit status. This keeps credentials, timeouts and caching in a script, where they belong; filters/ci-jenkins.sh demonstrates all three against Jenkins' REST API. The verdict is memoized, so the filter runs once per request rather than once for the tab and again for the redirect, and it governs the page as well as the tab, so a hidden tab cannot be reached by typing the url. Signed-off-by: Saya Andy <saya.andy@posteo.com>
Diffstat (limited to 'ui-ci.c')
-rw-r--r--ui-ci.c29
1 files changed, 26 insertions, 3 deletions
diff --git a/ui-ci.c b/ui-ci.c
index 1c9f39c..ffd3a65 100644
--- a/ui-ci.c
+++ b/ui-ci.c
@@ -73,9 +73,24 @@ static char *expand_ci_url(const char *template)
return strbuf_detach(&buf, NULL);
}
+/* Ask the ci filter whether the pipeline denoted by url actually exists.
+ * The filter must not write to stdout, and signals "yes" by exiting with
+ * a zero status.
+ */
+static int ci_filter_accepts(const char *refkind, const char *url)
+{
+ struct cgit_filter *filter = ctx.repo->ci_filter;
+
+ if (!filter)
+ return 1;
+ if (cgit_open_filter(filter, ctx.qry.head, refkind, url))
+ return 0;
+ return !cgit_close_filter(filter);
+}
+
static void resolve_ci_url(void)
{
- const char *template;
+ const char *template, *refkind;
if (ci_resolved != -1)
return;
@@ -84,16 +99,24 @@ static void resolve_ci_url(void)
if (!ctx.repo || !ctx.qry.head || !cgit_have_repository())
return;
- if (ref_is_tag(ctx.qry.head))
+ if (ref_is_tag(ctx.qry.head)) {
+ refkind = "tag";
template = ctx.repo->ci_tag_url;
- else
+ } else {
+ refkind = "branch";
template = ctx.repo->ci_branch_url;
+ }
if (!template)
template = ctx.repo->ci_url;
if (!template)
return;
ci_url = expand_ci_url(template);
+ if (!ci_filter_accepts(refkind, ci_url)) {
+ free(ci_url);
+ ci_url = NULL;
+ return;
+ }
ci_resolved = 1;
}