-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Support repo license #24872
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
techknowlogick
merged 209 commits into
go-gitea:main
from
yp05327:add-repo-license-display
Oct 1, 2024
Merged
Support repo license #24872
Changes from 178 commits
Commits
Show all changes
209 commits
Select commit
Hold shift + click to select a range
43129a1
add repo license check
yp05327 33ec600
fix incorrect location of {{end}}
yp05327 7d3f1d5
fix test
yp05327 8acb46e
remove debug code
yp05327 a4e0deb
use make tidy to add licensecheck
yp05327 5a75aab
use statistics in db
yp05327 973f995
check license change in HookPostReceive
yp05327 a876b2d
remove debug code
yp05327 a2ef8f6
update license when create a repo
yp05327 c4c6da5
add todo
yp05327 0278775
add license to fork repo
yp05327 c30bca1
fix lint
yp05327 aa91765
add license to mirror repo
yp05327 84801d5
move findFileInEntries to repo modules
yp05327 0421e98
update license when sync mirror repo
yp05327 cf02888
support search license file
yp05327 10b2a90
imporve debug info
yp05327 f285720
fix test
yp05327 7eb4584
fix test
yp05327 8ba16c0
fix
yp05327 0637b87
fix
yp05327 facd698
improve
yp05327 af1b031
fix fork repo
yp05327 30c25ba
remove check iswiki
yp05327 bc005dd
fix no commitID
yp05327 2f870f7
Merge branch 'main' into add-repo-license-display
yp05327 3518a63
fix lint
yp05327 0a9e4e8
Merge branch 'main' into add-repo-license-display
yp05327 763f104
improve
yp05327 f481624
add db migration
yp05327 07e91bf
fix migration
yp05327 744a032
add licensecheck test
yp05327 93d2c7f
fix lint
yp05327 ea2f23c
Merge branch 'main' into add-repo-license-display
silverwind 92d8df7
move the position of license
yp05327 ac84422
fix
yp05327 0dc4c3e
Merge branch 'main' into add-repo-license-display
yp05327 ef340f6
only use defaultbranch to display license file
yp05327 63a6da8
add licenses to api.Repository
yp05327 b9c2329
update licenses info when update default branch
yp05327 48da7a6
convert use licenseclassifier
yp05327 a000c38
Merge branch 'main' into add-repo-license-display
yp05327 fa8e347
fix
yp05327 7a01d3b
remove unnecessary code
yp05327 1cb2020
init licenseclassifier when service start
yp05327 58b4cc2
remove unnecessary code
yp05327 c58162e
fix test
yp05327 f2933cc
fix migration
yp05327 388bc26
add tooltips
yp05327 7f2b5d0
improve
yp05327 4cf79be
fix
yp05327 f45d592
Merge branch 'main' into add-repo-license-display
yp05327 84c7b98
generate same file list
yp05327 3da5a80
generate licenses
yp05327 d0e5676
Merge branch 'main' into add-repo-license-display
yp05327 1b0783c
fix conflict
yp05327 25966eb
fix lint
yp05327 59198d3
fix lint
yp05327 4a838ad
allow not existed git repo
yp05327 866de8d
make generate-swagger
yp05327 27cb436
Merge branch 'main' into add-repo-license-display
yp05327 e46fd13
fix
yp05327 c831ee3
improve
yp05327 ae27d02
remove GetBlobAll
yp05327 a79cb78
fix
yp05327 c6cc8b4
fix lint
yp05327 ea2c0be
convert name
yp05327 d193276
fix lint
yp05327 e67a771
improve test
yp05327 6f25294
convert license col into table
yp05327 44a8ece
fix lint
yp05327 376b91a
remove todo
yp05327 4ec4a0f
finish todo
yp05327 50150b8
Merge branch 'main' into add-repo-license-display
yp05327 9cbde72
avoid return same licenses
yp05327 f7da797
fix conflicts
yp05327 3a99e01
Merge branch 'main' into add-repo-license-display
yp05327 2904f34
fix conflicts
yp05327 e38161b
fix conflicts
yp05327 7c7bdea
Merge branch 'main' into add-repo-license-display
yp05327 2b56a5a
fix
yp05327 b168d1b
improve
yp05327 7640268
remove licenses when remove repo
yp05327 7a9d605
add fixtures
yp05327 7e2589c
Merge branch 'main' into add-repo-license-display
yp05327 16822cd
make tidy
yp05327 fc93550
rename to v270
yp05327 d6d2524
Merge branch 'main' into add-repo-license-display
yp05327 d57592f
fix lint
yp05327 d6f7006
rename to v271
yp05327 8369e93
Merge branch 'main' into add-repo-license-display
yp05327 3c554a5
fix lint
yp05327 f546aae
rename to v273
yp05327 05c844d
Merge branch 'main' into add-repo-license-display
yp05327 87ae3a6
rename to v274
yp05327 24b1c13
Merge branch 'main' into add-repo-license-display
yp05327 cbe1515
rename to v278
yp05327 f65eeec
Merge branch 'main' into add-repo-license-display
yp05327 e70bb25
recover changes in DeleteRepository
yp05327 498ea78
recover changes in CreateRepository
yp05327 83945ed
recover changes in SetDefaultBranchPost
yp05327 bae33d5
recover changes in templates/repo/sub_menu.tmpl
yp05327 ba60195
fix
yp05327 71ad15e
Merge branch 'main' into add-repo-license-display
lunny 91dda74
rename to v282
yp05327 fe1f087
Merge branch 'main' into add-repo-license-display
yp05327 462f7f5
fix package name of migration
yp05327 a335732
Merge branch 'main' into add-repo-license-display
GiteaBot df3e168
Update models/migrations/migrations.go
yp05327 3abe77e
rename to v283
yp05327 7a6c3b3
Merge branch 'main' into add-repo-license-display
yp05327 640a5e4
Update models/migrations/v1_22/v283.go
yp05327 d6ba4af
use slices.Contains
yp05327 8a1c767
fix
yp05327 7781e7d
sync funcs in migration from origin
yp05327 cd0b44c
fix typo
yp05327 c57d542
do not init classifier in init()
yp05327 44cf8e4
add return
yp05327 648d0a0
improve the logic of copy license info
yp05327 b45f907
improve variable name
yp05327 dac32ce
improve detect license
yp05327 21b1a7a
fix
yp05327 cd06857
fix test
yp05327 5ec4b50
add data-tooltip-placement
yp05327 a5d9763
fix bug
yp05327 9178d90
convert sameLicenses to license aliases
yp05327 093e71d
Update modules/repository/license.go
yp05327 1386780
remove generate licenses in migrations
yp05327 c5296f4
improve initClassifier
yp05327 121f2b2
fix
yp05327 c97caf8
improve
yp05327 bb46e01
Merge branch 'main' into add-repo-license-display
yp05327 727d5cc
add cron task
yp05327 da36554
use ctx.Locale.Tr
yp05327 3e45a9a
Update models/repo/license.go
yp05327 7621d98
fix lint
yp05327 d501891
fix test
yp05327 8e0929e
fix test
yp05327 db2e9eb
remove add update repo license notify todo
yp05327 030c0dd
rename to v285
yp05327 91c5454
Merge branch 'main' into add-repo-license-display
yp05327 5e72897
fix changes from 28691
yp05327 3ef4aa8
improve
yp05327 80934c3
Merge branch 'main' into add-repo-license-display
yp05327 cc3cf07
fix comment
yp05327 aabb200
fix
yp05327 a0e8a5d
Update build/generate-licenses.go
yp05327 86f8bec
Update build/generate-licenses.go
yp05327 841453d
convert v285 to v287
yp05327 d46b98e
Merge branch 'main' into add-repo-license-display
yp05327 baa29d4
update license
yp05327 d92bbab
Merge branch 'main' into add-repo-license-display
6543 7d92e47
use queue
yp05327 c79fbaa
fix not remove old records when license file not detected after branc…
yp05327 fe77ff5
remove unnecessary enter
yp05327 882767c
fix ci error
yp05327 a0a7e9a
add api and test
yp05327 11b5e09
convert v287 to v288
yp05327 2ec2083
Merge remote-tracking branch 'upstream/main' into add-repo-license-di…
yp05327 ce75061
convert code.gitea.io/gitea/modules/context into code.gitea.io/gitea/…
yp05327 51a5bce
Merge branch 'main' into add-repo-license-display
6543 7582a66
Merge branch 'main' into add-repo-license-display
delvh 60bfdea
Merge branch 'main' into add-repo-license-display
6543 49ab83b
Update tests/integration/api_repo_license_test.go
6543 46e1246
Apply suggestions from code review
6543 f434251
do not use time.Now(9 in test
yp05327 c218be0
remove commit
yp05327 00b182c
Update models/repo/license.go
yp05327 ccde201
fix lint
yp05327 5059a0f
Update modules/repository/license.go
yp05327 75cf5a2
convert v288 into v289
yp05327 0eb8545
Merge branch 'main' into add-repo-license-display
yp05327 0e3d512
import gitrepo
yp05327 8dc1c3b
fix test
yp05327 be50529
improve
yp05327 2f1af68
fix lint
yp05327 f87f857
move to services
yp05327 2910c9c
fix year
yp05327 60aba0c
fix typo
yp05327 d5ca326
renqme v289 to v305
yp05327 a938795
Merge branch 'main' into add-repo-license-display
yp05327 0f00895
fix migration
yp05327 fa0119b
go mod tidy
yp05327 cfe8cb5
fix repository size
yp05327 0717cb6
make generate-swagger
yp05327 051fdff
fix lint
yp05327 1043d39
fix lint
yp05327 da313ff
fix lint
yp05327 875daf8
fix swagger
yp05327 4e18872
fix test
yp05327 8991c24
Merge branch 'main' into add-repo-license-display
techknowlogick f1ddccf
Merge branch 'main' into add-repo-license-display
techknowlogick 47e7c58
Merge branch 'main' into add-repo-license-display
yp05327 a1d98a3
Merge branch 'main' into add-repo-license-display
yp05327 8f5a70d
adjust the length of license in db
yp05327 ae61ccd
remove INDEX
yp05327 286a889
remove INDEX for RepoID
yp05327 dd95d1b
remove DefaultBranch
yp05327 d26f2a0
move to license/etc/
yp05327 cdbdb3e
add copyright
yp05327 45fcea6
add return
yp05327 da6a1cf
remove returns
yp05327 bd2b334
use filepath.Join
yp05327 35f0800
detect license file by const filename
yp05327 2403c80
init license classifier when boot
yp05327 4e76dbf
improve
yp05327 22f7c41
fix lint
yp05327 317eef9
fix migration
yp05327 eca31c7
Merge branch 'main' into add-repo-license-display
yp05327 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] # empty |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2024 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package v1_22 //nolint | ||
|
||
import ( | ||
"code.gitea.io/gitea/modules/timeutil" | ||
|
||
"xorm.io/xorm" | ||
) | ||
|
||
func AddRepositoryLicenses(x *xorm.Engine) error { | ||
type RepoLicense struct { | ||
ID int64 `xorm:"pk autoincr"` | ||
RepoID int64 `xorm:"UNIQUE(s) INDEX NOT NULL"` | ||
CommitID string | ||
License string `xorm:"VARCHAR(50) UNIQUE(s) INDEX NOT NULL"` | ||
CreatedUnix timeutil.TimeStamp `xorm:"INDEX CREATED"` | ||
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX UPDATED"` | ||
} | ||
|
||
return x.Sync(new(RepoLicense)) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// Copyright 2024 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package repo | ||
|
||
import ( | ||
"context" | ||
|
||
"code.gitea.io/gitea/models/db" | ||
"code.gitea.io/gitea/modules/timeutil" | ||
) | ||
|
||
func init() { | ||
db.RegisterModel(new(RepoLicense)) | ||
} | ||
|
||
type RepoLicense struct { //revive:disable-line:exported | ||
ID int64 `xorm:"pk autoincr"` | ||
RepoID int64 `xorm:"UNIQUE(s) INDEX NOT NULL"` | ||
CommitID string | ||
// TODO: `INDEX` will be used to find repositories by license | ||
License string `xorm:"VARCHAR(50) UNIQUE(s) INDEX NOT NULL"` | ||
yp05327 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
CreatedUnix timeutil.TimeStamp `xorm:"INDEX CREATED"` | ||
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX UPDATED"` | ||
} | ||
|
||
// RepoLicenseList defines a list of repo licenses | ||
type RepoLicenseList []*RepoLicense //revive:disable-line:exported | ||
|
||
func (rll RepoLicenseList) StringList() []string { | ||
var licenses []string | ||
for _, rl := range rll { | ||
licenses = append(licenses, rl.License) | ||
} | ||
return licenses | ||
} | ||
|
||
// GetRepoLicenses returns the license statistics for a repository | ||
func GetRepoLicenses(ctx context.Context, repo *Repository) (RepoLicenseList, error) { | ||
licenses := make(RepoLicenseList, 0) | ||
if err := db.GetEngine(ctx).Where("`repo_id` = ?", repo.ID).Asc("`license`").Find(&licenses); err != nil { | ||
return nil, err | ||
} | ||
return licenses, nil | ||
} | ||
|
||
// UpdateRepoLicenses updates the license statistics for repository | ||
func UpdateRepoLicenses(ctx context.Context, repo *Repository, commitID string, licenses []string) error { | ||
wxiaoguang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
oldLicenses, err := GetRepoLicenses(ctx, repo) | ||
if err != nil { | ||
return err | ||
} | ||
for _, license := range licenses { | ||
upd := false | ||
for _, o := range oldLicenses { | ||
// Update already existing license | ||
if o.License == license { | ||
if _, err := db.GetEngine(ctx).ID(o.ID).Cols("`commit_id`").Update(o); err != nil { | ||
return err | ||
} | ||
upd = true | ||
break | ||
} | ||
} | ||
// Insert new license | ||
if !upd { | ||
if err := db.Insert(ctx, &RepoLicense{ | ||
RepoID: repo.ID, | ||
CommitID: commitID, | ||
License: license, | ||
}); err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
delvh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Delete old licenses | ||
licenseToDelete := make([]int64, 0, len(oldLicenses)) | ||
for _, o := range oldLicenses { | ||
if o.CommitID != commitID { | ||
licenseToDelete = append(licenseToDelete, o.ID) | ||
} | ||
} | ||
if len(licenseToDelete) > 0 { | ||
if _, err := db.GetEngine(ctx).In("`id`", licenseToDelete).Delete(&RepoLicense{}); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// CopyLicense Copy originalRepo license information to destRepo (use for forked repo) | ||
func CopyLicense(ctx context.Context, originalRepo, destRepo *Repository) error { | ||
repoLicenses, err := GetRepoLicenses(ctx, originalRepo) | ||
if err != nil { | ||
return err | ||
} | ||
if len(repoLicenses) > 0 { | ||
newRepoLicenses := make(RepoLicenseList, 0, len(repoLicenses)) | ||
|
||
for _, rl := range repoLicenses { | ||
newRepoLicense := &RepoLicense{ | ||
RepoID: destRepo.ID, | ||
CommitID: rl.CommitID, | ||
License: rl.License, | ||
} | ||
newRepoLicenses = append(newRepoLicenses, newRepoLicense) | ||
} | ||
if err := db.Insert(ctx, &newRepoLicenses); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.