Skip to content

Commit 8a238ed

Browse files
authored
Merge branch 'main' into oauth-client-type
2 parents 89626e2 + 9862936 commit 8a238ed

File tree

21 files changed

+142
-54
lines changed

21 files changed

+142
-54
lines changed

.gitpod.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
image: gitpod/workspace-full:latest
2+
3+
tasks:
4+
- name: Setup
5+
init: |
6+
make deps
7+
make build
8+
command: |
9+
gp sync-done setup
10+
exit 0
11+
- name: Run frontend
12+
command: |
13+
gp sync-await setup
14+
make watch-frontend
15+
- name: Run backend
16+
command: |
17+
gp sync-await setup
18+
mkdir -p custom/conf/
19+
echo -e "[server]\nROOT_URL=https://3000-$GITPOD_WORKSPACE_ID.${GITPOD_WORKSPACE_CLUSTER_HOST}/" > custom/conf/app.ini
20+
echo -e "\n[database]\nDB_TYPE = sqlite3\nPATH = /workspace/gitea/data/gitea.db" >> custom/conf/app.ini
21+
export TAGS="sqlite sqlite_unlock_notify"
22+
make watch-backend
23+
24+
vscode:
25+
extensions:
26+
- editorconfig.editorconfig
27+
- dbaeumer.vscode-eslint
28+
- golang.go
29+
- stylelint.vscode-stylelint
30+
- DavidAnson.vscode-markdownlint
31+
32+
ports:
33+
- name: Gitea
34+
port: 3000

contrib/systemd/gitea.service

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,8 @@ After=network.target
4949
###
5050

