Skip to content

Commit 320f547

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Prevent NPE whilst migrating if there is a team request review (go-gitea#19855) [skip ci] Updated translations via Crowdin Add support for rendering terminal output with colors (go-gitea#19497) Fix viewed images not loading in a PR (go-gitea#19919) Remove out-dated comments (go-gitea#19921) Automatically render wiki TOC (go-gitea#19873) Improve wording on delete access token modal (go-gitea#19909) [skip ci] Updated translations via Crowdin Add breaking email restrictions checker in doctor (go-gitea#19903) Ensure minimum mirror interval is reported on settings page (go-gitea#19895) Improve UX on modal for deleting an access token (go-gitea#19894) update discord invite (go-gitea#19907) Only log non ErrNotExist errors in git.GetNote (go-gitea#19884) [skip ci] Updated translations via Crowdin Update frontend guideline (go-gitea#19901) Make AppDataPath absolute against the AppWorkPath if it is not (go-gitea#19815)
2 parents 39c0dc7 + 7948cb3 commit 320f547

Some content is hidden

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

55 files changed

+805
-113
lines changed

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ contact_links:
44
url: https://tinyurl.com/security-gitea
55
about: For security concerns, please send a mail to [email protected] instead of opening a public issue.
66
- name: Discord Server
7-
url: https://discord.gg/gitea
7+
url: https://discord.gg/Gitea
88
about: Please ask questions and discuss configuration or deployment problems here.
99
- name: Discourse Forum
1010
url: https://discourse.gitea.io

docs/content/doc/developers/guidelines-frontend.md

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ The HTML pages are rendered by [Go HTML Template](https://pkg.go.dev/html/templa
2727

2828
The source files can be found in the following directories:
2929
* **Less styles:** `web_src/less/`
30-
* **Javascript files:** `web_src/js/`
31-
* **Vue layouts:** `web_src/js/components/`
32-
* **HTML templates:** `templates/`
30+
* **JavaScript files:** `web_src/js/`
31+
* **Vue components:** `web_src/js/components/`
32+
* **Go HTML templates:** `templates/`
3333

3434
## General Guidelines
3535

@@ -40,24 +40,29 @@ We recommend [Google HTML/CSS Style Guide](https://google.github.io/styleguide/h
4040
1. Every feature (Fomantic-UI/jQuery module) should be put in separate files/directories.
4141
2. HTML ids and classes should use kebab-case.
4242
3. HTML ids and classes used in JavaScript should be unique for the whole project, and should contain 2-3 feature related keywords. We recommend to use the `js-` prefix for classes that are only used in JavaScript.
43-
4. jQuery events across different features should use their own namespaces.
44-
5. CSS styling for classes provided by frameworks should not be overwritten. Always use new class-names to overwrite framework styles. We recommend to use the `us-` prefix for user defined styles.
43+
4. jQuery events across different features could use their own namespaces if there are potential conflicts.
44+
5. CSS styling for classes provided by frameworks should not be overwritten. Always use new class-names with 2-3 feature related keywords to overwrite framework styles.
4545
6. The backend can pass complex data to the frontend by using `ctx.PageData["myModuleData"] = map[]{}`
4646
7. Simple pages and SEO-related pages use Go HTML Template render to generate static Fomantic-UI HTML output. Complex pages can use Vue2 (or Vue3 in future).
4747

4848

4949
### Framework Usage
5050

51-
Mixing different frameworks together is highly discouraged. A JavaScript module should follow one major framework and follow the framework's best practice.
51+
Mixing different frameworks together is discouraged, it makes the code difficult to be maintained.
52+
A JavaScript module should follow one major framework and follow the framework's best practice.
5253

5354
Recommended implementations:
54-
* Vue + Native
55+
* Vue + Vanilla JS
5556
* Fomantic-UI (jQuery)
56-
* Native only
57+
* Vanilla JS
5758

5859
Discouraged implementations:
59-
* Vue + jQuery
60-
* jQuery + Native
60+
* Vue + Fomantic-UI (jQuery)
61+
* jQuery + Vanilla JS
62+
63+
To make UI consistent, Vue components can use Fomantic-UI CSS classes.
64+
Although mixing different frameworks is discouraged,
65+
it should also work if the mixing is necessary and the code is well-designed and maintainable.
6166

6267
### `async` Functions
6368

@@ -75,7 +80,8 @@ Some lint rules and IDEs also have warnings if the returned Promise is not handl
7580

7681
### HTML Attributes and `dataset`
7782

78-
We forbid `dataset` usage, its camel-casing behaviour makes it hard to grep for attributes. However there are still some special cases, so the current guideline is:
83+
The usage of `dataset` is forbidden, its camel-casing behaviour makes it hard to grep for attributes.
84+
However, there are still some special cases, so the current guideline is:
7985

8086
* For legacy code:
8187
* `$.data()` should be refactored to `$.attr()`.
@@ -86,6 +92,10 @@ We forbid `dataset` usage, its camel-casing behaviour makes it hard to grep for
8692
* never bind any user data to a DOM node, use a suitable design pattern to describe the relation between node and data.
8793

8894

95+
### Legacy Code
96+
97+
A lot of legacy code already existed before this document's written. It's recommended to refactor legacy code to follow the guidelines.
98+
8999
### Vue2/Vue3 and JSX
90100

91101
Gitea is using Vue2 now, we plan to upgrade to Vue3. We decided not to introduce JSX to keep the HTML and the JavaScript code separated.

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ require (
1515
github.com/PuerkitoBio/goquery v1.8.0
1616
github.com/alecthomas/chroma v0.10.0
1717
github.com/blevesearch/bleve/v2 v2.3.2
18+
github.com/buildkite/terminal-to-html/v3 v3.6.1
1819
github.com/caddyserver/certmagic v0.16.1
1920
github.com/chi-middleware/proxy v1.1.1
2021
github.com/denisenkom/go-mssqldb v0.12.0
@@ -42,7 +43,7 @@ require (
4243
github.com/gogs/cron v0.0.0-20171120032916-9f6c956d3e14
4344
github.com/gogs/go-gogs-client v0.0.0-20210131175652-1d7215cd8d85
4445
github.com/golang-jwt/jwt/v4 v4.4.1
45-
github.com/google/go-github/v39 v39.2.0
46+
github.com/google/go-github/v45 v45.0.0
4647
github.com/google/pprof v0.0.0-20220509035851-59ca7ad80af3
4748
github.com/google/uuid v1.3.0
4849
github.com/gorilla/feeds v1.1.1

go.sum

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ github.com/boombuler/barcode v1.0.1/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl
265265
github.com/bradfitz/gomemcache v0.0.0-20190329173943-551aad21a668/go.mod h1:H0wQNHz2YrLsuXOZozoeDmnHXkNCRmMW0gwFWDfEZDA=
266266
github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b h1:L/QXpzIa3pOvUGt1D1lA5KjYhPBAN/3iWdP7xeFS9F0=
267267
github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b/go.mod h1:H0wQNHz2YrLsuXOZozoeDmnHXkNCRmMW0gwFWDfEZDA=
268+
github.com/buildkite/terminal-to-html/v3 v3.6.1 h1:yHS+GXsPDXevb67YXjkVwZ4tolDCgPYa9RVOrzHlgGE=
269+
github.com/buildkite/terminal-to-html/v3 v3.6.1/go.mod h1:g0ME1XqbkBSgXR9YmlIHcJIjzaMyWW+HbsG0rPb5puo=
268270
github.com/caarlos0/ctrlc v1.0.0/go.mod h1:CdXpj4rmq0q/1Eb44M9zi2nKB0QraNKuRGYGrrHhcQw=
269271
github.com/caddyserver/certmagic v0.16.1 h1:rdSnjcUVJojmL4M0efJ+yHXErrrijS4YYg3FuwRdJkI=
270272
github.com/caddyserver/certmagic v0.16.1/go.mod h1:jKQ5n+ViHAr6DbPwEGLTSM2vDwTO6EvCKBblBRUvvuQ=
@@ -733,11 +735,11 @@ github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
733735
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
734736
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
735737
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
736-
github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
737738
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
739+
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
738740
github.com/google/go-github/v28 v28.1.1/go.mod h1:bsqJWQX05omyWVmc00nEUql9mhQyv38lDZ8kPZcQVoM=
739-
github.com/google/go-github/v39 v39.2.0 h1:rNNM311XtPOz5rDdsJXAp2o8F67X9FnROXTvto3aSnQ=
740-
github.com/google/go-github/v39 v39.2.0/go.mod h1:C1s8C5aCC9L+JXIYpJM5GYytdX52vC1bLvHEF1IhBrE=
741+
github.com/google/go-github/v45 v45.0.0 h1:LU0WBjYidxIVyx7PZeWb+FP4JZJ3Wh3FQgdumnGqiLs=
742+
github.com/google/go-github/v45 v45.0.0/go.mod h1:FObaZJEDSTa/WGCzZ2Z3eoCDXWJKMenWWTrd8jrta28=
741743
github.com/google/go-licenses v0.0.0-20210329231322-ce1d9163b77d/go.mod h1:+TYOmkVoJOpwnS0wfdsJCV9CoD5nJYsHoFk/0CrTK4M=
742744
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
743745
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
@@ -1499,6 +1501,7 @@ github.com/urfave/cli v1.22.4/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtX
14991501
github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
15001502
github.com/urfave/cli v1.22.9 h1:cv3/KhXGBGjEXLC4bH0sLuJ9BewaAbpk5oyMOveu4pw=
15011503
github.com/urfave/cli v1.22.9/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
1504+
github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
15021505
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
15031506
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
15041507
github.com/vektah/gqlparser v1.1.2/go.mod h1:1ycwN7Ij5njmMkPPAOaRFY4rET2Enx7IkVv3vaXspKw=

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"code.gitea.io/gitea/modules/setting"
1919

2020
// register supported doc types
21+
_ "code.gitea.io/gitea/modules/markup/console"
2122
_ "code.gitea.io/gitea/modules/markup/csv"
2223
_ "code.gitea.io/gitea/modules/markup/markdown"
2324
_ "code.gitea.io/gitea/modules/markup/orgmode"

modules/doctor/breaking.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright 2022 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 doctor
6+
7+
import (
8+
"context"
9+
"fmt"
10+
11+
"code.gitea.io/gitea/models/db"
12+
"code.gitea.io/gitea/models/user"
13+
"code.gitea.io/gitea/modules/log"
14+
15+
"xorm.io/builder"
16+
)
17+
18+
func iterateUserAccounts(ctx context.Context, each func(*user.User) error) error {
19+
err := db.Iterate(
20+
ctx,
21+
new(user.User),
22+
builder.Gt{"id": 0},
23+
func(idx int, bean interface{}) error {
24+
return each(bean.(*user.User))
25+
},
26+
)
27+
return err
28+
}
29+
30+
// Since 1.16.4 new restrictions has been set on email addresses. However users with invalid email
31+
// addresses would be currently facing a error due to their invalid email address.
32+
// Ref: https://github.com/go-gitea/gitea/pull/19085 & https://github.com/go-gitea/gitea/pull/17688
33+
func checkUserEmail(ctx context.Context, logger log.Logger, _ bool) error {
34+
// We could use quirky SQL to get all users that start without a [a-zA-Z0-9], but that would mean
35+
// DB provider-specific SQL and only works _now_. So instead we iterate trough all user accounts and
36+
// use the user.ValidateEmail function to be future-proof.
37+
var invalidUserCount int64
38+
if err := iterateUserAccounts(ctx, func(u *user.User) error {
39+
// Only check for users, skip
40+
if u.Type != user.UserTypeIndividual {
41+
return nil
42+
}
43+
44+
if err := user.ValidateEmail(u.Email); err != nil {
45+
invalidUserCount++
46+
logger.Warn("User[id=%d name=%q] have not a valid e-mail: %v", u.ID, u.Name, err)
47+
}
48+
return nil
49+
}); err != nil {
50+
return fmt.Errorf("iterateUserAccounts: %v", err)
51+
}
52+
53+
if invalidUserCount == 0 {
54+
logger.Info("All users have a valid e-mail.")
55+
} else {
56+
logger.Warn("%d user(s) have a non-valid e-mail.", invalidUserCount)
57+
}
58+
return nil
59+
}
60+
61+
func init() {
62+
Register(&Check{
63+
Title: "Check if users has an valid email address",
64+
Name: "check-user-email",
65+
IsDefault: false,
66+
Run: checkUserEmail,
67+
Priority: 9,
68+
})
69+
}

modules/git/notes_nogogit.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ func GetNote(ctx context.Context, repo *Repository, commitID string, note *Note)
4646
commitID = commitID[2:]
4747
}
4848
if err != nil {
49-
log.Error("Unable to find git note corresponding to the commit %q. Error: %v", originalCommitID, err)
49+
// Err may have been updated by the SubTree we need to recheck if it's again an ErrNotExist
50+
if !IsErrNotExist(err) {
51+
log.Error("Unable to find git note corresponding to the commit %q. Error: %v", originalCommitID, err)
52+
}
5053
return err
5154
}
5255
}

modules/markup/console/console.go

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// Copyright 2022 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 console
6+
7+
import (
8+
"bytes"
9+
"io"
10+
"path/filepath"
11+
"regexp"
12+
"strings"
13+
14+
"code.gitea.io/gitea/modules/markup"
15+
"code.gitea.io/gitea/modules/setting"
16+
17+
trend "github.com/buildkite/terminal-to-html/v3"
18+
"github.com/go-enry/go-enry/v2"
19+
)
20+
21+
// MarkupName describes markup's name
22+
var MarkupName = "console"
23+
24+
func init() {
25+
markup.RegisterRenderer(Renderer{})
26+
}
27+
28+
// Renderer implements markup.Renderer
29+
type Renderer struct{}
30+
31+
// Name implements markup.Renderer
32+
func (Renderer) Name() string {
33+
return MarkupName
34+
}
35+
36+
// NeedPostProcess implements markup.Renderer
37+
func (Renderer) NeedPostProcess() bool { return false }
38+
39+
// Extensions implements markup.Renderer
40+
func (Renderer) Extensions() []string {
41+
return []string{".sh-session"}
42+
}
43+
44+
// SanitizerRules implements markup.Renderer
45+
func (Renderer) SanitizerRules() []setting.MarkupSanitizerRule {
46+
return []setting.MarkupSanitizerRule{
47+
{Element: "span", AllowAttr: "class", Regexp: regexp.MustCompile(`^term-((fg[ix]?|bg)\d+|container)$`)},
48+
}
49+
}
50+
51+
// SanitizerDisabled disabled sanitize if return true
52+
func (Renderer) SanitizerDisabled() bool {
53+
return false
54+
}
55+
56+
// CanRender implements markup.RendererContentDetector
57+
func (Renderer) CanRender(filename string, input io.Reader) bool {
58+
buf, err := io.ReadAll(input)
59+
if err != nil {
60+
return false
61+
}
62+
if enry.GetLanguage(filepath.Base(filename), buf) != enry.OtherLanguage {
63+
return false
64+
}
65+
return bytes.ContainsRune(buf, '\x1b')
66+
}
67+
68+
// Render renders terminal colors to HTML with all specific handling stuff.
69+
func (Renderer) Render(ctx *markup.RenderContext, input io.Reader, output io.Writer) error {
70+
buf, err := io.ReadAll(input)
71+
if err != nil {
72+
return err
73+
}
74+
buf = trend.Render(buf)
75+
buf = bytes.ReplaceAll(buf, []byte("\n"), []byte(`<br>`))
76+
_, err = output.Write(buf)
77+
return err
78+
}
79+
80+
// Render renders terminal colors to HTML with all specific handling stuff.
81+
func Render(ctx *markup.RenderContext, input io.Reader, output io.Writer) error {
82+
if ctx.Type == "" {
83+
ctx.Type = MarkupName
84+
}
85+
return markup.Render(ctx, input, output)
86+
}
87+
88+
// RenderString renders terminal colors in string to HTML with all specific handling stuff and return string
89+
func RenderString(ctx *markup.RenderContext, content string) (string, error) {
90+
var buf strings.Builder
91+
if err := Render(ctx, strings.NewReader(content), &buf); err != nil {
92+
return "", err
93+
}
94+
return buf.String(), nil
95+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2022 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 console
6+
7+
import (
8+
"strings"
9+
"testing"
10+
11+
"code.gitea.io/gitea/modules/markup"
12+
13+
"github.com/stretchr/testify/assert"
14+
)
15+
16+
func TestRenderConsole(t *testing.T) {
17+
var render Renderer
18+
kases := map[string]string{
19+
"\x1b[37m\x1b[40mnpm\x1b[0m \x1b[0m\x1b[32minfo\x1b[0m \x1b[0m\x1b[35mit worked if it ends with\x1b[0m ok": "<span class=\"term-fg37 term-bg40\">npm</span> <span class=\"term-fg32\">info</span> <span class=\"term-fg35\">it worked if it ends with</span> ok",
20+
}
21+
22+
for k, v := range kases {
23+
var buf strings.Builder
24+
canRender := render.CanRender("test", strings.NewReader(k))
25+
assert.True(t, canRender)
26+
27+
err := render.Render(&markup.RenderContext{}, strings.NewReader(k), &buf)
28+
assert.NoError(t, err)
29+
assert.EqualValues(t, v, buf.String())
30+
}
31+
}

0 commit comments

Comments
 (0)