Skip to content

Commit 1bf3f66

Browse files
authored
Merge branch 'main' into github-like-repo-home-page
2 parents f217245 + d3ada91 commit 1bf3f66

File tree

110 files changed

+5227
-1064
lines changed

Some content is hidden

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

110 files changed

+5227
-1064
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ TEST_PGSQL_DBNAME ?= testgitea
179179
TEST_PGSQL_USERNAME ?= postgres
180180
TEST_PGSQL_PASSWORD ?= postgres
181181
TEST_PGSQL_SCHEMA ?= gtestschema
182+
TEST_MINIO_ENDPOINT ?= minio:9000
182183
TEST_MSSQL_HOST ?= mssql:1433
183184
TEST_MSSQL_DBNAME ?= gitea
184185
TEST_MSSQL_USERNAME ?= sa
@@ -574,6 +575,7 @@ generate-ini-pgsql:
574575
-e 's|{{TEST_PGSQL_USERNAME}}|${TEST_PGSQL_USERNAME}|g' \
575576
-e 's|{{TEST_PGSQL_PASSWORD}}|${TEST_PGSQL_PASSWORD}|g' \
576577
-e 's|{{TEST_PGSQL_SCHEMA}}|${TEST_PGSQL_SCHEMA}|g' \
578+
-e 's|{{TEST_MINIO_ENDPOINT}}|${TEST_MINIO_ENDPOINT}|g' \
577579
-e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
578580
-e 's|{{TEST_LOGGER}}|$(or $(TEST_LOGGER),test$(COMMA)file)|g' \
579581
-e 's|{{TEST_TYPE}}|$(or $(TEST_TYPE),integration)|g' \

assets/go-licenses.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/generate-licenses.go

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
// Copyright 2017 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
14
//go:build ignore
25

36
package main
47

