[PATCH] docker-playground[master]: Add osmocom-extended cgit container

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Wed Mar 28 11:09:03 UTC 2018


Review at  https://gerrit.osmocom.org/7548

Add osmocom-extended cgit container

This uses the debian-nginx container "ankitrgadiya/cgit:debian-nginx"
and adds pygments for syntax highlighting, as well as the osmocom
commit filter for linking to gerrit change-ids as well as
redmine issues

Change-Id: Iec75769a972950ed9df95d5b36aa930daad1565a
---
A cgit/Dockerfile
A cgit/Makefile
A cgit/osmo-commit-filter.py
A cgit/syntax-highlighting.py
4 files changed, 115 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/docker-playground refs/changes/48/7548/1

diff --git a/cgit/Dockerfile b/cgit/Dockerfile
new file mode 100644
index 0000000..8898427
--- /dev/null
+++ b/cgit/Dockerfile
@@ -0,0 +1,13 @@
+FROM	ankitrgadiya/cgit:debian-nginx
+
+# This adds the Osmocom specific syntax highlighting + redmine/gerrit integration
+
+RUN	apt-get update && \
+	apt-get install -y --no-install-recommends \
+		python \
+		python-pygments
+
+RUN	mkdir -p /usr/local/lib/cgit/filters
+
+COPY	osmo-commit-filter.py /usr/local/lib/cgit/filters/osmo-commit-filter.py
+COPY	syntax-highlighting.py /usr/local/lib/cgit/filters/syntax-highlighting.py
diff --git a/cgit/Makefile b/cgit/Makefile
new file mode 100644
index 0000000..8d0e10b
--- /dev/null
+++ b/cgit/Makefile
@@ -0,0 +1 @@
+include ../make/Makefile
diff --git a/cgit/osmo-commit-filter.py b/cgit/osmo-commit-filter.py
new file mode 100755
index 0000000..12ce14d
--- /dev/null
+++ b/cgit/osmo-commit-filter.py
@@ -0,0 +1,49 @@
+#!/usr/bin/env python2.7
+# (C) Harald Welte <laforge at gnumonks.org>
+
+# This is a python script intended to be used as a commit-filter of
+# cgit.  It recognizes certain patterns (such as a gerrit Change-Id, or
+# Related/Closed redmine issues.
+
+GERRIT_URL = 'https://gerrit.osmocom.org/r/%s'
+REDMINE_OS_URL = 'https://osmocom.org/issues/%s'
+REDMINE_SYS_URL = 'https://projects.sysmocom.de/redmine/issues/%s'
+RT_URL = 'https://rt.sysmocom.de/TicketDisplay.html?id=%s'
+
+import re
+import sys
+import cgi
+
+def hyperlink(txt, url):
+    return '<a href="%s">%s</a>' % (url, cgi.escape(txt))
+
+def chgid_repl(matchobj):
+    chg_id = matchobj.group(1)
+    url = GERRIT_URL % cgi.escape(chg_id)
+    return hyperlink(chg_id, url)
+
+def relates_repl(matchobj):
+    def process_item(x):
+        def repl_os(m):
+            url = REDMINE_OS_URL % cgi.escape(m.group(1))
+            return hyperlink(m.group(0), url)
+        def repl_sys(m):
+            url = REDMINE_SYS_URL % cgi.escape(m.group(1))
+            return hyperlink(m.group(0), url)
+        def repl_rt(m):
+            url = RT_URL % cgi.escape(m.group(1))
+            return hyperlink(m.group(0), url)
+        x = re.sub(r"OS#(\d+)", repl_os, x)
+        x = re.sub(r"SYS#(\d+)", repl_sys, x)
+        x = re.sub(r"RT#(\d+)", repl_rt, x)
+        return x
+    line = matchobj.group(3)
+    related_ids = [x.strip() for x in line.split(',')]
+    extd_ids = [process_item(x) for x in related_ids]
+    return '%s: %s' % (matchobj.group(1), ', '.join(extd_ids))
+
+for line in sys.stdin:
+    line = re.sub(r"(I\w{40})", chgid_repl, line)
+    line = re.sub(r"^((Relate|Close|Fixe)[ds]): (.*)$", relates_repl, line)
+    sys.stdout.write(line)
+
diff --git a/cgit/syntax-highlighting.py b/cgit/syntax-highlighting.py
new file mode 100755
index 0000000..0882604
--- /dev/null
+++ b/cgit/syntax-highlighting.py
@@ -0,0 +1,52 @@
+#!/usr/bin/env python2.7
+
+# This script uses Pygments and Python3. You must have both installed
+# for this to work.
+#
+# http://pygments.org/
+# http://python.org/
+#
+# It may be used with the source-filter or repo.source-filter settings
+# in cgitrc.
+#
+# The following environment variables can be used to retrieve the
+# configuration of the repository for which this script is called:
+# CGIT_REPO_URL        ( = repo.url       setting )
+# CGIT_REPO_NAME       ( = repo.name      setting )
+# CGIT_REPO_PATH       ( = repo.path      setting )
+# CGIT_REPO_OWNER      ( = repo.owner     setting )
+# CGIT_REPO_DEFBRANCH  ( = repo.defbranch setting )
+# CGIT_REPO_SECTION    ( = section        setting )
+# CGIT_REPO_CLONE_URL  ( = repo.clone-url setting )
+
+
+import sys
+from pygments import highlight
+from pygments.util import ClassNotFound
+from pygments.lexers import TextLexer
+from pygments.lexers import guess_lexer
+from pygments.lexers import guess_lexer_for_filename
+from pygments.formatters import HtmlFormatter
+
+
+data = sys.stdin.read()
+filename = sys.argv[1]
+formatter = HtmlFormatter(style='pastie')
+
+try:
+	lexer = guess_lexer_for_filename(filename, data)
+except ClassNotFound:
+	# check if there is any shebang
+	if data[0:2] == '#!':
+		lexer = guess_lexer(data)
+	else:
+		lexer = TextLexer()
+except TypeError:
+	lexer = TextLexer()
+
+# highlight! :-)
+# printout pygments' css definitions as well
+sys.stdout.write('<style>')
+sys.stdout.write(formatter.get_style_defs('.highlight'))
+sys.stdout.write('</style>')
+sys.stdout.write(highlight(data, lexer, formatter, outfile=None))

-- 
To view, visit https://gerrit.osmocom.org/7548
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iec75769a972950ed9df95d5b36aa930daad1565a
Gerrit-PatchSet: 1
Gerrit-Project: docker-playground
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>



More information about the gerrit-log mailing list