Skip to content

Commit 0502a21

Browse files
authored
Merge branch 'main' into auto-merge_webUI
2 parents eb33a2f + 7948cb3 commit 0502a21

File tree

137 files changed

+2620
-1868
lines changed

Some content is hidden

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

137 files changed

+2620
-1868
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

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ Leon Hofmeister <[email protected]> (@delvh)
4747
Gusted <[email protected]) (@Gusted)
4848
singuliere <[email protected]> (@singuliere)
4949
silentcode <[email protected]> (@silentcodeg)
50+
Wim <[email protected]> (@42wim)

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ generate-gitignore:
761761

762762
.PHONY: generate-images
763763
generate-images: | node_modules
764-
npm install --no-save --no-package-lock fabric@4 imagemin-zopfli@7
764+
npm install --no-save --no-package-lock fabric@5 imagemin-zopfli@7
765765
node build/generate-images.js $(TAGS)
766766

767767
.PHONY: generate-manpage

build/generate-images.js

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1+
#!/usr/bin/env node
12
import imageminZopfli from 'imagemin-zopfli';
23
import {optimize} from 'svgo';
34
import {fabric} from 'fabric';
4-
import fs from 'fs';
5-
import {resolve, dirname} from 'path';
6-
import {fileURLToPath} from 'url';
7-
8-
const {readFile, writeFile} = fs.promises;
9-
const __dirname = dirname(fileURLToPath(import.meta.url));
10-
const logoFile = resolve(__dirname, '../assets/logo.svg');
11-
const faviconFile = resolve(__dirname, '../assets/favicon.svg');
5+
import {readFile, writeFile} from 'fs/promises';
126

137
function exit(err) {
148
if (err) console.error(err);
@@ -23,8 +17,10 @@ function loadSvg(svg) {
2317
});
2418
}
2519

