Compare commits

..

11 Commits

Author SHA1 Message Date
6543
0bd05a9f1c
Add integration test for API raw content reference formats (#24388)
This pull request adds an integration test to validate the behavior of
raw content API's reference handling for all supported formats .

close  #24242

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
2023-04-28 22:38:22 -04:00
GiteaBot
ef9e0ce9c9 [skip ci] Updated translations via Crowdin 2023-04-29 00:23:39 +00:00
Yarden Shoham
c0ddec8a2a
Revert "Add Debian package registry" (#24412)
Reverts go-gitea/gitea#22854
2023-04-28 18:06:41 -04:00
KN4CK3R
bf77e2163b
Add Debian package registry (#22854)
Co-authored-by: @awkwardbunny

This PR adds a Debian package registry. You can follow [this
tutorial](https://www.baeldung.com/linux/create-debian-package) to build
a *.deb package for testing. Source packages are not supported at the
moment and I did not find documentation of the architecture "all" and
how these packages should be treated.

---------

Co-authored-by: Brian Hong <brian@hongs.me>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
2023-04-28 17:51:36 -04:00
wxiaoguang
bc4e06109d
Make repo size style matches others (commits/branches/tags) (#24408)
The "unit" part shouldn't have bold style.
2023-04-28 17:23:19 -04:00
John Olheiser
bc784a705b
Override alias template to preserve anchor fragment (#24394)
This PR fixes an annoyance where docs aliases aren't preserving their
anchor fragments.

The refactor included aliases to keep old links from dying, but
currently they redirect without their anchor, which was used _often_ to
jump to sections.

This overrides the alias template with an alternative that preserves the
anchor fragment.

To note, this is just a copy of the [embedded
template](5c7b79cf7f/tpl/tplimpl/embedded/templates/alias.html),
but defaults to a JS redirect that preserves the anchor, and uses the
meta tag as a fallback for noscript users.

---------

Signed-off-by: jolheiser <john.olheiser@gmail.com>
2023-04-28 15:51:17 -05:00
Yarden Shoham
3843252938
Changelog 1.19.2 (#24365) (#24403)
Frontport #24365

Add changelog for 1.19.2

Signed-off-by: jolheiser <john.olheiser@gmail.com>
Co-authored-by: John Olheiser <john.olheiser@gmail.com>
Co-authored-by: Giteabot <teabot@gitea.io>
2023-04-28 15:20:52 -04:00
yp05327
5bc9f7fcf9
Improve commit date in commit graph (#24399)
The commit date time is based on server's time zone not user's local
time zone.

Before:

![image](https://user-images.githubusercontent.com/18380374/235074112-cc1e032f-6b43-4876-a1bc-dd48b393866b.png)

After:

![image](https://user-images.githubusercontent.com/18380374/235074056-329811e8-3e81-4b55-b5a1-580ac22b6d72.png)
2023-04-28 14:58:59 -04:00
wxiaoguang
a6450494c3
Fix unclear IsRepositoryExist logic (#24374)
There was only one `IsRepositoryExist` function, it did: `has && isDir`

However it's not right, and it would cause 500 error when creating a new
repository if the dir exists.

Then, it was changed to `has || isDir`, it is still incorrect, it
affects the "adopt repo" logic.

To make the logic clear:

* IsRepositoryModelOrDirExist
* IsRepositoryModelExist
2023-04-28 14:14:26 -04:00
silverwind
572af214a7
Ensure final newline in assets/go-licenses.json (#24407)
This will ensure that the file always has a final newline. I'm not sure
where this bug with inconsistent final newline actually comes from, it
is likely Windows-related.

---------

Co-authored-by: delvh <dev.lh@web.de>
2023-04-28 13:39:18 -04:00
Maarten Becker
ad03c6e0a3
More detailed branch delete message (#22696)
Fix #22624 . Message explains that deleted branch can only be restored for a short time period.
2023-04-28 14:32:32 +08:00
20 changed files with 137 additions and 21 deletions

View File

@ -4,6 +4,53 @@ This changelog goes through all the changes that have been made in each release
without substantial changes to our git log; to see the highlights of what has
been added to each release, please refer to the [blog](https://blog.gitea.io).
## [1.19.2](https://github.com/go-gitea/gitea/releases/tag/1.19.2) - 2023-04-26
* SECURITY
* Require repo scope for PATs for private repos and basic authentication (#24362) (#24364)
* Only delete secrets belonging to its owner (#24284) (#24286)
* API
* Fix typo in API route (#24310) (#24332)
* Fix access token issue on some public endpoints (#24194) (#24259)
* ENHANCEMENTS
* Fix broken clone script on an empty archived repo (#24339) (#24348)
* Fix Monaco IOS keyboard button (#24341) (#24347)
* Don't set meta `theme-color` by default (#24340) (#24346)
* Wrap too long push mirror addresses (#21120) (#24334)
* Add --font-weight-bold and set previous bold to 601 (#24307) (#24331)
* Unify nightly naming across binaries and docker images (#24116) (#24308)
* Fix footer display (#24251) (#24269)
* Fix label color, fix divider in dropdown (#24215) (#24244)
* Vertical widths of containers removed (#24184) (#24211)
* Use correct locale key for forks page (#24172) (#24175)
* Sort repo topic labels by name (#24123) (#24153)
* Highlight selected file in the PR file tree (#23947) (#24126)
* BUGFIXES
* Fix auth check bug (#24382) (#24387)
* Add tags list for repos whose release setting is disabled (#23465) (#24369)
* Fix wrong error info in RepoRefForAPI (#24344) (#24351)
* Fix no edit/close/delete button in org repo project view page (#24349)
* Respect the REGISTER_MANUAL_CONFIRM setting when registering via OIDC (#24035) (#24333)
* Remove org users who belong to no teams (#24247) (#24313)
* Fix bug when deleting wiki with no code write permission (#24274) (#24295)
* Handle canceled workflow as a warning instead of a fail (#24282) (#24292)
* Load reviewer for comments when dismissing a review (#24281) (#24288)
* Show commit history for closed/merged PRs (#24238) (#24261)
* Fix owner team access mode value in team_unit table (#24224)
* Fix issue attachment handling (#24202) (#24221)
* Fix incorrect CORS default values (#24206) (#24217)
* Fix template error in pull request with deleted head repo (#24192) (#24216)
* Don't list root repository on compare page if pulls not allowed (#24183) (#24210)
* Fix calReleaseNumCommitsBehind (#24148) (#24197)
* Fix Org edit page bugs: renaming detection, maxlength (#24161) (#24171)
* Update redis library to support redis v7 (#24114) (#24156)
* Use 1.18's aria role for dropdown menus (#24144) (#24155)
* Fix 2-dot direct compare to use the right base commit (#24133) (#24150)
* Fix incorrect server error content in RunnersList (#24118) (#24121)
* Fix mismatch between hook events and github event types (#24048) (#24091)
* BUILD
* Support converting varchar to nvarchar for mssql database (#24105) (#24168)
## [1.19.1](https://github.com/go-gitea/gitea/releases/tag/v1.19.1) - 2023-04-12
* BREAKING

View File

@ -1104,4 +1104,4 @@
"path": "xorm.io/xorm/LICENSE",
"licenseText": "Copyright (c) 2013 - 2015 The Xorm Authors\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are met:\n\n* Redistributions of source code must retain the above copyright notice, this\n list of conditions and the following disclaimer.\n\n* Redistributions in binary form must reproduce the above copyright notice,\n this list of conditions and the following disclaimer in the documentation\n and/or other materials provided with the distribution.\n\n* Neither the name of the {organization} nor the names of its\n contributors may be used to endorse or promote products derived from\n this software without specific prior written permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\nAND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\nIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\nFOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\nDAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\nSERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\nCAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\nOR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\nOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
}
]
]

View File

@ -82,6 +82,11 @@ func main() {
panic(err)
}
// Ensure file has a final newline
if jsonBytes[len(jsonBytes)-1] != '\n' {
jsonBytes = append(jsonBytes, '\n')
}
err = os.WriteFile(out, jsonBytes, 0o644)
if err != nil {
panic(err)

13
docs/layouts/alias.html Normal file
View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html{{ with site.LanguageCode | default site.Language.Lang }} lang="{{ . }}"{{ end }}>
<head>
<meta charset="utf-8">
<title>{{ .Permalink }}</title>
<link rel="canonical" href="{{ .Permalink }}">
<meta name="robots" content="noindex">
<noscript><meta http-equiv="refresh" content="0; url={{ .Permalink }}"></noscript>
<script>
window.location = "{{ .Permalink }}" + window.location.search + window.location.hash;
</script>
</head>
</html>

View File

@ -726,12 +726,9 @@ func GetRepositoriesMapByIDs(ids []int64) (map[int64]*Repository, error) {
return repos, db.GetEngine(db.DefaultContext).In("id", ids).Find(&repos)
}
// IsRepositoryExist returns true if the repository with given name under user has already existed.
func IsRepositoryExist(ctx context.Context, u *user_model.User, repoName string) (bool, error) {
has, err := db.GetEngine(ctx).Get(&Repository{
OwnerID: u.ID,
LowerName: strings.ToLower(repoName),
})
// IsRepositoryModelOrDirExist returns true if the repository with given name under user has already existed.
func IsRepositoryModelOrDirExist(ctx context.Context, u *user_model.User, repoName string) (bool, error) {
has, err := IsRepositoryModelExist(ctx, u, repoName)
if err != nil {
return false, err
}
@ -739,6 +736,13 @@ func IsRepositoryExist(ctx context.Context, u *user_model.User, repoName string)
return has || isDir, err
}
func IsRepositoryModelExist(ctx context.Context, u *user_model.User, repoName string) (bool, error) {
return db.GetEngine(ctx).Get(&Repository{
OwnerID: u.ID,
LowerName: strings.ToLower(repoName),
})
}
// GetTemplateRepo populates repo.TemplateRepo for a generated repository and
// returns an error on failure (NOTE: no error is returned for
// non-generated repositories, and TemplateRepo will be left untouched)

View File

@ -116,7 +116,7 @@ func CheckCreateRepository(doer, u *user_model.User, name string, overwriteOrAdo
return err
}
has, err := IsRepositoryExist(db.DefaultContext, u, name)
has, err := IsRepositoryModelOrDirExist(db.DefaultContext, u, name)
if err != nil {
return fmt.Errorf("IsRepositoryExist: %w", err)
} else if has {
@ -147,7 +147,7 @@ func ChangeRepositoryName(doer *user_model.User, repo *Repository, newRepoName s
return err
}
has, err := IsRepositoryExist(db.DefaultContext, repo.Owner, newRepoName)
has, err := IsRepositoryModelOrDirExist(db.DefaultContext, repo.Owner, newRepoName)
if err != nil {
return fmt.Errorf("IsRepositoryExist: %w", err)
} else if has {

View File

@ -172,7 +172,7 @@ func CreatePendingRepositoryTransfer(ctx context.Context, doer, newOwner *user_m
}
// Check if new owner has repository with same name.
if has, err := repo_model.IsRepositoryExist(ctx, newOwner, repo.Name); err != nil {
if has, err := repo_model.IsRepositoryModelExist(ctx, newOwner, repo.Name); err != nil {
return fmt.Errorf("IsRepositoryExist: %w", err)
} else if has {
return repo_model.ErrRepoAlreadyExist{
@ -249,7 +249,7 @@ func TransferOwnership(doer *user_model.User, newOwnerName string, repo *repo_mo
newOwnerName = newOwner.Name // ensure capitalisation matches
// Check if new owner has repository with same name.
if has, err := repo_model.IsRepositoryExist(ctx, newOwner, repo.Name); err != nil {
if has, err := repo_model.IsRepositoryModelOrDirExist(ctx, newOwner, repo.Name); err != nil {
return fmt.Errorf("IsRepositoryExist: %w", err)
} else if has {
return repo_model.ErrRepoAlreadyExist{

View File

@ -35,7 +35,7 @@ func CreateRepositoryByExample(ctx context.Context, doer, u *user_model.User, re
return err
}
has, err := repo_model.IsRepositoryExist(ctx, u, repo.Name)
has, err := repo_model.IsRepositoryModelExist(ctx, u, repo.Name)
if err != nil {
return fmt.Errorf("IsRepositoryExist: %w", err)
} else if has {

View File

@ -18,3 +18,7 @@ func (su *StringUtils) HasPrefix(s, prefix string) bool {
func (su *StringUtils) Contains(s, substr string) bool {
return strings.Contains(s, substr)
}
func (su *StringUtils) Split(s, sep string) []string {
return strings.Split(s, sep)
}

View File

@ -13,6 +13,7 @@ import (
"code.gitea.io/gitea/modules/options"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/translation/i18n"
"code.gitea.io/gitea/modules/util"
"golang.org/x/text/language"
"golang.org/x/text/message"
@ -241,5 +242,12 @@ func (l *locale) TrN(cnt any, key1, keyN string, args ...any) string {
func (l *locale) PrettyNumber(v any) string {
// TODO: this mechanism is not good enough, the complete solution is to switch the translation system to ICU message format
if s, ok := v.(string); ok {
if num, err := util.ToInt64(s); err == nil {
v = num
} else if num, err := util.ToFloat64(s); err == nil {
v = num
}
}
return l.msgPrinter.Sprintf("%v", number.Decimal(v))
}

View File

@ -21,7 +21,12 @@ func TestPrettyNumber(t *testing.T) {
l := NewLocale("id-ID")
assert.EqualValues(t, "1.000.000", l.PrettyNumber(1000000))
assert.EqualValues(t, "1.000.000,1", l.PrettyNumber(1000000.1))
assert.EqualValues(t, "1.000.000", l.PrettyNumber("1000000"))
assert.EqualValues(t, "1.000.000", l.PrettyNumber("1000000.0"))
assert.EqualValues(t, "1.000.000,1", l.PrettyNumber("1000000.1"))
l = NewLocale("nosuch")
assert.EqualValues(t, "1,000,000", l.PrettyNumber(1000000))
assert.EqualValues(t, "1,000,000.1", l.PrettyNumber(1000000.1))
}

View File

@ -2380,7 +2380,7 @@ branch.already_exists = A branch named "%s" already exists.
branch.delete_head = Delete
branch.delete = Delete Branch "%s"
branch.delete_html = Delete Branch
branch.delete_desc = Deleting a branch is permanent. It <strong>CANNOT</strong> be undone. Continue?
branch.delete_desc = Deleting a branch is permanent. Although the deleted branch may exist for a short time before cleaning up, in most cases it CANNOT be undone. Continue?
branch.deletion_success = Branch "%s" has been deleted.
branch.deletion_failed = Failed to delete branch "%s".
branch.delete_branch_has_new_commits = Branch "%s" cannot be deleted because new commits have been added after merging.

View File

@ -61,7 +61,7 @@ new_project_column=创建列
manage_org=管理我的组织
admin_panel=管理后台
account_settings=帐户设置
settings=帐户设置
settings=设置
your_profile=个人信息
your_starred=已点赞
your_settings=设置

View File

@ -95,7 +95,7 @@ func AdoptRepository(ctx *context.APIContext) {
}
// check not a repo
has, err := repo_model.IsRepositoryExist(ctx, ctxUser, repoName)
has, err := repo_model.IsRepositoryModelExist(ctx, ctxUser, repoName)
if err != nil {
ctx.InternalServerError(err)
return
@ -157,7 +157,7 @@ func DeleteUnadoptedRepository(ctx *context.APIContext) {
}
// check not a repo
has, err := repo_model.IsRepositoryExist(ctx, ctxUser, repoName)
has, err := repo_model.IsRepositoryModelExist(ctx, ctxUser, repoName)
if err != nil {
ctx.InternalServerError(err)
return

View File

@ -133,7 +133,7 @@ func AdoptOrDeleteRepository(ctx *context.Context) {
repoName := dirSplit[1]
// check not a repo
has, err := repo_model.IsRepositoryExist(ctx, ctxUser, repoName)
has, err := repo_model.IsRepositoryModelExist(ctx, ctxUser, repoName)
if err != nil {
ctx.ServerError("IsRepositoryExist", err)
return

View File

@ -31,7 +31,7 @@ func AdoptOrDeleteRepository(ctx *context.Context) {
root := user_model.UserPath(ctxUser.LowerName)
// check not a repo
has, err := repo_model.IsRepositoryExist(ctx, ctxUser, dir)
has, err := repo_model.IsRepositoryModelExist(ctx, ctxUser, dir)
if err != nil {
ctx.ServerError("IsRepositoryExist", err)
return

View File

@ -206,7 +206,7 @@ func DeleteUnadoptedRepository(ctx context.Context, doer, u *user_model.User, re
}
}
if exist, err := repo_model.IsRepositoryExist(ctx, u, repoName); err != nil {
if exist, err := repo_model.IsRepositoryModelExist(ctx, u, repoName); err != nil {
return err
} else if exist {
return repo_model.ErrRepoAlreadyExist{

View File

@ -71,7 +71,7 @@
{{$userName}}
{{end}}
</span>
<span class="time gt-df gt-ac">{{$commit.Date}}</span>
<span class="time gt-df gt-ac">{{DateTime "full" $commit.Date}}</span>
{{end}}
</li>
{{end}}

View File

@ -15,7 +15,9 @@
</div>
{{end}}
<div class="item">
<span>{{svg "octicon-database"}} <b>{{FileSize .Repository.Size}}</b></span>
{{$fileSizeFormatted := FileSize .Repository.Size}}{{/* the formatted string is always "{val} {unit}" */}}
{{$fileSizeFields := StringUtils.Split $fileSizeFormatted " "}}
<span>{{svg "octicon-database"}} <b>{{.locale.PrettyNumber (index $fileSizeFields 0)}}</b> {{index $fileSizeFields 1}}</span>
</div>
{{end}}
</div>

View File

@ -4,6 +4,7 @@
package integration
import (
"io"
"net/http"
"net/url"
"testing"
@ -159,3 +160,30 @@ func testAPIGetContents(t *testing.T, u *url.URL) {
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/%s?token=%s", user3.Name, repo3.Name, treePath, token2)
MakeRequest(t, req, http.StatusOK)
}
func TestAPIGetContentsRefFormats(t *testing.T) {
onGiteaRun(t, func(t *testing.T, u *url.URL) {
file := "README.md"
sha := "65f1bf27bc3bf70f64657658635e66094edbcb4d"
content := "# repo1\n\nDescription for repo1"
noRef := setting.AppURL + "api/v1/repos/user2/repo1/raw/" + file
refInPath := setting.AppURL + "api/v1/repos/user2/repo1/raw/" + sha + "/" + file
refInQuery := setting.AppURL + "api/v1/repos/user2/repo1/raw/" + file + "?ref=" + sha
resp := MakeRequest(t, NewRequest(t, http.MethodGet, noRef), http.StatusOK)
raw, err := io.ReadAll(resp.Body)
assert.NoError(t, err)
assert.EqualValues(t, content, string(raw))
resp = MakeRequest(t, NewRequest(t, http.MethodGet, refInPath), http.StatusOK)
raw, err = io.ReadAll(resp.Body)
assert.NoError(t, err)
assert.EqualValues(t, content, string(raw))
resp = MakeRequest(t, NewRequest(t, http.MethodGet, refInQuery), http.StatusOK)
raw, err = io.ReadAll(resp.Body)
assert.NoError(t, err)
assert.EqualValues(t, content, string(raw))
})
}