Skip to content

Commit 39c0dc7

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Move some repository related code into sub package (go-gitea#19711) A minimal change to replace data calls with attr as per guidelines (go-gitea#19900) Modernize JS build scripts (go-gitea#19824) [skip ci] Updated translations via Crowdin Update MAINTAINERS (go-gitea#19896)
2 parents bca137d + 2609511 commit 39c0dc7

Some content is hidden

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

103 files changed

+1805
-1745
lines changed

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,

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

models/issue.go

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,6 +1343,48 @@ func (opts *IssuesOptions) setupSessionNoLimit(sess *xorm.Session) {
13431343
}
13441344
}
13451345

1346+
// teamUnitsRepoCond returns query condition for those repo id in the special org team with special units access
1347+
func teamUnitsRepoCond(id string, userID, orgID, teamID int64, units ...unit.Type) builder.Cond {
1348+
return builder.In(id,
1349+
builder.Select("repo_id").From("team_repo").Where(
1350+
builder.Eq{
1351+
"team_id": teamID,
1352+
}.And(
1353+
builder.Or(
1354+
// Check if the user is member of the team.
1355+
builder.In(
1356+
"team_id", builder.Select("team_id").From("team_user").Where(
1357+
builder.Eq{
1358+
"uid": userID,
1359+
},
1360+
),
1361+
),
1362+
// Check if the user is in the owner team of the organisation.
1363+
builder.Exists(builder.Select("team_id").From("team_user").
1364+
Where(builder.Eq{
1365+
"org_id": orgID,
1366+
"team_id": builder.Select("id").From("team").Where(
1367+
builder.Eq{
1368+
"org_id": orgID,
1369+
"lower_name": strings.ToLower(organization.OwnerTeamName),
1370+
}),
1371+
"uid": userID,
1372+
}),
1373+
),
1374+
)).And(
1375+
builder.In(
1376+
"team_id", builder.Select("team_id").From("team_unit").Where(
1377+
builder.Eq{
1378+
"`team_unit`.org_id": orgID,
1379+
}.And(
1380+
builder.In("`team_unit`.type", units),
1381+
),
1382+
),
1383+
),
1384+
),
1385+
))
1386+
}
1387+
13461388
// issuePullAccessibleRepoCond userID must not be zero, this condition require join repository table
13471389
func issuePullAccessibleRepoCond(repoIDstr string, userID int64, org *organization.Organization, team *organization.Team, isPull bool) builder.Cond {
13481390
cond := builder.NewCond()
@@ -1356,19 +1398,19 @@ func issuePullAccessibleRepoCond(repoIDstr string, userID int64, org *organizati
13561398
} else {
13571399
cond = cond.And(
13581400
builder.Or(
1359-
userOrgUnitRepoCond(repoIDstr, userID, org.ID, unitType), // team member repos
1360-
userOrgPublicUnitRepoCond(userID, org.ID), // user org public non-member repos, TODO: check repo has issues
1401+
repo_model.UserOrgUnitRepoCond(repoIDstr, userID, org.ID, unitType), // team member repos
1402+
repo_model.UserOrgPublicUnitRepoCond(userID, org.ID), // user org public non-member repos, TODO: check repo has issues
13611403
),
13621404
)
13631405
}
13641406
} else {
13651407
cond = cond.And(
13661408
builder.Or(
1367-
userOwnedRepoCond(userID), // owned repos
1368-
userCollaborationRepoCond(repoIDstr, userID), // collaboration repos
1369-
userAssignedRepoCond(repoIDstr, userID), // user has been assigned accessible public repos
1370-
userMentionedRepoCond(repoIDstr, userID), // user has been mentioned accessible public repos
1371-
userCreateIssueRepoCond(repoIDstr, userID, isPull), // user has created issue/pr accessible public repos
1409+
repo_model.UserOwnedRepoCond(userID), // owned repos
1410+
repo_model.UserCollaborationRepoCond(repoIDstr, userID), // collaboration repos
1411+
repo_model.UserAssignedRepoCond(repoIDstr, userID), // user has been assigned accessible public repos
1412+
repo_model.UserMentionedRepoCond(repoIDstr, userID), // user has been mentioned accessible public repos
1413+
repo_model.UserCreateIssueRepoCond(repoIDstr, userID, isPull), // user has created issue/pr accessible public repos
13721414
),
13731415
)
13741416
}
@@ -1434,7 +1476,7 @@ func GetRepoIDsForIssuesOptions(opts *IssuesOptions, user *user_model.User) ([]i
14341476

14351477
opts.setupSessionNoLimit(sess)
14361478

1437-
accessCond := accessibleRepositoryCondition(user)
1479+
accessCond := repo_model.AccessibleRepositoryCondition(user)
14381480
if err := sess.Where(accessCond).
14391481
Distinct("issue.repo_id").
14401482
Table("issue").

models/issue_list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (issues IssueList) loadRepositories(ctx context.Context) ([]*repo_model.Rep
7575
}
7676
}
7777
}
78-
return valuesRepository(repoMaps), nil
78+
return repo_model.ValuesRepository(repoMaps), nil
7979
}
8080