26-
async function generate(svg, outputFile, {size, bg}) {
27-
if (outputFile.endsWith('.svg')) {
20+
async function generate(svg, path, {size, bg}) {
21+
const outputFile = new URL(path, import.meta.url);
22+
23+
if (String(outputFile).endsWith('.svg')) {
2824
const {data} = optimize(svg, {
2925
plugins: [
3026
'preset-default',
@@ -69,19 +65,18 @@ async function generate(svg, outputFile, {size, bg}) {
6965

7066
async function main() {
7167
const gitea = process.argv.slice(2).includes('gitea');
72-
const logoSvg = await readFile(logoFile, 'utf8');
73-
const faviconSvg = await readFile(faviconFile, 'utf8');
68+
const logoSvg = await readFile(new URL('../assets/logo.svg', import.meta.url), 'utf8');
69+
const faviconSvg = await readFile(new URL('../assets/favicon.svg', import.meta.url), 'utf8');
7470

7571
await Promise.all([
76-
generate(logoSvg, resolve(__dirname, '../public/img/logo.svg'), {size: 32}),
77-
generate(logoSvg, resolve(__dirname, '../public/img/logo.png'), {size: 512}),
78-
generate(faviconSvg, resolve(__dirname, '../public/img/favicon.svg'), {size: 32}),
79-
generate(faviconSvg, resolve(__dirname, '../public/img/favicon.png'), {size: 180}),
80-
generate(logoSvg, resolve(__dirname, '../public/img/avatar_default.png'), {size: 200}),
81-
generate(logoSvg, resolve(__dirname, '../public/img/apple-touch-icon.png'), {size: 180, bg: true}),
82-
gitea && generate(logoSvg, resolve(__dirname, '../public/img/gitea.svg'), {size: 32}),
72+
generate(logoSvg, '../public/img/logo.svg', {size: 32}),
73+
generate(logoSvg, '../public/img/logo.png', {size: 512}),
74+
generate(faviconSvg, '../public/img/favicon.svg', {size: 32}),
75+
generate(faviconSvg, '../public/img/favicon.png', {size: 180}),
76+
generate(logoSvg, '../public/img/avatar_default.png', {size: 200}),
77+
generate(logoSvg, '../public/img/apple-touch-icon.png', {size: 180, bg: true}),
78+
gitea && generate(logoSvg, '../public/img/gitea.svg', {size: 32}),
8379
]);
8480
}
8581

8682
main().then(exit).catch(exit);
87-

build/generate-svg.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
#!/usr/bin/env node
12
import fastGlob from 'fast-glob';
23
import {optimize} from 'svgo';
3-
import {resolve, parse, dirname} from 'path';
4-
import fs from 'fs';
4+
import {parse} from 'path';
5+
import {readFile, writeFile, mkdir} from 'fs/promises';
56
import {fileURLToPath} from 'url';
67

7-
const {readFile, writeFile, mkdir} = fs.promises;
8-
const __dirname = dirname(fileURLToPath(import.meta.url));
9-
const glob = (pattern) => fastGlob.sync(pattern, {cwd: resolve(__dirname), absolute: true});
10-
const outputDir = resolve(__dirname, '../public/img/svg');
8+
const glob = (pattern) => fastGlob.sync(pattern, {
9+
cwd: fileURLToPath(new URL('..', import.meta.url)),
10+
absolute: true,
11+
});
1112

1213
function exit(err) {
1314
if (err) console.error(err);
@@ -16,7 +17,6 @@ function exit(err) {
1617

1718
async function processFile(file, {prefix, fullName} = {}) {
1819
let name;
19-
2020
if (fullName) {
2121
name = fullName;
2222
} else {
@@ -35,7 +35,8 @@ async function processFile(file, {prefix, fullName} = {}) {
3535
{name: 'addAttributesToSVGElement', params: {attributes: [{'width': '16'}, {'height': '16'}, {'aria-hidden': 'true'}]}},
3636
],
3737
});
38-
await writeFile(resolve(outputDir, `${name}.svg`), data);
38+
39+
await writeFile(fileURLToPath(new URL(`../public/img/svg/${name}.svg`, import.meta.url)), data);
3940
}
4041

4142
function processFiles(pattern, opts) {
@@ -44,15 +45,14 @@ function processFiles(pattern, opts) {
4445

4546
async function main() {
4647
try {
47-
await mkdir(outputDir);
48+
await mkdir(fileURLToPath(new URL('../public/img/svg', import.meta.url)), {recursive: true});
4849
} catch {}
4950

5051
await Promise.all([
51-
...processFiles('../node_modules/@primer/octicons/build/svg/*-16.svg', {prefix: 'octicon'}),
52-
...processFiles('../web_src/svg/*.svg'),
53-
...processFiles('../public/img/gitea.svg', {fullName: 'gitea-gitea'}),
52+
...processFiles('node_modules/@primer/octicons/build/svg/*-16.svg', {prefix: 'octicon'}),
53+
...processFiles('web_src/svg/*.svg'),
54+
...processFiles('public/img/gitea.svg', {fullName: 'gitea-gitea'}),
5455
]);
5556
}
5657

5758
main().then(exit).catch(exit);
58-

cmd/admin.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
asymkey_model "code.gitea.io/gitea/models/asymkey"
1818
"code.gitea.io/gitea/models/auth"
1919
"code.gitea.io/gitea/models/db"
20+
repo_model "code.gitea.io/gitea/models/repo"
2021
user_model "code.gitea.io/gitea/models/user"
2122
"code.gitea.io/gitea/modules/git"
2223
"code.gitea.io/gitea/modules/graceful"
@@ -722,9 +723,9 @@ func runRepoSyncReleases(_ *cli.Context) error {
722723

723724
log.Trace("Synchronizing repository releases (this may take a while)")
724725
for page := 1; ; page++ {
725-
repos, count, err := models.SearchRepositoryByName(&models.SearchRepoOptions{
726+
repos, count, err := repo_model.SearchRepositoryByName(&repo_model.SearchRepoOptions{
726727
ListOptions: db.ListOptions{
727-
PageSize: models.RepositoryListDefaultPageSize,
728+
PageSize: repo_model.RepositoryListDefaultPageSize,
728729
Page: page,
729730
},
730731
Private: true,

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"

models/action.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ func activityQueryCondition(opts GetFeedsOptions) (builder.Cond, error) {
393393

394394
// check readable repositories by doer/actor
395395
if opts.Actor == nil || !opts.Actor.IsAdmin {
396-
cond = cond.And(builder.In("repo_id", AccessibleRepoIDsQuery(opts.Actor)))
396+
cond = cond.And(builder.In("repo_id", repo_model.AccessibleRepoIDsQuery(opts.Actor)))
397397
}
398398

399399
if opts.RequestedRepo != nil {

models/asymkey/ssh_key_deploy.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,13 @@ func GetDeployKeyByRepo(ctx context.Context, keyID, repoID int64) (*DeployKey, e
190190
return key, nil
191191
}
192192

193+
// IsDeployKeyExistByKeyID return true if there is at least one deploykey with the key id
194+
func IsDeployKeyExistByKeyID(ctx context.Context, keyID int64) (bool, error) {
195+
return db.GetEngine(ctx).
196+
Where("key_id = ?", keyID).
197+
Get(new(DeployKey))
198+
}
199+
193200
// UpdateDeployKeyCols updates deploy key information in the specified columns.
194201
func UpdateDeployKeyCols(key *DeployKey, cols ...string) error {
195202
_, err := db.GetEngine(db.DefaultContext).ID(key.ID).Cols(cols...).Update(key)

models/db/engine.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,6 @@ func MaxBatchInsertSize(bean interface{}) int {
271271
return 999 / len(t.ColumnsSeq())
272272
}
273273

274-
// Count returns records number according struct's fields as database query conditions
275-
func Count(bean interface{}) (int64, error) {
276-
return x.Count(bean)
277-
}
278-
279274
// IsTableNotEmpty returns true if table has at least one record
280275
func IsTableNotEmpty(tableName string) (bool, error) {
281276
return x.Table(tableName).Exist()

0 commit comments

Comments
 (0)