5151
[Service]
52-
# Modify these two values and uncomment them if you have
53-
# repos with lots of files and get an HTTP error 500 because
54-
# of that
55-
###
56-
#LimitMEMLOCK=infinity
57-
#LimitNOFILE=65535
52+
# Uncomment the next line if you have repos with lots of files and get a HTTP 500 error because of that
53+
# LimitNOFILE=524288:524288
5854
RestartSec=2s
5955
Type=simple
6056
User=git

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -537,9 +537,9 @@ Certain queues have defaults that override the defaults set in `[queue]` (this o
537537
## Camo (`camo`)
538538

539539
- `ENABLED`: **false**: Enable media proxy, we support images only at the moment.
540-
- `SERVER_URL`: **<empty>**: url of camo server, it **is required** if camo is enabled.
541-
- `HMAC_KEY`: **<empty>**: Provide the HMAC key for encoding urls, it **is required** if camo is enabled.
542-
- `ALLWAYS`: **false**: Set to true to use camo for https too lese only non https urls are proxyed
540+
- `SERVER_URL`: **<empty>**: URL of camo server, it **is required** if camo is enabled.
541+
- `HMAC_KEY`: **<empty>**: Provide the HMAC key for encoding URLs, it **is required** if camo is enabled.
542+
- `ALLWAYS`: **false**: Set to true to use camo for both HTTP and HTTPS content, otherwise only non-HTTPS URLs are proxied
543543

544544
## OpenID (`openid`)
545545

docs/content/doc/developers/hacking-on-gitea.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ server as mentioned above.
171171

172172
### Working on JS and CSS
173173

174-
Frontend development should follow [Guidelines for Frontend Development](./guidelines-frontend.md)
174+
Frontend development should follow [Guidelines for Frontend Development]({{< relref "doc/developers/guidelines-frontend.en-us.md" >}})
175175

176176
To build with frontend resources, either use the `watch-frontend` target mentioned above or just build once:
177177

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ require (
9898
golang.org/x/net v0.0.0-20220927171203-f486391704dc
9999
golang.org/x/oauth2 v0.0.0-20220909003341-f21342109be1
100100
golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec
101-
golang.org/x/text v0.3.7
101+
golang.org/x/text v0.3.8
102102
golang.org/x/tools v0.1.12
103103
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
104104
gopkg.in/ini.v1 v1.67.0

go.sum

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1891,8 +1891,9 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
18911891
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
18921892
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
18931893
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
1894-
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
18951894
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
1895+
golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY=
1896+
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
18961897
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
18971898
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
18981899
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=

models/repo.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,15 +438,27 @@ func CheckRepoStats(ctx context.Context) error {
438438
repoStatsCorrectNumStars,
439439
"repository count 'num_stars'",
440440
},
441+
// Repository.NumIssues
442+
{
443+
statsQuery("SELECT repo.id FROM `repository` repo WHERE repo.num_issues!=(SELECT COUNT(*) FROM `issue` WHERE repo_id=repo.id AND is_closed=? AND is_pull=?)", false, false),
444+
repoStatsCorrectNumIssues,
445+
"repository count 'num_issues'",
446+
},
441447
// Repository.NumClosedIssues
442448
{
443449
statsQuery("SELECT repo.id FROM `repository` repo WHERE repo.num_closed_issues!=(SELECT COUNT(*) FROM `issue` WHERE repo_id=repo.id AND is_closed=? AND is_pull=?)", true, false),
444450
repoStatsCorrectNumClosedIssues,
445451
"repository count 'num_closed_issues'",
446452
},
453+
// Repository.NumPulls
454+
{
455+
statsQuery("SELECT repo.id FROM `repository` repo WHERE repo.num_pulls!=(SELECT COUNT(*) FROM `issue` WHERE repo_id=repo.id AND is_closed=? AND is_pull=?)", false, true),
456+
repoStatsCorrectNumPulls,
457+
"repository count 'num_pulls'",
458+
},
447459
// Repository.NumClosedPulls
448460
{
449-
statsQuery("SELECT repo.id FROM `repository` repo WHERE repo.num_closed_issues!=(SELECT COUNT(*) FROM `issue` WHERE repo_id=repo.id AND is_closed=? AND is_pull=?)", true, true),
461+
statsQuery("SELECT repo.id FROM `repository` repo WHERE repo.num_closed_pulls!=(SELECT COUNT(*) FROM `issue` WHERE repo_id=repo.id AND is_closed=? AND is_pull=?)", true, true),
450462
repoStatsCorrectNumClosedPulls,
451463
"repository count 'num_closed_pulls'",
452464
},

models/user/email_address.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func (err ErrEmailCharIsNotSupported) Error() string {
4141
}
4242

4343
// ErrEmailInvalid represents an error where the email address does not comply with RFC 5322
44+
// or has a leading '-' character
4445
type ErrEmailInvalid struct {
4546
Email string
4647
}
@@ -134,9 +135,7 @@ func ValidateEmail(email string) error {
134135
return ErrEmailCharIsNotSupported{email}
135136
}
136137

137-
if !(email[0] >= 'a' && email[0] <= 'z') &&
138-
!(email[0] >= 'A' && email[0] <= 'Z') &&
139-
!(email[0] >= '0' && email[0] <= '9') {
138+
if email[0] == '-' {
140139
return ErrEmailInvalid{email}
141140
}
142141

models/user/email_address_test.go

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -281,23 +281,25 @@ func TestEmailAddressValidate(t *testing.T) {
281281
282282
`first;[email protected]`: user_model.ErrEmailCharIsNotSupported{`first;[email protected]`},
283283
"[email protected]": user_model.ErrEmailInvalid{"[email protected]"},
284-
"[email protected]": user_model.ErrEmailInvalid{"[email protected]"},
285-
"#[email protected]": user_model.ErrEmailInvalid{"#[email protected]"},
286-
"[email protected]": user_model.ErrEmailInvalid{"[email protected]"},
287-
"%[email protected]": user_model.ErrEmailInvalid{"%[email protected]"},
288-
"&[email protected]": user_model.ErrEmailInvalid{"&[email protected]"},
289-
"'[email protected]": user_model.ErrEmailInvalid{"'[email protected]"},
290-
"*[email protected]": user_model.ErrEmailInvalid{"*[email protected]"},
291-
"[email protected]": user_model.ErrEmailInvalid{"[email protected]"},
292-
"/[email protected]": user_model.ErrEmailInvalid{"/[email protected]"},
293-
"[email protected]": user_model.ErrEmailInvalid{"[email protected]"},
294-
"[email protected]": user_model.ErrEmailInvalid{"[email protected]"},
295-
"^[email protected]": user_model.ErrEmailInvalid{"^[email protected]"},
296-
"`[email protected]": user_model.ErrEmailInvalid{"`[email protected]"},
297-
"{[email protected]": user_model.ErrEmailInvalid{"{[email protected]"},
298-
"|[email protected]": user_model.ErrEmailInvalid{"|[email protected]"},
299-
"}[email protected]": user_model.ErrEmailInvalid{"}[email protected]"},
300-
"[email protected]": user_model.ErrEmailInvalid{"[email protected]"},
284+
285+
286+
287+
288+
289+
290+
291+
292+
"[email protected]": user_model.ErrEmailInvalid{"[email protected]"},
293+
294+
295+
296+
297+
298+
299+
300+
301+
302+
301303
";[email protected]": user_model.ErrEmailCharIsNotSupported{";[email protected]"},
302304
"Foo <[email protected]>": user_model.ErrEmailCharIsNotSupported{"Foo <[email protected]>"},
303305
string([]byte{0xE2, 0x84, 0xAA}): user_model.ErrEmailCharIsNotSupported{string([]byte{0xE2, 0x84, 0xAA})},

modules/context/repo.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,11 +451,20 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
451451
owner, err = user_model.GetUserByName(ctx, userName)
452452
if err != nil {
453453
if user_model.IsErrUserNotExist(err) {
454+
// go-get does not support redirects
455+
// https://github.com/golang/go/issues/19760
454456
if ctx.FormString("go-get") == "1" {
455457
EarlyResponseForGoGetMeta(ctx)
456458
return
457459
}
458-
ctx.NotFound("GetUserByName", nil)
460+
461+
if redirectUserID, err := user_model.LookupUserRedirect(userName); err == nil {
462+
RedirectToUser(ctx, userName, redirectUserID)
463+
} else if user_model.IsErrUserRedirectNotExist(err) {
464+
ctx.NotFound("GetUserByName", nil)
465+
} else {
466+
ctx.ServerError("LookupUserRedirect", err)
467+
}
459468
} else {
460469
ctx.ServerError("GetUserByName", err)
461470
}

modules/convert/convert.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ func ToLFSLock(l *git_model.LFSLock) *api.LFSLock {
413413
Path: l.Path,
414414
LockedAt: l.Created.Round(time.Second),
415415
Owner: &api.LFSLockOwner{
416-
Name: u.DisplayName(),
416+
Name: u.Name,
417417
},
418418
}
419419
}

modules/private/internal.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"fmt"
1111
"net"
1212
"net/http"
13+
"os"
14+
"strings"
1315

1416
"code.gitea.io/gitea/modules/httplib"
1517
"code.gitea.io/gitea/modules/json"
@@ -18,13 +20,14 @@ import (
1820
"code.gitea.io/gitea/modules/setting"
1921
)
2022

21-
func newRequest(ctx context.Context, url, method string) *httplib.Request {
23+
func newRequest(ctx context.Context, url, method, sourceIP string) *httplib.Request {
2224
if setting.InternalToken == "" {
2325
log.Fatal(`The INTERNAL_TOKEN setting is missing from the configuration file: %q.
2426
Ensure you are running in the correct environment or set the correct configuration file with -c.`, setting.CustomConf)
2527
}
2628
return httplib.NewRequest(url, method).
2729
SetContext(ctx).
30+
Header("X-Real-IP", sourceIP).
2831
Header("Authorization", fmt.Sprintf("Bearer %s", setting.InternalToken))
2932
}
3033

@@ -42,8 +45,16 @@ func decodeJSONError(resp *http.Response) *Response {
4245
return &res
4346
}
4447

48+
func getClientIP() string {
49+
sshConnEnv := strings.TrimSpace(os.Getenv("SSH_CONNECTION"))
50+
if len(sshConnEnv) == 0 {
51+
return "127.0.0.1"
52+
}
53+
return strings.Fields(sshConnEnv)[0]
54+
}
55+
4556
func newInternalRequest(ctx context.Context, url, method string) *httplib.Request {
46-
req := newRequest(ctx, url, method).SetTLSClientConfig(&tls.Config{
57+
req := newRequest(ctx, url, method, getClientIP()).SetTLSClientConfig(&tls.Config{
4758
InsecureSkipVerify: true,
4859
ServerName: setting.Domain,
4960
})

options/locale/locale_pt-PT.ini

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,11 @@ users=Utilizadores
268268
organizations=Organizações
269269
search=Procurar
270270
code=Código
271+
search.type.tooltip=Tipo de pesquisa
271272
search.fuzzy=Aproximada
273+
search.fuzzy.tooltip=Incluir também os resultados que estejam próximos do termo de pesquisa
272274
search.match=Fiel
275+
search.match.tooltip=Incluir somente os resultados que correspondam rigorosamente ao termo de pesquisa
273276
code_search_unavailable=A pesquisa por código-fonte não está disponível, neste momento. Entre em contacto com o administrador.
274277
repo_no_results=Não foram encontrados quaisquer repositórios correspondentes.
275278
user_no_results=Não foram encontrados quaisquer utilizadores correspondentes.
@@ -507,6 +510,7 @@ activity=Trabalho público
507510
followers=Seguidores
508511
starred=Repositórios favoritos
509512
watched=Repositórios sob vigilância
513+
code=Código
510514
projects=Planeamentos
511515
following=Que segue
512516
follow=Seguir
@@ -1763,8 +1767,11 @@ activity.git_stats_deletion_n=%d eliminações
17631767

17641768
search=Procurar
17651769
search.search_repo=Procurar repositório
1770+
search.type.tooltip=Tipo de pesquisa
17661771
search.fuzzy=Aproximada
1772+
search.fuzzy.tooltip=Incluir também os resultados que estejam próximos do termo de pesquisa
17671773
search.match=Fiel
1774+
search.match.tooltip=Incluir somente os resultados que correspondam rigorosamente ao termo de pesquisa
17681775
search.results=Resultados da procura de "%s" em <a href="%s">%s</a>
17691776
search.code_no_results=Não foi encontrado qualquer código-fonte correspondente à sua pesquisa.
17701777
search.code_search_unavailable=A pesquisa por código-fonte não está disponível, neste momento. Entre em contacto com o administrador.
@@ -2310,6 +2317,7 @@ create_org=Criar organização
23102317
repo_updated=Modificado
23112318
people=Pessoas
23122319
teams=Equipas
2320+
code=Código
23132321
lower_members=membros
23142322
lower_repositories=repositórios
23152323
create_new_team=Nova equipa

routers/private/internal.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"code.gitea.io/gitea/modules/web"
1818

1919
"gitea.com/go-chi/binding"
20+
chi_middleware "github.com/go-chi/chi/v5/middleware"
2021
)
2122

2223
// CheckInternalToken check internal token is set
@@ -57,6 +58,9 @@ func Routes() *web.Route {
5758
r := web.NewRoute()
5859
r.Use(context.PrivateContexter())
5960
r.Use(CheckInternalToken)
61+
// Log the real ip address of the request from SSH is really helpful for diagnosing sometimes.
62+
// Since internal API will be sent only from Gitea sub commands and it's under control (checked by InternalToken), we can trust the headers.
63+
r.Use(chi_middleware.RealIP)
6064

6165
r.Post("/ssh/authorized_keys", AuthorizedPublicKeyByContent)
6266
r.Post("/ssh/{id}/update/{repoid}", UpdatePublicKeyInRepo)

routers/web/repo/activity.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ func Activity(ctx *context.Context) {
4747
ctx.Data["Period"] = "weekly"
4848
timeFrom = timeUntil.Add(-time.Hour * 168)
4949
}
50-
ctx.Data["DateFrom"] = timeFrom.Format("January 2, 2006")
51-
ctx.Data["DateUntil"] = timeUntil.Format("January 2, 2006")
50+
ctx.Data["DateFrom"] = timeFrom.Format("2006-01-02")
51+
ctx.Data["DateUntil"] = timeUntil.Format("2006-01-02")
5252
ctx.Data["PeriodText"] = ctx.Tr("repo.activity.period." + ctx.Data["Period"].(string))
5353

5454
var err error

routers/web/repo/view.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
455455
ctx.ServerError("GetTreePathLock", err)
456456
return
457457
}
458-
ctx.Data["LFSLockOwner"] = u.DisplayName()
458+
ctx.Data["LFSLockOwner"] = u.Name
459459
ctx.Data["LFSLockOwnerHomeLink"] = u.HomeLink()
460460
ctx.Data["LFSLockHint"] = ctx.Tr("repo.editor.this_file_locked")
461461
}

0 commit comments

Comments
 (0)