58
import (
69
"archive/tar"
710
"compress/gzip"
11+
"crypto/md5"
12+
"encoding/hex"
813
"flag"
914
"fmt"
1015
"io"
@@ -15,6 +20,8 @@ import (
1520
"path/filepath"
1621
"strings"
1722

23+
"code.gitea.io/gitea/build/license"
24+
"code.gitea.io/gitea/modules/json"
1825
"code.gitea.io/gitea/modules/util"
1926
)
2027

@@ -77,7 +84,7 @@ func main() {
7784
}
7885

7986
tr := tar.NewReader(gz)
80-
87+
aliasesFiles := make(map[string][]string)
8188
for {
8289
hdr, err := tr.Next()
8390

@@ -97,26 +104,73 @@ func main() {
97104
continue
98105
}
99106

100-
if strings.HasPrefix(filepath.Base(hdr.Name), "README") {
107+
fileBaseName := filepath.Base(hdr.Name)
108+
licenseName := strings.TrimSuffix(fileBaseName, ".txt")
109+
110+
if strings.HasPrefix(fileBaseName, "README") {
101111
continue
102112
}
103113

104-
if strings.HasPrefix(filepath.Base(hdr.Name), "deprecated_") {
114+
if strings.HasPrefix(fileBaseName, "deprecated_") {
105115
continue
106116
}
107-
out, err := os.Create(path.Join(destination, strings.TrimSuffix(filepath.Base(hdr.Name), ".txt")))
117+
out, err := os.Create(path.Join(destination, licenseName))
108118
if err != nil {
109119
log.Fatalf("Failed to create new file. %s", err)
110120
}
111121

112122
defer out.Close()
113123

114-
if _, err := io.Copy(out, tr); err != nil {
124+
// some license files have same content, so we need to detect these files and create a convert map into a json file
125+
// Later we use this convert map to avoid adding same license content with different license name
126+
h := md5.New()
127+
// calculate md5 and write file in the same time
128+
r := io.TeeReader(tr, h)
129+
if _, err := io.Copy(out, r); err != nil {
115130
log.Fatalf("Failed to write new file. %s", err)
116131
} else {
117132
fmt.Printf("Written %s\n", out.Name())
133+
134+
md5 := hex.EncodeToString(h.Sum(nil))
135+
aliasesFiles[md5] = append(aliasesFiles[md5], licenseName)
118136
}
119137
}
120138

139+
// generate convert license name map
140+
licenseAliases := make(map[string]string)
141+
for _, fileNames := range aliasesFiles {
142+
if len(fileNames) > 1 {
143+
licenseName := license.GetLicenseNameFromAliases(fileNames)
144+
if licenseName == "" {
145+
// license name should not be empty as expected
146+
// if it is empty, we need to rewrite the logic of GetLicenseNameFromAliases
147+
log.Fatalf("GetLicenseNameFromAliases: license name is empty")
148+
}
149+
for _, fileName := range fileNames {
150+
licenseAliases[fileName] = licenseName
151+
}
152+
}
153+
}
154+
// save convert license name map to file
155+
b, err := json.Marshal(licenseAliases)
156+
if err != nil {
157+
log.Fatalf("Failed to create json bytes. %s", err)
158+
}
159+
160+
licenseAliasesDestination := filepath.Join(destination, "etc", "license-aliases.json")
161+
if err := os.MkdirAll(filepath.Dir(licenseAliasesDestination), 0o755); err != nil {
162+
log.Fatalf("Failed to create directory for license aliases json file. %s", err)
163+
}
164+
165+
f, err := os.Create(licenseAliasesDestination)
166+
if err != nil {
167+
log.Fatalf("Failed to create license aliases json file. %s", err)
168+
}
169+
defer f.Close()
170+
171+
if _, err = f.Write(b); err != nil {
172+
log.Fatalf("Failed to write license aliases json file. %s", err)
173+
}
174+
121175
fmt.Println("Done")
122176
}

build/license/aliasgenerator.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2024 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package license
5+
6+
import "strings"
7+
8+
func GetLicenseNameFromAliases(fnl []string) string {
9+
if len(fnl) == 0 {
10+
return ""
11+
}
12+
13+
shortestItem := func(list []string) string {
14+
s := list[0]
15+
for _, l := range list[1:] {
16+
if len(l) < len(s) {
17+
s = l
18+
}
19+
}
20+
return s
21+
}
22+
allHasPrefix := func(list []string, s string) bool {
23+
for _, l := range list {
24+
if !strings.HasPrefix(l, s) {
25+
return false
26+
}
27+
}
28+
return true
29+
}
30+
31+
sl := shortestItem(fnl)
32+
slv := strings.Split(sl, "-")
33+
var result string
34+
for i := len(slv); i >= 0; i-- {
35+
result = strings.Join(slv[:i], "-")
36+
if allHasPrefix(fnl, result) {
37+
return result
38+
}
39+
}
40+
return ""
41+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2024 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package license
5+
6+
import (
7+
"testing"
8+
9+
"github.com/stretchr/testify/assert"
10+
)
11+
12+
func TestGetLicenseNameFromAliases(t *testing.T) {
13+
tests := []struct {
14+
target string
15+
inputs []string
16+
}{
17+
{
18+
// real case which you can find in license-aliases.json
19+
target: "AGPL-1.0",
20+
inputs: []string{
21+
"AGPL-1.0-only",
22+
"AGPL-1.0-or-late",
23+
},
24+
},
25+
{
26+
target: "",
27+
inputs: []string{
28+
"APSL-1.0",
29+
"AGPL-1.0-only",
30+
"AGPL-1.0-or-late",
31+
},
32+
},
33+
}
34+
35+
for _, tt := range tests {
36+
result := GetLicenseNameFromAliases(tt.inputs)
37+
assert.Equal(t, result, tt.target)
38+
}
39+
}

custom/conf/app.example.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,6 +1507,8 @@ LEVEL = Info
15071507
;; - manage_gpg_keys: a user cannot configure gpg keys
15081508
;; - manage_mfa: a user cannot configure mfa devices
15091509
;; - manage_credentials: a user cannot configure emails, passwords, or openid
1510+
;; - change_username: a user cannot change their username
1511+
;; - change_full_name: a user cannot change their full name
15101512
;;EXTERNAL_USER_DISABLE_FEATURES =
15111513

15121514
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ require (
6868
github.com/gogs/go-gogs-client v0.0.0-20210131175652-1d7215cd8d85
6969
github.com/golang-jwt/jwt/v5 v5.2.1
7070
github.com/google/go-github/v61 v61.0.0
71+
github.com/google/licenseclassifier/v2 v2.0.0
7172
github.com/google/pprof v0.0.0-20240618054019-d3b898a103f8
7273
github.com/google/uuid v1.6.0
7374
github.com/gorilla/feeds v1.2.0
@@ -330,7 +331,7 @@ replace github.com/hashicorp/go-version => github.com/6543/go-version v1.3.1
330331

331332
replace github.com/shurcooL/vfsgen => github.com/lunny/vfsgen v0.0.0-20220105142115-2c99e1ffdfa0
332333

333-
replace github.com/nektos/act => gitea.com/gitea/act v0.259.1
334+
replace github.com/nektos/act => gitea.com/gitea/act v0.261.3
334335

335336
replace github.com/charmbracelet/git-lfs-transfer => gitea.com/gitea/git-lfs-transfer v0.2.0
336337

go.sum

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
1616
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
1717
git.sr.ht/~mariusor/go-xsd-duration v0.0.0-20220703122237-02e73435a078 h1:cliQ4HHsCo6xi2oWZYKWW4bly/Ory9FuTpFPRxj/mAg=
1818
git.sr.ht/~mariusor/go-xsd-duration v0.0.0-20220703122237-02e73435a078/go.mod h1:g/V2Hjas6Z1UHUp4yIx6bATpNzJ7DYtD0FG3+xARWxs=
19-
gitea.com/gitea/act v0.259.1 h1:8GG1o/xtUHl3qjn5f0h/2FXrT5ubBn05TJOM5ry+FBw=
20-
gitea.com/gitea/act v0.259.1/go.mod h1:UxZWRYqQG2Yj4+4OqfGWW5a3HELwejyWFQyU7F1jUD8=
19+
gitea.com/gitea/act v0.261.3 h1:BhiYpGJQKGq0XMYYICCYAN4KnsEWHyLbA6dxhZwFcV4=
20+
gitea.com/gitea/act v0.261.3/go.mod h1:Pg5C9kQY1CEA3QjthjhlrqOC/QOT5NyWNjOjRHw23Ok=
2121
gitea.com/gitea/git-lfs-transfer v0.2.0 h1:baHaNoBSRaeq/xKayEXwiDQtlIjps4Ac/Ll4KqLMB40=
2222
gitea.com/gitea/git-lfs-transfer v0.2.0/go.mod h1:UrXUCm3xLQkq15fu7qlXHUMlrhdlXHoi13KH2Dfiits=
2323
gitea.com/go-chi/binding v0.0.0-20240430071103-39a851e106ed h1:EZZBtilMLSZNWtHHcgq2mt6NSGhJSZBuduAlinMEmso=
@@ -441,6 +441,8 @@ github.com/google/go-tpm v0.9.0/go.mod h1:FkNVkc6C+IsvDI9Jw1OveJmxGZUUaKxtrpOS47
441441
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
442442
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
443443
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
444+
github.com/google/licenseclassifier/v2 v2.0.0 h1:1Y57HHILNf4m0ABuMVb6xk4vAJYEUO0gDxNpog0pyeA=
445+
github.com/google/licenseclassifier/v2 v2.0.0/go.mod h1:cOjbdH0kyC9R22sdQbYsFkto4NGCAc+ZSwbeThazEtM=
444446
github.com/google/pprof v0.0.0-20240227163752-401108e1b7e7/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik=
445447
github.com/google/pprof v0.0.0-20240618054019-d3b898a103f8 h1:ASJ/LAqdCHOyMYI+dwNxn7Rd8FscNkMyTr1KZU1JI/M=
446448
github.com/google/pprof v0.0.0-20240618054019-d3b898a103f8/go.mod h1:K1liHPHnj73Fdn/EKuT8nrFqBihUSKXoLYU0BuatOYo=
@@ -735,6 +737,7 @@ github.com/sassoftware/go-rpmutils v0.4.0/go.mod h1:3goNWi7PGAT3/dlql2lv3+MSN5jN
735737
github.com/segmentio/asm v1.2.0 h1:9BQrFxC+YOHJlTlHGkTrFWf59nbL3XnCoFLTwDCI7ys=
736738
github.com/segmentio/asm v1.2.0/go.mod h1:BqMnlJP91P8d+4ibuonYZw9mfnzI9HfxselHZr5aAcs=
737739
github.com/serenize/snaker v0.0.0-20171204205717-a683aaf2d516/go.mod h1:Yow6lPLSAXx2ifx470yD/nUe22Dv5vBvxK/UK9UUTVs=
740+
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
738741
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8=
739742
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
740743
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=

models/admin/task.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -179,27 +179,6 @@ func GetMigratingTask(ctx context.Context, repoID int64) (*Task, error) {
179179
return &task, nil
180180
}
181181

182-
// GetMigratingTaskByID returns the migrating task by repo's id
183-
func GetMigratingTaskByID(ctx context.Context, id, doerID int64) (*Task, *migration.MigrateOptions, error) {
184-
task := Task{
185-
ID: id,
186-
DoerID: doerID,
187-
Type: structs.TaskTypeMigrateRepo,
188-
}
189-
has, err := db.GetEngine(ctx).Get(&task)
190-
if err != nil {
191-
return nil, nil, err
192-
} else if !has {
193-
return nil, nil, ErrTaskDoesNotExist{id, 0, task.Type}
194-
}
195-
196-
var opts migration.MigrateOptions
197-
if err := json.Unmarshal([]byte(task.PayloadContent), &opts); err != nil {
198-
return nil, nil, err
199-
}
200-
return &task, &opts, nil
201-
}
202-
203182
// CreateTask creates a task on database
204183
func CreateTask(ctx context.Context, task *Task) error {
205184
return db.Insert(ctx, task)

models/fixtures/repo_license.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[] # empty

0 commit comments

Comments
 (0)