Skip to content

Commit bd82533

Browse files
authored
Merge branch 'main' into introduce-tar-transform-to-prevent-tarbomb
2 parents 93e4cf8 + 1f05417 commit bd82533

Some content is hidden

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

41 files changed

+495
-163
lines changed

CHANGELOG.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,41 @@ 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.6](https://github.com/go-gitea/gitea/releases/tag/v1.16.6) - 2022-04-20
8+
9+
* ENHANCEMENTS
10+
* Only request write when necessary (#18657) (#19422)
11+
* Disable service worker by default (#18914) (#19342)
12+
* BUGFIXES
13+
* When dumping trim the standard suffices instead of a random suffix (#19440) (#19447)
14+
* Fix DELETE request for non-existent public key (#19443) (#19444)
15+
* Don't panic on ErrEmailInvalid (#19441) (#19442)
16+
* Add uploadpack.allowAnySHA1InWant to allow --filter=blob:none with older git clients (#19430) (#19438)
17+
* Warn on SSH connection for incorrect configuration (#19317) (#19437)
18+
* Search Issues via API, dont show 500 if filter result in empty list (#19244) (#19436)
19+
* When updating mirror repo intervals by API reschedule next update too (#19429) (#19433)
20+
* Fix nil error when some pages are rendered outside request context (#19427) (#19428)
21+
* Fix double blob-hunk on diff page (#19404) (#19405)
22+
* Don't allow merging PR's which are being conflict checked (#19357) (#19358)
23+
* Fix middleware function's placements (#19377) (#19378)
24+
* Fix invalid CSRF token bug, make sure CSRF tokens can be up-to-date (#19338)
25+
* Restore user autoregistration with email addresses (#19261) (#19312)
26+
* Move checks for pulls before merge into own function (#19271) (#19277)
27+
* Granular webhook events in editHook (#19251) (#19257)
28+
* Only send webhook events to active system webhooks and only deliver to active hooks (#19234) (#19248)
29+
* Use full output of git show-ref --tags to get tags for PushUpdateAddTag (#19235) (#19236)
30+
* Touch mirrors on even on fail to update (#19217) (#19233)
31+
* Hide sensitive content on admin panel progress monitor (#19218 & #19226) (#19231)
32+
* Fix clone url JS error for the empty repo page (#19209)
33+
* Bump goldmark to v1.4.11 (#19201) (#19203)
34+
* TESTING
35+
* Prevent intermittent failures in RepoIndexerTest (#19225 #19229) (#19228)
36+
* BUILD
37+
* Revert the minimal golang version requirement from 1.17 to 1.16 and add a warning in Makefile (#19319)
38+
* MISC
39+
* Performance improvement for add team user when org has more than 1000 repositories (#19227) (#19289)
40+
* Check go and nodejs version by go.mod and package.json (#19197) (#19254)
41+
742
## [1.16.5](https://github.com/go-gitea/gitea/releases/tag/v1.16.5) - 2022-03-23
843

944
* BREAKING

cmd/dump.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func (o outputType) String() string {
8686
}
8787

8888
var outputTypeEnum = &outputType{
89-
Enum: []string{"zip", "rar", "tar", "sz", "tar.gz", "tar.xz", "tar.bz2", "tar.br", "tar.lz4"},
89+
Enum: []string{"zip", "tar", "tar.sz", "tar.gz", "tar.xz", "tar.bz2", "tar.br", "tar.lz4"},
9090
Default: "zip",
9191
}
9292

@@ -160,7 +160,12 @@ func runDump(ctx *cli.Context) error {
160160
fatal("Deleting default logger failed. Can not write to stdout: %v", err)
161161
}
162162
} else {
163-
fileName = strings.TrimSuffix(fileName, path.Ext(fileName))
163+
for _, suffix := range outputTypeEnum.Enum {
164+
if strings.HasSuffix(fileName, "."+suffix) {
165+
fileName = strings.TrimSuffix(fileName, "."+suffix)
166+
break
167+
}
168+
}
164169
fileName += "." + outType
165170
}
166171
setting.LoadFromExisting()

docs/config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ params:
1818
description: Git with a cup of tea
1919
author: The Gitea Authors
2020
website: https://docs.gitea.io
21-
version: 1.16.5
21+
version: 1.16.6
2222
minGoVersion: 1.17
2323
goVersion: 1.18
24-
minNodeVersion: 12.17
24+
minNodeVersion: 14
2525

2626
outputs:
2727
home:

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,3 +348,18 @@ The added http-request will automatically add a trailing slash if needed and int
348348

349349
Then you **MUST** set something like `[server] ROOT_URL = http://example.com/gitea/` correctly in your configuration.
350350

351+
## Traefik
352+
353+
If you want traefik to serve your Gitea instance, you can add the following label section to your `docker-compose.yaml` (Assuming the provider is docker).
354+
355+
```yaml
356+
gitea:
357+
image: gitea/gitea
358+
...
359+
labels:
360+
- "traefik.enable=true"
361+
- "traefik.http.routers.gitea.rule=Host(`example.com`)"
362+
- "traefik.http.services.gitea-websecure.loadbalancer.server.port=3000"
363+
```
364+
365+
This config assumes that you are handling HTTPS on the traefik side and using HTTP between Gitea and traefik.

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,19 @@ git.example.com {
106106
```
107107

108108
然后您**必须**在 Gitea 的配置文件中正确的添加类似 `[server] ROOT_URL = http://git.example.com/git/` 的配置项。
109+
110+
## 使用 Traefik 作为反向代理服务
111+
112+
如果您想使用 traefik 作为 Gitea 的反向代理服务,您可以在 `docker-compose.yaml` 中添加 label 部分(假设使用 docker 作为 traefik 的 provider):
113+
114+
```yaml
115+
gitea:
116+
image: gitea/gitea
117+
...
118+
labels:
119+
- "traefik.enable=true"
120+
- "traefik.http.routers.gitea.rule=Host(`example.com`)"
121+
- "traefik.http.services.gitea-websecure.loadbalancer.server.port=3000"
122+
```
123+
124+
这份配置假设您使用 traefik 来处理 HTTPS 服务,并在其和 Gitea 之间使用 HTTP 进行通信。

integrations/api_user_email_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ func TestAPIAddEmail(t *testing.T) {
6969
Primary: false,
7070
},
7171
}, emails)
72+
73+
opts = api.CreateEmailOption{
74+
Emails: []string{"notAEmail"},
75+
}
76+
req = NewRequestWithJSON(t, "POST", "/api/v1/user/emails?token="+token, &opts)
77+
session.MakeRequest(t, req, http.StatusUnprocessableEntity)
7278
}
7379

7480
func TestAPIDeleteEmail(t *testing.T) {

integrations/pull_merge_test.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import (
2626
"code.gitea.io/gitea/modules/test"
2727
"code.gitea.io/gitea/modules/translation/i18n"
2828
"code.gitea.io/gitea/services/pull"
29+
repo_service "code.gitea.io/gitea/services/repository"
30+
files_service "code.gitea.io/gitea/services/repository/files"
2931

3032
"github.com/stretchr/testify/assert"
3133
)
@@ -346,3 +348,74 @@ func TestCantMergeUnrelated(t *testing.T) {
346348
gitRepo.Close()
347349
})
348350
}
351+
352+
func TestConflictChecking(t *testing.T) {
353+
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
354+
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
355+
356+
// Create new clean repo to test conflict checking.
357+
baseRepo, err := repo_service.CreateRepository(user, user, models.CreateRepoOptions{
358+
Name: "conflict-checking",
359+
Description: "Tempo repo",
360+
AutoInit: true,
361+
Readme: "Default",
362+
DefaultBranch: "main",
363+
})
364+
assert.NoError(t, err)
365+
assert.NotEmpty(t, baseRepo)
366+
367+
// create a commit on new branch.
368+
_, err = files_service.CreateOrUpdateRepoFile(git.DefaultContext, baseRepo, user, &files_service.UpdateRepoFileOptions{
369+
TreePath: "important_file",
370+
Message: "Add a important file",
371+
Content: "Just a non-important file",
372+
IsNewFile: true,
373+
OldBranch: "main",
374+
NewBranch: "important-secrets",
375+
})
376+
assert.NoError(t, err)
377+
378+
// create a commit on main branch.
379+
_, err = files_service.CreateOrUpdateRepoFile(git.DefaultContext, baseRepo, user, &files_service.UpdateRepoFileOptions{
380+
TreePath: "important_file",
381+
Message: "Add a important file",
382+
Content: "Not the same content :P",
383+
IsNewFile: true,
384+
OldBranch: "main",
385+
NewBranch: "main",
386+
})
387+
assert.NoError(t, err)
388+
389+
// create Pull to merge the important-secrets branch into main branch.
390+
pullIssue := &models.Issue{
391+
RepoID: baseRepo.ID,
392+
Title: "PR with conflict!",
393+
PosterID: user.ID,
394+
Poster: user,
395+
IsPull: true,
396+
}
397+
398+
pullRequest := &models.PullRequest{
399+
HeadRepoID: baseRepo.ID,
400+
BaseRepoID: baseRepo.ID,
401+
HeadBranch: "important-secrets",
402+
BaseBranch: "main",
403+
HeadRepo: baseRepo,
404+
BaseRepo: baseRepo,
405+
Type: models.PullRequestGitea,
406+
}
407+
err = pull.NewPullRequest(git.DefaultContext, baseRepo, pullIssue, nil, nil, pullRequest, nil)
408+
assert.NoError(t, err)
409+
410+
issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{Title: "PR with conflict!"}).(*models.Issue)
411+
conflictingPR, err := models.GetPullRequestByIssueID(issue.ID)
412+
assert.NoError(t, err)
413+
414+
// Ensure conflictedFiles is populated.
415+
assert.Equal(t, 1, len(conflictingPR.ConflictedFiles))
416+
// Check if status is correct.
417+
assert.Equal(t, models.PullRequestStatusConflict, conflictingPR.Status)
418+
// Ensure that mergeable returns false
419+
assert.False(t, conflictingPR.Mergeable())
420+
})
421+
}

models/organization/team_repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func GetTeamRepositories(ctx context.Context, opts *SearchTeamRepoOptions) ([]*r
4848
)
4949
}
5050
if opts.PageSize > 0 {
51-
sess.Limit(opts.PageSize, opts.Page*opts.PageSize)
51+
sess.Limit(opts.PageSize, (opts.Page-1)*opts.PageSize)
5252
}
5353
var repos []*repo_model.Repository
5454
return repos, sess.OrderBy("repository.name").

models/pull.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,3 +701,14 @@ func (pr *PullRequest) GetHeadBranchHTMLURL() string {
701701
}
702702
return pr.HeadRepo.HTMLURL() + "/src/branch/" + util.PathEscapeSegments(pr.HeadBranch)
703703
}
704+
705+
// Mergeable returns if the pullrequest is mergeable.
706+
func (pr *PullRequest) Mergeable() bool {
707+
// If a pull request isn't mergable if it's:
708+
// - Being conflict checked.
709+
// - Has a conflict.
710+
// - Received a error while being conflict checked.
711+
// - Is a work-in-progress pull request.
712+
return pr.Status != PullRequestStatusChecking && pr.Status != PullRequestStatusConflict &&
713+
pr.Status != PullRequestStatusError && !pr.IsWorkInProgress()
714+
}

modules/context/api.go

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -285,36 +285,6 @@ func APIContexter() func(http.Handler) http.Handler {
285285
}
286286
}
287287

288-
// ReferencesGitRepo injects the GitRepo into the Context
289-
func ReferencesGitRepo(allowEmpty bool) func(ctx *APIContext) (cancel context.CancelFunc) {
290-
return func(ctx *APIContext) (cancel context.CancelFunc) {
291-
// Empty repository does not have reference information.
292-
if !allowEmpty && ctx.Repo.Repository.IsEmpty {
293-
return
294-
}
295-
296-
// For API calls.
297-
if ctx.Repo.GitRepo == nil {
298-
repoPath := repo_model.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
299-
gitRepo, err := git.OpenRepository(ctx, repoPath)
300-
if err != nil {
301-
ctx.Error(http.StatusInternalServerError, "RepoRef Invalid repo "+repoPath, err)
302-
return
303-
}
304-
ctx.Repo.GitRepo = gitRepo
305-
// We opened it, we should close it
306-
return func() {
307-
// If it's been set to nil then assume someone else has closed it.
308-
if ctx.Repo.GitRepo != nil {
309-
ctx.Repo.GitRepo.Close()
310-
}
311-
}
312-
}
313-
314-
return
315-
}
316-
}
317-
318288
// NotFound handles 404s for APIContext
319289
// String will replace message, errors will be added to a slice
320290
func (ctx *APIContext) NotFound(objs ...interface{}) {
@@ -340,33 +310,62 @@ func (ctx *APIContext) NotFound(objs ...interface{}) {
340310
})
341311
}
342312

343-
// RepoRefForAPI handles repository reference names when the ref name is not explicitly given
344-
func RepoRefForAPI(next http.Handler) http.Handler {
345-
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
346-
ctx := GetAPIContext(req)
313+
// ReferencesGitRepo injects the GitRepo into the Context
314+
// you can optional skip the IsEmpty check
315+
func ReferencesGitRepo(allowEmpty ...bool) func(ctx *APIContext) (cancel context.CancelFunc) {
316+
return func(ctx *APIContext) (cancel context.CancelFunc) {
347317
// Empty repository does not have reference information.
348-
if ctx.Repo.Repository.IsEmpty {
318+
if ctx.Repo.Repository.IsEmpty && !(len(allowEmpty) != 0 && allowEmpty[0]) {
349319
return
350320
}
351321

352-
var err error
353-
322+
// For API calls.
354323
if ctx.Repo.GitRepo == nil {
355324
repoPath := repo_model.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
356-
ctx.Repo.GitRepo, err = git.OpenRepository(ctx, repoPath)
325+
gitRepo, err := git.OpenRepository(ctx, repoPath)
357326
if err != nil {
358-
ctx.InternalServerError(err)
327+
ctx.Error(http.StatusInternalServerError, "RepoRef Invalid repo "+repoPath, err)
359328
return
360329
}
330+
ctx.Repo.GitRepo = gitRepo
361331
// We opened it, we should close it
362-
defer func() {
332+
return func() {
363333
// If it's been set to nil then assume someone else has closed it.
364334
if ctx.Repo.GitRepo != nil {
365335
ctx.Repo.GitRepo.Close()
366336
}
367-
}()
337+
}
338+
}
339+
340+
return
341+
}
342+
}
343+
344+
// RepoRefForAPI handles repository reference names when the ref name is not explicitly given
345+
func RepoRefForAPI(next http.Handler) http.Handler {
346+
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
347+
ctx := GetAPIContext(req)
348+
349+
if ctx.Repo.GitRepo == nil {
350+
ctx.InternalServerError(fmt.Errorf("no open git repo"))
351+
return
352+
}
353+
354+
if ref := ctx.FormTrim("ref"); len(ref) > 0 {
355+
commit, err := ctx.Repo.GitRepo.GetCommit(ref)
356+
if err != nil {
357+
if git.IsErrNotExist(err) {
358+
ctx.NotFound()
359+
} else {
360+
ctx.Error(http.StatusInternalServerError, "GetBlobByPath", err)
361+
}
362+
return
363+
}
364+
ctx.Repo.Commit = commit
365+
return
368366
}
369367

368+
var err error
370369
refName := getRefName(ctx.Context, RepoRefAny)
371370

372371
if ctx.Repo.GitRepo.IsBranchExist(refName) {

modules/context/repo.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,21 @@ func (r *Repository) FileExists(path, branch string) (bool, error) {
221221

222222
// GetEditorconfig returns the .editorconfig definition if found in the
223223
// HEAD of the default repo branch.
224-
func (r *Repository) GetEditorconfig() (*editorconfig.Editorconfig, error) {
224+
func (r *Repository) GetEditorconfig(optCommit ...*git.Commit) (*editorconfig.Editorconfig, error) {
225225
if r.GitRepo == nil {
226226
return nil, nil
227227
}
228-
commit, err := r.GitRepo.GetBranchCommit(r.Repository.DefaultBranch)
229-
if err != nil {
230-
return nil, err
228+
var (
229+
err error
230+
commit *git.Commit
231+
)
232+
if len(optCommit) != 0 {
233+
commit = optCommit[0]
234+
} else {
235+
commit, err = r.GitRepo.GetBranchCommit(r.Repository.DefaultBranch)
236+
if err != nil {
237+
return nil, err
238+
}
231239
}
232240
treeEntry, err := commit.GetTreeEntryByPath(".editorconfig")
233241
if err != nil {
@@ -407,6 +415,12 @@ func RepoIDAssignment() func(ctx *Context) {
407415

408416
// RepoAssignment returns a middleware to handle repository assignment
409417
func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
418+
if _, repoAssignmentOnce := ctx.Data["repoAssignmentExecuted"]; repoAssignmentOnce {
419+
log.Trace("RepoAssignment was exec already, skipping second call ...")
420+
return
421+
}
422+
ctx.Data["repoAssignmentExecuted"] = true
423+
410424
var (
411425
owner *user_model.User
412426
err error
@@ -602,6 +616,9 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
602616
ctx.ServerError("RepoAssignment Invalid repo "+repo_model.RepoPath(userName, repoName), err)
603617
return
604618
}
619+
if ctx.Repo.GitRepo != nil {
620+
ctx.Repo.GitRepo.Close()
621+
}
605622
ctx.Repo.GitRepo = gitRepo
606623

607624
// We opened it, we should close it

0 commit comments

Comments
 (0)