Skip to content

Commit c7272c6

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Fix logging of Transfer API (go-gitea#19456) RepoAssignment ensure to close before overwrite (go-gitea#19449) node12 is EOL (go-gitea#19451) Add Changelog v1.16.6 (go-gitea#19339) (go-gitea#19450) Fix DELETE request for non-existent public key (go-gitea#19443) [skip ci] Updated translations via Crowdin Don't panic on `ErrEmailInvalid` (go-gitea#19441)
2 parents a6b983f + 3ec1b6c commit c7272c6

File tree

22 files changed

+198
-112
lines changed

22 files changed

+198
-112
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

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:

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) {

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

options/locale/locale_pt-BR.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ theme_desc=Este será o seu tema padrão em todo o site.
596596
primary=Principal
597597
activated=Ativado
598598
requires_activation=Requer ativação
599-
primary_email=Tornar privado
599+
primary_email=Tornar Primário
600600
activate_email=Enviar Ativação
601601
activations_pending=Ativações pendentes
602602
delete_email=Remover

options/locale/locale_pt-PT.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3042,6 +3042,9 @@ container.labels.key=Chave
30423042
container.labels.value=Valor
30433043
generic.download=Descarregar pacote usando a linha de comandos:
30443044
generic.documentation=Para obter mais informações sobre o registo genérico, consulte <a target="_blank" rel="noopener noreferrer" href="https://docs.gitea.io/en-us/packages/generic">a documentação</a>.
3045+
helm.registry=Configurar este registo usando a linha de comandos:
3046+
helm.install=Para instalar o pacote, execute o seguinte comando:
3047+
helm.documentation=Para obter mais informações sobre o registo do Helm, consulte <a target="_blank" rel="noopener noreferrer" href="https://docs.gitea.io/en-us/packages/helm/">a documentação</a>.
30453048
maven.registry=Configure este registo no seu ficheiro <code>pom.xml</code> do projecto:
30463049
maven.install=Para usar este pacote, inclua no bloco <code>dependencies</code> do ficheiro <code>pom.xml</code> o seguinte:
30473050
maven.install2=Executar usando a linha de comandos:

options/locale/locale_zh-CN.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3051,6 +3051,9 @@ container.labels.key=键
30513051
container.labels.value=值
30523052
generic.download=从命令行下载软件包:
30533053
generic.documentation=关于通用注册中心的更多信息,请参阅 <a target="_blank" rel="noopener noreferrer" href="https://docs.gitea.io/en-us/packages/generic">文档</a>。
3054+
helm.registry=从命令行设置此注册中心:
3055+
helm.install=要安装包,请运行以下命令:
3056+
helm.documentation=关于 Helm 注册中心的更多信息,请参阅 <a target="_blank" rel="noopener noreferrer" href="https://docs.gitea.io/en-us/packages/helm/">文档</a>。
30543057
maven.registry=在您项目的 <code>pom.xml</code> 文件中设置此注册中心:
30553058
maven.install=要使用这个软件包,在 <code>pom.xml</code> 文件中的 <code>依赖项</code> 块中包含以下内容:
30563059
maven.install2=通过命令行运行:

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"type": "module",
66
"engines": {
7-
"node": ">= 12.17.0"
7+
"node": ">= 14"
88
},
99
"dependencies": {
1010
"@claviska/jquery-minicolors": "2.3.6",

routers/api/v1/api.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ func Routes() *web.Route {
796796
m.Combo("").Get(repo.GetHook).
797797
Patch(bind(api.EditHookOption{}), repo.EditHook).
798798
Delete(repo.DeleteHook)
799-
m.Post("/tests", context.RepoRefForAPI, repo.TestHook)
799+
m.Post("/tests", context.ReferencesGitRepo(), context.RepoRefForAPI, repo.TestHook)
800800
})
801801
}, reqToken(), reqAdmin(), reqWebhooksEnabled())
802802
m.Group("/collaborators", func() {
@@ -813,16 +813,16 @@ func Routes() *web.Route {
813813
Put(reqAdmin(), repo.AddTeam).
814814
Delete(reqAdmin(), repo.DeleteTeam)
815815
}, reqToken())
816-
m.Get("/raw/*", context.RepoRefForAPI, reqRepoReader(unit.TypeCode), repo.GetRawFile)
816+
m.Get("/raw/*", context.ReferencesGitRepo(), context.RepoRefForAPI, reqRepoReader(unit.TypeCode), repo.GetRawFile)
817817
m.Get("/archive/*", reqRepoReader(unit.TypeCode), repo.GetArchive)
818818
m.Combo("/forks").Get(repo.ListForks).
819819
Post(reqToken(), reqRepoReader(unit.TypeCode), bind(api.CreateForkOption{}), repo.CreateFork)
820820
m.Group("/branches", func() {
821-
m.Get("", context.ReferencesGitRepo(false), repo.ListBranches)
822-
m.Get("/*", context.ReferencesGitRepo(false), repo.GetBranch)
823-
m.Delete("/*", reqRepoWriter(unit.TypeCode), context.ReferencesGitRepo(false), repo.DeleteBranch)
824-
m.Post("", reqRepoWriter(unit.TypeCode), context.ReferencesGitRepo(false), bind(api.CreateBranchRepoOption{}), repo.CreateBranch)
825-
}, reqRepoReader(unit.TypeCode))
821+
m.Get("", repo.ListBranches)
822+
m.Get("/*", repo.GetBranch)
823+
m.Delete("/*", reqRepoWriter(unit.TypeCode), repo.DeleteBranch)
824+
m.Post("", reqRepoWriter(unit.TypeCode), bind(api.CreateBranchRepoOption{}), repo.CreateBranch)
825+
}, context.ReferencesGitRepo(), reqRepoReader(unit.TypeCode))
826826
m.Group("/branch_protections", func() {
827827
m.Get("", repo.ListBranchProtections)
828828
m.Post("", bind(api.CreateBranchProtectionOption{}), repo.CreateBranchProtection)
@@ -941,10 +941,10 @@ func Routes() *web.Route {
941941
})
942942
m.Group("/releases", func() {
943943
m.Combo("").Get(repo.ListReleases).
944-
Post(reqToken(), reqRepoWriter(unit.TypeReleases), context.ReferencesGitRepo(false), bind(api.CreateReleaseOption{}), repo.CreateRelease)
944+
Post(reqToken(), reqRepoWriter(unit.TypeReleases), context.ReferencesGitRepo(), bind(api.CreateReleaseOption{}), repo.CreateRelease)
945945
m.Group("/{id}", func() {
946946
m.Combo("").Get(repo.GetRelease).
947-
Patch(reqToken(), reqRepoWriter(unit.TypeReleases), context.ReferencesGitRepo(false), bind(api.EditReleaseOption{}), repo.EditRelease).
947+
Patch(reqToken(), reqRepoWriter(unit.TypeReleases), context.ReferencesGitRepo(), bind(api.EditReleaseOption{}), repo.EditRelease).
948948
Delete(reqToken(), reqRepoWriter(unit.TypeReleases), repo.DeleteRelease)
949949
m.Group("/assets", func() {
950950
m.Combo("").Get(repo.ListReleaseAttachments).
@@ -961,7 +961,7 @@ func Routes() *web.Route {
961961
})
962962
}, reqRepoReader(unit.TypeReleases))
963963
m.Post("/mirror-sync", reqToken(), reqRepoWriter(unit.TypeCode), repo.MirrorSync)
964-
m.Get("/editorconfig/{filename}", context.RepoRefForAPI, reqRepoReader(unit.TypeCode), repo.GetEditorconfig)
964+
m.Get("/editorconfig/{filename}", context.ReferencesGitRepo(), context.RepoRefForAPI, reqRepoReader(unit.TypeCode), repo.GetEditorconfig)
965965
m.Group("/pulls", func() {
966966
m.Combo("").Get(repo.ListPullRequests).
967967
Post(reqToken(), mustNotBeArchived, bind(api.CreatePullRequestOption{}), repo.CreatePullRequest)
@@ -992,30 +992,30 @@ func Routes() *web.Route {
992992
Delete(reqToken(), bind(api.PullReviewRequestOptions{}), repo.DeleteReviewRequests).
993993
Post(reqToken(), bind(api.PullReviewRequestOptions{}), repo.CreateReviewRequests)
994994
})
995-
}, mustAllowPulls, reqRepoReader(unit.TypeCode), context.ReferencesGitRepo(false))
995+
}, mustAllowPulls, reqRepoReader(unit.TypeCode), context.ReferencesGitRepo())
996996
m.Group("/statuses", func() {
997997
m.Combo("/{sha}").Get(repo.GetCommitStatuses).
998998
Post(reqToken(), bind(api.CreateStatusOption{}), repo.NewCommitStatus)
999999
}, reqRepoReader(unit.TypeCode))
10001000
m.Group("/commits", func() {
1001-
m.Get("", context.ReferencesGitRepo(false), repo.GetAllCommits)
1001+
m.Get("", context.ReferencesGitRepo(), repo.GetAllCommits)
10021002
m.Group("/{ref}", func() {
10031003
m.Get("/status", repo.GetCombinedCommitStatusByRef)
10041004
m.Get("/statuses", repo.GetCommitStatusesByRef)
10051005
})
10061006
}, reqRepoReader(unit.TypeCode))
10071007
m.Group("/git", func() {
10081008
m.Group("/commits", func() {
1009-
m.Get("/{sha}", context.ReferencesGitRepo(false), repo.GetSingleCommit)
1009+
m.Get("/{sha}", repo.GetSingleCommit)
10101010
m.Get("/{sha}.{diffType:diff|patch}", repo.DownloadCommitDiffOrPatch)
10111011
})
10121012
m.Get("/refs", repo.GetGitAllRefs)
10131013
m.Get("/refs/*", repo.GetGitRefs)
1014-
m.Get("/trees/{sha}", context.RepoRefForAPI, repo.GetTree)
1015-
m.Get("/blobs/{sha}", context.RepoRefForAPI, repo.GetBlob)
1016-
m.Get("/tags/{sha}", context.RepoRefForAPI, repo.GetAnnotatedTag)
1014+
m.Get("/trees/{sha}", repo.GetTree)
1015+
m.Get("/blobs/{sha}", repo.GetBlob)
1016+
m.Get("/tags/{sha}", repo.GetAnnotatedTag)
10171017
m.Get("/notes/{sha}", repo.GetNote)
1018-
}, reqRepoReader(unit.TypeCode))
1018+
}, context.ReferencesGitRepo(), reqRepoReader(unit.TypeCode))
10191019
m.Post("/diffpatch", reqRepoWriter(unit.TypeCode), reqToken(), bind(api.ApplyDiffPatchFileOptions{}), repo.ApplyDiffPatch)
10201020
m.Group("/contents", func() {
10211021
m.Get("", repo.GetContentsList)
@@ -1035,7 +1035,7 @@ func Routes() *web.Route {
10351035
Delete(reqToken(), repo.DeleteTopic)
10361036
}, reqAdmin())
10371037
}, reqAnyRepoReader())
1038-
m.Get("/issue_templates", context.ReferencesGitRepo(false), repo.GetIssueTemplates)
1038+
m.Get("/issue_templates", context.ReferencesGitRepo(), repo.GetIssueTemplates)
10391039
m.Get("/languages", reqRepoReader(unit.TypeCode), repo.GetLanguages)
10401040
}, repoAssignment())
10411041
})

routers/api/v1/repo/blob.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ func GetBlob(ctx *context.APIContext) {
4545
ctx.Error(http.StatusBadRequest, "", "sha not provided")
4646
return
4747
}
48-
if blob, err := files_service.GetBlobBySHA(ctx, ctx.Repo.Repository, sha); err != nil {
48+
49+
if blob, err := files_service.GetBlobBySHA(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, sha); err != nil {
4950
ctx.Error(http.StatusBadRequest, "", err)
5051
} else {
5152
ctx.JSON(http.StatusOK, blob)

routers/api/v1/repo/commits.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ func DownloadCommitDiffOrPatch(ctx *context.APIContext) {
269269
// "404":
270270
// "$ref": "#/responses/notFound"
271271
repoPath := repo_model.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
272+
// TODO: use gitRepo from context
272273
if err := git.GetRawDiff(
273274
ctx,
274275
repoPath,

0 commit comments

Comments
 (0)