Skip to content

Commit f7ed1cd

Browse files
authored
Merge branch 'master' into prunehooktask
2 parents 14b6bef + 0f726ca commit f7ed1cd

File tree

787 files changed

+61712
-24951
lines changed

Some content is hidden

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

787 files changed

+61712
-24951
lines changed

.drone.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ steps:
6969

7070
- name: checks-backend
7171
pull: always
72-
image: golang:1.14
72+
image: golang:1.15
7373
commands:
7474
- make checks-backend
7575
depends_on: [lint-backend]
@@ -82,7 +82,7 @@ steps:
8282

8383
- name: build-backend-no-gcc
8484
pull: always
85-
image: golang:1.13 # this step is kept as the lowest version of golang that we support
85+
image: golang:1.14 # this step is kept as the lowest version of golang that we support
8686
environment:
8787
GO111MODULE: on
8888
GOPROXY: off

.golangci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ issues:
7070
- path: modules/log/
7171
linters:
7272
- errcheck
73-
- path: routers/routes/macaron.go
73+
- path: routers/routes/web.go
7474
linters:
7575
- dupl
7676
- path: routers/api/v1/repo/issue_subscription.go

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ HAS_GO = $(shell hash $(GO) > /dev/null 2>&1 && echo "GO" || echo "NOGO" )
2525
COMMA := ,
2626

2727
XGO_VERSION := go-1.15.x
28-
MIN_GO_VERSION := 001013000
28+
MIN_GO_VERSION := 001014000
2929
MIN_NODE_VERSION := 010013000
3030

3131
DOCKER_IMAGE ?= gitea/gitea

cmd/dump.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"code.gitea.io/gitea/modules/storage"
2222
"code.gitea.io/gitea/modules/util"
2323

24-
"gitea.com/macaron/session"
24+
"gitea.com/go-chi/session"
2525
archiver "github.com/mholt/archiver/v3"
2626
"github.com/urfave/cli"
2727
)

cmd/web.go

+3-37
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222

2323
context2 "github.com/gorilla/context"
2424
"github.com/urfave/cli"
25-
"golang.org/x/crypto/acme/autocert"
2625
ini "gopkg.in/ini.v1"
2726
)
2827

@@ -72,36 +71,6 @@ func runHTTPRedirector() {
7271
}
7372
}
7473

75-
func runLetsEncrypt(listenAddr, domain, directory, email string, m http.Handler) error {
76-
certManager := autocert.Manager{
77-
Prompt: autocert.AcceptTOS,
78-
HostPolicy: autocert.HostWhitelist(domain),
79-
Cache: autocert.DirCache(directory),
80-
Email: email,
81-
}
82-
go func() {
83-
log.Info("Running Let's Encrypt handler on %s", setting.HTTPAddr+":"+setting.PortToRedirect)
84-
// all traffic coming into HTTP will be redirect to HTTPS automatically (LE HTTP-01 validation happens here)
85-
var err = runHTTP("tcp", setting.HTTPAddr+":"+setting.PortToRedirect, certManager.HTTPHandler(http.HandlerFunc(runLetsEncryptFallbackHandler)))
86-
if err != nil {
87-
log.Fatal("Failed to start the Let's Encrypt handler on port %s: %v", setting.PortToRedirect, err)
88-
}
89-
}()
90-
return runHTTPSWithTLSConfig("tcp", listenAddr, certManager.TLSConfig(), context2.ClearHandler(m))
91-
}
92-
93-
func runLetsEncryptFallbackHandler(w http.ResponseWriter, r *http.Request) {
94-
if r.Method != "GET" && r.Method != "HEAD" {
95-
http.Error(w, "Use HTTPS", http.StatusBadRequest)
96-
return
97-
}
98-
// Remove the trailing slash at the end of setting.AppURL, the request
99-
// URI always contains a leading slash, which would result in a double
100-
// slash
101-
target := strings.TrimSuffix(setting.AppURL, "/") + r.URL.RequestURI()
102-
http.Redirect(w, r, target, http.StatusFound)
103-
}
104-
10574
func runWeb(ctx *cli.Context) error {
10675
managerCtx, cancel := context.WithCancel(context.Background())
10776
graceful.InitManager(managerCtx)
@@ -133,8 +102,7 @@ func runWeb(ctx *cli.Context) error {
133102
return err
134103
}
135104
}
136-
c := routes.NewChi()
137-
routes.RegisterInstallRoute(c)
105+
c := routes.InstallRoutes()
138106
err := listen(c, false)
139107
select {
140108
case <-graceful.GetManager().IsShutdown():
@@ -165,11 +133,9 @@ func runWeb(ctx *cli.Context) error {
165133
return err
166134
}
167135
}
168-
// Set up Chi routes
169-
c := routes.NewChi()
170-
c.Mount("/", routes.NormalRoutes())
171-
routes.DelegateToMacaron(c)
172136

137+
// Set up Chi routes
138+
c := routes.NormalRoutes()
173139
err := listen(c, true)
174140
<-graceful.GetManager().Done()
175141
log.Info("PID: %d Gitea Web Finished", os.Getpid())

cmd/web_letsencrypt.go

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright 2020 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package cmd
6+
7+
import (
8+
"net/http"
9+
"strings"
10+
11+
"code.gitea.io/gitea/modules/log"
12+
"code.gitea.io/gitea/modules/setting"
13+
14+
"github.com/caddyserver/certmagic"
15+
context2 "github.com/gorilla/context"
16+
)
17+
18+
func runLetsEncrypt(listenAddr, domain, directory, email string, m http.Handler) error {
19+
20+
// If HTTP Challenge enabled, needs to be serving on port 80. For TLSALPN needs 443.
21+
// Due to docker port mapping this can't be checked programatically
22+
// TODO: these are placeholders until we add options for each in settings with appropriate warning
23+
enableHTTPChallenge := true
24+
enableTLSALPNChallenge := true
25+
26+
magic := certmagic.NewDefault()
27+
magic.Storage = &certmagic.FileStorage{Path: directory}
28+
myACME := certmagic.NewACMEManager(magic, certmagic.ACMEManager{
29+
Email: email,
30+
Agreed: setting.LetsEncryptTOS,
31+
DisableHTTPChallenge: !enableHTTPChallenge,
32+
DisableTLSALPNChallenge: !enableTLSALPNChallenge,
33+
})
34+
35+
magic.Issuer = myACME
36+
37+
// this obtains certificates or renews them if necessary
38+
err := magic.ManageSync([]string{domain})
39+
if err != nil {
40+
return err
41+
}
42+
43+
tlsConfig := magic.TLSConfig()
44+
45+
if enableHTTPChallenge {
46+
go func() {
47+
log.Info("Running Let's Encrypt handler on %s", setting.HTTPAddr+":"+setting.PortToRedirect)
48+
// all traffic coming into HTTP will be redirect to HTTPS automatically (LE HTTP-01 validation happens here)
49+
var err = runHTTP("tcp", setting.HTTPAddr+":"+setting.PortToRedirect, myACME.HTTPChallengeHandler(http.HandlerFunc(runLetsEncryptFallbackHandler)))
50+
if err != nil {
51+
log.Fatal("Failed to start the Let's Encrypt handler on port %s: %v", setting.PortToRedirect, err)
52+
}
53+
}()
54+
}
55+
56+
return runHTTPSWithTLSConfig("tcp", listenAddr, tlsConfig, context2.ClearHandler(m))
57+
}
58+
59+
func runLetsEncryptFallbackHandler(w http.ResponseWriter, r *http.Request) {
60+
if r.Method != "GET" && r.Method != "HEAD" {
61+
http.Error(w, "Use HTTPS", http.StatusBadRequest)
62+
return
63+
}
64+
// Remove the trailing slash at the end of setting.AppURL, the request
65+
// URI always contains a leading slash, which would result in a double
66+
// slash
67+
target := strings.TrimSuffix(setting.AppURL, "/") + r.URL.RequestURI()
68+
http.Redirect(w, r, target, http.StatusFound)
69+
}

