Skip to content

Commit 39f9224

Browse files
authored
Merge branch 'main' into lunny/fix_history_count
2 parents e912ac3 + 5879ab8 commit 39f9224

Some content is hidden

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

77 files changed

+11027
-17593
lines changed

.air.conf renamed to .air.toml

File renamed without changes.

.eslintrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ rules:
117117
import/no-amd: [0]
118118
import/no-anonymous-default-export: [0]
119119
import/no-commonjs: [0]
120-
import/no-cycle: [2, {ignoreExternal: true}]
120+
import/no-cycle: [2, {ignoreExternal: true, maxDepth: 1}]
121121
import/no-default-export: [0]
122122
import/no-deprecated: [0]
123123
import/no-dynamic-require: [0]
@@ -371,6 +371,7 @@ rules:
371371
unicorn/no-fn-reference-in-iterator: [0]
372372
unicorn/no-for-loop: [0]
373373
unicorn/no-hex-escape: [0]
374+
unicorn/no-invalid-remove-event-listener: [2]
374375
unicorn/no-keyword-prefix: [0]
375376
unicorn/no-lonely-if: [2]
376377
unicorn/no-nested-ternary: [0]
@@ -385,6 +386,7 @@ rules:
385386
unicorn/no-unreadable-array-destructuring: [0]
386387
unicorn/no-unsafe-regex: [0]
387388
unicorn/no-unused-properties: [2]
389+
unicorn/no-useless-fallback-in-spread: [2]
388390
unicorn/no-useless-length-check: [2]
389391
unicorn/no-useless-spread: [2]
390392
unicorn/no-useless-undefined: [0]
@@ -434,6 +436,7 @@ rules:
434436
unicorn/require-number-to-fixed-digits-argument: [2]
435437
unicorn/require-post-message-target-origin: [0]
436438
unicorn/string-content: [0]
439+
unicorn/template-indent: [2]
437440
unicorn/throw-new-error: [2]
438441
use-isnan: [2]
439442
valid-typeof: [2, {requireStringLiterals: true}]

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ watch-backend: go-check
352352
@hash air > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
353353
$(GO) install github.com/cosmtrek/air@bedc18201271882c2be66d216d0e1a275b526ec4; \
354354
fi
355-
air -c .air.conf
355+
air -c .air.toml
356356

357357
.PHONY: test
358358
test: test-frontend test-backend

