aboutsummaryrefslogtreecommitdiff
diff refs
from: back
to: back
| flip
diff options
context:
space:
mode:
-rw-r--r--AUTHORS12
-rw-r--r--README99
-rw-r--r--README.md85
-rw-r--r--cgit.c38
-rw-r--r--cgit.h12
-rw-r--r--cgit.mk1
-rw-r--r--cgitrc.5.txt98
-rw-r--r--cmd.c11
-rw-r--r--filter.c10
-rwxr-xr-xfilters/ci-jenkins.sh58
-rw-r--r--shared.c14
-rw-r--r--tests/t0112-ci.sh127
-rw-r--r--tests/t0113-ci-lua.sh78
-rw-r--r--tests/t0114-broken-repo.sh71
-rw-r--r--ui-ci.c152
-rw-r--r--ui-ci.h7
-rw-r--r--ui-shared.c19
-rw-r--r--ui-shared.h2
18 files changed, 781 insertions, 113 deletions
diff --git a/AUTHORS b/AUTHORS
index 031de33..e68846e 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -1,13 +1,5 @@
Maintainer:
- Jason A. Donenfeld <Jason@zx2c4.com>
+ Saya Andy <saya.andy@posteo.com>
Contributors:
- Jason A. Donenfeld <Jason@zx2c4.com>
- Lukas Fleischer <cgit@cryptocrack.de>
- Johan Herland <johan@herland.net>
- Lars Hjemli <hjemli@gmail.com>
- Ferry Huberts <ferry.huberts@pelagic.nl>
- John Keeping <john@keeping.me.uk>
-
-Previous Maintainer:
- Lars Hjemli <hjemli@gmail.com>
+ Saya Andy <saya.andy@posteo.com>
diff --git a/README b/README
deleted file mode 100644
index 7a6b4a4..0000000
--- a/README
+++ /dev/null
@@ -1,99 +0,0 @@
-cgit - CGI for Git
-==================
-
-This is an attempt to create a fast web interface for the Git SCM, using a
-built-in cache to decrease server I/O pressure.
-
-Installation
-------------
-
-Building cgit involves building a proper version of Git. How to do this
-depends on how you obtained the cgit sources:
-
-a) If you're working in a cloned cgit repository, you first need to
-initialize and update the Git submodule:
-
- $ git submodule init # register the Git submodule in .git/config
- $ $EDITOR .git/config # if you want to specify a different url for git
- $ git submodule update # clone/fetch and checkout correct git version
-
-b) If you're building from a cgit tarball, you can download a proper git
-version like this:
-
- $ make get-git
-
-When either a) or b) has been performed, you can build and install cgit like
-this:
-
- $ make
- $ sudo make install
-
-This will install `cgit.cgi` and `cgit.css` into `/var/www/htdocs/cgit`. You
-can configure this location (and a few other things) by providing a `cgit.conf`
-file (see the Makefile for details).
-
-If you'd like to compile without Lua support, you may use:
-
- $ make NO_LUA=1
-
-And if you'd like to specify a Lua implementation, you may use:
-
- $ make LUA_PKGCONFIG=lua5.1
-
-If this is not specified, the Lua implementation will be auto-detected,
-preferring LuaJIT if many are present. Acceptable values are generally "lua",
-"luajit", "lua5.1", and "lua5.2".
-
-
-Dependencies
-------------
-
-* libzip
-* libcrypto (OpenSSL)
-* libssl (OpenSSL)
-* optional: luajit or lua, most reliably used when pkg-config is available
-
-Apache configuration
---------------------
-
-A new `Directory` section must probably be added for cgit, possibly something
-like this:
-
- <Directory "/var/www/htdocs/cgit/">
- AllowOverride None
- Options +ExecCGI
- Order allow,deny
- Allow from all
- </Directory>
-
-
-Runtime configuration
----------------------
-
-The file `/etc/cgitrc` is read by cgit before handling a request. In addition
-to runtime parameters, this file may also contain a list of repositories
-displayed by cgit (see `cgitrc.5.txt` for further details).
-
-The cache
----------
-
-When cgit is invoked it looks for a cache file matching the request and
-returns it to the client. If no such cache file exists (or if it has expired),
-the content for the request is written into the proper cache file before the
-file is returned.
-
-If the cache file has expired but cgit is unable to obtain a lock for it, the
-stale cache file is returned to the client. This is done to favour page
-throughput over page freshness.
-
-The generated content contains the complete response to the client, including
-the HTTP headers `Modified` and `Expires`.
-
-Online presence
----------------
-
-* The cgit homepage is hosted by cgit at <https://git.zx2c4.com/cgit/about/>
-
-* Patches, bug reports, discussions and support should go to the cgit
- mailing list: <cgit@lists.zx2c4.com>. To sign up, visit
- <https://lists.zx2c4.com/mailman/listinfo/cgit>
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..d4092ee
--- /dev/null
+++ b/README.md
@@ -0,0 +1,85 @@
+## cgitext - CGI for Git extension by Saya Andy
+
+This is a custom expansion to cgit. Its most prominent changes by now are:
+
+* CI/CD tab, linking to an external service on ref pages by using template. The Jenkins plugin is added to support a scenario when a ref lacks a pipeline.
+
+The original cgit project is hosted at [git.zx2c4.com](https://git.zx2c4.com/cgit/about/)
+
+## cgit - CGI for Git
+
+This is an attempt to create a fast web interface for the Git SCM, using a built-in cache to decrease server I/O pressure.
+
+### Installation
+
+Building cgit involves building a proper version of Git. How to do this depends on how you obtained the cgit sources:
+
+1. If you're working in a cloned cgit repository, you first need to initialize and update the Git submodule:
+
+ $ git submodule init # register the Git submodule in .git/config
+ $ $EDITOR .git/config # if you want to specify a different url for git
+ $ git submodule update # clone/fetch and checkout correct git version
+
+2. If you're building from a cgit tarball, you can download a proper git version like this:
+
+ $ make get-git
+
+When either `1.` or `2.` has been performed, you can build and install cgit like
+this:
+```
+make
+sudo make install
+```
+
+This will install `cgit.cgi` and `cgit.css` into `/var/www/htdocs/cgit`. You can configure this location (and a few other things) by providing a `cgit.conf` file (see the Makefile for details).
+
+If you'd like to compile without Lua support, you may use:
+```
+make NO_LUA=1
+```
+
+And if you'd like to specify a Lua implementation, you may use:
+```
+make LUA_PKGCONFIG=lua5.1
+```
+
+If this is not specified, the Lua implementation will be auto-detected, preferring LuaJIT if many are present. Acceptable values are generally "lua", "luajit", "lua5.1", and "lua5.2".
+
+
+### Dependencies
+
+* libzip
+* libcrypto (OpenSSL)
+* libssl (OpenSSL)
+* optional: luajit or lua, most reliably used when pkg-config is available
+
+### Apache configuration
+
+A new `Directory` section must probably be added for cgit, possibly something like this:
+
+```
+<Directory "/var/www/htdocs/cgit/">
+ AllowOverride None
+ Options +ExecCGI
+ Order allow,deny
+ Allow from all
+</Directory>
+```
+
+### Runtime configuration
+
+The file `/etc/cgitrc` is read by cgit before handling a request. In addition to runtime parameters, this file may also contain a list of repositories displayed by cgit (see `cgitrc.5.txt` for further details).
+
+### The cache
+
+When cgit is invoked it looks for a cache file matching the request and returns it to the client. If no such cache file exists (or if it has expired), the content for the request is written into the proper cache file before the file is returned.
+
+If the cache file has expired but cgit is unable to obtain a lock for it, the stale cache file is returned to the client. This is done to favour page throughput over page freshness.
+
+The generated content contains the complete response to the client, including the HTTP headers `Modified` and `Expires`.
+
+### Online presence
+
+* The cgit homepage is hosted by cgit at [git.zx2c4.com](https://git.zx2c4.com/cgit/about/)
+
+* Patches, bug reports, discussions and support should go to the cgit mailing list: [cgit@lists.zx2c4.com](mailto:cgit@lists.zx2c4.com). To sign up, visit [lists.zx2c4.com](https://lists.zx2c4.com/mailman/listinfo/cgit)
diff --git a/cgit.c b/cgit.c
index 5bf52f8..30c1d23 100644
--- a/cgit.c
+++ b/cgit.c
@@ -1,6 +1,10 @@
/* cgit.c: cgi for the git scm
*
* Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com>
+ * Copyright (C) 2026 Saya Andy <saya.andy@posteo.com>
+ *
+ * Modified 2026 by Saya Andy:
+ * Always check there is git repo on repo.path
*
* Licensed under GNU General Public License v2
* (see COPYING for full license text)
@@ -56,6 +60,20 @@ void cgit_repo_config(struct cgit_repo *repo, const char *name, const char *valu
repo->owner = strdup_first_line(value);
else if (!strcmp(name, "homepage"))
repo->homepage = strdup_first_line(value);
+ else if (!strcmp(name, "ci-url")) {
+ repo->ci_url = strdup_first_line(value);
+ /* An explicit repo.ci-url would otherwise never be used
+ * when the more specific urls are inherited from the
+ * global settings, so discard those.
+ */
+ if (repo->ci_branch_url == ctx.cfg.ci_branch_url)
+ repo->ci_branch_url = NULL;
+ if (repo->ci_tag_url == ctx.cfg.ci_tag_url)
+ repo->ci_tag_url = NULL;
+ } else if (!strcmp(name, "ci-branch-url"))
+ repo->ci_branch_url = strdup_first_line(value);
+ else if (!strcmp(name, "ci-tag-url"))
+ repo->ci_tag_url = strdup_first_line(value);
else if (!strcmp(name, "defbranch"))
repo->defbranch = strdup_first_line(value);
else if (!strcmp(name, "extra-head-content"))
@@ -122,6 +140,8 @@ void cgit_repo_config(struct cgit_repo *repo, const char *name, const char *valu
repo->email_filter = cgit_new_filter(value, EMAIL);
else if (!strcmp(name, "owner-filter"))
repo->owner_filter = cgit_new_filter(value, OWNER);
+ else if (!strcmp(name, "ci-filter"))
+ repo->ci_filter = cgit_new_filter(value, CI);
}
}
@@ -163,6 +183,12 @@ static void config_cb(const char *name, const char *value)
ctx.cfg.logo_link = strdup_first_line(value);
else if (!strcmp(name, "module-link"))
ctx.cfg.module_link = strdup_first_line(value);
+ else if (!strcmp(name, "ci-url"))
+ ctx.cfg.ci_url = strdup_first_line(value);
+ else if (!strcmp(name, "ci-branch-url"))
+ ctx.cfg.ci_branch_url = strdup_first_line(value);
+ else if (!strcmp(name, "ci-tag-url"))
+ ctx.cfg.ci_tag_url = strdup_first_line(value);
else if (!strcmp(name, "strict-export"))
ctx.cfg.strict_export = strdup_first_line(value);
else if (!strcmp(name, "virtual-root"))
@@ -233,6 +259,8 @@ static void config_cb(const char *name, const char *value)
ctx.cfg.owner_filter = cgit_new_filter(value, OWNER);
else if (!strcmp(name, "auth-filter"))
ctx.cfg.auth_filter = cgit_new_filter(value, AUTH);
+ else if (!strcmp(name, "ci-filter"))
+ ctx.cfg.ci_filter = cgit_new_filter(value, CI);
else if (!strcmp(name, "embedded"))
ctx.cfg.embedded = atoi(value);
else if (!strcmp(name, "max-atom-items"))
@@ -815,6 +843,12 @@ static void print_repo(FILE *f, struct cgit_repo *repo)
fprintf(f, "repo.section=%s\n", repo->section);
if (repo->homepage)
fprintf(f, "repo.homepage=%s\n", repo->homepage);
+ if (repo->ci_url)
+ fprintf(f, "repo.ci-url=%s\n", repo->ci_url);
+ if (repo->ci_branch_url)
+ fprintf(f, "repo.ci-branch-url=%s\n", repo->ci_branch_url);
+ if (repo->ci_tag_url)
+ fprintf(f, "repo.ci-tag-url=%s\n", repo->ci_tag_url);
if (repo->clone_url)
fprintf(f, "repo.clone-url=%s\n", repo->clone_url);
fprintf(f, "repo.enable-blame=%d\n",
@@ -837,6 +871,8 @@ static void print_repo(FILE *f, struct cgit_repo *repo)
cgit_fprintf_filter(repo->email_filter, f, "repo.email-filter=");
if (repo->owner_filter && repo->owner_filter != ctx.cfg.owner_filter)
cgit_fprintf_filter(repo->owner_filter, f, "repo.owner-filter=");
+ if (repo->ci_filter && repo->ci_filter != ctx.cfg.ci_filter)
+ cgit_fprintf_filter(repo->ci_filter, f, "repo.ci-filter=");
if (repo->snapshots != ctx.cfg.snapshots) {
char *tmp = build_snapshot_setting(repo->snapshots);
fprintf(f, "repo.snapshots=%s\n", tmp ? tmp : "");
@@ -965,7 +1001,7 @@ static void cgit_parse_args(int argc, const char **argv)
for (i = 1; i < argc; i++) {
if (!strcmp(argv[i], "--version")) {
- printf("CGit %s | https://git.zx2c4.com/cgit/\n\nCompiled in features:\n", CGIT_VERSION);
+ printf("CGit %s | https://sayag.it/cgitext.git | https://git.zx2c4.com/cgit/\n\nCompiled in features:\n", CGIT_VERSION);
#ifdef NO_LUA
printf("[-] ");
#else
diff --git a/cgit.h b/cgit.h
index 7d7ece7..847ab4e 100644
--- a/cgit.h
+++ b/cgit.h
@@ -63,7 +63,7 @@ typedef enum {
} diff_type;
typedef enum {
- ABOUT, COMMIT, SOURCE, EMAIL, AUTH, OWNER
+ ABOUT, COMMIT, SOURCE, EMAIL, AUTH, OWNER, CI
} filter_type;
struct cgit_filter {
@@ -90,6 +90,9 @@ struct cgit_repo {
char *extra_head_content;
char *owner;
char *homepage;
+ char *ci_url;
+ char *ci_branch_url;
+ char *ci_tag_url;
char *defbranch;
char *module_link;
struct string_list readme;
@@ -116,6 +119,7 @@ struct cgit_repo {
struct cgit_filter *source_filter;
struct cgit_filter *email_filter;
struct cgit_filter *owner_filter;
+ struct cgit_filter *ci_filter;
struct string_list submodules;
int hide;
int ignore;
@@ -196,6 +200,9 @@ struct cgit_query {
struct cgit_config {
char *agefile;
char *cache_root;
+ char *ci_url;
+ char *ci_branch_url;
+ char *ci_tag_url;
char *clone_prefix;
char *clone_url;
char *favicon;
@@ -274,6 +281,7 @@ struct cgit_config {
struct cgit_filter *email_filter;
struct cgit_filter *owner_filter;
struct cgit_filter *auth_filter;
+ struct cgit_filter *ci_filter;
};
struct cgit_page {
@@ -334,6 +342,8 @@ extern struct cgit_repo *cgit_get_repoinfo(const char *url);
extern void cgit_repo_config(struct cgit_repo *repo, const char *name,
const char *value);
+extern int cgit_have_repository(void);
+
extern int chk_zero(int result, char *msg);
extern int chk_positive(int result, char *msg);
extern int chk_non_negative(int result, char *msg);
diff --git a/cgit.mk b/cgit.mk
index 3fcc1ca..c4b735d 100644
--- a/cgit.mk
+++ b/cgit.mk
@@ -79,6 +79,7 @@ CGIT_OBJ_NAMES += shared.o
CGIT_OBJ_NAMES += ui-atom.o
CGIT_OBJ_NAMES += ui-blame.o
CGIT_OBJ_NAMES += ui-blob.o
+CGIT_OBJ_NAMES += ui-ci.o
CGIT_OBJ_NAMES += ui-clone.o
CGIT_OBJ_NAMES += ui-commit.o
CGIT_OBJ_NAMES += ui-diff.o
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index 7c39bf9..76b2085 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -100,6 +100,28 @@ cache-static-ttl::
version of repository pages accessed with a fixed SHA1. See also:
"CACHE". Default value: -1".
+ci-branch-url::
+ Url template used by the "ci" tab when a branch is being viewed. If
+ unspecified, `ci-url` is used instead. Default value: none. See also:
+ "CI URL EXPANSION".
+
+ci-filter::
+ Specifies a command which decides whether the "ci" tab is shown for
+ the ref currently being viewed, which is useful when only some refs
+ have a pipeline. Default value: none. See also: "FILTER API".
+
+ci-tag-url::
+ Url template used by the "ci" tab when a tag is being viewed. If
+ unspecified, `ci-url' is used instead. Default value: none. See also:
+ "CI URL EXPANSION".
+
+ci-url::
+ Url template used by the "ci" tab for refs which are not covered by
+ `ci-branch-url` or `ci-tag-url`. When at least one of the three ci url
+ settings is specified, cgit adds a "ci" tab which redirects to the
+ expanded url for the ref currently being viewed. Default value: none.
+ See also: "CI URL EXPANSION".
+
clone-prefix::
Space-separated list of common prefixes which, when combined with a
repository url, generates valid clone urls for the repository. This
@@ -468,6 +490,22 @@ repo.branch-sort::
list, and when set to "name" enables ordering by branch name. Default
value: "name".
+repo.ci-branch-url::
+ Override the global setting `ci-branch-url' for this repository.
+ Default value: <ci-branch-url>. See also: "CI URL EXPANSION".
+
+repo.ci-filter::
+ Override the default ci-filter. Default value: none. See also:
+ "enable-filter-overrides". See also: "FILTER API".
+
+repo.ci-tag-url::
+ Override the global setting `ci-tag-url' for this repository. Default
+ value: <ci-tag-url>. See also: "CI URL EXPANSION".
+
+repo.ci-url::
+ Override the global setting `ci-url' for this repository. Default
+ value: <ci-url>. See also: "CI URL EXPANSION".
+
repo.clone-url::
A list of space-separated urls which can be used to clone this repo.
Default value: none. See also: "MACRO EXPANSION".
@@ -710,6 +748,20 @@ auth filter::
Please see `filters/simple-authentication.lua` for a clear example
script that may be modified.
+ci filter::
+ This filter is given three parameters: the name of the branch or tag
+ being viewed, the string "branch" or "tag" to say which of the two it
+ is, and the ci url that the "ci" tab would redirect to. It decides
+ whether that tab is shown at all, by returning zero from the exit code
+ / close function to show it and non-zero to hide it. Nothing is written
+ to its standard input, and it must not write to standard output, since
+ that would land in the middle of the page being rendered.
+
+ The filter is consulted while rendering every page of the repository,
+ not only ref pages, so a filter which contacts the ci system should
+ cache its verdict and use a short timeout. Please see
+ `filters/ci-jenkins.sh` for an example.
+
commit filter::
This filter is given no arguments. The commit message text that is to
be filtered is available on standard input and the filtered text is
@@ -776,6 +828,46 @@ the environment variables defined in "FILTER API":
- repo.clone-url
+CI URL EXPANSION
+----------------
+The options `ci-url', `ci-branch-url' and `ci-tag-url' (and their
+`repo.'-prefixed counterparts) are url templates in which the following
+tokens are substituted when the "ci" tab is followed:
+
+$ref::
+ The name of the branch or tag currently being viewed.
+
+$repo::
+ The url of the repository, i.e. the value of `repo.url'.
+
+$slug::
+ $repo with any ".git" suffix removed and all slashes replaced by
+ dashes, e.g. "sayauz/web.git" becomes "sayauz-web".
+
+Two consecutive dollar signs produce a single literal one, and any other
+"$" is left untouched. Tokens are substituted verbatim, so the resulting
+url must already be properly encoded.
+
+When a tag is being viewed, `ci-tag-url' is used; for anything else
+`ci-branch-url' is used. Whichever of the two applies falls back to
+`ci-url' when it is unset, and the "ci" tab yields "404 Not found" when
+neither is set for the current ref. This makes it possible to point at a
+Jenkins multibranch pipeline, where branches and tags live at different
+locations:
+
+ ci-branch-url=https://ci.example.org/job/$slug/job/$ref
+ ci-tag-url=https://ci.example.org/job/$slug/view/tags/job/$ref
+
+Setting `repo.ci-url' discards the values which the repository would
+otherwise inherit from the global `ci-branch-url' and `ci-tag-url', so
+that a single repository can be pointed at a different ci system without
+having to override both of them.
+
+Note that cgit itself never contacts the ci system, so a tab shown for a
+ref which has no pipeline only reveals that after being followed. Use
+`ci-filter' to suppress the tab in that case.
+
+
CACHE
-----
@@ -828,6 +920,11 @@ clone-url=git://foo.org/$CGIT_REPO_URL git@foo.org:$CGIT_REPO_URL
css=/css/cgit.css
+# Add a "ci" tab pointing at a Jenkins multibranch pipeline
+ci-branch-url=https://ci.foo.org/job/$slug/job/$ref
+ci-tag-url=https://ci.foo.org/job/$slug/view/tags/job/$ref
+
+
# Show owner on index page
enable-index-owner=1
@@ -1020,3 +1117,4 @@ AUTHOR
------
Lars Hjemli <hjemli@gmail.com>
Jason A. Donenfeld <Jason@zx2c4.com>
+Saya Andy <saya.andy@posteo.com>
diff --git a/cmd.c b/cmd.c
index 0eb75b1..0ccd677 100644
--- a/cmd.c
+++ b/cmd.c
@@ -1,6 +1,10 @@
/* cmd.c: the cgit command dispatcher
*
* Copyright (C) 2006-2017 cgit Development Team <cgit@lists.zx2c4.com>
+ * Copyright (C) 2026 Saya Andy <saya.andy@posteo.com>
+ *
+ * Modified 2026 by Saya Andy:
+ * Include ci ui element
*
* Licensed under GNU General Public License v2
* (see COPYING for full license text)
@@ -13,6 +17,7 @@
#include "ui-atom.h"
#include "ui-blame.h"
#include "ui-blob.h"
+#include "ui-ci.h"
#include "ui-clone.h"
#include "ui-commit.h"
#include "ui-diff.h"
@@ -77,6 +82,11 @@ static void blob_fn(void)
cgit_print_blob(ctx.qry.oid, ctx.qry.path, ctx.qry.head, 0);
}
+static void ci_fn(void)
+{
+ cgit_print_ci();
+}
+
static void commit_fn(void)
{
cgit_print_commit(ctx.qry.oid, ctx.qry.path);
@@ -175,6 +185,7 @@ struct cgit_cmd *cgit_get_cmd(void)
def_cmd(about, 0, 0, 0),
def_cmd(blame, 1, 1, 0),
def_cmd(blob, 1, 0, 0),
+ def_cmd(ci, 1, 0, 0),
def_cmd(commit, 1, 1, 0),
def_cmd(diff, 1, 1, 0),
def_cmd(info, 1, 0, 1),
diff --git a/filter.c b/filter.c
index c778d05..7d722a3 100644
--- a/filter.c
+++ b/filter.c
@@ -1,6 +1,10 @@
/* filter.c: filter framework functions
*
* Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com>
+ * Copyright (C) 2026 Saya Andy <saya.andy@posteo.com>
+ *
+ * Modified 2026 by Saya Andy:
+ * Integrate ci filter
*
* Licensed under GNU General Public License v2
* (see COPYING for full license text)
@@ -30,12 +34,14 @@ void cgit_cleanup_filters(void)
reap_filter(ctx.cfg.email_filter);
reap_filter(ctx.cfg.owner_filter);
reap_filter(ctx.cfg.auth_filter);
+ reap_filter(ctx.cfg.ci_filter);
for (i = 0; i < cgit_repolist.count; ++i) {
reap_filter(cgit_repolist.repos[i].about_filter);
reap_filter(cgit_repolist.repos[i].commit_filter);
reap_filter(cgit_repolist.repos[i].source_filter);
reap_filter(cgit_repolist.repos[i].email_filter);
reap_filter(cgit_repolist.repos[i].owner_filter);
+ reap_filter(cgit_repolist.repos[i].ci_filter);
}
}
@@ -424,6 +430,10 @@ struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype)
argument_count = 12;
break;
+ case CI:
+ argument_count = 3;
+ break;
+
case EMAIL:
argument_count = 2;
break;
diff --git a/filters/ci-jenkins.sh b/filters/ci-jenkins.sh
new file mode 100755
index 0000000..842af21
--- /dev/null
+++ b/filters/ci-jenkins.sh
@@ -0,0 +1,58 @@
+#!/bin/sh
+# This script may be used with the ci-filter or repo.ci-filter setting in
+# cgitrc to hide the "ci" tab for refs which have no pipeline on a Jenkins
+# instance.
+#
+# Arguments:
+# $1 the name of the branch or tag being viewed
+# $2 "branch" or "tag"
+# $3 the ci url which the "ci" tab would redirect to
+#
+# Exit with a zero status to show the tab, non-zero to hide it. This script
+# must not write anything to standard output, as that would end up in the
+# middle of the page cgit is rendering.
+#
+# The filter is consulted while rendering every repository page, so the
+# verdict is cached on disk to keep Jenkins from being hammered, and the
+# probe is given a short timeout so that an unreachable Jenkins degrades
+# into a missing tab rather than a hanging web server.
+#
+# Set CI_NETRC to a netrc(5) file if the Jenkins instance requires
+# authentication; without it a private job answers 403 and the tab is
+# hidden even though the pipeline exists.
+
+CI_CACHE_DIR="${CI_CACHE_DIR:-/var/cache/cgit/ci-filter}"
+CI_CACHE_TTL_MINUTES="${CI_CACHE_TTL_MINUTES:-5}"
+CI_TIMEOUT="${CI_TIMEOUT:-2}"
+
+url="$3"
+test -n "$url" || exit 1
+
+# Jenkins job pages are often not readable anonymously, so query the REST
+# API rather than the page the tab points at.
+probe="$url/api/json?tree=name"
+
+key="$(printf '%s' "$url" | cksum | tr -cd '0-9')"
+cache="$CI_CACHE_DIR/$key"
+
+mkdir -p "$CI_CACHE_DIR" 2>/dev/null
+
+if test -f "$cache" &&
+ test -z "$(find "$cache" -mmin "+$CI_CACHE_TTL_MINUTES" 2>/dev/null)"
+then
+ exit "$(cat "$cache")"
+fi
+
+status=0
+curl --silent --fail --head --output /dev/null \
+ --max-time "$CI_TIMEOUT" \
+ ${CI_NETRC:+--netrc-file "$CI_NETRC"} \
+ "$probe" >/dev/null 2>&1 || status=1
+
+if test -d "$CI_CACHE_DIR"
+then
+ printf '%s\n' "$status" >"$cache.$$" 2>/dev/null &&
+ mv "$cache.$$" "$cache" 2>/dev/null
+fi
+
+exit "$status"
diff --git a/shared.c b/shared.c
index a39394d..8beb7c7 100644
--- a/shared.c
+++ b/shared.c
@@ -1,6 +1,11 @@
/* shared.c: global vars + some callback functions
*
* Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com>
+ * Copyright (C) 2026 Saya Andy <saya.andy@posteo.com>
+ *
+ * Modified 2026 by Saya Andy:
+ * Add cgit_have_repository()
+ * Add ci filter configuration
*
* Licensed under GNU General Public License v2
* (see COPYING for full license text)
@@ -13,6 +18,11 @@
struct cgit_repolist cgit_repolist;
struct cgit_context ctx;
+int cgit_have_repository(void)
+{
+ return startup_info->have_repository;
+}
+
int chk_zero(int result, char *msg)
{
if (result != 0)
@@ -59,6 +69,9 @@ struct cgit_repo *cgit_add_repo(const char *url)
ret->extra_head_content = NULL;
ret->owner = NULL;
ret->homepage = NULL;
+ ret->ci_url = ctx.cfg.ci_url;
+ ret->ci_branch_url = ctx.cfg.ci_branch_url;
+ ret->ci_tag_url = ctx.cfg.ci_tag_url;
ret->section = ctx.cfg.section;
ret->snapshots = ctx.cfg.snapshots;
ret->enable_blame = ctx.cfg.enable_blame;
@@ -80,6 +93,7 @@ struct cgit_repo *cgit_add_repo(const char *url)
ret->source_filter = ctx.cfg.source_filter;
ret->email_filter = ctx.cfg.email_filter;
ret->owner_filter = ctx.cfg.owner_filter;
+ ret->ci_filter = ctx.cfg.ci_filter;
ret->clone_url = ctx.cfg.clone_url;
ret->submodules.strdup_strings = 1;
ret->hide = ret->ignore = 0;
diff --git a/tests/t0112-ci.sh b/tests/t0112-ci.sh
new file mode 100644
index 0000000..33609d6
--- /dev/null
+++ b/tests/t0112-ci.sh
@@ -0,0 +1,127 @@
+#!/bin/sh
+
+test_description='Check content on ci page'
+. ./setup.sh
+
+# The ci settings are only inherited by repositories which are declared
+# after them, which is used below to get a repository with no ci url and
+# one with a tag-only ci url.
+cat >cgitrc.ci <<EOF
+virtual-root=/
+cache-root=$PWD/cache
+cache-size=0
+enable-filter-overrides=1
+
+repo.url=tagonly
+repo.path=$PWD/repos/foo/.git
+repo.ci-tag-url=https://ci.example.org/tagonly/\$ref
+
+ci-branch-url=https://ci.example.org/job/\$slug/job/\$ref
+ci-tag-url=https://ci.example.org/job/\$slug/view/tags/job/\$ref
+
+repo.url=foo
+repo.path=$PWD/repos/foo/.git
+
+repo.url=sayauz/web.git
+repo.path=$PWD/repos/foo/.git
+
+repo.url=override
+repo.path=$PWD/repos/foo/.git
+repo.ci-url=https://ci.example.org/override/\$repo/\$\$/\$ref
+
+repo.url=filtered
+repo.path=$PWD/repos/foo/.git
+repo.ci-filter=exec:$PWD/ci-filter.sh
+EOF
+
+# Records its arguments and only accepts tags.
+cat >ci-filter.sh <<EOF
+#!/bin/sh
+printf '%s|%s|%s\n' "\$1" "\$2" "\$3" >>"$PWD/ci-filter.log"
+test "\$2" = tag
+EOF
+chmod +x ci-filter.sh
+
+git --git-dir="$PWD/repos/foo/.git" tag v0.17.3.2 master
+
+cgit_ci()
+{
+ CGIT_CONFIG="$PWD/cgitrc.ci" QUERY_STRING="url=$1" cgit
+}
+
+test_expect_success 'redirect to the branch ci url' '
+ cgit_ci "foo/ci&h=master" >tmp &&
+ grep "^Status: 302 Found$" tmp &&
+ grep "^Location: https://ci.example.org/job/foo/job/master$" tmp
+'
+
+test_expect_success 'redirect to the tag ci url' '
+ cgit_ci "foo/ci&h=v0.17.3.2" >tmp &&
+ grep "^Status: 302 Found$" tmp &&
+ grep "^Location: https://ci.example.org/job/foo/view/tags/job/v0.17.3.2$" tmp
+'
+
+test_expect_success 'redirect to the default branch ci url' '
+ cgit_ci "foo/ci" >tmp &&
+ grep "^Location: https://ci.example.org/job/foo/job/master$" tmp
+'
+
+test_expect_success '$slug strips ".git" and replaces slashes' '
+ cgit_ci "sayauz/web.git/ci&h=v0.17.3.2" >tmp &&
+ grep "^Location: https://ci.example.org/job/sayauz-web/view/tags/job/v0.17.3.2$" tmp
+'
+
+test_expect_success 'repo.ci-url overrides and expands $repo and $$' '
+ cgit_ci "override/ci&h=master" >tmp &&
+ grep -F "Location: https://ci.example.org/override/override/\$/master" tmp
+'
+
+test_expect_success 'repo.ci-tag-url does not apply to branches' '
+ cgit_ci "tagonly/ci&h=v0.17.3.2" >tmp &&
+ grep "^Location: https://ci.example.org/tagonly/v0.17.3.2$" tmp &&
+ cgit_ci "tagonly/ci&h=master" >tmp &&
+ grep "^Status: 404 Not found$" tmp
+'
+
+test_expect_success 'find ci tab' '
+ cgit_ci "foo/refs&h=master" >tmp &&
+ grep "href=./foo/ci/.>ci</a>" tmp
+'
+
+test_expect_success 'no ci tab without a ci url' '
+ cgit_url "foo/refs" >tmp &&
+ ! grep ">ci</a>" tmp
+'
+
+test_expect_success 'ci filter accepts a tag' '
+ rm -f ci-filter.log &&
+ cgit_ci "filtered/ci&h=v0.17.3.2" >tmp &&
+ grep "^Location: https://ci.example.org/job/filtered/view/tags/job/v0.17.3.2$" tmp &&
+ echo "v0.17.3.2|tag|https://ci.example.org/job/filtered/view/tags/job/v0.17.3.2" >expected &&
+ test_cmp expected ci-filter.log
+'
+
+test_expect_success 'ci filter rejects a branch' '
+ rm -f ci-filter.log &&
+ cgit_ci "filtered/ci&h=master" >tmp &&
+ grep "^Status: 404 Not found$" tmp &&
+ echo "master|branch|https://ci.example.org/job/filtered/job/master" >expected &&
+ test_cmp expected ci-filter.log
+'
+
+test_expect_success "ci filter hides the tab and is consulted once" '
+ rm -f ci-filter.log &&
+ cgit_ci "filtered/refs&h=master" >tmp &&
+ ! grep ">ci</a>" tmp &&
+ test_line_count = 1 ci-filter.log &&
+ cgit_ci "filtered/refs&h=v0.17.3.2" >tmp &&
+ grep "href=./filtered/ci/?h=v0.17.3.2.>ci</a>" tmp
+'
+
+test_expect_success 'ci filter is not consulted without a ci url' '
+ rm -f ci-filter.log &&
+ cgit_url "foo/refs" >tmp &&
+ test_path_is_missing ci-filter.log
+'
+
+test_done
diff --git a/tests/t0113-ci-lua.sh b/tests/t0113-ci-lua.sh
new file mode 100644
index 0000000..1e095b1
--- /dev/null
+++ b/tests/t0113-ci-lua.sh
@@ -0,0 +1,78 @@
+#!/bin/sh
+
+test_description='Check ci filter written in Lua'
+. ./setup.sh
+
+if test $CGIT_HAS_LUA -ne 1
+then
+ skip_all='Skipping Lua ci filter tests: Lua support not compiled in'
+ test_done
+ exit
+fi
+
+cat >cgitrc.cilua <<EOF
+virtual-root=/
+cache-root=$PWD/cache
+cache-size=0
+
+ci-url=https://ci.example.org/job/\$slug/job/\$ref
+ci-filter=lua:$PWD/ci-filter.lua
+
+repo.url=foo
+repo.path=$PWD/repos/foo/.git
+EOF
+
+# Accepts tags only, and records its arguments.
+cat >ci-filter.lua <<EOF
+function filter_open(ref, refkind, url)
+ local log = io.open("$PWD/ci-filter.log", "a")
+ log:write(ref .. "|" .. refkind .. "|" .. url .. "\n")
+ log:close()
+ accepted = (refkind == "tag")
+end
+
+function filter_write(buffer)
+end
+
+function filter_close()
+ if accepted then
+ return 0
+ end
+ return 1
+end
+EOF
+
+git --git-dir="$PWD/repos/foo/.git" tag v1.0 master
+
+cgit_ci()
+{
+ CGIT_CONFIG="$PWD/cgitrc.cilua" QUERY_STRING="url=$1" cgit
+}
+
+test_expect_success 'Lua ci filter accepts a tag' '
+ rm -f ci-filter.log &&
+ cgit_ci "foo/ci&h=v1.0" >tmp &&
+ grep "^Location: https://ci.example.org/job/foo/job/v1.0$" tmp &&
+ echo "v1.0|tag|https://ci.example.org/job/foo/job/v1.0" >expected &&
+ test_cmp expected ci-filter.log
+'
+
+test_expect_success 'Lua ci filter rejects a branch' '
+ cgit_ci "foo/ci&h=master" >tmp &&
+ grep "^Status: 404 Not found$" tmp
+'
+
+test_expect_success 'Lua ci filter controls the tab' '
+ cgit_ci "foo/refs&h=v1.0" >tmp &&
+ grep "href=./foo/ci/?h=v1.0.>ci</a>" tmp &&
+ cgit_ci "foo/refs&h=master" >tmp &&
+ ! grep ">ci</a>" tmp
+'
+
+test_expect_success 'page is still rendered correctly around the filter' '
+ cgit_ci "foo/refs&h=v1.0" >tmp &&
+ grep "</html>" tmp &&
+ ! grep "|tag|" tmp
+'
+
+test_done
diff --git a/tests/t0114-broken-repo.sh b/tests/t0114-broken-repo.sh
new file mode 100644
index 0000000..61367e6
--- /dev/null
+++ b/tests/t0114-broken-repo.sh
@@ -0,0 +1,71 @@
+#!/bin/sh
+
+test_description='Check that a misconfigured repo.path is reported'
+. ./setup.sh
+
+mkdir -p plaindir
+
+cat >cgitrc.broken <<EOF
+virtual-root=/
+cache-root=$PWD/cache
+cache-size=0
+
+ci-branch-url=https://ci.example.org/job/\$slug/job/\$ref
+
+repo.url=missing
+repo.path=$PWD/no/such/repo.git
+
+repo.url=notarepo
+repo.path=$PWD/plaindir
+EOF
+
+# cgit used to spin forever on these requests, so give it a deadline and
+# report a failure rather than hanging the test suite.
+cgit_broken()
+{
+ CGIT_CONFIG="$PWD/cgitrc.broken" QUERY_STRING="url=$1" perl -e '
+ my $pid = fork();
+ if ($pid == 0) {
+ exec("cgit") or die "exec: $!";
+ }
+ eval {
+ local $SIG{ALRM} = sub { die "timeout\n" };
+ alarm(20);
+ waitpid($pid, 0);
+ alarm(0);
+ };
+ if ($@) {
+ kill "KILL", $pid;
+ print STDERR "cgit did not terminate\n";
+ exit 1;
+ }
+ ' </dev/null
+}
+
+test_expect_success 'report a repo.path that does not exist' '
+ cgit_broken "missing/&h=master" >tmp &&
+ grep "Failed to open missing" tmp
+'
+
+test_expect_success 'report a repo.path that is not a repository' '
+ cgit_broken "notarepo/&h=master" >tmp &&
+ grep "Failed to open notarepo" tmp
+'
+
+test_expect_success 'report an unknown page for a broken repo' '
+ cgit_broken "missing/nosuchpage/&h=master" >tmp &&
+ grep "^Status: 404 Not found$" tmp &&
+ grep "Invalid request" tmp
+'
+
+test_expect_success 'no ci tab for a broken repo' '
+ cgit_broken "missing/nosuchpage/&h=master" >tmp &&
+ ! grep ">ci</a>" tmp
+'
+
+test_expect_success 'report a broken repo on the ci page' '
+ cgit_broken "missing/ci/&h=master" >tmp &&
+ grep "Failed to open missing" tmp
+'
+
+test_done
diff --git a/ui-ci.c b/ui-ci.c
new file mode 100644
index 0000000..f2561a2
--- /dev/null
+++ b/ui-ci.c
@@ -0,0 +1,152 @@
+/* ui-ci.c: redirect to an external CI system
+ *
+ * Copyright (C) 2026 Saya Andy <saya.andy@posteo.com>
+ *
+ * Licensed under GNU General Public License v2
+ * (see COPYING for full license text)
+ */
+
+#define USE_THE_REPOSITORY_VARIABLE
+
+#include "cgit.h"
+#include "ui-ci.h"
+#include "html.h"
+#include "ui-shared.h"
+
+/* Memoized outcome of resolving the ci url for this request: -1 while
+ * unresolved, 0 when there is no ci url for the current ref, and 1 when
+ * ci_url holds the url to redirect to.
+ */
+static int ci_resolved = -1;
+static char *ci_url;
+
+static int ref_is_tag(const char *ref)
+{
+ struct strbuf fullref = STRBUF_INIT;
+ struct object_id oid;
+ int is_tag;
+
+ strbuf_addf(&fullref, "refs/tags/%s", ref);
+ is_tag = !repo_get_oid(the_repository, fullref.buf, &oid);
+ strbuf_release(&fullref);
+ return is_tag;
+}
+
+/* Append the repository url with any ".git" suffix removed and all
+ * slashes replaced by dashes, e.g. "sayauz/web.git" becomes
+ * "sayauz-web".
+ */
+static void add_repo_slug(struct strbuf *buf, const char *url)
+{
+ size_t len, i;
+
+ if (!strip_suffix(url, ".git", &len))
+ len = strlen(url);
+ for (i = 0; i < len; i++)
+ strbuf_addch(buf, url[i] == '/' ? '-' : url[i]);
+}
+
+static char *expand_ci_url(const char *template)
+{
+ const char *p, *rest;
+ struct strbuf buf = STRBUF_INIT;
+
+ for (p = template; *p; p++) {
+ if (*p != '$') {
+ strbuf_addch(&buf, *p);
+ continue;
+ }
+ if (skip_prefix(p, "$ref", &rest))
+ strbuf_addstr(&buf, ctx.qry.head);
+ else if (skip_prefix(p, "$repo", &rest))
+ strbuf_addstr(&buf, ctx.repo->url);
+ else if (skip_prefix(p, "$slug", &rest))
+ add_repo_slug(&buf, ctx.repo->url);
+ else if (skip_prefix(p, "$$", &rest))
+ strbuf_addch(&buf, '$');
+ else {
+ strbuf_addch(&buf, '$');
+ continue;
+ }
+ p = rest - 1;
+ }
+ 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, *refkind;
+
+ if (ci_resolved != -1)
+ return;
+ ci_resolved = 0;
+
+ if (!ctx.repo || !ctx.qry.head || !cgit_have_repository())
+ return;
+
+ if (ref_is_tag(ctx.qry.head)) {
+ refkind = "tag";
+ template = ctx.repo->ci_tag_url;
+ } 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;
+}
+
+int cgit_ci_available(void)
+{
+ resolve_ci_url();
+ return ci_resolved == 1;
+}
+
+void cgit_print_ci(void)
+{
+ resolve_ci_url();
+
+ if (ci_resolved != 1) {
+ cgit_print_error_page(404, "Not found",
+ "No ci url available for %s",
+ ctx.qry.head);
+ return;
+ }
+
+ /* The expanded template is emitted verbatim rather than through
+ * cgit_redirect(), which percent-encodes characters such as '?',
+ * '=' and '%' that are meaningful in a ci url. Refuse anything
+ * which could be used to smuggle in extra response headers.
+ */
+ if (strpbrk(ci_url, "\r\n")) {
+ cgit_print_error_page(500, "Internal server error",
+ "Malformed ci url");
+ return;
+ }
+
+ htmlf("Status: 302 Found\nLocation: %s\n\n", ci_url);
+}
diff --git a/ui-ci.h b/ui-ci.h
new file mode 100644
index 0000000..3d7ce02
--- /dev/null
+++ b/ui-ci.h
@@ -0,0 +1,7 @@
+#ifndef UI_CI_H
+#define UI_CI_H
+
+extern int cgit_ci_available(void);
+extern void cgit_print_ci(void);
+
+#endif /* UI_CI_H */
diff --git a/ui-shared.c b/ui-shared.c
index 9f7625c..97d1839 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -1,6 +1,12 @@
/* ui-shared.c: common web output functions
*
* Copyright (C) 2006-2017 cgit Development Team <cgit@lists.zx2c4.com>
+ * Copyright (C) 2026 Saya Andy <saya.andy@posteo.com>
+ *
+ * Modified 2026 by Saya Andy:
+ * Implement ci link tab
+ * Check repo existence
+ * Replace memrchr() for macOS compatibility
*
* Licensed under GNU General Public License v2
* (see COPYING for full license text)
@@ -12,6 +18,7 @@
#include "ui-shared.h"
#include "cmd.h"
#include "html.h"
+#include "ui-ci.h"
#include "version.h"
static const char cgit_doctype[] =
@@ -342,6 +349,12 @@ void cgit_tag_link(const char *name, const char *title, const char *class,
reporevlink("tag", name, title, class, tag, NULL, NULL);
}
+void cgit_ci_link(const char *name, const char *title, const char *class,
+ const char *head)
+{
+ reporevlink("ci", name, title, class, head, NULL, NULL);
+}
+
void cgit_tree_link(const char *name, const char *title, const char *class,
const char *head, const char *rev, const char *path)
{
@@ -877,7 +890,7 @@ void cgit_print_docend(void)
if (ctx.cfg.footer)
html_include(ctx.cfg.footer);
else {
- htmlf("<div class='footer'>generated by <a href='https://git.zx2c4.com/cgit/about/'>cgit %s</a> "
+ htmlf("<div class='footer'>generated by <a href='https://sayag.it/cgitext.git/about/'>cgitext %s</a> "
"(<a href='https://git-scm.com/'>git %s</a>) at ", cgit_version, git_version_string);
html_txt(show_date(time(NULL), 0, cgit_date_mode(DATE_ISO8601)));
html("</div>\n");
@@ -1042,7 +1055,7 @@ static void print_header(void)
cgit_index_link("index", NULL, NULL, NULL, NULL, 0, 1);
html(" : ");
cgit_summary_link(ctx.repo->name, NULL, NULL, NULL);
- if (ctx.env.authenticated) {
+ if (ctx.env.authenticated && cgit_have_repository()) {
html("</td><td class='form'>");
html("<form method='get'>\n");
cgit_add_hidden_formfields(0, 1, ctx.qry.page);
@@ -1110,6 +1123,8 @@ void cgit_print_pageheader(void)
if (ctx.repo->max_stats)
cgit_stats_link("stats", NULL, hc("stats"),
ctx.qry.head, ctx.qry.vpath);
+ if (cgit_ci_available())
+ cgit_ci_link("ci", NULL, hc("ci"), ctx.qry.head);
if (ctx.repo->homepage) {
html("<a href='");
html_attr(ctx.repo->homepage);
diff --git a/ui-shared.h b/ui-shared.h
index 2a3a7f5..a6627d4 100644
--- a/ui-shared.h
+++ b/ui-shared.h
@@ -21,6 +21,8 @@ extern void cgit_summary_link(const char *name, const char *title,
const char *class, const char *head);
extern void cgit_tag_link(const char *name, const char *title,
const char *class, const char *tag);
+extern void cgit_ci_link(const char *name, const char *title,
+ const char *class, const char *head);
extern void cgit_tree_link(const char *name, const char *title,
const char *class, const char *head,
const char *rev, const char *path);