Skip to content

Commit f5bf43a

Browse files
authored
Merge branch 'main' into fix-flushall-loop
2 parents 8cb77da + c258131 commit f5bf43a

Some content is hidden

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

50 files changed

+499
-151
lines changed

.golangci.yml

+4
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,7 @@ issues:
110110
- text: "exitAfterDefer:"
111111
linters:
112112
- gocritic
113+
- path: modules/graceful/manager_windows.go
114+
linters:
115+
- staticcheck
116+
text: "svc.IsAnInteractiveSession is deprecated: Use IsWindowsService instead."

docs/content/doc/advanced/customizing-gitea.en-us.md

+9-13
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,18 @@ To make Gitea serve custom public files (like pages and images), use the folder
5858
For example, a file `image.png` stored in `$GITEA_CUSTOM/public/`, can be accessed with
5959
the url `http://gitea.domain.tld/image.png`.
6060

61-
## Changing the default logo
61+
## Changing the logo
6262

63-
To build a custom logo replace `assets/logo.svg` and run `make generate-images`. This will update
64-
these customizable logo files which you can then place in `$GITEA_CUSTOM/public/img` on your server:
63+
To build a custom logo clone the Gitea source repository, replace `assets/logo.svg` and run
64+
`make generate-images`. This will update below output files which you can then place in `$GITEA_CUSTOM/public/img` on your server:
6565

66-
- `public/img/logo.svg`
67-
- `public/img/logo.png`
68-
- `public/img/favicon.png`
69-
- `public/img/avatar_default.png`
70-
- `public/img/apple-touch-icon.png`
66+
- `public/img/logo.svg` - Used for favicon, site icon, app icon
67+
- `public/img/logo.png` - Used for Open Graph
68+
- `public/img/favicon.png` - Used as fallback for browsers that don't support SVG favicons
69+
- `public/img/avatar_default.png` - Used as the default avatar image
70+
- `public/img/apple-touch-icon.png` - Used on iOS devices for bookmarks
7171