cmd/serv.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func fail(userMessage, logMessage string, args ...interface{}) error {
8080
fmt.Fprintln(os.Stderr, "Gitea:", userMessage)
8181

8282
if len(logMessage) > 0 {
83-
if !setting.IsProd() {
83+
if !setting.IsProd {
8484
fmt.Fprintf(os.Stderr, logMessage+"\n", args...)
8585
}
8686
}

docs/content/doc/installation/with-docker.en-us.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,16 @@ sudo -u git ssh-keygen -t rsa -b 4096 -C "Gitea Host Key"
333333
In the next step a file named `/app/gitea/gitea` (with executable permissions) needs to be created on the host. This file will issue the SSH forwarding from the host to the container. Add the following contents to `/app/gitea/gitea`:
334334

335335
```bash
336+
#!/bin/sh
336337
ssh -p 2222 -o StrictHostKeyChecking=no [email protected] "SSH_ORIGINAL_COMMAND=\"$SSH_ORIGINAL_COMMAND\" $0 $@"
337338
```
338339

340+
Here you should also make sure that you've set the permisson of `/app/gitea/gitea` correctly:
341+
342+
```bash
343+
sudo chmod +x /app/gitea/gitea
344+
```
345+
339346
To make the forwarding work, the SSH port of the container (22) needs to be mapped to the host port 2222 in `docker-compose.yml` . Since this port does not need to be exposed to the outside world, it can be mapped to the `localhost` of the host machine:
340347

341348
```bash

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ require (
8282
github.com/mattn/go-runewidth v0.0.13 // indirect
8383
github.com/mattn/go-sqlite3 v1.14.8
8484
github.com/mholt/archiver/v3 v3.5.0
85-
github.com/microcosm-cc/bluemonday v1.0.15
85+
github.com/microcosm-cc/bluemonday v1.0.16
8686
github.com/miekg/dns v1.1.43 // indirect
8787
github.com/minio/md5-simd v1.1.2 // indirect
8888
github.com/minio/minio-go/v7 v7.0.12

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -869,8 +869,8 @@ github.com/mholt/acmez v0.1.3 h1:J7MmNIk4Qf9b8mAGqAh4XkNeowv3f1zW816yf4zt7Qk=
869869
github.com/mholt/acmez v0.1.3/go.mod h1:8qnn8QA/Ewx8E3ZSsmscqsIjhhpxuy9vqdgbX2ceceM=
870870
github.com/mholt/archiver/v3 v3.5.0 h1:nE8gZIrw66cu4osS/U7UW7YDuGMHssxKutU8IfWxwWE=
871871
github.com/mholt/archiver/v3 v3.5.0/go.mod h1:qqTTPUK/HZPFgFQ/TJ3BzvTpF/dPtFVJXdQbCmeMxwc=
872-
github.com/microcosm-cc/bluemonday v1.0.15 h1:J4uN+qPng9rvkBZBoBb8YGR+ijuklIMpSOZZLjYpbeY=
873-
github.com/microcosm-cc/bluemonday v1.0.15/go.mod h1:ZLvAzeakRwrGnzQEvstVzVt3ZpqOF2+sdFr0Om+ce30=
872+
github.com/microcosm-cc/bluemonday v1.0.16 h1:kHmAq2t7WPWLjiGvzKa5o3HzSfahUKiOq7fAPUiMNIc=
873+
github.com/microcosm-cc/bluemonday v1.0.16/go.mod h1:Z0r70sCuXHig8YpBzCc5eGHAap2K7e/u082ZUpDRRqM=
874874
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
875875
github.com/miekg/dns v1.1.42/go.mod h1:+evo5L0630/F6ca/Z9+GAqzhjGyn8/c+TBaOyfEl0V4=
876876
github.com/miekg/dns v1.1.43 h1:JKfpVSCB84vrAmHzyrsxB5NAr5kLoMXZArPSw7Qlgyg=

integrations/api_user_heatmap_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import (
88
"fmt"
99
"net/http"
1010
"testing"
11+
"time"
1112

1213
"code.gitea.io/gitea/models"
14+
"code.gitea.io/gitea/modules/timeutil"
1315

1416
"github.com/stretchr/testify/assert"
1517
)
@@ -20,6 +22,10 @@ func TestUserHeatmap(t *testing.T) {
2022
normalUsername := "user2"
2123
session := loginUser(t, adminUsername)
2224

25+
var fakeNow = time.Date(2011, 10, 20, 0, 0, 0, 0, time.Local)
26+
timeutil.Set(fakeNow)
27+
defer timeutil.Unset()
28+
2329
urlStr := fmt.Sprintf("/api/v1/users/%s/heatmap", normalUsername)
2430
req := NewRequest(t, "GET", urlStr)
2531
resp := session.MakeRequest(t, req, http.StatusOK)

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export default {
22
rootDir: 'web_src',
3-
setupFilesAfterEnv: ['jest-extended'],
3+
setupFilesAfterEnv: ['jest-extended/all'],
44
testEnvironment: 'jsdom',
55
testMatch: ['<rootDir>/**/*.test.js'],
66
testTimeout: 20000,

models/db/engine.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ func NewTestEngine() (err error) {
136136
}
137137

138138
x.SetMapper(names.GonicMapper{})
139-
x.SetLogger(NewXORMLogger(!setting.IsProd()))
140-
x.ShowSQL(!setting.IsProd())
139+
x.SetLogger(NewXORMLogger(!setting.IsProd))
140+
x.ShowSQL(!setting.IsProd)
141141
return syncTables()
142142
}
143143

models/user_heatmap_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ package models
77
import (
88
"fmt"
99
"testing"
10+
"time"
1011

1112
"code.gitea.io/gitea/models/db"
1213
"code.gitea.io/gitea/modules/json"
14+
"code.gitea.io/gitea/modules/timeutil"
1315

1416
"github.com/stretchr/testify/assert"
1517
)
@@ -39,6 +41,10 @@ func TestGetUserHeatmapDataByUser(t *testing.T) {
3941
// Prepare
4042
assert.NoError(t, db.PrepareTestDatabase())
4143

44+
// Mock time
45+
timeutil.Set(time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC))
46+
defer timeutil.Unset()
47+
4248
for i, tc := range testCases {
4349
user := db.AssertExistsAndLoadBean(t, &User{ID: tc.userID}).(*User)
4450

modules/context/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (ctx *APIContext) Error(status int, title string, obj interface{}) {
9595
if status == http.StatusInternalServerError {
9696
log.ErrorWithSkip(1, "%s: %s", title, message)
9797

98-
if setting.IsProd() && !(ctx.User != nil && ctx.User.IsAdmin) {
98+
if setting.IsProd && !(ctx.User != nil && ctx.User.IsAdmin) {
9999
message = ""
100100
}
101101
}
@@ -112,7 +112,7 @@ func (ctx *APIContext) InternalServerError(err error) {
112112
log.ErrorWithSkip(1, "InternalServerError: %v", err)
113113

114114
var message string
115-
if !setting.IsProd() || (ctx.User != nil && ctx.User.IsAdmin) {
115+
if !setting.IsProd || (ctx.User != nil && ctx.User.IsAdmin) {
116116
message = err.Error()
117117
}
118118

modules/context/context.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ func (ctx *Context) NotFound(title string, err error) {
225225
func (ctx *Context) notFoundInternal(title string, err error) {
226226
if err != nil {
227227
log.ErrorWithSkip(2, "%s: %v", title, err)
228-
if !setting.IsProd() {
228+
if !setting.IsProd {
229229
ctx.Data["ErrorMsg"] = err
230230
}
231231
}
@@ -261,7 +261,7 @@ func (ctx *Context) ServerError(title string, err error) {
261261
func (ctx *Context) serverErrorInternal(title string, err error) {
262262
if err != nil {
263263
log.ErrorWithSkip(2, "%s: %v", title, err)
264-
if !setting.IsProd() {
264+
if !setting.IsProd {
265265
ctx.Data["ErrorMsg"] = err
266266
}
267267
}
@@ -645,7 +645,7 @@ func Contexter() func(next http.Handler) http.Handler {
645645
"CurrentURL": setting.AppSubURL + req.URL.RequestURI(),
646646
"PageStartTime": startTime,
647647
"Link": link,
648-
"IsProd": setting.IsProd(),
648+
"IsProd": setting.IsProd,
649649
},
650650
}
651651
// PageData is passed by reference, and it will be rendered to `window.config.pageData` in `head.tmpl` for JavaScript modules

modules/csv/csv.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ func CreateReaderAndGuessDelimiter(rd io.Reader) (*stdcsv.Reader, error) {
3131
var data = make([]byte, 1e4)
3232
size, err := rd.Read(data)
3333
if err != nil {
34+
if err == io.EOF {
35+
return CreateReader(bytes.NewReader([]byte{}), rune(',')), nil
36+
}
3437
return nil, err
3538
}
3639

modules/httpcache/httpcache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818

1919
// AddCacheControlToHeader adds suitable cache-control headers to response
2020
func AddCacheControlToHeader(h http.Header, d time.Duration) {
21-
if setting.IsProd() {
21+
if setting.IsProd {
2222
h.Set("Cache-Control", "private, max-age="+strconv.Itoa(int(d.Seconds())))
2323
} else {
2424
h.Set("Cache-Control", "no-store")

modules/setting/setting.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -419,17 +419,13 @@ var (
419419
PIDFile = "/run/gitea.pid"
420420
WritePIDFile bool
421421
RunMode string
422+
IsProd bool
422423
RunUser string
423424
IsWindows bool
424425
HasRobotsTxt bool
425426
InternalToken string // internal access token
426427
)
427428

428-
// IsProd if it's a production mode
429-
func IsProd() bool {
430-
return strings.EqualFold(RunMode, "prod")
431-
}
432-
433429
func getAppPath() (string, error) {
434430
var appPath string
435431
var err error
@@ -906,6 +902,7 @@ func NewContext() {
906902
// Please don't use root as a bandaid to "fix" something that is broken, instead the broken thing should instead be fixed properly.
907903
unsafeAllowRunAsRoot := Cfg.Section("").Key("I_AM_BEING_UNSAFE_RUNNING_AS_ROOT").MustBool(false)
908904
RunMode = Cfg.Section("").Key("RUN_MODE").MustString("prod")
905+
IsProd = strings.EqualFold(RunMode, "prod")
909906
// Does not check run user when the install lock is off.
910907
if InstallLock {
911908
currentUser, match := IsRunUserMatchCurrentUser(RunUser)

modules/ssh/ssh.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,66 @@ func Listen(host string, port int, ciphers []string, keyExchanges []string, macs
316316
}
317317
}
318318

319+
// Workaround slightly broken behaviour in x/crypto/ssh/handshake.go:458-463
320+
//
321+
// Fundamentally the issue here is that HostKeyAlgos make the incorrect assumption
322+
// that the PublicKey().Type() matches the signature algorithm.
323+
//
324+
// Therefore we need to add duplicates for the RSA with different signing algorithms.
325+
signers := make([]ssh.Signer, 0, len(srv.HostSigners))
326+
for _, signer := range srv.HostSigners {
327+
if signer.PublicKey().Type() == "ssh-rsa" {
328+
signers = append(signers,
329+
&wrapSigner{
330+
Signer: signer,
331+
algorithm: gossh.SigAlgoRSASHA2512,
332+
},
333+
&wrapSigner{
334+
Signer: signer,
335+
algorithm: gossh.SigAlgoRSASHA2256,
336+
},
337+
)
338+
}
339+
signers = append(signers, signer)
340+
}
341+
srv.HostSigners = signers
342+
319343
go listen(&srv)
320344

321345
}
322346

347+
// wrapSigner wraps a signer and overrides its public key type with the provided algorithm
348+
type wrapSigner struct {
349+
ssh.Signer
350+
algorithm string
351+
}
352+
353+
// PublicKey returns an associated PublicKey instance.
354+
func (s *wrapSigner) PublicKey() gossh.PublicKey {
355+
return &wrapPublicKey{
356+
PublicKey: s.Signer.PublicKey(),
357+
algorithm: s.algorithm,
358+
}
359+
}
360+
361+
// Sign returns raw signature for the given data. This method
362+
// will apply the hash specified for the keytype to the data using
363+
// the algorithm assigned for this key
364+
func (s *wrapSigner) Sign(rand io.Reader, data []byte) (*gossh.Signature, error) {
365+
return s.Signer.(gossh.AlgorithmSigner).SignWithAlgorithm(rand, data, s.algorithm)
366+
}
367+
368+
// wrapPublicKey wraps a PublicKey and overrides its type
369+
type wrapPublicKey struct {
370+
gossh.PublicKey
371+
algorithm string
372+
}
373+
374+
// Type returns the algorithm
375+
func (k *wrapPublicKey) Type() string {
376+
return k.algorithm
377+
}
378+
323379
// GenKeyPair make a pair of public and private keys for SSH access.
324380
// Public key is encoded in the format for inclusion in an OpenSSH authorized_keys file.
325381
// Private Key generated is PEM encoded

modules/templates/base.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func HTMLRenderer() *render.Render {
9191
Funcs: NewFuncMap(),
9292
Asset: GetAsset,
9393
AssetNames: GetAssetNames,
94-
IsDevelopment: !setting.IsProd(),
94+
IsDevelopment: !setting.IsProd,
9595
DisableHTTPErrorRendering: true,
9696
})
9797
}

modules/timeutil/timestamp.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,24 @@ import (
1313
// TimeStamp defines a timestamp
1414
type TimeStamp int64
1515

16+
// mock is NOT concurrency-safe!!
17+
var mock time.Time
18+
19+
// Set sets the time to a mocked time.Time
20+
func Set(now time.Time) {
21+
mock = now
22+
}
23+
24+
// Unset will unset the mocked time.Time
25+
func Unset() {
26+
mock = time.Time{}
27+
}
28+
1629
// TimeStampNow returns now int64
1730
func TimeStampNow() TimeStamp {
31+
if !mock.IsZero() {
32+
return TimeStamp(mock.Unix())
33+
}
1834
return TimeStamp(time.Now().Unix())
1935
}
2036

options/locale/locale_en-US.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,9 @@ star_guest_user = Sign in to star this repository.
927927
copy_link = Copy
928928
copy_link_success = Link has been copied
929929
copy_link_error = Use ⌘C or Ctrl-C to copy
930+
copy_branch = Copy
931+
copy_branch_success = Branch name has been copied
932+
copy_branch_error = Use ⌘C or Ctrl-C to copy
930933
copied = Copied OK
931934
unwatch = Unwatch
932935
watch = Watch

options/locale/locale_ja-JP.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,6 +2026,8 @@ diff.file_image_height=高さ
20262026
diff.file_byte_size=サイズ
20272027
diff.file_suppressed=ファイル差分が大きすぎるため省略します
20282028
diff.file_suppressed_line_too_long=長すぎる行があるためファイル差分は表示されません
2029+
diff.too_many_files=変更されたファイルが多すぎるため、一部のファイルは表示されません
2030+
diff.show_more=さらに表示
20292031
diff.generated=generated
20302032
diff.vendored=vendored
20312033
diff.comment.placeholder=コメントを残す

0 commit comments

Comments
 (0)