8181
// LoadRepositories loads issues' all repositories

models/issue_user.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func init() {
2626
}
2727

2828
func newIssueUsers(ctx context.Context, repo *repo_model.Repository, issue *Issue) error {
29-
assignees, err := getRepoAssignees(ctx, repo)
29+
assignees, err := repo_model.GetRepoAssignees(ctx, repo)
3030
if err != nil {
3131
return fmt.Errorf("getAssignees: %v", err)
3232
}

models/lfs.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func LFSObjectAccessible(user *user_model.User, oid string) (bool, error) {
142142
count, err := db.GetEngine(db.DefaultContext).Count(&LFSMetaObject{Pointer: lfs.Pointer{Oid: oid}})
143143
return count > 0, err
144144
}
145-
cond := accessibleRepositoryCondition(user)
145+
cond := repo_model.AccessibleRepositoryCondition(user)
146146
count, err := db.GetEngine(db.DefaultContext).Where(cond).Join("INNER", "repository", "`lfs_meta_object`.repository_id = `repository`.id").Count(&LFSMetaObject{Pointer: lfs.Pointer{Oid: oid}})
147147
return count > 0, err
148148
}
@@ -173,7 +173,7 @@ func LFSAutoAssociate(metas []*LFSMetaObject, user *user_model.User, repoID int6
173173
newMetas := make([]*LFSMetaObject, 0, len(metas))
174174
cond := builder.In(
175175
"`lfs_meta_object`.repository_id",
176-
builder.Select("`repository`.id").From("repository").Where(accessibleRepositoryCondition(user)),
176+
builder.Select("`repository`.id").From("repository").Where(repo_model.AccessibleRepositoryCondition(user)),
177177
)
178178
err = sess.Cols("oid").Where(cond).In("oid", oids...).GroupBy("oid").Find(&newMetas)
179179
if err != nil {
@@ -246,3 +246,12 @@ func CopyLFS(ctx context.Context, newRepo, oldRepo *repo_model.Repository) error
246246

247247
return nil
248248
}
249+
250+
// GetRepoLFSSize return a repository's lfs files size
251+
func GetRepoLFSSize(ctx context.Context, repoID int64) (int64, error) {
252+
lfsSize, err := db.GetEngine(ctx).Where("repository_id = ?", repoID).SumInt(new(LFSMetaObject), "size")
253+
if err != nil {
254+
return 0, fmt.Errorf("updateSize: GetLFSMetaObjects: %v", err)
255+
}
256+
return lfsSize, nil
257+
}

models/notification.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,10 @@ func createOrUpdateIssueNotifications(ctx context.Context, issueID, commentID, n
266266

267267
return err
268268
}
269-
if issue.IsPull && !checkRepoUnitUser(ctx, issue.Repo, user, unit.TypePullRequests) {
269+
if issue.IsPull && !CheckRepoUnitUser(ctx, issue.Repo, user, unit.TypePullRequests) {
270270
continue
271271
}
272-
if !issue.IsPull && !checkRepoUnitUser(ctx, issue.Repo, user, unit.TypeIssues) {
272+
if !issue.IsPull && !CheckRepoUnitUser(ctx, issue.Repo, user, unit.TypeIssues) {
273273
continue
274274
}
275275

@@ -510,9 +510,9 @@ func (nl NotificationList) getPendingRepoIDs() []int64 {
510510
}
511511

512512
// LoadRepos loads repositories from database
513-
func (nl NotificationList) LoadRepos() (RepositoryList, []int, error) {
513+
func (nl NotificationList) LoadRepos() (repo_model.RepositoryList, []int, error) {
514514
if len(nl) == 0 {
515-
return RepositoryList{}, []int{}, nil
515+
return repo_model.RepositoryList{}, []int{}, nil
516516
}
517517

518518
repoIDs := nl.getPendingRepoIDs()
@@ -548,7 +548,7 @@ func (nl NotificationList) LoadRepos() (RepositoryList, []int, error) {
548548

549549
failed := []int{}
550550

551-
reposList := make(RepositoryList, 0, len(repoIDs))
551+
reposList := make(repo_model.RepositoryList, 0, len(repoIDs))
552552
for i, notification := range nl {
553553
if notification.Repository == nil {
554554
notification.Repository = repos[notification.RepoID]

models/org.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func GetUserOrgsList(user *user_model.User) ([]*MinimalOrg, error) {
5454
Join("LEFT", builder.
5555
Select("id as repo_id, owner_id as repo_owner_id").
5656
From("repository").
57-
Where(accessibleRepositoryCondition(user)), "`repository`.repo_owner_id = `team`.org_id").
57+
Where(repo_model.AccessibleRepositoryCondition(user)), "`repository`.repo_owner_id = `team`.org_id").
5858
Where("`team_user`.uid = ?", user.ID).
5959
GroupBy(groupByStr)
6060

0 commit comments

Comments
 (0)