72-
## Changing the default avatar
73-
74-
Either generate it via above method or place the png image at the following path:
75-
76-
- `$GITEA_CUSTOM/public/img/avatar_default.png`
72+
In case the source image is not in vector format, you can attempt to convert a raster image using tools like [this](https://www.aconvert.com/image/png-to-svg/).
7773

7874
## Customizing Gitea pages and resources
7975

docs/content/doc/advanced/external-renderers.en-us.md

+33
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,36 @@ Once your configuration changes have been made, restart Gitea to have changes ta
9898

9999
**Note**: Prior to Gitea 1.12 there was a single `markup.sanitiser` section with keys that were redefined for multiple rules, however,
100100
there were significant problems with this method of configuration necessitating configuration through multiple sections.
101+
102+
## Customizing CSS
103+
The external renderer is specified in the .ini in the format `[markup.XXXXX]` and the HTML supplied by your external renderer will be wrapped in a `<div>` with classes `markup` and `XXXXX`. The `markup` class provides out of the box styling (as does `markdown` if `XXXXX` is `markdown`). Otherwise you can use these classes to specifically target the contents of your rendered HTML.
104+
105+
And so you could write some CSS:
106+
```css
107+
.markup.XXXXX html {
108+
font-size: 100%;
109+
overflow-y: scroll;
110+
-webkit-text-size-adjust: 100%;
111+
-ms-text-size-adjust: 100%;
112+
}
113+
114+
.markup.XXXXX body {
115+
color: #444;
116+
font-family: Georgia, Palatino, 'Palatino Linotype', Times, 'Times New Roman', serif;
117+
font-size: 12px;
118+
line-height: 1.7;
119+
padding: 1em;
120+
margin: auto;
121+
max-width: 42em;
122+
background: #fefefe;
123+
}
124+
125+
.markup.XXXXX p {
126+
color: orangered;
127+
}
128+
```
129+
130+
Add your stylesheet to your custom directory e.g `custom/public/css/my-style-XXXXX.css` and import it using a custom header file `custom/templates/custom/header.tmpl`:
131+
```html
132+
<link type="text/css" href="{{AppSubUrl}}/css/my-style-XXXXX.css" />
133+
```

integrations/release_test.go

+82-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import (
1010
"testing"
1111
"time"
1212

13+
"code.gitea.io/gitea/models"
1314
"code.gitea.io/gitea/modules/setting"
1415
"code.gitea.io/gitea/modules/test"
1516

17+
"github.com/PuerkitoBio/goquery"
1618
"github.com/stretchr/testify/assert"
1719
"github.com/unknwon/i18n"
1820
)
@@ -83,7 +85,7 @@ func TestCreateRelease(t *testing.T) {
8385
session := loginUser(t, "user2")
8486
createNewRelease(t, session, "/user2/repo1", "v0.0.1", "v0.0.1", false, false)
8587

86-
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", i18n.Tr("en", "repo.release.stable"), 2)
88+
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", i18n.Tr("en", "repo.release.stable"), 3)
8789
}
8890

8991
func TestCreateReleasePreRelease(t *testing.T) {
@@ -92,7 +94,7 @@ func TestCreateReleasePreRelease(t *testing.T) {
9294
session := loginUser(t, "user2")
9395
createNewRelease(t, session, "/user2/repo1", "v0.0.1", "v0.0.1", true, false)
9496

95-
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", i18n.Tr("en", "repo.release.prerelease"), 2)
97+
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", i18n.Tr("en", "repo.release.prerelease"), 3)
9698
}
9799

98100
func TestCreateReleaseDraft(t *testing.T) {
@@ -101,7 +103,7 @@ func TestCreateReleaseDraft(t *testing.T) {
101103
session := loginUser(t, "user2")
102104
createNewRelease(t, session, "/user2/repo1", "v0.0.1", "v0.0.1", false, true)
103105

104-
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", i18n.Tr("en", "repo.release.draft"), 2)
106+
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", i18n.Tr("en", "repo.release.draft"), 3)
105107
}
106108

107109
func TestCreateReleasePaging(t *testing.T) {
@@ -127,3 +129,80 @@ func TestCreateReleasePaging(t *testing.T) {
127129
session2 := loginUser(t, "user4")
128130
checkLatestReleaseAndCount(t, session2, "/user2/repo1", "v0.0.11", i18n.Tr("en", "repo.release.stable"), 10)
129131
}
132+
133+
func TestViewReleaseListNoLogin(t *testing.T) {
134+
defer prepareTestEnv(t)()
135+
136+
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
137+
138+
link := repo.Link() + "/releases"
139+
140+
req := NewRequest(t, "GET", link)
141+
rsp := MakeRequest(t, req, http.StatusOK)
142+
143+
htmlDoc := NewHTMLParser(t, rsp.Body)
144+
releases := htmlDoc.Find("#release-list li.ui.grid")
145+
assert.Equal(t, 1, releases.Length())
146+
147+
links := make([]string, 0, 5)
148+
releases.Each(func(i int, s *goquery.Selection) {
149+
link, exist := s.Find(".release-list-title a").Attr("href")
150+
if !exist {
151+
return
152+
}
153+
links = append(links, link)
154+
})
155+
156+
assert.EqualValues(t, []string{"/user2/repo1/releases/tag/v1.1"}, links)
157+
}
158+
159+
func TestViewReleaseListLogin(t *testing.T) {
160+
defer prepareTestEnv(t)()
161+
162+
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
163+
164+
link := repo.Link() + "/releases"
165+
166+
session := loginUser(t, "user1")
167+
req := NewRequest(t, "GET", link)
168+
rsp := session.MakeRequest(t, req, http.StatusOK)
169+
170+
htmlDoc := NewHTMLParser(t, rsp.Body)
171+
releases := htmlDoc.Find("#release-list li.ui.grid")
172+
assert.Equal(t, 2, releases.Length())
173+
174+
links := make([]string, 0, 5)
175+
releases.Each(func(i int, s *goquery.Selection) {
176+
link, exist := s.Find(".release-list-title a").Attr("href")
177+
if !exist {
178+
return
179+
}
180+
links = append(links, link)
181+
})
182+
183+
assert.EqualValues(t, []string{"/user2/repo1/releases/tag/draft-release",
184+
"/user2/repo1/releases/tag/v1.1"}, links)
185+
}
186+
187+
func TestViewTagsList(t *testing.T) {
188+
defer prepareTestEnv(t)()
189+
190+
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
191+
192+
link := repo.Link() + "/tags"
193+
194+
session := loginUser(t, "user1")
195+
req := NewRequest(t, "GET", link)
196+
rsp := session.MakeRequest(t, req, http.StatusOK)
197+
198+
htmlDoc := NewHTMLParser(t, rsp.Body)
199+
tags := htmlDoc.Find(".tag-list tr")
200+
assert.Equal(t, 2, tags.Length())
201+
202+
tagNames := make([]string, 0, 5)
203+
tags.Each(func(i int, s *goquery.Selection) {
204+
tagNames = append(tagNames, s.Find(".tag a.df.ac").Text())
205+
})
206+
207+
assert.EqualValues(t, []string{"delete-tag", "v1.1"}, tagNames)
208+
}

integrations/user_avatar_test.go

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// Copyright 2021 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package integrations
6+
7+
import (
8+
"bytes"
9+
"image/png"
10+
"io"
11+
"mime/multipart"
12+
"net/http"
13+
"net/url"
14+
"strings"
15+
"testing"
16+
17+
"code.gitea.io/gitea/models"
18+
"code.gitea.io/gitea/modules/avatar"
19+
"github.com/stretchr/testify/assert"
20+
)
21+
22+
func TestUserAvatar(t *testing.T) {
23+
onGiteaRun(t, func(t *testing.T, u *url.URL) {
24+
user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of the repo3, is an org
25+
26+
seed := user2.Email
27+
if len(seed) == 0 {
28+
seed = user2.Name
29+
}
30+
31+
img, err := avatar.RandomImage([]byte(seed))
32+
if err != nil {
33+
assert.NoError(t, err)
34+
return
35+
}
36+
37+
session := loginUser(t, "user2")
38+
csrf := GetCSRF(t, session, "/user/settings")
39+
40+
imgData := &bytes.Buffer{}
41+
42+
body := &bytes.Buffer{}
43+
44+
//Setup multi-part
45+
writer := multipart.NewWriter(body)
46+
writer.WriteField("source", "local")
47+
part, err := writer.CreateFormFile("avatar", "avatar-for-testuseravatar.png")
48+
if err != nil {
49+
assert.NoError(t, err)
50+
return
51+
}
52+
53+
if err := png.Encode(imgData, img); err != nil {
54+
assert.NoError(t, err)
55+
return
56+
}
57+
58+
if _, err := io.Copy(part, imgData); err != nil {
59+
assert.NoError(t, err)
60+
return
61+
}
62+
63+
if err := writer.Close(); err != nil {
64+
assert.NoError(t, err)
65+
return
66+
}
67+
68+
req := NewRequestWithBody(t, "POST", "/user/settings/avatar", body)
69+
req.Header.Add("X-Csrf-Token", csrf)
70+
req.Header.Add("Content-Type", writer.FormDataContentType())
71+
72+
session.MakeRequest(t, req, http.StatusFound)
73+
74+
user2 = models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of the repo3, is an org
75+
76+
req = NewRequest(t, "GET", user2.AvatarLink())
77+
resp := session.MakeRequest(t, req, http.StatusFound)
78+
location := resp.Header().Get("Location")
79+
if !strings.HasPrefix(location, "/avatars") {
80+
assert.Fail(t, "Avatar location is not local: %s", location)
81+
}
82+
req = NewRequest(t, "GET", location)
83+
session.MakeRequest(t, req, http.StatusOK)
84+
85+
// Can't test if the response matches because the image is regened on upload but checking that this at least doesn't give a 404 should be enough.
86+
})
87+
}

models/fixtures/release.yml

+12
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,15 @@
4343
is_tag: true
4444
created_unix: 946684800
4545

46+
-
47+
id: 4
48+
repo_id: 1
49+
publisher_id: 2
50+
tag_name: "draft-release"
51+
lower_tag_name: "draft-release"
52+
target: "master"
53+
title: "draft-release"
54+
is_draft: true
55+
is_prerelease: false
56+
is_tag: false
57+
created_unix: 1619524806

models/models.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ func DumpDatabase(filePath, dbType string) error {
320320
ID int64 `xorm:"pk autoincr"`
321321
Version int64
322322
}
323-
t, err := x.TableInfo(Version{})
323+
t, err := x.TableInfo(&Version{})
324324
if err != nil {
325325
return err
326326
}

models/models_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestDumpDatabase(t *testing.T) {
2525
ID int64 `xorm:"pk autoincr"`
2626
Version int64
2727
}
28-
assert.NoError(t, x.Sync2(Version{}))
28+
assert.NoError(t, x.Sync2(new(Version)))
2929

3030
for _, dbName := range setting.SupportedDatabases {
3131
dbType := setting.GetDBTypeByName(dbName)

0 commit comments

Comments
 (0)