-
-
Save lf-/f2e31a329c3c48f09198c865e21618e6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 1acc2fde5ab9bdea666fd1c9d1aba2496d4ce1a8 Mon Sep 17 00:00:00 2001 | |
From: Jade Lovelace <software@lfcode.ca> | |
Date: Thu, 16 May 2024 18:15:54 -0700 | |
Subject: [PATCH] lix: Make a Code Review (Gerrit) tab | |
--- | |
templates/repo/header.tmpl | 6 ++++++ | |
1 file changed, 6 insertions(+) | |
diff --git a/templates/repo/header.tmpl b/templates/repo/header.tmpl | |
index 21017415c1..6f8e9eb341 100644 | |
--- a/templates/repo/header.tmpl | |
+++ b/templates/repo/header.tmpl | |
@@ -99,6 +99,12 @@ | |
</a> | |
{{end}} | |
+ {{if and (eq .Repository.Name "lix") (eq .Repository.OwnerName "lix-project")}} | |
+ <a class="item" href="https://gerrit.lix.systems/q/project:lix"> | |
+ {{svg "octicon-code-review"}} Code Review (Gerrit) | |
+ </a> | |
+ {{end}} | |
+ | |
{{if .Permission.CanRead $.UnitTypeExternalTracker}} | |
<a class="{{if .PageIsIssueList}}active {{end}}item" href="{{.RepoExternalIssuesLink}}" target="_blank" rel="noopener noreferrer"> | |
{{svg "octicon-link-external"}} {{ctx.Locale.Tr "repo.issues"}} | |
-- | |
2.45.1 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 2de1868210f800047ee044fbf1b66988c668b399 Mon Sep 17 00:00:00 2001 | |
From: Jade Lovelace <software@lfcode.ca> | |
Date: Thu, 16 May 2024 19:56:25 -0700 | |
Subject: [PATCH] lix: link gerrit cl/ and change-ids | |
This code is a bit dubious but you know, golang | |
--- | |
modules/markup/html.go | 60 ++++++++++++++++++++++++++++++++++++++++++ | |
1 file changed, 60 insertions(+) | |
diff --git a/modules/markup/html.go b/modules/markup/html.go | |
index 56f63b8a76..fc4b05abaa 100644 | |
--- a/modules/markup/html.go | |
+++ b/modules/markup/html.go | |
@@ -50,6 +50,20 @@ var ( | |
// so that abbreviated hash links can be used as well. This matches git and GitHub usability. | |
hashCurrentPattern = regexp.MustCompile(`(?:\s|^|\(|\[)([0-9a-f]{7,64})(?:\s|$|\)|\]|[.,](\s|$))`) | |
+ // Gerrit change ID pattern | |
+ changeIdPattern = GerritPattern{ | |
+ urlMatch: 1, | |
+ displayMatch: 1, | |
+ pattern: regexp.MustCompile(`(?:\s|^|\(|\[)(I[0-9a-f]{8,40})(?:\s|$|\)|\]|[.,](\s|$))`), | |
+ } | |
+ | |
+ // Gerrit cl/ pattern | |
+ clSlashPattern = GerritPattern{ | |
+ urlMatch: 2, | |
+ displayMatch: 1, | |
+ pattern: regexp.MustCompile(`(?:^|[\s\]\[(){},.;:!?])(cl/([0-9]{0,6}))(?:$|[\s\]\[(){},.;:!?])`), | |
+ } | |
+ | |
// shortLinkPattern matches short but difficult to parse [[name|link|arg=test]] syntax | |
shortLinkPattern = regexp.MustCompile(`\[\[(.*?)\]\](\w*)`) | |
@@ -75,6 +89,14 @@ var ( | |
EmojiShortCodeRegex = regexp.MustCompile(`:[-+\w]+:`) | |
) | |
+type GerritPattern struct { | |
+ // The match group to put in the URL | |
+ urlMatch int | |
+ // The match group to render as the link | |
+ displayMatch int | |
+ pattern *regexp.Regexp | |
+} | |
+ | |
// CSS class for action keywords (e.g. "closes: #1") | |
const keywordClass = "issue-keyword" | |
@@ -179,6 +201,7 @@ var defaultProcessors = []processor{ | |
issueIndexPatternProcessor, | |
commitCrossReferencePatternProcessor, | |
hashCurrentPatternProcessor, | |
+ gerritCLPatternProcessor, | |
emailAddressProcessor, | |
emojiProcessor, | |
emojiShortCodeProcessor, | |
@@ -206,6 +229,7 @@ var commitMessageProcessors = []processor{ | |
issueIndexPatternProcessor, | |
commitCrossReferencePatternProcessor, | |
hashCurrentPatternProcessor, | |
+ gerritCLPatternProcessor, | |
emailAddressProcessor, | |
emojiProcessor, | |
emojiShortCodeProcessor, | |
@@ -782,6 +806,42 @@ func shortLinkProcessor(ctx *RenderContext, node *html.Node) { | |
} | |
} | |
+func gerritCLPatternProcessor(ctx *RenderContext, node *html.Node) { | |
+ if ctx.Metas == nil || node == nil { | |
+ return | |
+ } | |
+ | |
+ pats := []*GerritPattern{ | |
+ &changeIdPattern, | |
+ &clSlashPattern, | |
+ } | |
+ | |
+ next := node.NextSibling | |
+ for node != nil && node != next { | |
+ for _, pat := range pats { | |
+ ms := pat.pattern.FindAllStringSubmatchIndex(node.Data, -1) | |
+ if ms == nil { | |
+ continue | |
+ } | |
+ for _, m := range ms { | |
+ linkPart := node.Data[m[pat.urlMatch * 2]:m[pat.urlMatch * 2 + 1]] | |
+ linkNamePart := node.Data[m[pat.displayMatch * 2]:m[pat.displayMatch * 2 + 1]] | |
+ link := util.URLJoin("https://gerrit.lix.systems/q", linkPart) | |
+ replaceContent(node, m[pat.displayMatch * 2], m[pat.displayMatch * 2 + 1], createCodeLink(link, linkNamePart, "")) | |
+ } | |
+ } | |
+ | |
+ // FIXME: I don't understand how any of this stuff was supposed to work to | |
+ // begin with, since it seems like it returns if it doesn't just match in | |
+ // the first node???! | |
+ if node.NextSibling == nil { | |
+ return | |
+ } | |
+ | |
+ node = node.NextSibling.NextSibling | |
+ } | |
+} | |
+ | |
func fullIssuePatternProcessor(ctx *RenderContext, node *html.Node) { | |
if ctx.Metas == nil { | |
return | |
-- | |
2.45.1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment