Skip to content

Commit 86ab980

Browse files
authored
Merge branch 'main' into request-as-process
2 parents 7446c87 + b9a2f26 commit 86ab980

File tree

106 files changed

+5554
-3625
lines changed

Some content is hidden

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

106 files changed

+5554
-3625
lines changed

custom/conf/app.example.ini

+13
Original file line numberDiff line numberDiff line change
@@ -1925,6 +1925,19 @@ PATH =
19251925
;SCHEDULE = @every 168h
19261926
;OLDER_THAN = 8760h
19271927

1928+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1929+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1930+
;; Check for new Gitea versions
1931+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1932+
;[cron.update_checker]
1933+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1934+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1935+
;ENABLED = false
1936+
;RUN_AT_START = false
1937+
;ENABLE_SUCCESS_NOTICE = false
1938+
;SCHEDULE = @every 168h
1939+
;HTTP_ENDPOINT = https://dl.gitea.io/gitea/version.json
1940+
19281941
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19291942
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19301943
;; Git Operation timeout in seconds

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

+10-3
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ or any corresponding location. When installing from a distribution, this will
2323
typically be found at `/etc/gitea/conf/app.ini`.
2424

2525
The defaults provided here are best-effort (not built automatically). They are
26-
accurately recorded in [app.example.ini](https://github.com/go-gitea/gitea/blob/master/custom/conf/app.example.ini)
27-
(s/master/\<tag|release\>). Any string in the format `%(X)s` is a feature powered
26+
accurately recorded in [app.example.ini](https://github.com/go-gitea/gitea/blob/main/custom/conf/app.example.ini)
27+
(s/main/\<tag|release\>). Any string in the format `%(X)s` is a feature powered
2828
by [ini](https://github.com/go-ini/ini/#recursive-values), for reading values recursively.
2929

3030
Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
@@ -824,9 +824,16 @@ NB: You must have `DISABLE_ROUTER_LOG` set to `false` for this option to take ef
824824
- `ENABLED`: **false**: Enable service.
825825
- `RUN_AT_START`: **false**: Run tasks at start up time (if ENABLED).
826826
- `NO_SUCCESS_NOTICE`: **false**: Set to true to switch off success notices.
827-
- `SCHEDULE`: **@every 128h**: Cron syntax for scheduling a work, e.g. `@every 128h`.
827+
- `SCHEDULE`: **@every 168h**: Cron syntax to set how often to check.
828828
- `OLDER_THAN`: **@every 8760h**: any action older than this expression will be deleted from database, suggest using `8760h` (1 year) because that's the max length of heatmap.
829829

830+
#### Cron - Check for new Gitea versions ('cron.update_checker')
831+
- `ENABLED`: **false**: Enable service.
832+
- `RUN_AT_START`: **false**: Run tasks at start up time (if ENABLED).
833+
- `ENABLE_SUCCESS_NOTICE`: **true**: Set to false to switch off success notices.
834+
- `SCHEDULE`: **@every 168h**: Cron syntax for scheduling a work, e.g. `@every 168h`.
835+
- `HTTP_ENDPOINT`: **https://dl.gitea.io/gitea/version.json**: the endpoint that Gitea will check for newer versions
836+
830837
## Git (`git`)
831838

832839
- `PATH`: **""**: The path of git executable. If empty, Gitea searches through the PATH environment.

docs/content/doc/developers/guidelines-frontend.md

-7
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,6 @@ We recommend [Google HTML/CSS Style Guide](https://google.github.io/styleguide/h
3939
6. The backend can pass complex data to the frontend by using `ctx.PageData["myModuleData"] = map[]{}`
4040
7. Simple pages and SEO-related pages use Go HTML Template render to generate static Fomantic-UI HTML output. Complex pages can use Vue2 (or Vue3 in future).
4141

42-
## Legacy Problems and Solutions
43-
44-
### Too much code in `web_src/index.js`
45-
46-
Previously, most JavaScript code was written into `web_src/index.js` directly, making the file unmaintainable.
47-
Try to keep this file small by creating new modules instead. These modules can be put in the `web_src/js/features` directory for now.
48-
4942
### Vue2/Vue3 and JSX
5043

5144
Gitea is using Vue2 now, we plan to upgrade to Vue3. We decided not to introduce JSX to keep the HTML and the JavaScript code separated.

docs/content/doc/usage/reverse-proxies.en-us.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,15 @@ server {
4343
listen 80;
4444
server_name git.example.com;
4545
46-
location /git/ { # Note: Trailing slash
47-
proxy_pass http://localhost:3000/; # Note: Trailing slash
46+
# Note: Trailing slash
47+
location /git/ {
48+
# Note: Trailing slash
49+
proxy_pass http://localhost:3000/;
4850
}
4951
}
5052
```
5153

52-
Then set `[server] ROOT_URL = http://git.example.com/git/` in your configuration.
54+
Then you **MUST** set something like `[server] ROOT_URL = http://git.example.com/git/` correctly in your configuration.
5355

5456
## Nginx and serve static resources directly
5557

@@ -139,11 +141,10 @@ If you want Apache HTTPD to serve your Gitea instance, you can add the following
139141
ProxyRequests off
140142
AllowEncodedSlashes NoDecode
141143
ProxyPass / http://localhost:3000/ nocanon
142-
ProxyPassReverse / http://localhost:3000/
143144
</VirtualHost>
144145
```
145146

146-
Note: The following Apache HTTPD mods must be enabled: `proxy`, `proxy_http`
147+
Note: The following Apache HTTPD mods must be enabled: `proxy`, `proxy_http`.
147148

148149
If you wish to use Let's Encrypt with webroot validation, add the line `ProxyPass /.well-known !` before `ProxyPass` to disable proxying these requests to Gitea.
149150

@@ -161,13 +162,12 @@ In case you already have a site, and you want Gitea to share the domain name, yo
161162
AllowEncodedSlashes NoDecode
162163
# Note: no trailing slash after either /git or port
163164
ProxyPass /git http://localhost:3000 nocanon
164-
ProxyPassReverse /git http://localhost:3000
165165
</VirtualHost>
166166
```
167167

168-
Then set `[server] ROOT_URL = http://git.example.com/git/` in your configuration.
168+
Then you **MUST** set something like `[server] ROOT_URL = http://git.example.com/git/` correctly in your configuration.
169169

170-
Note: The following Apache HTTPD mods must be enabled: `proxy`, `proxy_http`
170+
Note: The following Apache HTTPD mods must be enabled: `proxy`, `proxy_http`.
171171

172172
## Caddy
173173

docs/content/doc/usage/reverse-proxies.zh-cn.md

+10-9
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@ server {
3737
listen 80;
3838
server_name git.example.com;
3939
40-
location /git/ { # Note: Trailing slash
41-
proxy_pass http://localhost:3000/; # Note: Trailing slash
40+
# 注意: /git/ 最后需要有一个路径符号
41+
location /git/ {
42+
# 注意: 反向代理后端 URL 的最后需要有一个路径符号
43+
proxy_pass http://localhost:3000/;
4244
}
4345
}
4446
```
4547

46-
然后在您的 Gitea 配置文件中添加 `[server] ROOT_URL = http://git.example.com/git/`
48+
然后您**必须** Gitea 的配置文件中正确的添加类似 `[server] ROOT_URL = http://git.example.com/git/` 的配置项
4749

4850
## 使用 Apache HTTPD 作为反向代理服务
4951

@@ -56,7 +58,6 @@ server {
5658
ProxyRequests off
5759
AllowEncodedSlashes NoDecode
5860
ProxyPass / http://localhost:3000/ nocanon
59-
ProxyPassReverse / http://localhost:3000/
6061
</VirtualHost>
6162
```
6263

@@ -74,13 +75,12 @@ server {
7475
Allow from all
7576
</Proxy>
7677
AllowEncodedSlashes NoDecode
77-
# Note: no trailing slash after either /git or port
78+
# 注意: 路径和 URL 后面都不要写路径符号 '/'
7879
ProxyPass /git http://localhost:3000 nocanon
79-
ProxyPassReverse /git http://localhost:3000
8080
</VirtualHost>
8181
```
8282

83-
然后在您的 Gitea 配置文件中添加 `[server] ROOT_URL = http://git.example.com/git/`
83+
然后您**必须** Gitea 的配置文件中正确的添加类似 `[server] ROOT_URL = http://git.example.com/git/` 的配置项
8484

8585
注:必须启用以下 Apache HTTPD 组件:`proxy``proxy_http`
8686

@@ -100,8 +100,9 @@ git.example.com {
100100

101101
```
102102
git.example.com {
103-
proxy /git/ http://localhost:3000 # Note: Trailing Slash after /git/
103+
# 注意: 路径 /git/ 最后需要有路径符号
104+
proxy /git/ http://localhost:3000
104105
}
105106
```
106107

107-
然后在您的 Gitea 配置文件中添加 `[server] ROOT_URL = http://git.example.com/git/`
108+
然后您**必须** Gitea 的配置文件中正确的添加类似 `[server] ROOT_URL = http://git.example.com/git/` 的配置项

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ require (
5757
github.com/google/go-querystring v1.1.0 // indirect
5858
github.com/google/uuid v1.2.0
5959
github.com/gorilla/context v1.1.1
60+
github.com/gorilla/feeds v1.1.1
6061
github.com/gorilla/mux v1.8.0 // indirect
6162
github.com/gorilla/sessions v1.2.1 // indirect
6263
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,8 @@ github.com/gorilla/context v1.1.1 h1:AWwleXJkX/nhcU9bZSnZoi3h/qGYqQAGhq6zZe/aQW8
598598
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
599599
github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY=
600600
github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c=
601+
github.com/gorilla/feeds v1.1.1 h1:HwKXxqzcRNg9to+BbvJog4+f3s/xzvtZXICcQGutYfY=
602+
github.com/gorilla/feeds v1.1.1/go.mod h1:Nk0jZrvPFZX1OBe5NPiddPw7CfwF6Q9eqzaBbaightA=
601603
github.com/gorilla/handlers v1.5.1 h1:9lRY6j8DEeeBT10CvO9hGW0gmky0BprnvDI5vfhUHH4=
602604
github.com/gorilla/handlers v1.5.1/go.mod h1:t8XrUpc4KVXb7HGyJ4/cEnwQiaxrX/hz1Zv/4g96P1Q=
603605
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=

models/migrations/migrations.go

+2
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@ var migrations = []Migration{
350350
NewMigration("Add renamed_branch table", addRenamedBranchTable),
351351
// v198 -> v199
352352
NewMigration("Add issue content history table", addTableIssueContentHistory),
353+
// v199 -> v200
354+
NewMigration("Add remote version table", addRemoteVersionTable),
353355
}
354356

355357
// GetCurrentDBVersion returns the current db version

models/migrations/v199.go

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2021 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 migrations
6+
7+
import (
8+
"fmt"
9+
10+
"xorm.io/xorm"
11+
)
12+
13+
func addRemoteVersionTable(x *xorm.Engine) error {
14+
type RemoteVersion struct {
15+
ID int64 `xorm:"pk autoincr"`
16+
Version string `xorm:"VARCHAR(50)"`
17+
}
18+
19+
if err := x.Sync2(new(RemoteVersion)); err != nil {
20+
return fmt.Errorf("Sync2: %v", err)
21+
}
22+
return nil
23+
}

models/update_checker.go

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
// Copyright 2021 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 models
6+
7+
import (
8+
"encoding/json"
9+
"fmt"
10+
"io/ioutil"
11+
"net/http"
12+
13+
"code.gitea.io/gitea/models/db"
14+
"code.gitea.io/gitea/modules/proxy"
15+
"code.gitea.io/gitea/modules/setting"
16+
17+
"github.com/hashicorp/go-version"
18+
)
19+
20+
// RemoteVersion stores the remote version from the JSON endpoint
21+
type RemoteVersion struct {
22+
ID int64 `xorm:"pk autoincr"`
23+
Version string `xorm:"VARCHAR(50)"`
24+
}
25+
26+
func init() {
27+
db.RegisterModel(new(RemoteVersion))
28+
}
29+
30+
// GiteaUpdateChecker returns error when new version of Gitea is available
31+
func GiteaUpdateChecker(httpEndpoint string) error {
32+
httpClient := &http.Client{
33+
Transport: &http.Transport{
34+
Proxy: proxy.Proxy(),
35+
},
36+
}
37+
38+
req, err := http.NewRequest("GET", httpEndpoint, nil)
39+
if err != nil {
40+
return err
41+
}
42+
resp, err := httpClient.Do(req)
43+
if err != nil {
44+
return err
45+
}
46+
defer resp.Body.Close()
47+
body, err := ioutil.ReadAll(resp.Body)
48+
if err != nil {
49+
return err
50+
}
51+
52+
type v struct {
53+
Latest struct {
54+
Version string `json:"version"`
55+
} `json:"latest"`
56+
}
57+
ver := v{}
58+
err = json.Unmarshal(body, &ver)
59+
if err != nil {
60+
return err
61+
}
62+
63+
return UpdateRemoteVersion(ver.Latest.Version)
64+
65+
}
66+
67+
// UpdateRemoteVersion updates the latest available version of Gitea
68+
func UpdateRemoteVersion(version string) (err error) {
69+
sess := db.NewSession(db.DefaultContext)
70+
defer sess.Close()
71+
if err = sess.Begin(); err != nil {
72+
return err
73+
}
74+
75+
currentVersion := &RemoteVersion{ID: 1}
76+
has, err := sess.Get(currentVersion)
77+
if err != nil {
78+
return fmt.Errorf("get: %v", err)
79+
} else if !has {
80+
currentVersion.ID = 1
81+
currentVersion.Version = version
82+
83+
if _, err = sess.InsertOne(currentVersion); err != nil {
84+
return fmt.Errorf("insert: %v", err)
85+
}
86+
return nil
87+
}
88+
89+
if _, err = sess.Update(&RemoteVersion{ID: 1, Version: version}); err != nil {
90+
return err
91+
}
92+
93+
return sess.Commit()
94+
}
95+
96+
// GetRemoteVersion returns the current remote version (or currently installed verson if fail to fetch from DB)
97+
func GetRemoteVersion() string {
98+
e := db.GetEngine(db.DefaultContext)
99+
v := &RemoteVersion{ID: 1}
100+
_, err := e.Get(&v)
101+
if err != nil {
102+
// return current version if fail to fetch from DB
103+
return setting.AppVer
104+
}
105+
return v.Version
106+
}
107+
108+
// GetNeedUpdate returns true whether a newer version of Gitea is available
109+
func GetNeedUpdate() bool {
110+
curVer, err := version.NewVersion(setting.AppVer)
111+
if err != nil {
112+
// return false to fail silently
113+
return false
114+
}
115+
remoteVer, err := version.NewVersion(GetRemoteVersion())
116+
if err != nil {
117+
// return false to fail silently
118+
return false
119+
}
120+
return curVer.LessThan(remoteVer)
121+
}

modules/context/context.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ func (ctx *Context) PlainText(status int, bs []byte) {
320320
ctx.Resp.WriteHeader(status)
321321
ctx.Resp.Header().Set("Content-Type", "text/plain;charset=utf-8")
322322
if _, err := ctx.Resp.Write(bs); err != nil {
323-
ctx.ServerError("Render JSON failed", err)
323+
ctx.ServerError("Write bytes failed", err)
324324
}
325325
}
326326

modules/cron/tasks_extended.go

+19
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,24 @@ func registerDeleteOldActions() {
131131
})
132132
}
133133

134+
func registerUpdateGiteaChecker() {
135+
type UpdateCheckerConfig struct {
136+
BaseConfig
137+
HTTPEndpoint string
138+
}
139+
RegisterTaskFatal("update_checker", &UpdateCheckerConfig{
140+
BaseConfig: BaseConfig{
141+
Enabled: true,
142+
RunAtStart: false,
143+
Schedule: "@every 168h",
144+
},
145+
HTTPEndpoint: "https://dl.gitea.io/gitea/version.json",
146+
}, func(ctx context.Context, _ *models.User, config Config) error {
147+
updateCheckerConfig := config.(*UpdateCheckerConfig)
148+
return models.GiteaUpdateChecker(updateCheckerConfig.HTTPEndpoint)
149+
})
150+
}
151+
134152
func initExtendedTasks() {
135153
registerDeleteInactiveUsers()
136154
registerDeleteRepositoryArchives()
@@ -142,4 +160,5 @@ func initExtendedTasks() {
142160
registerDeleteMissingRepositories()
143161
registerRemoveRandomAvatars()
144162
registerDeleteOldActions()
163+
registerUpdateGiteaChecker()
145164
}

options/locale/locale_bg-BG.ini

-1
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,6 @@ diff.file_image_width=Ширина
942942
diff.file_image_height=Височина
943943
diff.file_byte_size=Големина
944944
diff.file_suppressed=Файловите разлики са ограничени, защото са твърде много
945-
diff.too_many_files=Някои файлове не бяха показани, защото твърде много файлове са промени
946945
diff.comment.placeholder=Оставяне на коментар
947946
diff.comment.add_review_comment=Добавяне на коментар
948947
diff.comment.reply=Отговор

options/locale/locale_cs-CZ.ini

-1
Original file line numberDiff line numberDiff line change
@@ -1945,7 +1945,6 @@ diff.file_image_height=Výška
19451945
diff.file_byte_size=Velikost
19461946
diff.file_suppressed=Rozdílový obsah nebyl zobrazen, protože je příliš veliký
19471947
diff.file_suppressed_line_too_long=Rozdílový obsah nebyl zobrazen, protože některé řádky jsou příliš dlouhá
1948-
diff.too_many_files=Některé soubory nejsou zobrazny, neboť je v této revizi změněno mnoho souborů
19491948
diff.comment.placeholder=Zanechat komentář
19501949
diff.comment.markdown_info=Je podporována úprava vzhledu pomocí markdown.
19511950
diff.comment.add_single_comment=Přidat jeden komentář

0 commit comments

Comments
 (0)