contrib/pr/checkout.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,7 @@ func runPR() {
116116
//routers.GlobalInit()
117117
external.RegisterParsers()
118118
markup.Init()
119-
c := routes.NewChi()
120-
c.Mount("/", routes.NormalRoutes())
121-
routes.DelegateToMacaron(c)
119+
c := routes.NormalRoutes()
122120

123121
log.Printf("[PR] Ready for testing !\n")
124122
log.Printf("[PR] Login with user1, user2, user3, ... with pass: password\n")

docs/config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ params:
1919
author: The Gitea Authors
2020
website: https://docs.gitea.io
2121
version: 1.13.1
22-
minGoVersion: 1.13
22+
minGoVersion: 1.14
2323
goVersion: 1.15
2424
minNodeVersion: 10.13
2525

docs/content/doc/advanced/config-cheat-sheet.en-us.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ Define allowed algorithms and their minimum key length (use -1 to disable a type
549549

550550
## Session (`session`)
551551

552-
- `PROVIDER`: **memory**: Session engine provider \[memory, file, redis, mysql, couchbase, memcache, nodb, postgres\].
552+
- `PROVIDER`: **memory**: Session engine provider \[memory, file, redis, mysql, couchbase, memcache, postgres\].
553553
- `PROVIDER_CONFIG`: **data/sessions**: For file, the root path; for others, the connection string.
554554
- `COOKIE_SECURE`: **false**: Enable this to force using HTTPS for all session access.
555555
- `COOKIE_NAME`: **i\_like\_gitea**: The name of the cookie used for the session ID.
@@ -609,16 +609,14 @@ Default templates for project boards:
609609
- `MODE`: **console**: Logging mode. For multiple modes, use a comma to separate values. You can configure each mode in per mode log subsections `\[log.modename\]`. By default the file mode will log to `$ROOT_PATH/gitea.log`.
610610
- `LEVEL`: **Info**: General log level. \[Trace, Debug, Info, Warn, Error, Critical, Fatal, None\]
611611
- `STACKTRACE_LEVEL`: **None**: Default log level at which to log create stack traces. \[Trace, Debug, Info, Warn, Error, Critical, Fatal, None\]
612-
- `REDIRECT_MACARON_LOG`: **false**: Redirects the Macaron log to its own logger or the default logger.
613-
- `MACARON`: **file**: Logging mode for the macaron logger, use a comma to separate values. Configure each mode in per mode log subsections `\[log.modename.macaron\]`. By default the file mode will log to `$ROOT_PATH/macaron.log`. (If you set this to `,` it will log to default gitea logger.)
614612
- `ROUTER_LOG_LEVEL`: **Info**: The log level that the router should log at. (If you are setting the access log, its recommended to place this at Debug.)
615613
- `ROUTER`: **console**: The mode or name of the log the router should log to. (If you set this to `,` it will log to default gitea logger.)
616614
NB: You must `REDIRECT_MACARON_LOG` and have `DISABLE_ROUTER_LOG` set to `false` for this option to take effect. Configure each mode in per mode log subsections `\[log.modename.router\]`.
617615
- `ENABLE_ACCESS_LOG`: **false**: Creates an access.log in NCSA common log format, or as per the following template
618616
- `ACCESS`: **file**: Logging mode for the access logger, use a comma to separate values. Configure each mode in per mode log subsections `\[log.modename.access\]`. By default the file mode will log to `$ROOT_PATH/access.log`. (If you set this to `,` it will log to the default gitea logger.)
619617
- `ACCESS_LOG_TEMPLATE`: **`{{.Ctx.RemoteAddr}} - {{.Identity}} {{.Start.Format "[02/Jan/2006:15:04:05 -0700]" }} "{{.Ctx.Req.Method}} {{.Ctx.Req.URL.RequestURI}} {{.Ctx.Req.Proto}}" {{.ResponseWriter.Status}} {{.ResponseWriter.Size}} "{{.Ctx.Req.Referer}}\" \"{{.Ctx.Req.UserAgent}}"`**: Sets the template used to create the access log.
620618
- The following variables are available:
621-
- `Ctx`: the `macaron.Context` of the request.
619+
- `Ctx`: the `context.Context` of the request.
622620
- `Identity`: the SignedUserName or `"-"` if not logged in.
623621
- `Start`: the start time of the request.
624622
- `ResponseWriter`: the responseWriter from the request.

docs/content/doc/advanced/logging-documentation.en-us.md

+4-33
Original file line numberDiff line numberDiff line change
@@ -67,40 +67,11 @@ The provider type of the sublogger can be set using the `MODE` value in
6767
its subsection, but will default to the name. This allows you to have
6868
multiple subloggers that will log to files.
6969

70-
### The "Macaron" logger
71-
72-
By default Macaron will log to its own go `log` instance. This writes
73-
to `os.Stdout`. You can redirect this log to a Gitea configurable logger
74-
through setting the `REDIRECT_MACARON_LOG` setting in the `[log]`
75-
section which you can configure the outputs of by setting the `MACARON`
76-
value in the `[log]` section of the configuration. `MACARON` defaults
77-
to `file` if unset.
78-
79-
Please note, the macaron logger will log at `INFO` level, setting the
80-
`LEVEL` of this logger to `WARN` or above will result in no macaron logs.
81-
82-
Each output sublogger for this logger is configured in
83-
`[log.sublogger.macaron]` sections. There are certain default values
84-
which will not be inherited from the `[log]` or relevant
85-
`[log.sublogger]` sections:
86-
87-
- `FLAGS` is `stdflags` (Equal to
88-
`date,time,medfile,shortfuncname,levelinitial`)
89-
- `FILE_NAME` will default to `%(ROOT_PATH)/macaron.log`
90-
- `EXPRESSION` will default to `""`
91-
- `PREFIX` will default to `""`
92-
93-
NB: You can redirect the macaron logger to send its events to the gitea
94-
log using the value: `MACARON = ,`
95-
9670
### The "Router" logger
9771

98-
There are two types of Router log. By default Macaron send its own
99-
router log which will be directed to Macaron's go `log`, however if you
100-
`REDIRECT_MACARON_LOG` you will enable Gitea's router log. You can
101-
disable both types of Router log by setting `DISABLE_ROUTER_LOG`.
72+
You can disable Router log by setting `DISABLE_ROUTER_LOG`.
10273

103-
If you enable the redirect, you can configure the outputs of this
74+
You can configure the outputs of this
10475
router log by setting the `ROUTER` value in the `[log]` section of the
10576
configuration. `ROUTER` will default to `console` if unset. The Gitea
10677
Router logs the same data as the Macaron log but has slightly different
@@ -162,11 +133,11 @@ This value represent a go template. It's default value is:
162133

163134
The template is passed following options:
164135

165-
- `Ctx` is the `macaron.Context`
136+
- `Ctx` is the `context.Context`
166137
- `Identity` is the `SignedUserName` or `"-"` if the user is not logged
167138
in
168139
- `Start` is the start time of the request
169-
- `ResponseWriter` is the `macaron.ResponseWriter`
140+
- `ResponseWriter` is the `http.ResponseWriter`
170141

171142
Caution must be taken when changing this template as it runs outside of
172143
the standard panic recovery trap. The template should also be as simple

docs/content/page/index.en-us.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ Windows, on architectures like amd64, i386, ARM, PowerPC, and others.
267267

268268
## Components
269269

270-
* Web framework: [Macaron](http://go-macaron.com/)
270+
* Web framework: [Chi](http://github.com/go-chi/chi)
271271
* ORM: [XORM](https://xorm.io)
272272
* UI components:
273273
* [Semantic UI](http://semantic-ui.com/)

docs/content/page/index.fr-fr.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ Le but de ce projet est de fournir de la manière la plus simple, la plus rapide
254254

255255
## Composants
256256

257-
* Framework web : [Macaron](http://go-macaron.com/)
257+
* Framework web : [Chi](http://github.com/go-chi/chi)
258258
* ORM: [XORM](https://xorm.io)
259259
* Interface graphique :
260260
* [Semantic UI](http://semantic-ui.com/)

docs/content/page/index.zh-cn.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Gitea的首要目标是创建一个极易安装,运行非常快速,安装和
4747

4848
## 组件
4949

50-
* Web框架: [Macaron](http://go-macaron.com/)
50+
* Web框架: [Chi](http://github.com/go-chi/chi)
5151
* ORM: [XORM](https://xorm.io)
5252
* UI组件:
5353
* [Semantic UI](http://semantic-ui.com/)

docs/content/page/index.zh-tw.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Gitea 的首要目標是建立一個容易安裝,運行快速,安装和使
4747

4848
## 元件
4949

50-
* Web 框架: [Macaron](http://go-macaron.com/)
50+
* Web 框架: [Chi](http://github.com/go-chi/chi)
5151
* ORM: [XORM](https://xorm.io)
5252
* UI 元件:
5353
* [Semantic UI](http://semantic-ui.com/)

go.mod

+6-11
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,19 @@ go 1.14
55
require (
66
code.gitea.io/gitea-vet v0.2.1
77
code.gitea.io/sdk/gitea v0.13.1
8+
gitea.com/go-chi/binding v0.0.0-20210113025129-03f1d313373c
9+
gitea.com/go-chi/cache v0.0.0-20210110083709-82c4c9ce2d5e
10+
gitea.com/go-chi/captcha v0.0.0-20210110083842-e7696c336a1e
811
gitea.com/go-chi/session v0.0.0-20210108030337-0cb48c5ba8ee
912
gitea.com/lunny/levelqueue v0.3.0
10-
gitea.com/macaron/binding v0.0.0-20190822013154-a5f53841ed2b
11-
gitea.com/macaron/cache v0.0.0-20200924044943-905232fba10b
12-
gitea.com/macaron/captcha v0.0.0-20200825161008-e8597820aaca
13-
gitea.com/macaron/cors v0.0.0-20190826180238-95aec09ea8b4
14-
gitea.com/macaron/csrf v0.0.0-20190822024205-3dc5a4474439
15-
gitea.com/macaron/gzip v0.0.0-20200827120000-efa5e8477cf5
16-
gitea.com/macaron/i18n v0.0.0-20200911004404-4ca3dd0cbd60
17-
gitea.com/macaron/inject v0.0.0-20190805023432-d4c86e31027a
18-
gitea.com/macaron/macaron v1.5.1-0.20201027213641-0db5d4584804
19-
gitea.com/macaron/session v0.0.0-20201103015045-a177a2701dee
20-
gitea.com/macaron/toolbox v0.0.0-20190822013122-05ff0fc766b7
13+
github.com/NYTimes/gziphandler v1.1.1
2114
github.com/PuerkitoBio/goquery v1.5.1
2215
github.com/RoaringBitmap/roaring v0.5.5 // indirect
2316
github.com/alecthomas/chroma v0.8.2
2417
github.com/andybalholm/brotli v1.0.1 // indirect
2518
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be // indirect
2619
github.com/blevesearch/bleve/v2 v2.0.1
20+
github.com/caddyserver/certmagic v0.12.0
2721
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
2822
github.com/denisenkom/go-mssqldb v0.9.0
2923
github.com/dgrijalva/jwt-go v3.2.0+incompatible
@@ -35,6 +29,7 @@ require (
3529
github.com/gliderlabs/ssh v0.3.1
3630
github.com/glycerine/go-unsnap-stream v0.0.0-20190901134440-81cf024a9e0a // indirect
3731
github.com/go-chi/chi v1.5.1
32+
github.com/go-chi/cors v1.1.1
3833
github.com/go-enry/go-enry/v2 v2.6.0
3934
github.com/go-git/go-billy/v5 v5.0.0
4035
github.com/go-git/go-git/v5 v5.2.0

0 commit comments

Comments
 (0)