Skip to content

Commit 06817b1

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: (28 commits) Added auto-save whitespace behavior if it changed manually (go-gitea#15566) Support custom ACME provider (go-gitea#18340) Refactor i18n, use Locale to provide i18n/translation related functions (go-gitea#18648) Only request write when necessary (go-gitea#18657) [skip ci] Updated translations via Crowdin Add separate SSH_USER config option (go-gitea#17584) Be more lenient with label colors (go-gitea#17752) remove redundant call to UpdateRepoStats during migration (go-gitea#18591) more repo dump/restore tests, including pull requests (go-gitea#18621) No longer show the db-downgrade SQL in production (go-gitea#18653) Fix the missing i18n key for update checker (go-gitea#18646) Update gitea-vet (go-gitea#18640) Future proof for 1.18 (go-gitea#18644) Add `contrib/upgrade.sh` (go-gitea#18286) If rendering has failed due to a net.OpError stop rendering (go-gitea#18642) Delete old git.NewCommand() and use it as git.NewCommandContext() (go-gitea#18552) Update JS dependencies (go-gitea#18636) fix commits_list_small.tmpl (go-gitea#18641) Fix `make fmt` and `make fmt-check` (go-gitea#18633) Frontport of changelog for v1.16.1 (go-gitea#18615) ...
2 parents c9122a5 + 4d93984 commit 06817b1

File tree

169 files changed

+2459
-1940
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

169 files changed

+2459
-1940
lines changed

CHANGELOG.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,35 @@ This changelog goes through all the changes that have been made in each release
44
without substantial changes to our git log; to see the highlights of what has
55
been added to each release, please refer to the [blog](https://blog.gitea.io).
66

7+
## [1.16.1](https://github.com/go-gitea/gitea/releases/tag/v1.16.1) - 2022-02-06
8+
9+
* SECURITY
10+
* Update JS dependencies, fix lint (#18389) (#18540)
11+
* ENHANCEMENTS
12+
* Add dropdown icon to label set template dropdown (#18564) (#18571)
13+
* BUGFIXES
14+
* comments on migrated issues/prs must link to the comment ID (#18630) (#18637)
15+
* Stop logging an error when notes are not found (#18626) (#18635)
16+
* Ensure that blob-excerpt links work for wiki (#18587) (#18624)
17+
* Only attempt to flush queue if the underlying worker pool is not finished (#18593) (#18620)
18+
* Ensure commit-statuses box is sized correctly in headers (#18538) (#18606)
19+
* Prevent merge messages from being sorted to the top of email chains (#18566) (#18588)
20+
* Prevent panic on prohibited user login with oauth2 (#18562) (#18563)
21+
* Collaborator trust model should trust collaborators (#18539) (#18557)
22+
* Detect conflicts with 3way merge (#18536) (#18537)
23+
* In docker rootless use $GITEA_APP_INI if provided (#18524) (#18535)
24+
* Add `GetUserTeams` (#18499) (#18531)
25+
* Fix review excerpt (#18502) (#18530)
26+
* Fix for AvatarURL database type (#18487) (#18529)
27+
* Use `ImagedProvider` for gplus oauth2 provider (#18504) (#18505)
28+
* Fix OAuth Source Edit Page (#18495) (#18503)
29+
* Use "read" value for General Access (#18496) (#18500)
30+
* Prevent NPE on partial match of compare URL and allow short SHA1 compare URLs (#18472) (#18473)
31+
* BUILD
32+
* Make docker gitea/gitea:v1.16-dev etc refer to the latest build on that branch (#18551) (#18569)
33+
* DOCS
34+
* Update 1.16.0 changelog to set #17846 as breaking (#18533) (#18534)
35+
736
## [1.16.0](https://github.com/go-gitea/gitea/releases/tag/v1.16.0) - 2022-01-30
837

938
* BREAKING

Makefile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ endif
6060

6161
EXTRA_GOFLAGS ?=
6262

63-
MAKE_VERSION := $(shell $(MAKE) -v | head -n 1)
63+
MAKE_VERSION := $(shell "$(MAKE)" -v | head -n 1)
6464
MAKE_EVIDENCE_DIR := .make_evidence
6565

6666
ifeq ($(RACE_ENABLED),true)
@@ -231,13 +231,11 @@ clean:
231231

232232
.PHONY: fmt
233233
fmt:
234-
@echo "Running gitea-fmt(with gofmt)..."
235-
@$(GO) run build/code-batch-process.go gitea-fmt -s -w '{file-list}'
236-
@echo "Running gofumpt"
237234
@hash gofumpt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
238235
$(GO) install mvdan.cc/gofumpt@latest; \
239236
fi
240-
@gofumpt -w -l -extra -lang 1.16 .
237+
@echo "Running gitea-fmt (with gofumpt)..."
238+
@$(GO) run build/code-batch-process.go gitea-fmt -w '{file-list}'
241239

242240
.PHONY: vet
243241
vet:
@@ -285,8 +283,11 @@ errcheck:
285283

286284
.PHONY: fmt-check
287285
fmt-check:
286+
@hash gofumpt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
287+
$(GO) install mvdan.cc/gofumpt@latest; \
288+
fi
288289
# get all go files and run gitea-fmt (with gofmt) on them
289-
@diff=$$($(GO) run build/code-batch-process.go gitea-fmt -s -d '{file-list}'); \
290+
@diff=$$($(GO) run build/code-batch-process.go gitea-fmt -l '{file-list}'); \
290291
if [ -n "$$diff" ]; then \
291292
echo "Please run 'make fmt' and commit the result:"; \
292293
echo "$${diff}"; \

build/code-batch-process.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,9 @@ func containsString(a []string, s string) bool {
229229
return false
230230
}
231231

232-
func giteaFormatGoImports(files []string) error {
232+
func giteaFormatGoImports(files []string, hasChangedFiles, doWriteFile bool) error {
233233
for _, file := range files {
234-
if err := codeformat.FormatGoImports(file); err != nil {
234+
if err := codeformat.FormatGoImports(file, hasChangedFiles, doWriteFile); err != nil {
235235
log.Printf("failed to format go imports: %s, err=%v", file, err)
236236
return err
237237
}
@@ -267,10 +267,11 @@ func main() {
267267
logVerbose("batch cmd: %s %v", subCmd, substArgs)
268268
switch subCmd {
269269
case "gitea-fmt":
270-
if containsString(subArgs, "-w") {
271-
cmdErrors = append(cmdErrors, giteaFormatGoImports(files))
270+
if containsString(subArgs, "-d") {
271+
log.Print("the -d option is not supported by gitea-fmt")
272272
}
273-
cmdErrors = append(cmdErrors, passThroughCmd("gofmt", substArgs))
273+
cmdErrors = append(cmdErrors, giteaFormatGoImports(files, containsString(subArgs, "-l"), containsString(subArgs, "-w")))
274+
cmdErrors = append(cmdErrors, passThroughCmd("gofumpt", append([]string{"-extra", "-lang", "1.16"}, substArgs...)))
274275
case "misspell":
275276
cmdErrors = append(cmdErrors, passThroughCmd("misspell", substArgs))
276277
default:

build/codeformat/formatimports.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package codeformat
77
import (
88
"bytes"
99
"errors"
10+
"fmt"
1011
"io"
1112
"os"
1213
"sort"
@@ -158,7 +159,7 @@ func formatGoImports(contentBytes []byte) ([]byte, error) {
158159
}
159160

160161
// FormatGoImports format the imports by our rules (see unit tests)
161-
func FormatGoImports(file string) error {
162+
func FormatGoImports(file string, doChangedFiles, doWriteFile bool) error {
162163
f, err := os.Open(file)
163164
if err != nil {
164165
return err
@@ -181,11 +182,20 @@ func FormatGoImports(file string) error {
181182
if bytes.Equal(contentBytes, formattedBytes) {
182183
return nil
183184
}
184-
f, err = os.OpenFile(file, os.O_TRUNC|os.O_WRONLY, 0o644)
185-
if err != nil {
185+
186+
if doChangedFiles {
187+
fmt.Println(file)
188+
}
189+
190+
if doWriteFile {
191+
f, err = os.OpenFile(file, os.O_TRUNC|os.O_WRONLY, 0o644)
192+
if err != nil {
193+
return err
194+
}
195+
defer f.Close()
196+
_, err = f.Write(formattedBytes)
186197
return err
187198
}
188-
defer f.Close()
189-
_, err = f.Write(formattedBytes)
199+
190200
return err
191201
}

cmd/hook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ func runHookPostReceive(c *cli.Context) error {
309309
defer cancel()
310310

311311
// First of all run update-server-info no matter what
312-
if _, err := git.NewCommandContext(ctx, "update-server-info").Run(); err != nil {
312+
if _, err := git.NewCommand(ctx, "update-server-info").Run(); err != nil {
313313
return fmt.Errorf("Failed to call 'git update-server-info': %v", err)
314314
}
315315

cmd/web.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -222,18 +222,19 @@ func listen(m http.Handler, handleRedirector bool) error {
222222
}
223223
err = runHTTP("tcp", listenAddr, "Web", m)
224224
case setting.HTTPS:
225-
if setting.EnableLetsEncrypt {
226-
err = runLetsEncrypt(listenAddr, setting.Domain, setting.LetsEncryptDirectory, setting.LetsEncryptEmail, m)
225+
if setting.EnableAcme {
226+
err = runACME(listenAddr, m)
227227
break
228-
}
229-
if handleRedirector {
230-
if setting.RedirectOtherPort {
231-
go runHTTPRedirector()
232-
} else {
233-
NoHTTPRedirector()
228+
} else {
229+
if handleRedirector {
230+
if setting.RedirectOtherPort {
231+
go runHTTPRedirector()
232+
} else {
233+
NoHTTPRedirector()
234+
}
234235
}
236+
err = runHTTPS("tcp", listenAddr, "Web", setting.CertFile, setting.KeyFile, m)
235237
}
236-
err = runHTTPS("tcp", listenAddr, "Web", setting.CertFile, setting.KeyFile, m)
237238
case setting.FCGI:
238239
if handleRedirector {
239240
NoHTTPRedirector()

cmd/web_letsencrypt.go renamed to cmd/web_acme.go

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
package cmd
66

77
import (
8+
"crypto/x509"
9+
"encoding/pem"
10+
"fmt"
811
"net/http"
12+
"os"
913
"strconv"
1014
"strings"
1115

@@ -16,7 +20,25 @@ import (
1620
"github.com/caddyserver/certmagic"
1721
)
1822

19-
func runLetsEncrypt(listenAddr, domain, directory, email string, m http.Handler) error {
23+
func getCARoot(path string) (*x509.CertPool, error) {
24+
r, err := os.ReadFile(path)
25+
if err != nil {
26+
return nil, err
27+
}
28+
block, _ := pem.Decode(r)
29+
if block == nil {
30+
return nil, fmt.Errorf("no PEM found in the file %s", path)
31+
}
32+
caRoot, err := x509.ParseCertificate(block.Bytes)
33+
if err != nil {
34+
return nil, err
35+
}
36+
certPool := x509.NewCertPool()
37+
certPool.AddCert(caRoot)
38+
return certPool, nil
39+
}
40+
41+
func runACME(listenAddr string, m http.Handler) error {
2042
// If HTTP Challenge enabled, needs to be serving on port 80. For TLSALPN needs 443.
2143
// Due to docker port mapping this can't be checked programmatically
2244
// TODO: these are placeholders until we add options for each in settings with appropriate warning
@@ -33,10 +55,21 @@ func runLetsEncrypt(listenAddr, domain, directory, email string, m http.Handler)
3355
}
3456

3557
magic := certmagic.NewDefault()
36-
magic.Storage = &certmagic.FileStorage{Path: directory}
58+
magic.Storage = &certmagic.FileStorage{Path: setting.AcmeLiveDirectory}
59+
// Try to use private CA root if provided, otherwise defaults to system's trust
60+
var certPool *x509.CertPool
61+
if setting.AcmeCARoot != "" {
62+
var err error
63+
certPool, err = getCARoot(setting.AcmeCARoot)
64+
if err != nil {
65+
log.Warn("Failed to parse CA Root certificate, using default CA trust: %v", err)
66+
}
67+
}
3768
myACME := certmagic.NewACMEManager(magic, certmagic.ACMEManager{
38-
Email: email,
39-
Agreed: setting.LetsEncryptTOS,
69+
CA: setting.AcmeURL,
70+
TrustedRoots: certPool,
71+
Email: setting.AcmeEmail,
72+
Agreed: setting.AcmeTOS,
4073
DisableHTTPChallenge: !enableHTTPChallenge,
4174
DisableTLSALPNChallenge: !enableTLSALPNChallenge,
4275
ListenHost: setting.HTTPAddr,
@@ -47,7 +80,7 @@ func runLetsEncrypt(listenAddr, domain, directory, email string, m http.Handler)
4780
magic.Issuers = []certmagic.Issuer{myACME}
4881

4982
// this obtains certificates or renews them if necessary
50-
err := magic.ManageSync(graceful.GetManager().HammerContext(), []string{domain})
83+
err := magic.ManageSync(graceful.GetManager().HammerContext(), []string{setting.Domain})
5184
if err != nil {
5285
return err
5386
}

contrib/upgrade.sh

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# This is an update script for gitea installed via the binary distribution
5+
# from dl.gitea.io on linux as systemd service. It performs a backup and updates
6+
# Gitea in place.
7+
# NOTE: This adds the GPG Signing Key of the Gitea maintainers to the keyring.
8+
# Depends on: bash, curl, xz, sha256sum, gpg. optionally jq.
9+
# Usage: [environment vars] upgrade.sh [version]
10+
# See section below for available environment vars.
11+
# When no version is specified, updates to the latest release.
12+
# Examples:
13+
# upgrade.sh 1.15.10
14+
# giteahome=/opt/gitea giteaconf=$giteahome/app.ini upgrade.sh
15+
16+
# apply variables from environment
17+
: "${giteabin:="/usr/local/bin/gitea"}"
18+
: "${giteahome:="/var/lib/gitea"}"
19+
: "${giteaconf:="/etc/gitea/app.ini"}"
20+
: "${giteauser:="git"}"
21+
: "${sudocmd:="sudo"}"
22+
: "${arch:="linux-amd64"}"
23+
: "${backupopts:=""}" # see `gitea dump --help` for available options
24+
25+
function giteacmd {
26+
"$sudocmd" --user "$giteauser" "$giteabin" --config "$giteaconf" --work-path "$giteahome" "$@"
27+
}
28+
29+
function require {
30+
for exe in "$@"; do
31+
command -v "$exe" &>/dev/null || (echo "missing dependency '$exe'"; exit 1)
32+
done
33+
}
34+
require systemctl curl xz sha256sum gpg "$sudocmd"
35+
36+
# select version to install
37+
if [[ -z "${1:-}" ]]; then
38+
require jq
39+
giteaversion=$(curl --connect-timeout 10 -sL https://dl.gitea.io/gitea/version.json | jq -r .latest.version)
40+
else
41+
giteaversion="$1"
42+
fi
43+
44+
# confirm update
45+
current=$(giteacmd --version | cut --delimiter=' ' --fields=3)
46+
[[ "$current" == "$giteaversion" ]] && echo "$current is already installed, stopping." && exit 1
47+
echo "Make sure to read the changelog first: https://github.com/go-gitea/gitea/blob/main/CHANGELOG.md"
48+
echo "Are you ready to update Gitea from ${current} to ${giteaversion}? (y/N)"
49+
read -r confirm
50+
[[ "$confirm" == "y" ]] || [[ "$confirm" == "Y" ]] || exit 1
51+
52+
pushd "$(pwd)" &>/dev/null
53+
cd "$giteahome" # needed for gitea dump later
54+
55+
# download new binary
56+
binname="gitea-${giteaversion}-${arch}"
57+
binurl="https://dl.gitea.io/gitea/${giteaversion}/${binname}.xz"
58+
echo "Downloading $binurl..."
59+
curl --connect-timeout 10 --silent --show-error --fail --location -O "$binurl{,.sha256,.asc}"
60+
61+
# validate checksum & gpg signature (exit script if error)
62+
sha256sum --check "${binname}.xz.sha256"
63+
gpg --keyserver keys.openpgp.org --recv 7C9E68152594688862D62AF62D9AE806EC1592E2
64+
gpg --verify "${binname}.xz.asc" "${binname}.xz" || { echo 'Signature does not match'; exit 1; }
65+
rm "${binname}".xz.{sha256,asc}
66+
67+
# unpack binary + make executable
68+
xz --decompress "${binname}.xz"
69+
chown "$giteauser" "$binname"
70+
chmod +x "$binname"
71+
72+
# stop gitea, create backup, replace binary, restart gitea
73+
echo "Stopping gitea at $(date)"
74+
giteacmd manager flush-queues
75+
$sudocmd systemctl stop gitea
76+
echo "Creating backup in $giteahome"
77+
giteacmd dump $backupopts
78+
echo "Updating binary at $giteabin"
79+
mv --force --backup "$binname" "$giteabin"
80+
$sudocmd systemctl start gitea
81+
$sudocmd systemctl status gitea
82+
83+
popd

custom/conf/app.example.ini

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,15 @@ RUN_MODE = ; prod
8282
;; Whether to use the builtin SSH server or not.
8383
;START_SSH_SERVER = false
8484
;;
85-
;; Username to use for the builtin SSH server. If blank, then it is the value of RUN_USER.
86-
;BUILTIN_SSH_SERVER_USER =
85+
;; Username to use for the builtin SSH server.
86+
;BUILTIN_SSH_SERVER_USER = %(RUN_USER)s
8787
;;
8888
;; Domain name to be exposed in clone URL
8989
;SSH_DOMAIN = %(DOMAIN)s
9090
;;
91+
;; SSH username displayed in clone URLs.
92+
;SSH_USER = %(BUILTIN_SSH_SERVER_USER)s
93+
;;
9194
;; The network interface the builtin SSH server should listen on
9295
;SSH_LISTEN_HOST =
9396
;;
@@ -175,6 +178,36 @@ RUN_MODE = ; prod
175178
;OFFLINE_MODE = false
176179
;DISABLE_ROUTER_LOG = false
177180
;;
181+
;; TLS Settings: Either ACME or manual
182+
;; (Other common TLS configuration are found before)
183+
;ENABLE_ACME = false
184+
;;
185+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
186+
;;
187+
;; ACME automatic TLS settings
188+
;;
189+
;; ACME directory URL (e.g. LetsEncrypt's staging/testing URL: https://acme-staging-v02.api.letsencrypt.org/directory)
190+
;; Leave empty to default to LetsEncrypt's (production) URL
191+
;ACME_URL =
192+
;;
193+
;; Explicitly accept the ACME's TOS. The specific TOS cannot be retrieved at the moment.
194+
;ACME_ACCEPTTOS = false
195+
;;
196+
;; If the ACME CA is not in your system's CA trust chain, it can be manually added here
197+
;ACME_CA_ROOT =
198+
;;
199+
;; Email used for the ACME registration service
200+
;; Can be left blank to initialize at first run and use the cached value
201+
;ACME_EMAIL =
202+
;;
203+
;; ACME live directory (not to be confused with ACME directory URL: ACME_URL)
204+
;; (Refer to caddy's ACME manager https://github.com/caddyserver/certmagic)
205+
;ACME_DIRECTORY = https
206+
;;
207+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
208+
;;
209+
;; Manual TLS settings: (Only applicable if ENABLE_ACME=false)
210+
;;
178211
;; Generate steps:
179212
;; $ ./gitea cert -ca=true -duration=8760h0m0s -host=myhost.example.com
180213
;;

0 commit comments

Comments
 (0)