mirror of
https://codeberg.org/git-pages/git-pages.git
synced 2026-10-22 07:22:33 +00:00
Use our fork of go-redirects.
This also fixes an issue with unparsing bare parameters (not that this syntax is currently used anywhere).
This commit is contained in:
@@ -23,7 +23,7 @@ jobs:
|
||||
- name: Set up toolchain
|
||||
uses: https://code.forgejo.org/actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6.5.0
|
||||
with:
|
||||
go-version: '>=1.26.0 <1.27.2' # upper limit for staticcheck at 2026-10-09
|
||||
go-version: '>=1.26.1 <1.27.2' # upper limit for staticcheck at 2026-10-09
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
apt-get -y update
|
||||
@@ -61,7 +61,7 @@ jobs:
|
||||
- name: Set up toolchain
|
||||
uses: https://code.forgejo.org/actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6.5.0
|
||||
with:
|
||||
go-version: '>=1.26.0'
|
||||
go-version: '>=1.26.1'
|
||||
- name: Build release assets
|
||||
# If you want more platforms to be represented, send a pull request.
|
||||
run: |
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module codeberg.org/git-pages/git-pages
|
||||
|
||||
go 1.26.0
|
||||
go 1.26.1
|
||||
|
||||
require (
|
||||
codeberg.org/git-pages/go-headers v1.1.1
|
||||
@@ -21,13 +21,13 @@ require (
|
||||
github.com/pquerna/cachecontrol v0.2.0
|
||||
github.com/prometheus/client_golang v1.23.2
|
||||
github.com/samber/slog-multi v1.8.0
|
||||
github.com/tj/go-redirects v0.0.0-20200911105812-fd1ba1020b37
|
||||
github.com/valyala/fasttemplate v1.2.2
|
||||
golang.org/x/net v0.60.0
|
||||
google.golang.org/protobuf v1.36.11
|
||||
)
|
||||
|
||||
require (
|
||||
codeberg.org/git-pages/go-redirects v1.0.0 // indirect
|
||||
github.com/Microsoft/go-winio v0.6.2 // indirect
|
||||
github.com/ProtonMail/go-crypto v1.4.1 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
codeberg.org/git-pages/go-headers v1.1.1 h1:fpIBELKo66Z2k+gCeYl5mCEXVQ99Lmx1iup1nbo2shE=
|
||||
codeberg.org/git-pages/go-headers v1.1.1/go.mod h1:N4gwH0U3YPwmuyxqH7xBA8j44fTPX+vOEP7ejJVBPts=
|
||||
codeberg.org/git-pages/go-redirects v1.0.0 h1:RfrPwtk60ii5JyQgH1XkUmsUrTqPjwvbqy3CGapPVwA=
|
||||
codeberg.org/git-pages/go-redirects v1.0.0/go.mod h1:0zdliclTux3tFONB7E6ZWV7WoWrK7cXHIi2hrMcLf8g=
|
||||
codeberg.org/git-pages/go-slog-syslog v0.1.0 h1:z6G7b+gilu3iYAyDyEiT958vt9JXhH4d4QsyJLiHGLg=
|
||||
codeberg.org/git-pages/go-slog-syslog v0.1.0/go.mod h1:8NPSXbYcVb71qqNM5cIgn1/uQgMisLbu2dVD1BNxsUw=
|
||||
github.com/BurntSushi/toml v1.6.0 h1:dRaEfpa2VI55EwlIW72hMRHdWouJeRF7TPYhI+AUQjk=
|
||||
@@ -135,8 +137,8 @@ github.com/tinylib/msgp v1.6.1 h1:ESRv8eL3u+DNHUoSAAQRE50Hm162zqAnBoGv9PzScPY=
|
||||
github.com/tinylib/msgp v1.6.1/go.mod h1:RSp0LW9oSxFut3KzESt5Voq4GVWyS+PSulT77roAqEA=
|
||||
github.com/tj/assert v0.0.3 h1:Df/BlaZ20mq6kuai7f5z2TvPFiwC3xaWJSDQNiIS3Rk=
|
||||
github.com/tj/assert v0.0.3/go.mod h1:Ne6X72Q+TB1AteidzQncjw9PabbMp4PBMZ1k+vd1Pvk=
|
||||
github.com/tj/go-redirects v0.0.0-20200911105812-fd1ba1020b37 h1:K11tjwz8zTTSZkz4TUjfLN+y8uJWP38BbyPqZ2yB/Yk=
|
||||
github.com/tj/go-redirects v0.0.0-20200911105812-fd1ba1020b37/go.mod h1:E0E2H2gQA+uoi27VCSU+a/BULPtadQA78q3cpTjZbZw=
|
||||
codeberg.org/git-pages/go-redirects v0.0.0-20200911105812-fd1ba1020b37 h1:K11tjwz8zTTSZkz4TUjfLN+y8uJWP38BbyPqZ2yB/Yk=
|
||||
codeberg.org/git-pages/go-redirects v0.0.0-20200911105812-fd1ba1020b37/go.mod h1:E0E2H2gQA+uoi27VCSU+a/BULPtadQA78q3cpTjZbZw=
|
||||
github.com/twmb/murmur3 v1.1.8 h1:8Yt9taO/WN3l08xErzjeschgZU2QSrwm1kclYq+0aRg=
|
||||
github.com/twmb/murmur3 v1.1.8/go.mod h1:Qq/R7NUyOfr65zD+6Q5IHKsJLwP7exErjN6lyyq3OSQ=
|
||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||
|
||||
+27
-24
@@ -4,6 +4,9 @@ schema = 3
|
||||
[mod."codeberg.org/git-pages/go-headers"]
|
||||
version = "v1.1.1"
|
||||
hash = "sha256-qgL7l1FHXxcBWhBnBLEI0yENd6P+frvwlKxEAXLA3VY="
|
||||
[mod."codeberg.org/git-pages/go-redirects"]
|
||||
version = "v1.0.0"
|
||||
hash = "sha256-xsttC58ofAVdn8Jn3fn3Y+AyOakarwKx3qPsmCIaL7g="
|
||||
[mod."codeberg.org/git-pages/go-slog-syslog"]
|
||||
version = "v0.1.0"
|
||||
hash = "sha256-ye+DBIyxqTEOViYRrQPWyGJCaLmyKSDwH5btlqDPizM="
|
||||
@@ -56,14 +59,11 @@ schema = 3
|
||||
version = "v2.0.2"
|
||||
hash = "sha256-icqMDeC/tEg/3979EuEN67Ml5KjdDA0R3QvR6iLLrSI="
|
||||
[mod."github.com/go-git/go-billy/v6"]
|
||||
version = "v6.0.0-alpha.1"
|
||||
hash = "sha256-w4dyO5X4OdE3TMzoP4pRNqhw3wCeLduT8p/nV5GEIfs="
|
||||
version = "v6.0.0-alpha.2"
|
||||
hash = "sha256-qqhhuxHorEj5PgSdReABtLKKPYqWdx9AlK1+QjDnt98="
|
||||
[mod."github.com/go-git/go-git/v6"]
|
||||
version = "v6.0.0-alpha.4"
|
||||
hash = "sha256-mOaq2I8uII4SCOaW36k9BB7abNk8Z7qrE4jqJgBkQmw="
|
||||
[mod."github.com/go-ini/ini"]
|
||||
version = "v1.67.0"
|
||||
hash = "sha256-V10ahGNGT+NLRdKUyRg1dos5RxLBXBk1xutcnquc/+4="
|
||||
version = "v6.0.0-alpha.5"
|
||||
hash = "sha256-r1lcplSi5Rl+p3iqAIePYUVmrMn9tg5Jpm/KQFDE554="
|
||||
[mod."github.com/google/uuid"]
|
||||
version = "v1.6.0"
|
||||
hash = "sha256-VWl9sqUzdOuhW0KzQlv0gwwUQClYkmZwSydHG2sALYw="
|
||||
@@ -77,8 +77,8 @@ schema = 3
|
||||
version = "v1.6.0"
|
||||
hash = "sha256-i/EYNJx0+HbAGFVoiKV4QF/zqb4fWewh+bpBKUkXDCc="
|
||||
[mod."github.com/klauspost/compress"]
|
||||
version = "v1.18.5"
|
||||
hash = "sha256-H9b5iFJf4XbEnkGQCjGQAJ3aYhVDiolKrDewTbhuzQo="
|
||||
version = "v1.19.0"
|
||||
hash = "sha256-8tAQw82P+RzHACxt5Y8vV8jY+oHvKGCVyHCvMNdNiXM="
|
||||
[mod."github.com/klauspost/cpuid/v2"]
|
||||
version = "v2.3.0"
|
||||
hash = "sha256-50JhbQyT67BK38HIdJihPtjV7orYp96HknI2VP7A9Yc="
|
||||
@@ -104,8 +104,8 @@ schema = 3
|
||||
version = "v1.1.2"
|
||||
hash = "sha256-vykcXvy2VBBAXnJott/XsGTT0gk2UL36JzZKfJ1KAUY="
|
||||
[mod."github.com/minio/minio-go/v7"]
|
||||
version = "v7.0.100"
|
||||
hash = "sha256-MjWYoX4b+OOSOkjsitQQqcTbpQ7CYNghN9XCdrqgYaM="
|
||||
version = "v7.2.1"
|
||||
hash = "sha256-P0DMI8oXFq/l1gKn8tx4AzLtkcR9Cmn84BIWNHYDdzM="
|
||||
[mod."github.com/munnerz/goautoneg"]
|
||||
version = "v0.0.0-20191010083416-a7dc8b61c822"
|
||||
hash = "sha256-79URDDFenmGc9JZu+5AXHToMrtTREHb3BC84b/gym9Q="
|
||||
@@ -163,15 +163,15 @@ schema = 3
|
||||
[mod."github.com/tj/assert"]
|
||||
version = "v0.0.3"
|
||||
hash = "sha256-4xhmZcHpUafabaXejE9ucVnGxG/txomvKzBg6cbkusg="
|
||||
[mod."github.com/tj/go-redirects"]
|
||||
version = "v0.0.0-20200911105812-fd1ba1020b37"
|
||||
hash = "sha256-GpYpxdT4F7PkwGXLo7cYVcIRJrzd1sKHtFDH+bRb6Tk="
|
||||
[mod."github.com/valyala/bytebufferpool"]
|
||||
version = "v1.0.0"
|
||||
hash = "sha256-I9FPZ3kCNRB+o0dpMwBnwZ35Fj9+ThvITn8a3Jr8mAY="
|
||||
[mod."github.com/valyala/fasttemplate"]
|
||||
version = "v1.2.2"
|
||||
hash = "sha256-gp+lNXE8zjO+qJDM/YbS6V43HFsYP6PKn4ux1qa5lZ0="
|
||||
[mod."github.com/zeebo/xxh3"]
|
||||
version = "v1.1.0"
|
||||
hash = "sha256-UuyNDofnjry9qKddcVhkTZFYUXgCYoLuKmCoOcyd504="
|
||||
[mod."go.yaml.in/yaml/v2"]
|
||||
version = "v2.4.2"
|
||||
hash = "sha256-oC8RWdf1zbMYCtmR0ATy/kCkhIwPR9UqFZSMOKLVF/A="
|
||||
@@ -179,23 +179,26 @@ schema = 3
|
||||
version = "v3.0.4"
|
||||
hash = "sha256-NkGFiDPoCxbr3LFsI6OCygjjkY0rdmg5ggvVVwpyDQ4="
|
||||
[mod."golang.org/x/crypto"]
|
||||
version = "v0.51.0"
|
||||
hash = "sha256-/R74sc1mcOaOuBeXRQzrXrHAgA5VhNWc6SfQJaxb17U="
|
||||
version = "v0.57.0"
|
||||
hash = "sha256-3/hkB+mZVBKnoxUaJv7DOzvxaL+8uQ7V6ofW4JiHhz4="
|
||||
[mod."golang.org/x/net"]
|
||||
version = "v0.55.0"
|
||||
hash = "sha256-Phi2mSmBGOJcvqPPAit3uqF3UP8SKRI9dHj6yTM3s5s="
|
||||
version = "v0.60.0"
|
||||
hash = "sha256-Xxed9Zp1f2+e8Gsrz8OQ4hI/Xo8+2RfwaV3+aaykvro="
|
||||
[mod."golang.org/x/sync"]
|
||||
version = "v0.20.0"
|
||||
hash = "sha256-ybcjhCfK6lroUM0yswUvWooW8MOQZBXyiSqoxG6Uy0Y="
|
||||
version = "v0.23.0"
|
||||
hash = "sha256-nF8YZFVC+TitjkderlqgGwJkuMqJCxI+fIElVLjBT2M="
|
||||
[mod."golang.org/x/sys"]
|
||||
version = "v0.45.0"
|
||||
hash = "sha256-hkBoNazrDA67ER6sWhb+EKxx9nJ24+nz3zGy+zT5Hvw="
|
||||
version = "v0.48.0"
|
||||
hash = "sha256-u+LwI76YIeg1asQKZItD2mnL4Yvx8veLhBuL8wv60Ls="
|
||||
[mod."golang.org/x/text"]
|
||||
version = "v0.37.0"
|
||||
hash = "sha256-8XDOnlPIybcDRy89fkjG5VqtIt5Ku+LmaqYhgKl7i1E="
|
||||
version = "v0.42.0"
|
||||
hash = "sha256-bviKbNmkN4Yf2dpgwmP6yNcZEakCcv1R+YyAxCdJGkY="
|
||||
[mod."google.golang.org/protobuf"]
|
||||
version = "v1.36.11"
|
||||
hash = "sha256-7W+6jntfI/awWL3JP6yQedxqP5S9o3XvPgJ2XxxsIeE="
|
||||
[mod."gopkg.in/ini.v1"]
|
||||
version = "v1.67.2"
|
||||
hash = "sha256-fvrkZDKE3sx3zwXDs8gZzL/9fARfLza5Mo7DAm3S4Vc="
|
||||
[mod."gopkg.in/yaml.v3"]
|
||||
version = "v3.0.1"
|
||||
hash = "sha256-FqL9TKYJ0XkNwJFnq9j0VvJ5ZUU1RvH/52h/f5bkYAU="
|
||||
|
||||
+11
-26
@@ -9,15 +9,15 @@ import (
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/tj/go-redirects"
|
||||
"codeberg.org/git-pages/go-redirects"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
const RedirectsFileName string = "_redirects"
|
||||
|
||||
// Converts our Protobuf representation to tj/go-redirects.
|
||||
func exportRedirectRule(rule *RedirectRule) *redirects.Rule {
|
||||
return &redirects.Rule{
|
||||
func exportRedirectRule(rule *RedirectRule) redirects.Rule {
|
||||
return redirects.Rule{
|
||||
From: rule.GetFrom(),
|
||||
To: rule.GetTo(),
|
||||
Status: int(rule.GetStatus()),
|
||||
@@ -25,24 +25,6 @@ func exportRedirectRule(rule *RedirectRule) *redirects.Rule {
|
||||
}
|
||||
}
|
||||
|
||||
func unparseRedirectRule(rule *redirects.Rule) string {
|
||||
var statusPart string
|
||||
if rule.Force {
|
||||
statusPart = fmt.Sprintf("%d!", rule.Status)
|
||||
} else {
|
||||
statusPart = fmt.Sprintf("%d", rule.Status)
|
||||
}
|
||||
parts := []string{
|
||||
rule.From,
|
||||
rule.To,
|
||||
statusPart,
|
||||
}
|
||||
for name, value := range rule.Params {
|
||||
parts = append(parts, fmt.Sprintf("%s=%s", name, value))
|
||||
}
|
||||
return strings.Join(parts, " ")
|
||||
}
|
||||
|
||||
var validRedirectHTTPStatuses []int = []int{
|
||||
http.StatusOK,
|
||||
http.StatusMovedPermanently,
|
||||
@@ -122,8 +104,9 @@ func ProcessRedirectsFile(ctx context.Context, manifest *Manifest) error {
|
||||
|
||||
for index, rule := range rules {
|
||||
if err := validateRedirectRule(&rule); err != nil {
|
||||
ruleString := redirects.Must(redirects.UnparseString([]redirects.Rule{rule}))
|
||||
AddProblem(manifest, RedirectsFileName,
|
||||
"rule #%d %q: %s", index+1, unparseRedirectRule(&rule), err)
|
||||
"rule #%d %q: %s", index+1, strings.TrimSpace(ruleString), err)
|
||||
continue
|
||||
}
|
||||
manifest.Redirects = append(manifest.Redirects, &RedirectRule{
|
||||
@@ -137,11 +120,11 @@ func ProcessRedirectsFile(ctx context.Context, manifest *Manifest) error {
|
||||
}
|
||||
|
||||
func CollectRedirectsFile(manifest *Manifest) string {
|
||||
var rules []string
|
||||
var rules []redirects.Rule
|
||||
for _, rule := range manifest.GetRedirects() {
|
||||
rules = append(rules, unparseRedirectRule(exportRedirectRule(rule))+"\n")
|
||||
rules = append(rules, exportRedirectRule(rule))
|
||||
}
|
||||
return strings.Join(rules, "")
|
||||
return redirects.Must(redirects.UnparseString(rules))
|
||||
}
|
||||
|
||||
func pathSegments(path string) []string {
|
||||
@@ -253,10 +236,12 @@ func LintRedirects(manifest *Manifest) {
|
||||
if entry.GetType() == Type_Directory {
|
||||
entryDesc = "directory"
|
||||
}
|
||||
ruleString := redirects.Must(redirects.UnparseString(
|
||||
[]redirects.Rule{exportRedirectRule(rule)}))
|
||||
AddProblem(manifest, name,
|
||||
"%s shadows redirect %q; remove the %s or use a %d! forced redirect instead",
|
||||
entryDesc,
|
||||
unparseRedirectRule(exportRedirectRule(rule)),
|
||||
strings.TrimSpace(ruleString),
|
||||
entryDesc,
|
||||
rule.GetStatus(),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user